<<< Date Index >>>     <<< Thread Index >>>

Re: [patch] make headers wrap at wrapmargin rather than hardcoded value



Here's a variant that should do the right things both when sending
and displaying messages.  I'd be happy for a second pair of eyes on
this one, since wraplen is no longer a fixed small integer.

(Is it just me, or does code that tries to do stuff with multibyte
strings get extremely nasty extremely quickly? *sigh*)
-- 
Thomas Roessler   <roessler@xxxxxxxxxxxxxxxxxx>






On 2007-01-04 20:51:25 +0100, Rado S wrote:
> From: Rado S <inmx027@xxxxxxxxxxxxxxxxxxx>
> To: mutt-dev@xxxxxxxx
> Date: Thu, 4 Jan 2007 20:51:25 +0100
> Subject: [patch] make headers wrap at wrapmargin rather than hardcoded
>       value
> X-Spam-Level: 
> 
> ... afterall we're using wide-terminal for a reason. ;)
> 
> Moin, and enjoy.
> 
> -- 
> © Rado S. -- You must provide YOUR effort for your goal!
> Even if it seems insignificant, in fact EVERY effort counts
> for a shared task, at least to show your deserving attitude.






RCS file: /cvs/mutt/mutt/copy.c,v
retrieving revision 3.28
diff -u -r3.28 copy.c
--- copy.c      16 Aug 2006 20:32:23 -0000      3.28
+++ copy.c      8 Jan 2007 11:14:45 -0000
@@ -28,6 +28,7 @@
 #include "mime.h"
 #include "mutt_crypt.h"
 #include "mutt_idna.h"
+#include "mutt_curses.h"
 
 #include <string.h>
 #include <stdlib.h>
@@ -280,7 +281,7 @@
       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;
Index: protos.h
===================================================================
RCS file: /cvs/mutt/mutt/protos.h,v
retrieving revision 3.47
diff -u -r3.47 protos.h
--- protos.h    2 Jan 2007 17:10:34 -0000       3.47
+++ protos.h    8 Jan 2007 11:14:46 -0000
@@ -350,7 +350,7 @@
 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 *);
Index: sendlib.c
===================================================================
RCS file: /cvs/mutt/mutt/sendlib.c,v
retrieving revision 3.41
diff -u -r3.41 sendlib.c
--- sendlib.c   16 Aug 2006 20:32:23 -0000      3.41
+++ sendlib.c   8 Jan 2007 11:14:46 -0000
@@ -1518,8 +1518,6 @@
 }
 
 
-#define WRAPLEN 76
-
 static void foldingstrfcpy (char *d, const char *s, int n)
 {
   while (--n >= 0 && *s)
@@ -1533,7 +1531,7 @@
   *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 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 @@
      * 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 @@
        }
 
        if (iswspace (w) && 
-           (!k || col <= WRAPLEN))
+           (!k || col <= wraplen))
        {
          if (!k || i != n)
            k = i;
@@ -1685,7 +1686,6 @@
   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 @@
     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 @@
        }
       }
       
-      mutt_write_one_header (fp, tmp->data, p, NULL);
+      mutt_write_one_header (fp, tmp->data, p, NULL, 0);
       *q = ':';
     }
   }
cvs diff: Diffing contrib