+static int fold_one_header (FILE *fp, const char *tag, const char *value,
+ const char *pfx, int wraplen, int flags)
+{
+ const char *p = value, *next, *sp;
+ char buf[HUGE_STRING] = "";
+ int first = 1, enc, col = 0, w, l = 0, fold;
+
+ dprint(4,(debugfile,"mwoh: pfx=[%s], tag=[%s], flags=%d value=[%s]\n",
+ pfx, tag, flags, value));
+
+ if (fprintf (fp, "%s%s: ", NONULL (pfx), tag) < 0)
+ return -1;
+ col = mutt_strlen (tag) + 2 + mutt_strlen (pfx);
+
+ while (p && *p)
+ {
+ fold = 0;
+
+ /* find the next word and place it in `buf'. it may start with
+ * whitespace we can fold before */
+ next = find_word (p);
+ l = MIN(sizeof (buf), next - p);
+ memcpy (buf, p, l);
+ buf[l] = 0;
+
+ /* determine width: character cells for display, bytes for sending
+ * (we get pure ascii only) */
+ w = my_width (buf, col, flags);
+ enc = mutt_strncmp (buf, "=?", 2) == 0;
+
+ dprint(5,(debugfile,"mwoh: word=[%s], col=%d, w=%d, next=[0x0%x]\n",
+ buf, col, w, *next));
+
+ /* insert a folding \n before the current word's lwsp except for
+ * header name, first word on a line (word longer than wrap width)
+ * and encoded words */
+ if (!first && !enc && col && col + w >= wraplen)