From: Thomas Roessler Date: Tue, 9 Jan 2007 10:29:09 +0000 (+0000) Subject: Smarter header wrapping -- different behavior for display X-Git-Tag: mutt-1-5-14-rel~13 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2f53c22bbf5f0d0c944f8e7902b112af18a17b46;p=mutt Smarter header wrapping -- different behavior for display purposes and sent messages. --- diff --git a/copy.c b/copy.c index 68cfcae1..114b99c4 100644 --- a/copy.c +++ b/copy.c @@ -28,6 +28,7 @@ #include "mime.h" #include "mutt_crypt.h" #include "mutt_idna.h" +#include "mutt_curses.h" #include #include @@ -280,7 +281,7 @@ mutt_copy_hdr (FILE *in, FILE *out, LOFF_T off_start, LOFF_T off_end, int flags, if (flags & (CH_DECODE|CH_PREFIX)) { if (mutt_write_one_header (out, 0, headers[x], - flags & CH_PREFIX ? prefix : 0) == -1) + flags & CH_PREFIX ? prefix : 0, COLS - WrapMargin) == -1) { error = TRUE; break; diff --git a/protos.h b/protos.h index f0456fe6..baec526b 100644 --- a/protos.h +++ b/protos.h @@ -350,7 +350,7 @@ int mutt_which_case (const char *); int mutt_write_fcc (const char *path, HEADER *hdr, const char *msgid, int, char *); int mutt_write_mime_body (BODY *, FILE *); int mutt_write_mime_header (BODY *, FILE *); -int mutt_write_one_header (FILE *fp, const char *tag, const char *value, const char *pfx); +int mutt_write_one_header (FILE *fp, const char *tag, const char *value, const char *pfx, int wraplen); int mutt_write_rfc822_header (FILE *, ENVELOPE *, BODY *, int, int); int mutt_yesorno (const char *, int); void mutt_set_header_color(CONTEXT *, HEADER *); diff --git a/sendlib.c b/sendlib.c index 1543a6bf..13b03920 100644 --- a/sendlib.c +++ b/sendlib.c @@ -1518,8 +1518,6 @@ static void write_references (LIST *r, FILE *f) } -#define WRAPLEN 76 - static void foldingstrfcpy (char *d, const char *s, int n) { while (--n >= 0 && *s) @@ -1533,7 +1531,7 @@ static void foldingstrfcpy (char *d, const char *s, int n) *d = '\0'; } -int mutt_write_one_header (FILE *fp, const char *tag, const char *value, const char *pfx) +int mutt_write_one_header (FILE *fp, const char *tag, const char *value, const char *pfx, int wraplen) { int col = 0; int i, k, n; @@ -1545,6 +1543,9 @@ int mutt_write_one_header (FILE *fp, const char *tag, const char *value, const c int wrapped = 0; int in_encoded_word = 0; + if (wraplen <= 0) + wraplen = 76; + if (tag) { if (fprintf (fp, "%s%s: ", NONULL (pfx), tag) < 0) @@ -1588,8 +1589,8 @@ int mutt_write_one_header (FILE *fp, const char *tag, const char *value, const c * yuck */ - for (i = 0, k = 0, l = 0, n = 0; i < sizeof (buf) && cp[i] != '\0' && - ((col < (WRAPLEN + (k ? 0 : WRAPLEN)) || in_encoded_word)); + for (i = 0, k = 0, l = 0, n = 0; i + MB_CUR_MAX < sizeof (buf) && cp[i] != '\0' && + ((col < (wraplen + (k ? 0 : wraplen)) || in_encoded_word)); i += l) { @@ -1631,7 +1632,7 @@ int mutt_write_one_header (FILE *fp, const char *tag, const char *value, const c } if (iswspace (w) && - (!k || col <= WRAPLEN)) + (!k || col <= wraplen)) { if (!k || i != n) k = i; @@ -1685,7 +1686,6 @@ int mutt_write_one_header (FILE *fp, const char *tag, const char *value, const c return 0; } -#undef WRAPLEN /* Note: all RFC2047 encoding should be done outside of this routine, except * for the "real name." This will allow this routine to be used more than @@ -1754,13 +1754,13 @@ int mutt_write_rfc822_header (FILE *fp, ENVELOPE *env, BODY *attach, fputs ("Bcc: \n", fp); if (env->subject) - mutt_write_one_header (fp, "Subject", env->subject, NULL); + mutt_write_one_header (fp, "Subject", env->subject, NULL, 0); else if (mode == 1) fputs ("Subject: \n", fp); /* save message id if the user has set it */ if (env->message_id && !privacy) - mutt_write_one_header (fp, "Message-ID", env->message_id, NULL); + mutt_write_one_header (fp, "Message-ID", env->message_id, NULL, 0); if (env->reply_to) { @@ -1824,7 +1824,7 @@ int mutt_write_rfc822_header (FILE *fp, ENVELOPE *env, BODY *attach, } } - mutt_write_one_header (fp, tmp->data, p, NULL); + mutt_write_one_header (fp, tmp->data, p, NULL, 0); *q = ':'; } }