From: David Levine Date: Fri, 29 Mar 2013 17:09:15 +0000 (-0500) Subject: A bug fix and an enhancement to mhfixmsg based on patches X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/26cad4056c927e609753103897a60d00611ac9f7?ds=inline A bug fix and an enhancement to mhfixmsg based on patches provided by M. Levinson: 1) Set status to NOTOK in get_multipart_boundary() if the message is missing its end boundary. This avoids a seg fault in fix_boundary(); also added check for null return from parse_mime(). If this turns out to be a common problem, we could consider adding code to repair it. Now, mhfixmsg ignores the condition and proceeeds with any other transformations. 2) With -decodetext 7bit, mhfixmsg now converts base64-encoded parts to quoted-printable 8bit if the part will not fit into 7bit. --- diff --git a/man/mhfixmsg.man b/man/mhfixmsg.man index cac4d9e7..68f06871 100644 --- a/man/mhfixmsg.man +++ b/man/mhfixmsg.man @@ -52,8 +52,13 @@ The .B \-decodetext switch enables a transformation to decode each base64 and quoted-printable text message part to the selected 8bit or 7bit -encoding. If the decoded text would not fit the selected encoding as -defined by RFC-2045, the part is not decoded. +encoding. If 7bit is selected for a base64 part but it will only fit +8bit, as defined by RFC-2045, then it will be decoded to 8bit +quoted-printable. Otherwise, if the decoded text would not fit the +selected encoding, the part is not decoded (and a message will be +displayed if +.B \-verbose +is enabled). .PP The .B \-textcodeset diff --git a/uip/mhfixmsg.c b/uip/mhfixmsg.c index 8abb96de..10a8e1b3 100644 --- a/uip/mhfixmsg.c +++ b/uip/mhfixmsg.c @@ -308,8 +308,7 @@ main (int argc, char **argv) { adios (NULL, "out of memory"); ctp = cts; - if ((ct = parse_mime (file))) - *ctp++ = ct; + if ((ct = parse_mime (file))) *ctp++ = ct; } else { /* * message(s) are coming from a folder @@ -348,8 +347,7 @@ main (int argc, char **argv) { char *msgnam; msgnam = m_name (msgnum); - if ((ct = parse_mime (msgnam))) - *ctp++ = ct; + if ((ct = parse_mime (msgnam))) *ctp++ = ct; } } @@ -520,12 +518,14 @@ fix_boundary (CT *ct, int *message_mods) { char *filename = add ((*ct)->c_file, NULL); free_content (*ct); - *ct = parse_mime (fixed); - (*ct)->c_unlink = 1; + if ((*ct = parse_mime (fixed))) { + (*ct)->c_unlink = 1; - ++*message_mods; - if (verbosw) { - report (NULL, filename, "fix multipart boundary"); + ++*message_mods; + if (verbosw) { + report (NULL, filename, + "fix multipart boundary"); + } } free (filename); } else { @@ -601,15 +601,18 @@ get_multipart_boundary (CT ct, char **part_boundary) { if (cp && cp - buffer >= 2 && *--cp == '-' && *--cp == '-' && (cp > buffer && *--cp == '\n')) { + status = OK; break; } - /* Else the start and end boundaries didn't match, or - the start boundary doesn't begin with "\n--" (or - "--" if at the beginning of buffer). Keep trying. */ } else { + /* The start and end boundaries didn't match, or the + start boundary doesn't begin with "\n--" (or "--" + if at the beginning of buffer). Keep trying. */ status = NOTOK; } } + } else { + status = NOTOK; } if (status == OK) { @@ -1457,7 +1460,8 @@ decode_text_parts (CT ct, int encoding, int *message_mods) { unlink (ct->c_cefile.ce_file); free (ct->c_cefile.ce_file); ct->c_cefile.ce_file = NULL; - } else if (ct_encoding == CE_8BIT && encoding == CE_7BIT) { + } else if (ct->c_encoding == CE_QUOTED && + ct_encoding == CE_8BIT && encoding == CE_7BIT) { if (verbosw) { report (ct->c_partno, ct->c_file, "will not decode%s because it is 8bit", @@ -1469,9 +1473,13 @@ decode_text_parts (CT ct, int encoding, int *message_mods) { free (ct->c_cefile.ce_file); ct->c_cefile.ce_file = NULL; } else { - int enc = ct_encoding == CE_BINARY - ? CE_BINARY - : charset_encoding (ct); + int enc; + if (ct_encoding == CE_BINARY) + enc = CE_BINARY; + else if (ct_encoding == CE_8BIT && encoding == CE_7BIT) + enc = CE_QUOTED; + else + enc = charset_encoding (ct); if (set_ce (ct, enc) == OK) { ++*message_mods; if (verbosw) { diff --git a/uip/mhparse.c b/uip/mhparse.c index daf7c40c..3d4d7733 100644 --- a/uip/mhparse.c +++ b/uip/mhparse.c @@ -3129,7 +3129,7 @@ ce_str (int encoding) { case CE_BASE64: return "base64"; case CE_QUOTED: - return "quoted"; + return "quoted-printable"; case CE_8BIT: return "8bit"; case CE_7BIT: