]> diplodocus.org Git - nmh/blobdiff - uip/mhbuildsbr.c
mhfixmsg now replaces RFC 2047 encoding with RFC 2231 encoding of
[nmh] / uip / mhbuildsbr.c
index 850ec8f8ac699f78096ae284701c92e6b0236ba1..26d8524d767a9f72005a641924ce4e2325135d57 100644 (file)
@@ -17,7 +17,6 @@
 
 #include <h/mh.h>
 #include <fcntl.h>
-#include <h/signals.h>
 #include <h/md5.h>
 #include <h/mts.h>
 #include <h/tws.h>
@@ -361,15 +360,17 @@ finish_field:
     }
     m_getfld_state_destroy (&gstate);
 
-    /*
-     * Iterate through the list of headers and call the function to MIME-ify
-     * them if required.
-     */
+    if (header_encoding != CE_8BIT) {
+        /*
+         * Iterate through the list of headers and call the function to MIME-ify
+         * them if required.
+         */
 
-    for (hp = ct->c_first_hf; hp != NULL; hp = hp->next) {
-       if (encode_rfc2047(hp->name, &hp->value, header_encoding, NULL)) {
-           adios(NULL, "Unable to encode header \"%s\"", hp->name);
-       }
+        for (hp = ct->c_first_hf; hp != NULL; hp = hp->next) {
+            if (encode_rfc2047(hp->name, &hp->value, header_encoding, NULL)) {
+                adios(NULL, "Unable to encode header \"%s\"", hp->name);
+            }
+        }
     }
 
     /*
@@ -1749,8 +1750,11 @@ build_headers (CT ct, int header_encoding)
     if (ct->c_descr) {
        np = add (DESCR_FIELD, NULL);
        vp = concat (" ", ct->c_descr, NULL);
-       if (encode_rfc2047(DESCR_FIELD, &vp, header_encoding, NULL))
-           adios(NULL, "Unable to encode %s header", DESCR_FIELD);
+       if (header_encoding != CE_8BIT) {
+           if (encode_rfc2047(DESCR_FIELD, &vp, header_encoding, NULL)) {
+               adios(NULL, "Unable to encode %s header", DESCR_FIELD);
+           }
+       }
        add_header (ct, np, vp);
     }
 
@@ -2160,7 +2164,7 @@ expand_pseudoheaders (CT ct, struct multipart *m, const char *infile,
                             part->mp_part->c_ctinfo.ci_subtype, NULL);
 
                 if (part->mp_part->c_type == CT_MULTIPART) {
-                    expand_pseudoheaders (part->mp_part, mp, infile,
+                    expand_pseudoheaders (part->mp_part, m, infile,
                                           convert_head);
                 } else {
                     const convert_list *c;
@@ -2221,6 +2225,7 @@ expand_pseudoheader (CT ct, CT *text_plain_ct, struct multipart *m,
     struct str2init *s2i;
     CT reply_ct;
     struct part *part;
+    int status;
 
     type_p = getcpy (type);
     if ((subtype_p = strchr (type_p, '/'))) {
@@ -2247,7 +2252,9 @@ expand_pseudoheader (CT ct, CT *text_plain_ct, struct multipart *m,
     /* Convert here . . . */
     ct->c_storeproc = getcpy (convert_command);
     ct->c_umask = ~m_gmprot ();
-    if (show_content_aux (ct, 0, convert_command, NULL, NULL) == NOTOK) {
+
+    if ((status = show_content_aux (ct, 0, convert_command, NULL, NULL)) !=
+        OK) {
         admonish (NULL, "store of %s content failed", type);
     }
     free (convert_command);
@@ -2294,7 +2301,8 @@ expand_pseudoheader (CT ct, CT *text_plain_ct, struct multipart *m,
     if (reply_ct->c_type == CT_TEXT  &&
         reply_ct->c_subtype == TEXT_PLAIN) {
         if (! *text_plain_ct  &&  m->mp_parts  &&  m->mp_parts->mp_part  &&
-            m->mp_parts->mp_part->c_type == CT_TEXT) {
+            m->mp_parts->mp_part->c_type == CT_TEXT  &&
+            m->mp_parts->mp_part->c_subtype == TEXT_PLAIN) {
             *text_plain_ct = m->mp_parts->mp_part;
             /* Make sure that the charset is set in the text/plain
                part. */
@@ -2323,6 +2331,7 @@ expand_pseudoheader (CT ct, CT *text_plain_ct, struct multipart *m,
 
                 if (text_plain_reply != NOTOK  &&  addl_reply != NOTOK) {
                     /* Insert blank line before each addl part. */
+                    /* It would be nice not to do this for the first one. */
                     if (write (text_plain_reply, "\n", 1) == 1) {
                         /* Copy the text from the new reply and
                            then free its Content struct. */
@@ -2386,12 +2395,15 @@ extract_headers (CT ct, char *reply_file, FILE **reply_fp) {
     buffer[statbuf.st_size] = '\0';
 
     /* Look for a header in the convert reply. */
-    if ((end_of_header = strstr (buffer, "\r\n\r\n"))) {
-        end_of_header += 2;
-        found_header = 1;
-    } else if ((end_of_header = strstr (buffer, "\n\n"))) {
-        ++end_of_header;
-        found_header = 1;
+    if (strncasecmp (buffer, TYPE_FIELD, strlen (TYPE_FIELD)) == 0  &&
+        buffer[strlen (TYPE_FIELD)] == ':') {
+        if ((end_of_header = strstr (buffer, "\r\n\r\n"))) {
+            end_of_header += 2;
+            found_header = 1;
+        } else if ((end_of_header = strstr (buffer, "\n\n"))) {
+            ++end_of_header;
+            found_header = 1;
+        }
     }
 
     if (found_header) {