Various charset fixes

This commit is contained in:
Alexander S. Aganichev 2001-11-05 14:40:27 +00:00
parent 35e87d37d4
commit 808511750e
6 changed files with 121 additions and 67 deletions

View File

@ -12,6 +12,8 @@ ______________________________________________________________________
Notes for GoldED+ 1.1.5, /snapshot/ Notes for GoldED+ 1.1.5, /snapshot/
______________________________________________________________________ ______________________________________________________________________
- Fixed more quirks with charset.
- Fixed quotewrap in internal editor if quotestring contains a space - Fixed quotewrap in internal editor if quotestring contains a space
inside. inside.

View File

@ -415,28 +415,51 @@ void DoKludges(int mode, GMsg* msg, bool attronly) {
const char* rfc = AA->Internetrfcbody() ? "" : "\001"; const char* rfc = AA->Internetrfcbody() ? "" : "\001";
char to_buf[256];
*to_buf = NUL;
if(AA->isemail() and (*msg->ito or strchr(msg->to, '@'))) { if(AA->isemail() and (*msg->ito or strchr(msg->to, '@'))) {
INam _toname;
IAdr _toaddr;
char* ptr = *msg->ito ? msg->ito : msg->to; char* ptr = *msg->ito ? msg->ito : msg->to;
mime_header_encode(buf, ptr, msg); strxcpy(buf2, ptr, 1024);
sprintf(to_buf, "%s%sTo: %s", rfc, AA->isnewsgroup() ? "X-" : "", buf); ParseInternetAddr(buf2, _toname, _toaddr);
line = AddKludge(line, to_buf); 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; line->kludge = GKLUD_RFC;
} }
if(*msg->ifrom) { if(*msg->ifrom) {
mime_header_encode(buf2, msg->ifrom, msg); INam _fromname;
sprintf(buf, "%sFrom: %s", rfc, buf2); 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 = AddKludge(line, buf);
line->kludge = GKLUD_RFC; line->kludge = GKLUD_RFC;
} }
else if(*msg->iorig) { else if(*msg->iorig) {
mime_header_encode(buf2, msg->By(), msg); mime_header_encode(buf2, msg->By(), msg);
if(*buf2) if(*buf2) {
sprintf(buf, "%sFrom: \"%s\" <%s>", rfc, buf2, msg->iorig); char quot[2] = "\"";
else 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); sprintf(buf, "%sFrom: %s", rfc, msg->iorig);
line = AddKludge(line, buf); line = AddKludge(line, buf);
line->kludge = GKLUD_RFC; line->kludge = GKLUD_RFC;
@ -513,14 +536,12 @@ void DoKludges(int mode, GMsg* msg, bool attronly) {
line = AddKludge(line, buf); line = AddKludge(line, buf);
line->kludge = GKLUD_RFC; line->kludge = GKLUD_RFC;
if(*to_buf and AA->isnewsgroup()) {
line = AddKludge(line, to_buf);
line->kludge = GKLUD_RFC;
}
if(*msg->iorig) { if(*msg->iorig) {
mime_header_encode(buf2, msg->By(), msg); 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 = AddKludge(line, buf);
line->kludge = GKLUD_RFC; line->kludge = GKLUD_RFC;
} }
@ -541,7 +562,7 @@ void DoKludges(int mode, GMsg* msg, bool attronly) {
} }
if(AA->isnewsgroup() or AA->isemail()) { 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 = AddKludge(line, buf);
line->kludge = GKLUD_RFC; line->kludge = GKLUD_RFC;
} }

View File

@ -465,12 +465,20 @@ int EditHeaderinfo(int mode, GMsgHeaderView &view, bool doedithdr) {
strcpy(msg->to, "UUCP"); strcpy(msg->to, "UUCP");
else else
strcpy(msg->to, msg->idest); strcpy(msg->to, msg->idest);
if(*msg->realby and *msg->iorig) if(*msg->realby and *msg->iorig) {
sprintf(msg->ifrom, "\"%s\" <%s>", msg->realby, 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 else
strcpy(msg->ifrom, msg->iorig); strcpy(msg->ifrom, msg->iorig);
if(*msg->realto) if(*msg->realto) {
sprintf(msg->ito, "\"%s\" <%s>", msg->realto, msg->idest); 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 else
strcpy(msg->ito, msg->idest); strcpy(msg->ito, msg->idest);
if(msg->orig.net == 0) 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())) { if(not (CFG->internetgateexp == RFCAddress) and *msg->To() and (strpbrk(msg->iaddr, "<>()\"") == NULL) and not isuucp(msg->To())) {
Name name; Name name;
strcpy(name, msg->To()); strcpy(name, msg->To());
if(CFG->internetgateexp == ((RFCName << 2) | RFCAddress)) StripQuotes(name);
sprintf(msg->ito, "\"%s\" <%s>", StripQuotes(name), msg->iaddr); 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 else
sprintf(msg->ito, "%s (%s)", msg->iaddr, StripQuotes(name)); sprintf(msg->ito, "%s (%s)", msg->iaddr, name);
} }
else else
strcpy(msg->ito, msg->iaddr); strcpy(msg->ito, msg->iaddr);

View File

@ -558,7 +558,6 @@ static void KludgePID(GMsg* msg, const char* ptr) {
static void KludgeREPLYADDR(GMsg* msg, const char* ptr) { static void KludgeREPLYADDR(GMsg* msg, const char* ptr) {
INam name; INam name;
name[0] = NUL;
char *buf=throw_strdup(ptr); char *buf=throw_strdup(ptr);
ParseInternetAddr(buf, *msg->realby ? name : msg->realby, msg->iaddr); ParseInternetAddr(buf, *msg->realby ? name : msg->realby, msg->iaddr);
if(*name) if(*name)
@ -582,7 +581,7 @@ static void KludgeFROM(GMsg* msg, const char* ptr) {
INam _fromname; INam _fromname;
IAdr _fromaddr; IAdr _fromaddr;
char* buf = throw_strdup(ptr); 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); ParseInternetAddr(buf, _fromname, _fromaddr);
throw_free(buf); throw_free(buf);
if(*_fromaddr) if(*_fromaddr)
@ -599,7 +598,7 @@ static void KludgeTO(GMsg* msg, const char* ptr) {
INam _toname; INam _toname;
IAdr _toaddr; IAdr _toaddr;
char* buf = throw_strdup(ptr); 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); ParseInternetAddr(buf, _toname, _toaddr);
throw_free(buf); throw_free(buf);
if(*_toaddr) if(*_toaddr)
@ -616,7 +615,7 @@ static void KludgeBCC(GMsg* msg, const char* ptr) {
char* ibcc = msg->ibcc; char* ibcc = msg->ibcc;
char* buf = (char*)throw_malloc(strlen(ibcc) + strlen(ptr) + 3); char* buf = (char*)throw_malloc(strlen(ibcc) + strlen(ptr) + 3);
strcpy(stpcpy(stpcpy(buf, ibcc), *ibcc ? ", " : ""), ptr); 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); throw_free(buf);
} }
@ -651,10 +650,8 @@ static void KludgeREPLY_TO(GMsg* msg, const char* ptr) {
static void KludgeSUBJECT(GMsg* msg, const char* ptr) { static void KludgeSUBJECT(GMsg* msg, const char* ptr) {
char* buf = throw_strdup(ptr); if(not (msg->attr.frq() or msg->attr.att() or msg->attr.urq()))
if(not msg->attr.att()) strxmimecpy(msg->re, ptr, 0, sizeof(msg->re), true);
strxcpy(msg->re, buf, sizeof(msg->re));
throw_free(buf);
} }
@ -807,7 +804,7 @@ static void KludgeORGANIZATION(GMsg* msg, const char* ptr) {
static void KludgeX_FTN_TO(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)) { if(striinc("multipart", ptr)) {
const char* boundptr = striinc("boundary=", ptr); const char* boundptr = striinc("boundary=", ptr);
if(not boundptr)
boundptr = striinc("boundary=", keptr+1);
if(boundptr) { if(boundptr) {
boundptr += 9; boundptr += 9;
const char* boundend; const char* boundend;
if(*boundptr == '"') { if(*boundptr == '\"') {
boundptr++; boundptr++;
boundend = strchr(boundptr, '"'); boundend = strchr(boundptr, '\"');
} }
else { else {
boundend = strpbrk(boundptr, " \r\n"); boundend = strpbrk(boundptr, " \r\n");
@ -1867,6 +1862,7 @@ void MakeLineIndex(GMsg* msg, int margin, bool header_recode) {
bool gotmime = false; bool gotmime = false;
bool gotmultipart = false; bool gotmultipart = false;
bool inheader = false; bool inheader = false;
gstrarray boundary_set;
char boundary[100]; char boundary[100];
*buf = *qbuf = *qbuf2 = NUL; *buf = *qbuf = *qbuf2 = NUL;
@ -1976,8 +1972,14 @@ void MakeLineIndex(GMsg* msg, int margin, bool header_recode) {
if(wraps == 0) { if(wraps == 0) {
if(gotmultipart) { if(gotmultipart) {
if(*ptr == '-' and ptr[1] == '-' and strneql(ptr+2, boundary, strlen(boundary))) 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; inheader = true;
break;
}
}
else if(*ptr == '\n' or *ptr == '\r') else if(*ptr == '\n' or *ptr == '\r')
inheader = false; inheader = false;
} }
@ -2061,10 +2063,15 @@ void MakeLineIndex(GMsg* msg, int margin, bool header_recode) {
} }
else if(kludgetype == RFC_CONTENT_TYPE) { else if(kludgetype == RFC_CONTENT_TYPE) {
// Content-Type: text/plain; charset="us-ascii" // Content-Type: text/plain; charset="us-ascii"
string tmp = ptr; while(keptr and ((keptr[1] == ' ') or (keptr[1] == '\t'))) {
if(keptr and (keptr[1] == ' ')) *keptr = endchar;
tmp += keptr+1; keptr = strpbrk(keptr+1, "\r\n");
const char *mime_charset = striinc("charset=", tmp.c_str()); if(keptr) {
endchar = *keptr;
*keptr = NUL;
}
}
const char *mime_charset = striinc("charset=", ptr);
if(mime_charset != NULL) { if(mime_charset != NULL) {
if(mime_charset[8] == '\"') { if(mime_charset[8] == '\"') {
strxcpy(chsbuf, mime_charset+9, sizeof(chsbuf)); strxcpy(chsbuf, mime_charset+9, sizeof(chsbuf));
@ -2088,7 +2095,8 @@ void MakeLineIndex(GMsg* msg, int margin, bool header_recode) {
strcpy(msg->charset, chsbuf); strcpy(msg->charset, chsbuf);
gotmime = true; gotmime = true;
} }
else if(check_multipart(ptr, keptr, boundary)) { else if(check_multipart(ptr, boundary)) {
boundary_set.push_back(boundary);
gotmultipart = true; gotmultipart = true;
gotmime = true; gotmime = true;
} }
@ -2532,19 +2540,6 @@ void MakeLineIndex(GMsg* msg, int margin, bool header_recode) {
// Scan for kludge-, tear- and originlines // Scan for kludge-, tear- and originlines
ScanKludges(msg, getvalue); 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);
}
} }
} }

View File

@ -182,6 +182,34 @@ void Area::InitData() {
strcpy(adat->xlatexport, CFG->xlatexport); strcpy(adat->xlatexport, CFG->xlatexport);
strcpy(adat->xlatimport, CFG->xlatimport); 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); LoadLanguage(adat->loadlanguage);
} }
@ -212,17 +240,14 @@ void Area::RandomizeData(int mode) {
*_groupid = NUL; *_groupid = NUL;
} }
Echo _echoid; const char* found = CFG->grp.SetGrp(echoid());
strcpy(_echoid, echoid());
const char* found = CFG->grp.SetGrp(_echoid);
int curgrp = CFG->grp.currgrpno; int curgrp = CFG->grp.currgrpno;
if(*_groupid) { if(*_groupid) {
found = CFG->grp.SetGrp(_groupid); found = CFG->grp.SetGrp(_groupid);
if(found and (strieql(found, "*") or ((curgrp >= 0) and (curgrp < CFG->grp.currgrpno)))) if(found and (strieql(found, "*") or ((curgrp >= 0) and (curgrp < CFG->grp.currgrpno))))
found = NULL; found = NULL;
if(not found) if(not found)
found = CFG->grp.SetGrp(_echoid); found = CFG->grp.SetGrp(echoid());
} }
if(found) { if(found) {
@ -385,9 +410,6 @@ void Area::RandomizeData(int mode) {
GetRandomLine(buf, sizeof(buf), buf+1); GetRandomLine(buf, sizeof(buf), buf+1);
strxcpy(adat->whoto, buf, sizeof(adat->whoto)); 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<MailList>::iterator z; std::vector<MailList>::iterator z;

View File

@ -81,6 +81,7 @@ const char *get_charset(void)
strcpy(charsetbuf, "LATIN-1"); strcpy(charsetbuf, "LATIN-1");
cp = setlocale(LC_CTYPE, ""); cp = setlocale(LC_CTYPE, "");
if((cp != NULL) and ((cp = strchr(cp, '.')) != NULL)) { if((cp != NULL) and ((cp = strchr(cp, '.')) != NULL)) {
cp++;
if(strieql(cp, "KOI8R") or strieql(cp, "KOI8")) if(strieql(cp, "KOI8R") or strieql(cp, "KOI8"))
cp = "KOI8-R"; cp = "KOI8-R";
if(strieql(cp, "KOI8U")) if(strieql(cp, "KOI8U"))