[prev in list] [next in list] [prev in thread] [next in thread]
List: listar-dev
Subject: [EDev] another base64 patch
From: Sergey Stremin <stem () bcosm ! ru>
Date: 2002-11-22 13:51:01
[Download RAW message or body]
Symptom: Ecartis eats 'Content-Transfer-Encoding: base64' in plain
text messages when 'humanize-qp' or 'humanize-mime' is set and doesn't
decode the body of the message.
With this patch 'humanize-qp' will not change message unless it's
quoted-printable and 'humanize-mime' will correctly decode message
body for plain/text and multipart/alternative messages.
What this patch changes:
1) unquote() in unmime.c: any Content-Transfer-Encoding not equal to
'quoted-printable' passes unchanged
2) mimehandle_multiple: decoding 'base64' and 'quoted-printable' is
delegated to mimehandle_text
3) mimehandle_text: decode 'base64' and 'quoted-printable'
Patch (against current CVS or snapshot)
=========================
--- ecartis.old/src/unmime.c Sat Sep 14 20:49:34 2002
+++ ecartis/src/unmime.c Fri Nov 22 17:06:08 2002
@@ -483,70 +483,20 @@
outfile = open_file(subfilename,"w");
- temp = mime_fieldval(subheader,"content-transfer-encoding");
-
- if (temp) {
- if (strcasecmp(temp,"base64") == 0) coding = 1; else
- if (strcasecmp(temp,"quoted-printable") == 0) coding = 2;
- else coding = 0;
- }
-
haveread = 0;
- switch(coding) {
- case 0:
- while(read_file(templine, sizeof(templine), infile) && !donechunk) \
{
- if (strlen(templine) > 3 ?
- (strncmp(&templine[2],bound,strlen(bound)) == 0)
- : 0) {
- donechunk = 1;
- } else write_file(outfile,"%s",templine);
- haveread = 1;
- }
- close_file(outfile);
- handler->handler(subheader,subfilename);
- havewritten = 1;
- break;
- case 1:
- {
- char **boundaries;
- int boundcount;
- char tbuf[BIG_BUF];
-
- boundaries = (char **)malloc(2 * sizeof(char *));
- buffer_printf(tbuf, sizeof(tbuf) - 1, "--%s", bound);
- boundaries[0] = &tbuf[0];
- boundcount = 1;
-
- from64(infile,outfile,boundaries,&boundcount);
- close_file(outfile);
- handler->handler(subheader,subfilename);
- loop2 = 0;
- havewritten = 1;
- }
- break;
- case 2:
- {
- char **boundaries;
- int boundcount;
- char tbuf[BIG_BUF];
-
- boundaries = (char **)malloc(2 * sizeof(char *));
- buffer_printf(tbuf, sizeof(tbuf) - 1, "--%s", bound);
- boundaries[0] = &tbuf[0];
- boundcount = 1;
-
- fromqp(infile,outfile,boundaries,&boundcount);
- close_file(outfile);
- handler->handler(subheader,subfilename);
- havewritten = 1;
- loop2 = 0;
- }
- break;
- case 3:
- close_file(outfile);
- break;
+ /* Write message to outfile, handler will take care of \
Content-Transfer-Encoding */ + while(read_file(templine, sizeof(templine), \
infile) && !donechunk) { + if (strlen(templine) > 3 ?
+ (strncmp(&templine[2],bound,strlen(bound)) == 0)
+ : 0) {
+ donechunk = 1;
+ } else write_file(outfile,"%s",templine);
+ haveread = 1;
}
+ close_file(outfile);
+ handler->handler(subheader,subfilename);
+ havewritten = 1;
if (havewritten) {
FILE *infile2;
@@ -598,6 +548,7 @@
FILE *tempfile, *infile;
char tempfilename[BIG_BUF], tempbuf[BIG_BUF];
const char *temp;
+ int coding;
buffer_printf(tempfilename, sizeof(tempfilename) - 1, "%s.altertext", mimefile);
if ((infile = open_file(mimefile,"r")) == NULL) {
@@ -624,9 +575,29 @@
write_file(tempfile,"\n");
} else clean_var("unmime-first-level", VAR_TEMP);
- while(read_file(tempbuf, sizeof(tempbuf), infile)) {
- write_file(tempfile,"%s",tempbuf);
+ /* Decode Content-Transfer-Encodning here (quoted-printable and base64) */
+ temp = mime_fieldval(header,"content-transfer-encoding");
+
+ if (temp) {
+ if (strcasecmp(temp,"base64") == 0) coding = 1; else
+ if (strcasecmp(temp,"quoted-printable") == 0) coding = 2;
+ else coding = 0;
+ }
+
+ switch(coding) {
+ case 0:
+ while(read_file(tempbuf, sizeof(tempbuf), infile)) {
+ write_file(tempfile,"%s",tempbuf);
+ }
+ break;
+ case 1:
+ from64(infile,tempfile,NULL,NULL);
+ break;
+ case 2:
+ fromqp(infile,tempfile,NULL,NULL);
+ break;
}
+
close_file(infile);
close_file(tempfile);
@@ -986,6 +957,9 @@
write_file(outfile,"X-MIME-Autoconverted: from quoted-printable to 8bit \
by %s\n", SERVICE_NAME_MC); fromqp(infile, outfile, NULL, NULL);
done = 1;
+ } else {
+ /* otherwise leave Content-Transfer-Encoding unchanged */
+ write_file(outfile, "%s", tbuf);
}
}
else if (strncasecmp(tbuf,"Content-type:",13) == 0) {
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic