From: David Levine Date: Tue, 4 Oct 2016 01:30:14 +0000 (-0400) Subject: Base Content-Transfer-Encoding on decoded and new text parts on X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/b917dfff6eaf472363fd4933e9c2239eb2e6877f?hp=ae0ecdc14e4fe091c063495971bc6fdd85e4e2f3 Base Content-Transfer-Encoding on decoded and new text parts on content rather than the user's charset. --- diff --git a/test/mhfixmsg/test-mhfixmsg b/test/mhfixmsg/test-mhfixmsg index ab0ebcb0..bd63446a 100755 --- a/test/mhfixmsg/test-mhfixmsg +++ b/test/mhfixmsg/test-mhfixmsg @@ -212,13 +212,13 @@ Content-Type: multipart/alternative; boundary="----=_nmh-multipart" ------=_nmh-multipart Content-Type: text/plain; charset="Windows-1252" -Content-Transfer-Encoding: 8bit +Content-Transfer-Encoding: 7bit Need to go! Need ... to ... go! ------=_nmh-multipart Content-Type: text/html; charset="Windows-1252" -Content-Transfer-Encoding: 8bit +Content-Transfer-Encoding: 7bit @@ -291,7 +291,7 @@ Content-Type: multipart/alternative; boundary="----=_nmh-multipart-3" ------=_nmh-multipart-3 Content-Type: text/plain; charset="Windows-1252" -Content-Transfer-Encoding: 8bit +Content-Transfer-Encoding: 7bit ------=_nmh-multipart ------=_nmh-multipart-1 @@ -299,7 +299,7 @@ Content-Transfer-Encoding: 8bit ------=_nmh-multipart-3 Content-Type: text/html; charset="Windows-1252" -Content-Transfer-Encoding: 8bit +Content-Transfer-Encoding: 7bit @@ -369,7 +369,7 @@ Content-Type: multipart/alternative; boundary="----=_nmh-multipart" ------=_nmh-multipart Content-Type: text/plain; charset="Windows-1252" -Content-Transfer-Encoding: 8bit +Content-Transfer-Encoding: 7bit Need to go! Need ... to ... go! @@ -443,7 +443,7 @@ Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="iso-8859-1"; name="test4.txt" Content-Disposition: attachment; filename="test4.txt" -Content-Transfer-Encoding: 8bit +Content-Transfer-Encoding: 7bit This is a text/plain part. @@ -500,7 +500,7 @@ This is additional content after the last subpart of the multipart. Content-Type: text/plain; charset="iso-8859-1" Content-Disposition: attachment; filename="test2.txt" Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA== -Content-Transfer-Encoding: 8bit +Content-Transfer-Encoding: 7bit This is the second text/plain part. @@ -513,7 +513,7 @@ This is the third text/plain part. ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="iso-8859-1"; name="test4.txt" Content-Disposition: attachment; filename="test4.txt" -Content-Transfer-Encoding: 8bit +Content-Transfer-Encoding: 7bit This is the fourth text/plain part. @@ -611,7 +611,7 @@ Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="iso-8859-1" -Content-Transfer-Encoding: 8bit +Content-Transfer-Encoding: 7bit This is a text plain part @@ -700,7 +700,7 @@ Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="iso-8859-1" -Content-Transfer-Encoding: 8bit +Content-Transfer-Encoding: 7bit This is a text plain part @@ -750,7 +750,7 @@ Content-Type: multipart/alternative; boundary="----=_nmh-multipart" ------=_nmh-multipart Content-Type: text/plain; charset="ISO-8859-1" -Content-Transfer-Encoding: 8bit +Content-Transfer-Encoding: 7bit Mile $0.00 Time $78.71 @@ -1198,7 +1198,7 @@ Content-Type: multipart/alternative; boundary="----=_Part_876302" ------=_Part_876302 Content-Type: text/plain; charset="UTF-8" -Content-Transfer-Encoding: 8bit +Content-Transfer-Encoding: 7bit Yes, the text/plain part really was empty. @@ -1428,14 +1428,14 @@ Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-Type: text/plain; charset="iso-8859-1" Content-Disposition: attachment; filename="test1.txt" Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA== -Content-Transfer-Encoding: 8bit +Content-Transfer-Encoding: 7bit This is the text/plain part. ------- =_aaaaaaaaaa0 Content-Type: text/html; charset="iso-8859-1"; name="test2.txt" Content-Disposition: attachment; filename="test2.txt" -Content-Transfer-Encoding: 8bit +Content-Transfer-Encoding: 7bit @@ -1489,7 +1489,7 @@ Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-Type: text/plain; charset="iso-8859-1" Content-Disposition: attachment; filename="test1.txt" Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA== -Content-Transfer-Encoding: 8bit +Content-Transfer-Encoding: 7bit This is the text/plain part. @@ -1546,14 +1546,14 @@ Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-Type: text/plain; charset="iso-8859-1" Content-Disposition: attachment; filename="test1.txt" Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA== -Content-Transfer-Encoding: 8bit +Content-Transfer-Encoding: 7bit This is the text/plain part. ------- =_aaaaaaaaaa0 Content-Type: application/ics; charset="iso-8859-1"; name="invite.ics" Content-Disposition: attachment; filename="invite.ics" -Content-Transfer-Encoding: 8bit +Content-Transfer-Encoding: 7bit BEGIN:VCALENDAR VERSION:2.0 @@ -1614,14 +1614,14 @@ Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-Type: text/plain; charset="iso-8859-1" Content-Disposition: attachment; filename="test1.txt" Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA== -Content-Transfer-Encoding: 8bit +Content-Transfer-Encoding: 7bit This is the text/plain part. ------- =_aaaaaaaaaa0 Content-Type: application/ics; charset="iso-8859-1"; name="invite.ics" Content-Disposition: attachment; filename="invite.ics" -Content-Transfer-Encoding: 8bit +Content-Transfer-Encoding: 7bit BEGIN:VCALENDAR VERSION:2.0 diff --git a/uip/mhfixmsg.c b/uip/mhfixmsg.c index 55db2c0b..c237ea87 100644 --- a/uip/mhfixmsg.c +++ b/uip/mhfixmsg.c @@ -108,7 +108,6 @@ static CT divide_part (CT); static void copy_ctinfo (CI, CI); static int decode_part (CT); static int reformat_part (CT, char *, char *, char *, int); -static int charset_encoding (CT); static CT build_multipart_alt (CT, CT, int, int); static int boundary_in_content (FILE **, char *, const char *); static void transfer_noncontent_headers (CT, CT); @@ -526,7 +525,8 @@ mhfixmsgsbr (CT *ctp, const fix_transformations *fx, char *outfile) { ensure_text_plain (ctp, NULL, &message_mods, fx->replacetextplain); } if (status == OK && fx->decodetext) { - status = decode_text_parts (*ctp, fx->decodetext, fx->decodetypes, &message_mods); + status = decode_text_parts (*ctp, fx->decodetext, fx->decodetypes, + &message_mods); } if (status == OK && fx->textcharset != NULL) { status = convert_charsets (*ctp, fx->textcharset, &message_mods); @@ -1581,6 +1581,7 @@ decode_part (CT ct) { static int reformat_part (CT ct, char *file, char *type, char *subtype, int c_type) { int output_subtype, output_encoding; + const char *reason = NULL; char *cp, *cf; int status; @@ -1626,8 +1627,8 @@ reformat_part (CT ct, char *file, char *type, char *subtype, int c_type) { /* Set subtype to 0, which is always an UNKNOWN subtype. */ output_subtype = 0; } - output_encoding = charset_encoding (ct); + output_encoding = content_encoding (ct, &reason); if (set_ct_type (ct, c_type, output_subtype, output_encoding) == OK) { ct->c_cefile.ce_file = file; ct->c_cefile.ce_unlink = 1; @@ -1640,20 +1641,6 @@ reformat_part (CT ct, char *file, char *type, char *subtype, int c_type) { } -/* - * Identifies 7bit or 8bit content based on charset. - */ -static int -charset_encoding (CT ct) { - char *ct_charset = content_charset (ct); - int encoding = strcasecmp (ct_charset, "US-ASCII") ? CE_8BIT : CE_7BIT; - - free (ct_charset); - - return encoding; -} - - /* * Fill in a multipart/alternative part. */ @@ -1925,7 +1912,8 @@ set_ct_type (CT ct, int type, int subtype, int encoding) { * that character set again after decoding." */ static int -decode_text_parts (CT ct, int encoding, const char *decodetypes, int *message_mods) { +decode_text_parts (CT ct, int encoding, const char *decodetypes, + int *message_mods) { int status = OK; int lf_line_endings = 0; @@ -1937,7 +1925,8 @@ decode_text_parts (CT ct, int encoding, const char *decodetypes, int *message_mo /* Should check to see if the body for this part is encoded? For now, it gets passed along as-is by InitMultiPart(). */ for (part = m->mp_parts; status == OK && part; part = part->mp_next) { - status = decode_text_parts (part->mp_part, encoding, decodetypes, message_mods); + status = decode_text_parts (part->mp_part, encoding, decodetypes, + message_mods); } break; } @@ -1946,7 +1935,8 @@ decode_text_parts (CT ct, int encoding, const char *decodetypes, int *message_mo if (ct->c_subtype == MESSAGE_EXTERNAL) { struct exbody *e = (struct exbody *) ct->c_ctparams; - status = decode_text_parts (e->eb_content, encoding, decodetypes, message_mods); + status = decode_text_parts (e->eb_content, encoding, decodetypes, + message_mods); } break; @@ -1997,12 +1987,13 @@ decode_text_parts (CT ct, int encoding, const char *decodetypes, int *message_mo ct->c_cefile.ce_file = NULL; } else { 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); + enc = ct_encoding; } if (set_ce (ct, enc) == OK) { ++*message_mods;