Encoding fixes, Win95 kbd fix, boundary checking added

This commit is contained in:
Alexander S. Aganichev
2000-12-20 19:53:25 +00:00
parent 420527ccfe
commit fe6812d9a6
8 changed files with 87 additions and 73 deletions

View File

@@ -2016,79 +2016,81 @@ void MakeLineIndex(GMsg* msg, int margin, bool header_recode) {
}
if(kludgetype == FSC_I51) {
msg->i51 = true;
if(getvalue) {
// Convert FSC-0051.003 to FSC-0054.003
strcpy(chsbuf, "LATIN-1");
chslev = LoadCharset(chsbuf, CFG->xlatlocalset);
if(chslev) {
level = msg->charsetlevel = chslev;
strcpy(msg->charset, chsbuf);
}
// Convert FSC-0051.003 to FSC-0054.003
strcpy(chsbuf, "LATIN-1");
chslev = LoadCharset(chsbuf, CFG->xlatlocalset);
if(chslev) {
level = msg->charsetlevel = chslev;
strcpy(msg->charset, chsbuf);
}
}
else if(kludgetype == FSC_CHARSET) {
if(getvalue) {
*chsbuf = NUL;
qpencoded = striinc("LATIN1QP", ptr) ? true : false;
strxcpy(chsbuf, qpencoded ? "LATIN-1" : ptr, sizeof(chsbuf));
// Workaround for buggy mailreaders which stores '_' in charset name
strchg(chsbuf,'_',' ');
*chsbuf = NUL;
qpencoded = striinc("LATIN1QP", ptr) ? true : false;
strxcpy(chsbuf, qpencoded ? "LATIN-1" : ptr, sizeof(chsbuf));
// Workaround for buggy mailreaders which stores '_' in charset name
strchg(chsbuf,'_',' ');
chslev = LoadCharset(chsbuf, CFG->xlatlocalset);
if(chslev) {
level = msg->charsetlevel = chslev;
strcpy(msg->charset, chsbuf);
}
if(*msg->charset == NUL)
strcpy(msg->charset, chsbuf);
}
else if(kludgetype == RFC_CONTENT_TYPE) {
// Content-Type: text/plain; charset="us-ascii"
const char *mime_charset = striinc("charset=", ptr);
if(mime_charset != NULL) {
if(mime_charset[8] == '\"') {
strxcpy(chsbuf, mime_charset+9, sizeof(chsbuf));
char *quote = strchr(chsbuf, '\"');
if(quote != NULL) *quote = NUL;
}
else
strxcpy(chsbuf, strrword(mime_charset+8), sizeof(chsbuf));
chslev = LoadCharset(chsbuf, CFG->xlatlocalset);
if(chslev) {
level = msg->charsetlevel = chslev;
strcpy(msg->charset, chsbuf);
}
if(*msg->charset == NUL)
strcpy(msg->charset, chsbuf);
gotmime = true;
}
}
else if(kludgetype == RFC_CONTENT_TYPE) {
if(getvalue) {
if(striinc("iso-8859-1", ptr)) {
strcpy(chsbuf, "LATIN-1");
chslev = LoadCharset(chsbuf, CFG->xlatlocalset);
if(chslev) {
level = msg->charsetlevel = chslev;
strcpy(msg->charset, chsbuf);
}
gotmime = true;
}
if(check_multipart(ptr, keptr, boundary)) {
gotmultipart = true;
gotmime = true;
}
if(check_multipart(ptr, keptr, boundary)) {
gotmultipart = true;
gotmime = true;
}
}
else if(kludgetype == RFC_CONTENT_TRANSFER_ENCODING) {
if(getvalue) {
if(striinc("quoted-printable", ptr)) {
qpencoded = true;
msg->charsetencoding |= GCHENC_QP;
if(striinc("LATIN-1", msg->charset)) {
strcpy(chsbuf, "LATIN1QP");
chslev = LoadCharset("LATIN-1", CFG->xlatlocalset);
if(chslev) {
level = msg->charsetlevel = chslev;
strcpy(msg->charset, chsbuf);
}
if(striinc("quoted-printable", ptr)) {
qpencoded = true;
msg->charsetencoding |= GCHENC_QP;
// ASA: What the stuff below for? I never saw such messages...
if(striinc("LATIN-1", msg->charset)) {
strcpy(chsbuf, "LATIN1QP");
chslev = LoadCharset("LATIN-1", CFG->xlatlocalset);
if(chslev) {
level = msg->charsetlevel = chslev;
strcpy(msg->charset, chsbuf);
}
}
}
}
else if(kludgetype == RFC_X_CHARSET) {
if(getvalue) {
if(not gotmime) {
strcpy(chsbuf, (striinc("8859-1", ptr) or striinc("Latin1", ptr)) ? "LATIN-1" : CFG->xlatlocalset);
chslev = LoadCharset(chsbuf, CFG->xlatlocalset);
if(chslev) {
level = msg->charsetlevel = chslev;
strcpy(msg->charset, chsbuf);
}
if(not gotmime) {
strcpy(chsbuf, (striinc("8859-1", ptr) or striinc("Latin1", ptr)) ? "LATIN-1" : ptr);
chslev = LoadCharset(chsbuf, CFG->xlatlocalset);
if(chslev) {
level = msg->charsetlevel = chslev;
strcpy(msg->charset, chsbuf);
}
}
}
else if(kludgetype == RFC_X_CHAR_ESC) {
if(getvalue)
if(not gotmime)
msg->charsetencoding |= GCHENC_MNE;
if(not gotmime)
msg->charsetencoding |= GCHENC_MNE;
}
if(keptr)
*keptr = endchar;
@@ -2535,10 +2537,10 @@ void MakeLineIndex(GMsg* msg, int margin, bool header_recode) {
// Charset translate header fields
if(header_recode) {
strxmimecpy(msg->realby, msg->realby, 0, sizeof(INam));
strxmimecpy(msg->realto, msg->realto, 0, sizeof(INam));
strxmimecpy(msg->by, msg->by, level, sizeof(INam));
strxmimecpy(msg->to, msg->to, level, sizeof(INam));
strxmimecpy(msg->realby, msg->realby, 0, sizeof(INam), true);
strxmimecpy(msg->realto, msg->realto, 0, sizeof(INam), true);
strxmimecpy(msg->by, msg->by, level, sizeof(INam), true);
strxmimecpy(msg->to, msg->to, level, sizeof(INam), true);
if(not (msg->attr.frq() or msg->attr.att() or msg->attr.urq()))
strxmimecpy(msg->re, msg->re, level, sizeof(ISub), true);

View File

@@ -65,10 +65,10 @@ int Area::LoadHdr(GMsg* msg, ulong msgno, bool enable_recode) {
msg->charsetlevel = LoadCharset(CFG->xlatcharset[table].imp, CFG->xlatcharset[table].exp);
// Charset translate header fields
strxmimecpy(msg->realby, msg->realby, msg->charsetlevel, sizeof(INam));
strxmimecpy(msg->realto, msg->realto, msg->charsetlevel, sizeof(INam));
strxmimecpy(msg->by , msg->by , msg->charsetlevel, sizeof(INam));
strxmimecpy(msg->to , msg->to , msg->charsetlevel, sizeof(INam));
strxmimecpy(msg->realby, msg->realby, msg->charsetlevel, sizeof(INam), true);
strxmimecpy(msg->realto, msg->realto, msg->charsetlevel, sizeof(INam), true);
strxmimecpy(msg->by , msg->by , msg->charsetlevel, sizeof(INam), true);
strxmimecpy(msg->to , msg->to , msg->charsetlevel, sizeof(INam), true);
if(not (msg->attr.frq() or msg->attr.att() or msg->attr.urq()))
strxmimecpy(msg->re , msg->re , msg->charsetlevel, sizeof(ISub), true);

View File

@@ -38,6 +38,8 @@ char* GetRandomLine(char* __buf, size_t __bufsize, const char* __file) {
FILE* fp = fsopen(AddPath(CFG->goldpath, __file), "rb", CFG->sharemode);
if(fp) {
setvbuf(fp, NULL, _IOFBF, 32000);
// Check if index exists or if it is older than the textfile
const char* idxfile = AddPath(CFG->goldpath, indexfile);
int idxexist = fexist(idxfile);
@@ -47,9 +49,8 @@ char* GetRandomLine(char* __buf, size_t __bufsize, const char* __file) {
// Create index if one was missing
if(not idxexist) {
FILE* fpi = fsopen(idxfile, "wb+", CFG->sharemode);
FILE* fpi = fsopen(idxfile, "wb", CFG->sharemode);
if(fpi) {
setvbuf(fp, NULL, _IOFBF, 32000);
setvbuf(fpi, NULL, _IOFBF, 16000);
long fpos = 0;
char buf[512];
@@ -64,6 +65,8 @@ char* GetRandomLine(char* __buf, size_t __bufsize, const char* __file) {
FILE* fpi = fsopen(idxfile, "rb", CFG->sharemode);
if(fpi) {
setvbuf(fpi, NULL, _IOFBF, 16000);
// Get random line if there is at least one
int _lines = (int)(fsize(fpi)/sizeof(long));
if(_lines > 0) {