- int prefixlen = name ? strlen(name) + 2: 0, outlen = 0, column, newline = 1;
- int charsetlen = strlen(charset), utf8;
- char *output = NULL, *p, *q = NULL;
-
- /*
- * Right now we just encode the whole thing. Maybe later on we'll
- * only encode things on a per-atom basis.
- */
-
- p = *value;
-
- column = prefixlen + 2; /* Header name plus ": " */
-
- utf8 = strcasecmp(charset, "UTF-8") == 0;
-
- while (*p != '\0') {
- /*
- * Start a new line, if it's time
- */
- if (newline) {
- /*
- * 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) + 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).
- *
- */
-
- int tokenlen;
-
- 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 ": " */
- output = mh_xrealloc(output, outlen);
- q = output + curlen;
- *q++ = '?';
- *q++ = '=';
- *q++ = '\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++;
- }
-
- tokenlen = snprintf(q, outlen - (q - output), "=?%s?Q?", charset);
- q += tokenlen;
- column = prefixlen + tokenlen;
- newline = 0;
- }
+ int prefixlen = name ? strlen(name) + 2: 0;
+ int outlen = 0, column, newline = 1, utf8;
+ int charsetlen = strlen(charset);
+ char *output = NULL, *p, *q = NULL;