Thread View: news.software.readers
1 messages
1 total messages
Started by Rev. Bob 'Bob' Crispen
Thu, 11 May 2000 00:00
Xnews wish: alt char sets in subjects and senders
Author: Rev. Bob 'Bob' Crispen
Date: Thu, 11 May 2000 00:00
Date: Thu, 11 May 2000 00:00
130 lines
4400 bytes
4400 bytes
I sure wish I didn't see "=?ISO-xxxx" in all those subject lines and
sender names. And a good percentage of the time, those characters
decode to something pretty readable.
Here's how I'm doing it on a newsreader I'm working on. Btw, my
newsreader is really crummy, and I'm not even going to give you the URL
for it, but it does international character sets sort of right.
Three notes:
(a) strnicmp is an ignore-case strncmp(). It may be called
strncmpi() or something else on your system.
(b) I have a really ugly b64decode which is called either with a FILE*
or a char*, and it checks to see which is null. Yuck. Otherwise, it's
Jorgen Hagg's routine pretty much verbatim -- I did get his permission,
but I wasn't brave enough to show him that awful thing I did to it.
(c) Just to prove I'm an old geezer, I still use bzero. On systems that
don't have it I define:
#define bzero(x,y) memset((x),0,(y))
Here's the function. Use it if you like, free (about what it's worth):
/*
* Catch and convert any alternate character sets
* XXX - we assume that Windows can print the character.
*/
void convert_alt_char_set(char* in, char* out)
{
int i, j, k, n;
char szWork[BUFSIZE];
char szWork2[BUFSIZE];
char* sp;
char* sp2;
j = 0;
// Get out quickly if we can
sp = strstr(in, "=?");
if (sp == NULL) {
strcpy(out, in);
return;
}
// We can output verbatim everything up to the questionable string
for (sp2=in; sp2<sp; sp2++)
out[j++] = *sp2;
// Make a copy of the questionable part
bzero(szWork, BUFSIZE);
strcpy(szWork, sp);
// Check for the designators we've been able to find so far
if (!strnicmp(szWork, "=?iso-8859-1", 12)) {
i = 12;
} else if (!strnicmp(szWork, "=?iso-2022-", 11)) {
i = 13; // Country code is 2 characters long
} else if (!strnicmp(szWork, "=?koi8-r", 8)) {
i = 8;
} else {
// Beats me -- just copy it out and quit
strcpy(out, in);
return;
}
k = 0;
// Quoted printable?
if (!(strnicmp(&szWork[i], "?q?", 3))) {
// Discard the designator
for (i+=3; i<BUFSIZE; i++)
szWork[k++] = szWork[i];
for (i=0; szWork[i] != '\0'; i++) {
if ((szWork[i] == '?') && (szWork[i+1] == '='))
break;
if (szWork[i] == '=') {
// XXX - assume the string is correct
(void)sscanf(&szWork[i+1], "%x", &n);
out[j++] = n;
i += 2;
} else {
out[j++] = szWork[i];
}
}
k=0;
// Let's clean up again, just so we can debug this darn thing
for (i+=2; i<BUFSIZE; i++)
szWork[k++] = szWork[i];
if (szWork[0] != '\0')
// There might be yet another ISO string. Let's try again.
convert_alt_char_set(szWork, &out[j]);
// Binary (base64 encoded?)
} else if (!(strnicmp(&szWork[i], "?b?", 3))) {
// Discard the designator
for (i+=3; i<BUFSIZE; i++)
szWork[k++] = szWork[i];
// Now copy just the first encoded string to the buffer
bzero(szWork2, BUFSIZE);
for (i=0; szWork[i] != '\0'; i++) {
if ((szWork[i] == '?') && (szWork[i+1] == '='))
break;
szWork2[i] = szWork[i];
}
k = 0;
j+= b64decode(szWork2, (FILE*)NULL, &out[j]);
for (i+=2; i<BUFSIZE; i++)
szWork[k++] = szWork[i];
if (szWork[0] != '\0')
// There might be yet another ISO string. Let's try again.
convert_alt_char_set(szWork, &out[j]);
// Beats me what this string is, just copy it out
} else {
strcpy(out, in);
}
}
--
Rev. Bob "Bob" Crispen
crispen at hiwaay dot net
How long is this Beta guy going to keep testing our stuff?
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads