From 3215d1ade197b75a8c00fc476d8dcedc9f572004 Mon Sep 17 00:00:00 2001 From: Brendan Cully Date: Wed, 28 Oct 2009 23:03:26 -0700 Subject: [PATCH] Unfold headers to wrap length in pager, when weed is set. From Rocco's patch queue. --- sendlib.c | 63 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 52 insertions(+), 11 deletions(-) diff --git a/sendlib.c b/sendlib.c index c4f5e469..45e62c02 100644 --- a/sendlib.c +++ b/sendlib.c @@ -1721,6 +1721,35 @@ static int fold_one_header (FILE *fp, const char *tag, const char *value, 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) @@ -1789,8 +1818,12 @@ int mutt_write_one_header (FILE *fp, const char *tag, const char *value, 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)) @@ -1807,19 +1840,23 @@ int mutt_write_one_header (FILE *fp, const char *tag, const char *value, { /* 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'); @@ -1839,7 +1876,7 @@ int mutt_write_one_header (FILE *fp, const char *tag, const char *value, 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; } @@ -1847,9 +1884,13 @@ int mutt_write_one_header (FILE *fp, const char *tag, const char *value, 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; } -- 2.40.0