From d203e649775fb5543a3871f3c0f7df6dd4ac8577 Mon Sep 17 00:00:00 2001 From: Philip Hazel Date: Tue, 5 Sep 2006 15:34:40 +0000 Subject: Nico Erfurth's patch to refactor mime.c (quoted-printable decoding). Added a small, simple test for quoted-printable decoding. --- doc/doc-txt/ChangeLog | 5 ++- src/src/mime.c | 84 +++++++++++------------------------------ test/confs/4000 | 5 ++- test/mail/4000.userx | 40 ++++++++++++++++---- test/scripts/4000-scanning/4000 | 10 +++++ 5 files changed, 72 insertions(+), 72 deletions(-) diff --git a/doc/doc-txt/ChangeLog b/doc/doc-txt/ChangeLog index 9091f0d86..6847ff51d 100644 --- a/doc/doc-txt/ChangeLog +++ b/doc/doc-txt/ChangeLog @@ -1,4 +1,4 @@ -$Cambridge: exim/doc/doc-txt/ChangeLog,v 1.388 2006/09/05 14:14:32 ph10 Exp $ +$Cambridge: exim/doc/doc-txt/ChangeLog,v 1.389 2006/09/05 15:34:40 ph10 Exp $ Change log file for Exim from version 4.21 ------------------------------------------- @@ -31,6 +31,9 @@ PH/03 On Solaris, an unexpectedly close socket (dropped connection) can session, the daemon ignores ECONNECT errors and logs others; it now ignores EPIPE as well. +PH/04 Applied Nico Erfurth's refactoring patch to tidy up mime.c + (quoted-printable decoding). + Exim version 4.63 ----------------- diff --git a/src/src/mime.c b/src/src/mime.c index c215b7bcf..45825950f 100644 --- a/src/src/mime.c +++ b/src/src/mime.c @@ -1,4 +1,4 @@ -/* $Cambridge: exim/src/src/mime.c,v 1.14 2006/02/22 14:46:44 ph10 Exp $ */ +/* $Cambridge: exim/src/src/mime.c,v 1.15 2006/09/05 15:34:41 ph10 Exp $ */ /************************************************* * Exim - an Internet mail transport agent * @@ -41,80 +41,40 @@ void mime_set_anomaly(int level, char *text) { 0-255 - char to write */ -unsigned int mime_qp_hstr_i(uschar *cptr) { - unsigned int i, j = 0; - while (cptr && *cptr && isxdigit(*cptr)) { - i = *cptr++ - '0'; - if (9 < i) i -= 7; - j <<= 4; - j |= (i & 0x0f); - } - return(j); -} - -uschar *mime_decode_qp_char(uschar *qp_p,int *c) { - uschar hex[] = {0,0,0}; - int nan = 0; +uschar *mime_decode_qp_char(uschar *qp_p, int *c) { uschar *initial_pos = qp_p; /* advance one char */ qp_p++; - REPEAT_FIRST: - if ( (*qp_p == '\t') || (*qp_p == ' ') || (*qp_p == '\r') ) { - /* tab or whitespace may follow - just ignore it, but remember - that this is not a valid hex - encoding any more */ - nan = 1; + /* Check for two hex digits and decode them */ + if (isxdigit(*qp_p) && isxdigit(qp_p[1])) { + /* Do hex conversion */ + if (isdigit(*qp_p)) {*c = *qp_p - '0';} + else {*c = toupper(*qp_p) - 'A' + 10;}; + *c <<= 4; + if (isdigit(qp_p[1])) {*c |= qp_p[1] - '0';} + else {*c |= toupper(qp_p[1]) - 'A' + 10;}; + return qp_p + 2; + }; + + /* tab or whitespace may follow just ignore it if it precedes \n */ + while (*qp_p == '\t' || *qp_p == ' ' || *qp_p == '\r') qp_p++; - goto REPEAT_FIRST; - } - else if ( (('0' <= *qp_p) && (*qp_p <= '9')) || (('A' <= *qp_p) && (*qp_p <= 'F')) || (('a' <= *qp_p) && (*qp_p <= 'f')) ) { - /* this is a valid hex char, if nan is unset */ - if (nan) { - /* this is illegal */ - *c = -2; - return initial_pos; - } - else { - hex[0] = *qp_p; - qp_p++; - }; - } - else if (*qp_p == '\n') { - /* hit soft line break already, continue */ + + if (*qp_p == '\n') { + /* hit soft line break */ *c = -1; return qp_p; - } - else { - /* illegal char here */ - *c = -2; - return initial_pos; }; - if ( (('0' <= *qp_p) && (*qp_p <= '9')) || (('A' <= *qp_p) && (*qp_p <= 'F')) || (('a' <= *qp_p) && (*qp_p <= 'f')) ) { - if (hex[0] > 0) { - hex[1] = *qp_p; - /* do hex conversion */ - *c = mime_qp_hstr_i(hex); - qp_p++; - return qp_p; - } - else { - /* huh ? */ - *c = -2; - return initial_pos; - }; - } - else { - /* illegal char */ - *c = -2; - return initial_pos; - }; + /* illegal char here */ + *c = -2; + return initial_pos; } + uschar *mime_parse_line(uschar *buffer, uschar *data, uschar *encoding, int *num_decoded) { if (encoding == NULL) { diff --git a/test/confs/4000 b/test/confs/4000 index 1b33ff795..daf5a687e 100644 --- a/test/confs/4000 +++ b/test/confs/4000 @@ -62,7 +62,10 @@ check_mime: X-$mime_part_count-is-rfc822: $mime_is_rfc822\n\ X-$mime_part_count-decode-filename: $mime_decoded_filename\n\ X-$mime_part_count-content-size: $mime_content_size - + warn mime_regex = (?s)\ + (?=Test quoted-printable =)\ + (?=.*?Continued line with this) + add_header = X-mime-regex: matched accept diff --git a/test/mail/4000.userx b/test/mail/4000.userx index 65ac8a331..34c51ccfc 100644 --- a/test/mail/4000.userx +++ b/test/mail/4000.userx @@ -93,13 +93,13 @@ X-0-is-multipart: 1 X-0-is-coverletter: 1 X-0-is-rfc822: 0 X-0-decode-filename: TESTSUITE/spool/scan/10HmbC-0005vi-00/10HmbC-0005vi-00-00000 -X-0-content-size: 1 +X-0-content-size: 2 X-1-content-type: text/plain X-1-filename: -X-1-charset: us-ascii +X-1-charset: US-ASCII X-1-boundary: X-1-content-disposition: inline -X-1-content-transfer-encoding: +X-1-content-transfer-encoding: quoted-printable X-1-content-id: X-1-content-description: X-1-is-multipart: 0 @@ -107,11 +107,12 @@ X-1-is-coverletter: 1 X-1-is-rfc822: 0 X-1-decode-filename: TESTSUITE/spool/scan/10HmbC-0005vi-00/10HmbC-0005vi-00-00001 X-1-content-size: 1 +X-mime-regex: matched X-2-content-type: text/plain -X-2-filename: working-patch +X-2-filename: X-2-charset: us-ascii X-2-boundary: -X-2-content-disposition: attachment +X-2-content-disposition: inline X-2-content-transfer-encoding: X-2-content-id: X-2-content-description: @@ -121,11 +122,11 @@ X-2-is-rfc822: 0 X-2-decode-filename: TESTSUITE/spool/scan/10HmbC-0005vi-00/10HmbC-0005vi-00-00002 X-2-content-size: 1 X-3-content-type: text/plain -X-3-filename: +X-3-filename: working-patch X-3-charset: us-ascii X-3-boundary: -X-3-content-disposition: inline -X-3-content-transfer-encoding: 7bit +X-3-content-disposition: attachment +X-3-content-transfer-encoding: X-3-content-id: X-3-content-description: X-3-is-multipart: 0 @@ -133,8 +134,31 @@ X-3-is-coverletter: 0 X-3-is-rfc822: 0 X-3-decode-filename: TESTSUITE/spool/scan/10HmbC-0005vi-00/10HmbC-0005vi-00-00003 X-3-content-size: 1 +X-4-content-type: text/plain +X-4-filename: +X-4-charset: us-ascii +X-4-boundary: +X-4-content-disposition: inline +X-4-content-transfer-encoding: 7bit +X-4-content-id: +X-4-content-description: +X-4-is-multipart: 0 +X-4-is-coverletter: 0 +X-4-is-rfc822: 0 +X-4-decode-filename: TESTSUITE/spool/scan/10HmbC-0005vi-00/10HmbC-0005vi-00-00004 +X-4-content-size: 1 X-Router-SSint: was preserved +--T4sUOijqQbZv57TR +Content-Type: text/plain; charset=US-ASCII +Content-Transfer-Encoding: quoted-printable +Content-Disposition: inline + +Test quoted-printable =3D +Space at end of line=40 +Continued line = +with this text. + --T4sUOijqQbZv57TR Content-Type: text/plain; charset=us-ascii Content-Disposition: inline diff --git a/test/scripts/4000-scanning/4000 b/test/scripts/4000-scanning/4000 index d0f132ce5..6f66b27ae 100644 --- a/test/scripts/4000-scanning/4000 +++ b/test/scripts/4000-scanning/4000 @@ -74,6 +74,16 @@ X-BeenThere: a-list00@exim.org X-Mailman-Version: 2.1.5 Precedence: list +--T4sUOijqQbZv57TR +Content-Type: text/plain; charset=US-ASCII +Content-Transfer-Encoding: quoted-printable +Content-Disposition: inline + +Test quoted-printable =3D +Space at end of line=40 +Continued line = +with this text. + --T4sUOijqQbZv57TR Content-Type: text/plain; charset=us-ascii Content-Disposition: inline -- cgit v1.2.3