Nico Erfurth's patch to refactor mime.c (quoted-printable decoding).
authorPhilip Hazel <ph10@hermes.cam.ac.uk>
Tue, 5 Sep 2006 15:34:40 +0000 (15:34 +0000)
committerPhilip Hazel <ph10@hermes.cam.ac.uk>
Tue, 5 Sep 2006 15:34:40 +0000 (15:34 +0000)
Added a small, simple test for quoted-printable decoding.

doc/doc-txt/ChangeLog
src/src/mime.c
test/confs/4000
test/mail/4000.userx
test/scripts/4000-scanning/4000

index 9091f0d86a040fe3b33dcd76d7bcb0602c6c7f4d..6847ff51dc49b7e4586b52d9a9df54e7e119acfa 100644 (file)
@@ -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
 -----------------
index c215b7bcf159d430f6f631a34a2b6fb2a4ab92a2..45825950fcd119e77340d68abbda083e1b2b14ee 100644 (file)
@@ -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) {
index 1b33ff795d50922d0da6b4e71bb695e444a5eaf7..daf5a687ea4ff487f7e9d4ff0754bf82393c48c6 100644 (file)
@@ -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
 
 
index 65ac8a33196c2da3dc56fefdc51ccf521ea6d9db..34c51ccfc5c536f92d9f699155e6455698ce387b 100644 (file)
@@ -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
index d0f132ce5bac69c84b33dfdb0e7f007a9f55c550..6f66b27ae50e832830682cc99e1bd35e619693de 100644 (file)
@@ -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