]> granicus.if.org Git - neomutt/commitdiff
We need to re-format address headers instead of just decoding them.
authorThomas Roessler <roessler@does-not-exist.org>
Wed, 12 Mar 2003 13:00:03 +0000 (13:00 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Wed, 12 Mar 2003 13:00:03 +0000 (13:00 +0000)
copy.c
sendlib.c

diff --git a/copy.c b/copy.c
index 389608edbc1006fa10d8f09a45df912b8239fa99..dfc4f2d6b864ad495ae8793db02d6cd5a3b93686 100644 (file)
--- a/copy.c
+++ b/copy.c
@@ -775,13 +775,75 @@ static int copy_delete_attach (BODY *b, FILE *fpin, FILE *fpout, char *date)
   return 0;
 }
 
+/* 
+ * This function is the equivalent of mutt_write_address_list(),
+ * but writes to a buffer instead of writing to a stream.
+ * mutt_write_address_list could be re-used if we wouldn't store
+ * all the decoded headers in a huge array, first. 
+ *
+ * XXX - fix that. 
+ */
+
+static void format_address_header (char **h, ADDRESS *a)
+{
+  char buf[HUGE_STRING];
+  char cbuf[STRING];
+  char c2buf[STRING];
+  
+  int l, linelen, buflen, count;
+  linelen = mutt_strlen (*h);
+  buflen  = linelen + 3;
+  
+  
+  safe_realloc ((void **) h, buflen);
+  for (count = 0; a; a = a->next, count++)
+  {
+    ADDRESS *tmp = a->next;
+    a->next = NULL;
+    *buf = *cbuf = *c2buf = '\0';
+    rfc822_write_address (buf, sizeof (buf), a, 0);
+    a->next = tmp;
+    
+    l = mutt_strlen (buf);
+    if (count && linelen + l > 74) 
+    {
+      strcpy (cbuf, "\n\t");   /* __STRCPY_CHECKED__ */
+      linelen = l + 8;
+    }
+    else
+    {
+      if (a->mailbox)
+      {
+       strcpy (cbuf, " ");     /* __STRCPY_CHECKED__ */
+       linelen++;
+      }
+      linelen += l;
+    }
+    if (!a->group && a->next && a->next->mailbox)
+    {
+      linelen++;
+      buflen++;
+      strcpy (c2buf, ",");     /* __STRCPY_CHECKED__ */
+    }
+    
+    buflen += l + mutt_strlen (cbuf) + mutt_strlen (c2buf);
+    safe_realloc ((void **) h, buflen);
+    strcat (*h, cbuf);         /* __STRCAT_CHECKED__ */
+    strcat (*h, buf);          /* __STRCAT_CHECKED__ */
+    strcat (*h, c2buf);                /* __STRCAT_CHECKED__ */
+  }
+  
+  /* Space for this was allocated in the beginning of this function. */
+  strcat (*h, "\n");           /* __STRCAT_CHECKED__ */
+}
+
 static int address_header_decode (char **h)
 {
   char *s = *h;
-  int l, ll;
-  
+  int l;
+
   ADDRESS *a = NULL;
-  
+
   switch (tolower (*s))
   {
     case 'r': 
@@ -850,17 +912,13 @@ static int address_header_decode (char **h)
   mutt_addrlist_to_local (a);
   rfc2047_decode_adrlist (a);
   
-  ll = mutt_strlen (s) * 6 + 3;        /* XXX -- should be safe  */
-  *h = safe_calloc (1, ll);
+  *h = safe_calloc (1, l + 2);
   
-  strncpy (*h, s, l);
-  strncat (*h, " ", ll);
-  rfc822_write_address (*h + l + 1, ll - l - 1, a, 0);
-  rfc822_free_address (&a);
-
-  strncat (*h, "\n", ll);
+  strfcpy (*h, s, l + 1);
   
-  safe_realloc ((void **) h, mutt_strlen (*h) + 1);
+  format_address_header (h, a);
+
+  rfc822_free_address (&a);
   
   FREE (&s);
   return 1;
index 975a65fc93f3a8cf17ef9be6b951ffbd1509a9ee..acd1f1e889705bc9ac6008caf36923fa4db40957 100644 (file)
--- a/sendlib.c
+++ b/sendlib.c
@@ -1514,11 +1514,8 @@ void mutt_write_address_list (ADDRESS *adr, FILE *fp, int linelen, int display)
     len = mutt_strlen (buf);
     if (count && linelen + len > 74)
     {
-      if (count)
-      {
-       fputs ("\n\t", fp);
-       linelen = len + 8; /* tab is usually about 8 spaces... */
-      }
+      fputs ("\n\t", fp);
+      linelen = len + 8; /* tab is usually about 8 spaces... */
     }
     else
     {