From 808511750e662af9e48c48b077071b0a3dac9f0d Mon Sep 17 00:00:00 2001 From: "Alexander S. Aganichev" Date: Mon, 5 Nov 2001 14:40:27 +0000 Subject: [PATCH] Various charset fixes --- docs/notework.txt | 2 ++ golded3/gectrl.cpp | 57 ++++++++++++++++++++++++----------- golded3/gehdre.cpp | 27 ++++++++++++----- golded3/geline.cpp | 63 ++++++++++++++++++--------------------- golded3/gerand.cpp | 38 ++++++++++++++++++----- goldlib/gall/gcharset.cpp | 1 + 6 files changed, 121 insertions(+), 67 deletions(-) diff --git a/docs/notework.txt b/docs/notework.txt index 5b11321..5276581 100644 --- a/docs/notework.txt +++ b/docs/notework.txt @@ -12,6 +12,8 @@ ______________________________________________________________________ Notes for GoldED+ 1.1.5, /snapshot/ ______________________________________________________________________ +- Fixed more quirks with charset. + - Fixed quotewrap in internal editor if quotestring contains a space inside. diff --git a/golded3/gectrl.cpp b/golded3/gectrl.cpp index a7c4028..e6c3f36 100644 --- a/golded3/gectrl.cpp +++ b/golded3/gectrl.cpp @@ -415,28 +415,51 @@ void DoKludges(int mode, GMsg* msg, bool attronly) { const char* rfc = AA->Internetrfcbody() ? "" : "\001"; - char to_buf[256]; - *to_buf = NUL; - if(AA->isemail() and (*msg->ito or strchr(msg->to, '@'))) { + INam _toname; + IAdr _toaddr; char* ptr = *msg->ito ? msg->ito : msg->to; - mime_header_encode(buf, ptr, msg); - sprintf(to_buf, "%s%sTo: %s", rfc, AA->isnewsgroup() ? "X-" : "", buf); - line = AddKludge(line, to_buf); + strxcpy(buf2, ptr, 1024); + ParseInternetAddr(buf2, _toname, _toaddr); + if(_toname[0] != NUL) { + mime_header_encode(buf2, _toname, msg); + char quot[2] = "\""; + if((buf2[0] == '\"') or (strpbrk(buf2, " \t") == NULL)) + quot[0] = NUL; + sprintf(buf, "%s%sTo: %s%s%s <%s>", rfc, AA->isnewsgroup() ? "X-" : "", quot, buf2, quot, _toaddr); + } + else + sprintf(buf, "%s%sTo: %s", rfc, AA->isnewsgroup() ? "X-" : "", ptr); + line = AddKludge(line, buf); line->kludge = GKLUD_RFC; } if(*msg->ifrom) { - mime_header_encode(buf2, msg->ifrom, msg); - sprintf(buf, "%sFrom: %s", rfc, buf2); + INam _fromname; + IAdr _fromaddr; + + strcpy(buf2, msg->ifrom); + ParseInternetAddr(buf2, _fromname, _fromaddr); + if(_fromname[0] != NUL) { + mime_header_encode(buf2, _fromname, msg); + char quot[2] = "\""; + if((buf2[0] == '\"') or (strpbrk(buf2, " \t") == NULL)) + quot[0] = NUL; + sprintf(buf, "%sFrom: %s%s%s <%s>", rfc, quot, buf2, quot, _fromaddr); + } + else + sprintf(buf, "%sFrom: %s", rfc, msg->ifrom); line = AddKludge(line, buf); line->kludge = GKLUD_RFC; } else if(*msg->iorig) { mime_header_encode(buf2, msg->By(), msg); - if(*buf2) - sprintf(buf, "%sFrom: \"%s\" <%s>", rfc, buf2, msg->iorig); - else + if(*buf2) { + char quot[2] = "\""; + if((buf2[0] == '\"') or (strpbrk(buf2, " \t") == NULL)) + quot[0] = NUL; + sprintf(buf, "%sFrom: %s%s%s <%s>", rfc, quot, buf2, quot, msg->iorig); + } else sprintf(buf, "%sFrom: %s", rfc, msg->iorig); line = AddKludge(line, buf); line->kludge = GKLUD_RFC; @@ -513,14 +536,12 @@ void DoKludges(int mode, GMsg* msg, bool attronly) { line = AddKludge(line, buf); line->kludge = GKLUD_RFC; - if(*to_buf and AA->isnewsgroup()) { - line = AddKludge(line, to_buf); - line->kludge = GKLUD_RFC; - } - if(*msg->iorig) { mime_header_encode(buf2, msg->By(), msg); - sprintf(buf, "%sSender: \"%s\" <%s>", rfc, buf2, msg->iorig); + char quot[2] = "\""; + if((buf2[0] == '\"') or (strpbrk(buf2, " \t") == NULL)) + quot[0] = NUL; + sprintf(buf, "%sSender: %s%s%s <%s>", rfc, quot, buf2, quot, msg->iorig); line = AddKludge(line, buf); line->kludge = GKLUD_RFC; } @@ -541,7 +562,7 @@ void DoKludges(int mode, GMsg* msg, bool attronly) { } if(AA->isnewsgroup() or AA->isemail()) { - sprintf(buf, "%sX-%s: %s", rfc, AA->isnewsgroup() ? "Newsreader" : "Mailer", get_informative_string()); + sprintf(buf, "%sX-%s: %s", rfc, AA->isnewsgroup() ? "Newsreader" : "Mailreader", get_informative_string()); line = AddKludge(line, buf); line->kludge = GKLUD_RFC; } diff --git a/golded3/gehdre.cpp b/golded3/gehdre.cpp index 66c729e..483c870 100644 --- a/golded3/gehdre.cpp +++ b/golded3/gehdre.cpp @@ -465,12 +465,20 @@ int EditHeaderinfo(int mode, GMsgHeaderView &view, bool doedithdr) { strcpy(msg->to, "UUCP"); else strcpy(msg->to, msg->idest); - if(*msg->realby and *msg->iorig) - sprintf(msg->ifrom, "\"%s\" <%s>", msg->realby, msg->iorig); + if(*msg->realby and *msg->iorig) { + char quot[2] = "\""; + if((msg->realby[0] == '\"') or (strpbrk(msg->realby, " \t") == NULL)) + quot[0] = NUL; + sprintf(msg->ifrom, "%s%s%s <%s>", quot, msg->realby, quot, msg->iorig); + } else strcpy(msg->ifrom, msg->iorig); - if(*msg->realto) - sprintf(msg->ito, "\"%s\" <%s>", msg->realto, msg->idest); + if(*msg->realto) { + char quot[2] = "\""; + if((msg->realto[0] == '\"') or (strpbrk(msg->realto, " \t") == NULL)) + quot[0] = NUL; + sprintf(msg->ito, "%s%s%s <%s>", quot, msg->realto, quot, msg->idest); + } else strcpy(msg->ito, msg->idest); if(msg->orig.net == 0) @@ -502,10 +510,15 @@ int EditHeaderinfo(int mode, GMsgHeaderView &view, bool doedithdr) { if(not (CFG->internetgateexp == RFCAddress) and *msg->To() and (strpbrk(msg->iaddr, "<>()\"") == NULL) and not isuucp(msg->To())) { Name name; strcpy(name, msg->To()); - if(CFG->internetgateexp == ((RFCName << 2) | RFCAddress)) - sprintf(msg->ito, "\"%s\" <%s>", StripQuotes(name), msg->iaddr); + StripQuotes(name); + if(CFG->internetgateexp == ((RFCName << 2) | RFCAddress)) { + char quot[2] = "\""; + if((name[0] == '\"') or (strpbrk(name, " \t") == NULL)) + quot[0] = NUL; + sprintf(msg->ito, "%s%s%s <%s>", quot, name, quot, msg->iaddr); + } else - sprintf(msg->ito, "%s (%s)", msg->iaddr, StripQuotes(name)); + sprintf(msg->ito, "%s (%s)", msg->iaddr, name); } else strcpy(msg->ito, msg->iaddr); diff --git a/golded3/geline.cpp b/golded3/geline.cpp index 9352726..582f12b 100644 --- a/golded3/geline.cpp +++ b/golded3/geline.cpp @@ -558,7 +558,6 @@ static void KludgePID(GMsg* msg, const char* ptr) { static void KludgeREPLYADDR(GMsg* msg, const char* ptr) { INam name; - name[0] = NUL; char *buf=throw_strdup(ptr); ParseInternetAddr(buf, *msg->realby ? name : msg->realby, msg->iaddr); if(*name) @@ -582,7 +581,7 @@ static void KludgeFROM(GMsg* msg, const char* ptr) { INam _fromname; IAdr _fromaddr; char* buf = throw_strdup(ptr); - strxcpy(msg->ifrom, buf, sizeof(msg->ifrom)); + strxmimecpy(msg->ifrom, buf, 0, sizeof(msg->ifrom), true); ParseInternetAddr(buf, _fromname, _fromaddr); throw_free(buf); if(*_fromaddr) @@ -599,7 +598,7 @@ static void KludgeTO(GMsg* msg, const char* ptr) { INam _toname; IAdr _toaddr; char* buf = throw_strdup(ptr); - strxcpy(msg->ito, buf, sizeof(msg->ito)); + strxmimecpy(msg->ito, buf, 0, sizeof(msg->ito), true); ParseInternetAddr(buf, _toname, _toaddr); throw_free(buf); if(*_toaddr) @@ -616,7 +615,7 @@ static void KludgeBCC(GMsg* msg, const char* ptr) { char* ibcc = msg->ibcc; char* buf = (char*)throw_malloc(strlen(ibcc) + strlen(ptr) + 3); strcpy(stpcpy(stpcpy(buf, ibcc), *ibcc ? ", " : ""), ptr); - strxcpy(ibcc, buf, sizeof(msg->ibcc)); + strxmimecpy(msg->ibcc, buf, 0, sizeof(msg->ibcc), true); throw_free(buf); } @@ -651,10 +650,8 @@ static void KludgeREPLY_TO(GMsg* msg, const char* ptr) { static void KludgeSUBJECT(GMsg* msg, const char* ptr) { - char* buf = throw_strdup(ptr); - if(not msg->attr.att()) - strxcpy(msg->re, buf, sizeof(msg->re)); - throw_free(buf); + if(not (msg->attr.frq() or msg->attr.att() or msg->attr.urq())) + strxmimecpy(msg->re, ptr, 0, sizeof(msg->re), true); } @@ -807,7 +804,7 @@ static void KludgeORGANIZATION(GMsg* msg, const char* ptr) { static void KludgeX_FTN_TO(GMsg* msg, const char* ptr) { - strxcpy(msg->realto, ptr, sizeof(msg->realto)); + strxmimecpy(msg->realto, ptr, 0, sizeof(msg->realto), true); } @@ -1793,18 +1790,16 @@ void GMsg::TextToLines(int __line_width, bool header_recode) { // ------------------------------------------------------------------ -bool check_multipart(const char* ptr, const char* keptr, char* boundary) { +static bool check_multipart(const char* ptr, char* boundary) { if(striinc("multipart", ptr)) { const char* boundptr = striinc("boundary=", ptr); - if(not boundptr) - boundptr = striinc("boundary=", keptr+1); if(boundptr) { boundptr += 9; const char* boundend; - if(*boundptr == '"') { + if(*boundptr == '\"') { boundptr++; - boundend = strchr(boundptr, '"'); + boundend = strchr(boundptr, '\"'); } else { boundend = strpbrk(boundptr, " \r\n"); @@ -1867,6 +1862,7 @@ void MakeLineIndex(GMsg* msg, int margin, bool header_recode) { bool gotmime = false; bool gotmultipart = false; bool inheader = false; + gstrarray boundary_set; char boundary[100]; *buf = *qbuf = *qbuf2 = NUL; @@ -1976,8 +1972,14 @@ void MakeLineIndex(GMsg* msg, int margin, bool header_recode) { if(wraps == 0) { if(gotmultipart) { - if(*ptr == '-' and ptr[1] == '-' and strneql(ptr+2, boundary, strlen(boundary))) - inheader = true; + if(*ptr == '-' and ptr[1] == '-') { + gstrarray::iterator ib; + for(ib = boundary_set.begin(); ib != boundary_set.end(); ib++) + if(strneql(ptr+2, (*ib).c_str(), (*ib).length())) { + inheader = true; + break; + } + } else if(*ptr == '\n' or *ptr == '\r') inheader = false; } @@ -2061,10 +2063,15 @@ void MakeLineIndex(GMsg* msg, int margin, bool header_recode) { } else if(kludgetype == RFC_CONTENT_TYPE) { // Content-Type: text/plain; charset="us-ascii" - string tmp = ptr; - if(keptr and (keptr[1] == ' ')) - tmp += keptr+1; - const char *mime_charset = striinc("charset=", tmp.c_str()); + while(keptr and ((keptr[1] == ' ') or (keptr[1] == '\t'))) { + *keptr = endchar; + keptr = strpbrk(keptr+1, "\r\n"); + if(keptr) { + endchar = *keptr; + *keptr = NUL; + } + } + const char *mime_charset = striinc("charset=", ptr); if(mime_charset != NULL) { if(mime_charset[8] == '\"') { strxcpy(chsbuf, mime_charset+9, sizeof(chsbuf)); @@ -2088,7 +2095,8 @@ void MakeLineIndex(GMsg* msg, int margin, bool header_recode) { strcpy(msg->charset, chsbuf); gotmime = true; } - else if(check_multipart(ptr, keptr, boundary)) { + else if(check_multipart(ptr, boundary)) { + boundary_set.push_back(boundary); gotmultipart = true; gotmime = true; } @@ -2532,19 +2540,6 @@ void MakeLineIndex(GMsg* msg, int margin, bool header_recode) { // Scan for kludge-, tear- and originlines ScanKludges(msg, getvalue); - - // Charset translate header fields - if(header_recode) { - strxmimecpy(msg->realby, msg->realby, 0, sizeof(INam), true); - strxmimecpy(msg->realto, msg->realto, 0, sizeof(INam), true); - strxmimecpy(msg->ifrom, msg->ifrom, 0, sizeof(INam), true); - strxmimecpy(msg->ito, msg->ito, 0, sizeof(msg->ito), true); - - strxmimecpy(msg->by, msg->by, 0, sizeof(INam), true); - strxmimecpy(msg->to, msg->to, 0, sizeof(INam), true); - if(not (msg->attr.frq() or msg->attr.att() or msg->attr.urq())) - strxmimecpy(msg->re, msg->re, 0, sizeof(ISub), true); - } } } diff --git a/golded3/gerand.cpp b/golded3/gerand.cpp index ddf2f80..a8eb0ce 100644 --- a/golded3/gerand.cpp +++ b/golded3/gerand.cpp @@ -182,6 +182,34 @@ void Area::InitData() { strcpy(adat->xlatexport, CFG->xlatexport); strcpy(adat->xlatimport, CFG->xlatimport); + char _groupid[10]; + if(CFG->areafilegroups and groupid()) { + if(groupid() & 0x8000u) + sprintf(_groupid, "#%u", groupid() & 0x7FFF); + else { + _groupid[0] = (char)(isalpha(groupid()) ? groupid() : NUL); + _groupid[1] = NUL; + } + } + else { + *_groupid = NUL; + } + + const char* found = CFG->grp.SetGrp(echoid()); + int curgrp = CFG->grp.currgrpno; + if(*_groupid) { + found = CFG->grp.SetGrp(_groupid); + if(found and (strieql(found, "*") or ((curgrp >= 0) and (curgrp < CFG->grp.currgrpno)))) + found = NULL; + if(not found) + found = CFG->grp.SetGrp(echoid()); + } + + if(found) { + CFG->grp.GetItm(GRP_XLATEXPORT, adat->xlatexport, sizeof(adat->xlatexport)); + CFG->grp.GetItm(GRP_XLATIMPORT, adat->xlatimport, sizeof(adat->xlatimport)); + } + LoadLanguage(adat->loadlanguage); } @@ -212,17 +240,14 @@ void Area::RandomizeData(int mode) { *_groupid = NUL; } - Echo _echoid; - strcpy(_echoid, echoid()); - - const char* found = CFG->grp.SetGrp(_echoid); + const char* found = CFG->grp.SetGrp(echoid()); int curgrp = CFG->grp.currgrpno; if(*_groupid) { found = CFG->grp.SetGrp(_groupid); if(found and (strieql(found, "*") or ((curgrp >= 0) and (curgrp < CFG->grp.currgrpno)))) found = NULL; if(not found) - found = CFG->grp.SetGrp(_echoid); + found = CFG->grp.SetGrp(echoid()); } if(found) { @@ -385,9 +410,6 @@ void Area::RandomizeData(int mode) { GetRandomLine(buf, sizeof(buf), buf+1); strxcpy(adat->whoto, buf, sizeof(adat->whoto)); } - - CFG->grp.GetItm(GRP_XLATEXPORT, adat->xlatexport, sizeof(adat->xlatexport)); - CFG->grp.GetItm(GRP_XLATIMPORT, adat->xlatimport, sizeof(adat->xlatimport)); } std::vector::iterator z; diff --git a/goldlib/gall/gcharset.cpp b/goldlib/gall/gcharset.cpp index 2d91fa9..c66746a 100644 --- a/goldlib/gall/gcharset.cpp +++ b/goldlib/gall/gcharset.cpp @@ -81,6 +81,7 @@ const char *get_charset(void) strcpy(charsetbuf, "LATIN-1"); cp = setlocale(LC_CTYPE, ""); if((cp != NULL) and ((cp = strchr(cp, '.')) != NULL)) { + cp++; if(strieql(cp, "KOI8R") or strieql(cp, "KOI8")) cp = "KOI8-R"; if(strieql(cp, "KOI8U"))