]> diplodocus.org Git - nmh/commitdiff
It looks like simple quoted-printable encoding of headers works!
authorKen Hornstein <kenh@pobox.com>
Wed, 30 Oct 2013 18:04:16 +0000 (14:04 -0400)
committerKen Hornstein <kenh@pobox.com>
Wed, 30 Oct 2013 18:04:16 +0000 (14:04 -0400)
sbr/encode_rfc2047.c
uip/mhbuildsbr.c

index 0d3c2784b7f37a0b37f83834ea81eced45d97e92..4cacd8379d1b055b3be140b76a7a3a1987e783f3 100644 (file)
@@ -173,14 +173,20 @@ field_encode_quoted(const char *name, char **value, const char *charset,
             * If it's the start of the header, we don't need to pad it
             *
             * The length of the output string is ...
             * If it's the start of the header, we don't need to pad it
             *
             * The length of the output string is ...
-            * =?charset?Q?...?=  so that's 7+strlen(charset) + 1 for NUL
+            * =?charset?Q?...?=  so that's 7+strlen(charset) + 2 for \n NUL
             *
             * plus 1 for every ASCII character and 3 for every eight bit
             * or special character (eight bit characters are written as =XX).
             *
             */
 
             *
             * plus 1 for every ASCII character and 3 for every eight bit
             * or special character (eight bit characters are written as =XX).
             *
             */
 
-           outlen += 8 + charsetlen + ascii + 3 * encoded;
+           outlen += 9 + charsetlen + ascii + 3 * encoded;
+
+           /*
+            * If output is set, then we're continuing the header.  Otherwise
+            * do the initial allocation.
+            */
+
            if (output) {
                int curlen = q - output, i;
                outlen += prefixlen + 1;        /* Header plus \n ": " */
            if (output) {
                int curlen = q - output, i;
                outlen += prefixlen + 1;        /* Header plus \n ": " */
@@ -192,8 +198,15 @@ field_encode_quoted(const char *name, char **value, const char *charset,
                for (i = 0; i < prefixlen; i++)
                    *q++ = ' ';
            } else {
                for (i = 0; i < prefixlen; i++)
                    *q++ = ' ';
            } else {
+               /*
+                * A bit of a hack here; the header can contain multiple
+                * spaces (probably at least one) until we get to the
+                * actual text.  Copy until we get to a non-space.
+                */
                output = mh_xmalloc(outlen);
                q = output;
                output = mh_xmalloc(outlen);
                q = output;
+               while (is_fws(*p))
+                   *q++ = *p++;
            }
 
            q += snprintf(q, outlen - (q - output), "=?%s?Q?", charset);
            }
 
            q += snprintf(q, outlen - (q - output), "=?%s?Q?", charset);
@@ -214,7 +227,7 @@ field_encode_quoted(const char *name, char **value, const char *charset,
            *q++ = *p;
            ascii--;
        } else {
            *q++ = *p;
            ascii--;
        } else {
-           snprintf(q, outlen - (q - output), "=%02X", (unsigned int) *p);
+           snprintf(q, outlen - (q - output), "=%02X", *((unsigned char *) p));
            q += 3;
            column += 3;
            encoded--;
            q += 3;
            column += 3;
            encoded--;
@@ -255,7 +268,7 @@ field_encode_quoted(const char *name, char **value, const char *charset,
        }
     }
 
        }
     }
 
-    strcat(q, "?=");
+    strcat(q, "?=\n");
 
     free(*value);
 
 
     free(*value);
 
@@ -307,9 +320,12 @@ unfold_header(char **value, int len)
            /*
             * When we get a newline, skip to the next non-whitespace
             * character and add a space to replace all of the whitespace
            /*
             * When we get a newline, skip to the next non-whitespace
             * character and add a space to replace all of the whitespace
+            *
+            * This has the side effect of stripping off the final newline
+            * for the header; we put it back in the encoding routine.
             */
             */
-           while (is_fws(*q))
-               q++;
+           while (is_fws(*q++))
+               ;
            if (*q == '\0')
                break;
 
            if (*q == '\0')
                break;
 
index 8d3a76dfb17506450a56c7f8cb51becb57cb18b7..79268399261973f681cb570a485d77c94244078d 100644 (file)
@@ -137,6 +137,7 @@ build_mime (char *infile, int directives)
     struct part **pp;
     CT ct;
     FILE *in;
     struct part **pp;
     CT ct;
     FILE *in;
+    HF hp;
     m_getfld_state_t gstate = 0;
 
     directive_init(directives);
     m_getfld_state_t gstate = 0;
 
     directive_init(directives);
@@ -227,6 +228,17 @@ finish_field:
     }
     m_getfld_state_destroy (&gstate);
 
     }
     m_getfld_state_destroy (&gstate);
 
+    /*
+     * 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, CE_UNKNOWN, NULL)) {
+           adios(NULL, "Unable to encode header \"%s\"", hp->name);
+       }
+    }
+
     /*
      * Now add the MIME-Version header field
      * to the list of header fields.
     /*
      * Now add the MIME-Version header field
      * to the list of header fields.