* 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).
*
*/
- 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 ": " */
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;
+ while (is_fws(*p))
+ *q++ = *p++;
}
q += snprintf(q, outlen - (q - output), "=?%s?Q?", charset);
*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--;
}
}
- strcat(q, "?=");
+ strcat(q, "?=\n");
free(*value);
/*
* 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;
struct part **pp;
CT ct;
FILE *in;
+ HF hp;
m_getfld_state_t gstate = 0;
directive_init(directives);
}
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.