return 0;
}
+static char *unfold_header (char *s)
+{
+ char *p = s, *q = s;
+
+ while (p && *p)
+ {
+ /* remove CRLF prior to FWSP, turn \t into ' ' */
+ if (*p == '\r' && *(p + 1) && *(p + 1) == '\n' && *(p + 2) &&
+ (*(p + 2) == ' ' || *(p + 2) == '\t'))
+ {
+ *q++ = ' ';
+ p += 3;
+ continue;
+ }
+ /* remove LF prior to FWSP, turn \t into ' ' */
+ else if (*p == '\n' && *(p + 1) && (*(p + 1) == ' ' || *(p + 1) == '\t'))
+ {
+ *q++ = ' ';
+ p += 2;
+ continue;
+ }
+ *q++ = *p++;
+ }
+ if (q)
+ *q = 0;
+
+ return s;
+}
+
static int write_one_header (FILE *fp, int pfxw, int max, int wraplen,
const char *pfx, const char *start, const char *end,
int flags)
const char *pfx, int wraplen, int flags)
{
char *p = (char *)value, *last, *line;
- int max = 0, w;
+ int max = 0, w, rc = -1;
int pfxw = mutt_strwidth (pfx);
+ char *v = safe_strdup (value);
+
+ if (!(flags & CH_DISPLAY) || option (OPTWEED))
+ v = unfold_header (v);
/* when not displaying, use sane wrap value */
if (!(flags & CH_DISPLAY))
{
/* if header is short enough, simply print it */
if (!(flags & CH_DISPLAY) && mutt_strwidth (tag) + 2 + pfxw +
- mutt_strwidth (value) <= wraplen)
+ mutt_strwidth (v) <= wraplen)
{
dprint(4,(debugfile,"mwoh: buf[%s%s: %s] is short enough\n",
- NONULL(pfx), tag, value));
- if (fprintf (fp, "%s%s: %s\n", NONULL(pfx), tag, value) <= 0)
- return -1;
- return 0;
+ NONULL(pfx), tag, v));
+ if (fprintf (fp, "%s%s: %s\n", NONULL(pfx), tag, v) <= 0)
+ goto out;
+ rc = 0;
+ goto out;
}
else
- return fold_one_header (fp, tag, value, pfx, wraplen, flags);
+ {
+ rc = fold_one_header (fp, tag, v, pfx, wraplen, flags);
+ goto out;
+ }
}
- p = last = line = (char *)value;
+ p = last = line = (char *)v;
while (p && *p)
{
p = strchr (p, '\n');
if (*p != ' ' && *p != '\t')
{
if (write_one_header (fp, pfxw, max, wraplen, pfx, last, p, flags) < 0)
- return -1;
+ goto out;
last = p;
max = 0;
}
if (last && *last)
if (write_one_header (fp, pfxw, max, wraplen, pfx, last, p, flags) < 0)
- return -1;
+ goto out;
- return 0;
+ rc = 0;
+
+out:
+ FREE (&v);
+ return rc;
}