]> granicus.if.org Git - mutt/commitdiff
Unify mutt_write_references
authorAron Griffis <agriffis@n01se.net>
Thu, 10 Jul 2008 13:38:25 +0000 (09:38 -0400)
committerAron Griffis <agriffis@n01se.net>
Thu, 10 Jul 2008 13:38:25 +0000 (09:38 -0400)
copy.c and sendlib.c have independent and different implementations of writing
references to a file.  Choose the one in sendlib since it's conservative with
mallocs and supports trimming the list.

Signed-off-by: Aron Griffis <agriffis@n01se.net>
copy.c
protos.h
sendlib.c

diff --git a/copy.c b/copy.c
index d7a9666754609b406facbf059c52287c1e0e2220..044841730544424aa08da83cd8a027e96589ac1c 100644 (file)
--- a/copy.c
+++ b/copy.c
@@ -369,11 +369,11 @@ mutt_copy_header (FILE *in, HEADER *h, FILE *out, int flags, const char *prefix)
       if (h->env->irt_changed && h->env->in_reply_to)
       {
        LIST *listp = h->env->in_reply_to;
-       fputs ("In-Reply-To: ", out);
+       fputs ("In-Reply-To:", out);
        for (; listp; listp = listp->next)
        {
-         fputs (listp->data, out);
          fputc (' ', out);
+         fputs (listp->data, out);
        }
        fputc ('\n', out);
       }
@@ -381,27 +381,8 @@ mutt_copy_header (FILE *in, HEADER *h, FILE *out, int flags, const char *prefix)
       if (h->env->refs_changed && h->env->references)
       {
        LIST *listp = h->env->references, *refs = NULL, *t;
-       fputs ("References: ", out);
-
-       /* Mutt stores references in reverse order, thus we create
-        * a reordered refs list that we can put in the headers */
-       for (; listp; listp = listp->next, refs = t)
-       {
-         t = (LIST *)safe_malloc (sizeof (LIST));
-         t->data = listp->data;
-         t->next = refs;
-       }
-
-       for (; refs; refs = refs->next)
-       {
-         fputs (refs->data, out);
-         fputc (' ', out);
-       }
-
-       /* clearing refs from memory */
-       for (t = refs; refs; refs = t->next, t = refs)
-         FREE (&refs);
-
+       fputs ("References:", out);
+       mutt_write_references (h->env->references, out, 0);
        fputc ('\n', out);
       }
 
index d98a16876f3cdff96e7ac33244c31c47ebe8ac7a..bb80973af51d89101670888e8d522b47fd2a208b 100644 (file)
--- a/protos.h
+++ b/protos.h
@@ -371,6 +371,7 @@ 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 wraplen);
 int mutt_write_rfc822_header (FILE *, ENVELOPE *, BODY *, int, int);
+void mutt_write_references (LIST *, FILE *, int);
 int mutt_yesorno (const char *, int);
 void mutt_set_header_color(CONTEXT *, HEADER *);
 void mutt_sleep (short);
index 9073bd4fbbbc4f6129c6d8acf243c68036d82499..7f9350cb3c7380fb87ff74007b9d6368cbfdb163 100644 (file)
--- a/sendlib.c
+++ b/sendlib.c
@@ -1520,17 +1520,15 @@ void mutt_write_address_list (ADDRESS *adr, FILE *fp, int linelen, int display)
 /* arbitrary number of elements to grow the array by */
 #define REF_INC 16
 
-#define TrimRef 10
-
 /* need to write the list in reverse because they are stored in reverse order
  * when parsed to speed up threading
  */
-static void write_references (LIST *r, FILE *f)
+void mutt_write_references (LIST *r, FILE *f, int trim)
 {
   LIST **ref = NULL;
   int refcnt = 0, refmax = 0;
 
-  for ( ; (TrimRef == 0 || refcnt < TrimRef) && r ; r = r->next)
+  for ( ; (trim == 0 || refcnt < trim) && r ; r = r->next)
   {
     if (refcnt == refmax)
       safe_realloc (&ref, (refmax += REF_INC) * sizeof (LIST *));
@@ -1825,7 +1823,7 @@ int mutt_write_rfc822_header (FILE *fp, ENVELOPE *env, BODY *attach,
     if (env->references)
     {
       fputs ("References:", fp);
-      write_references (env->references, fp);
+      mutt_write_references (env->references, fp, 10);
       fputc('\n', fp);
     }
 
@@ -1837,7 +1835,7 @@ int mutt_write_rfc822_header (FILE *fp, ENVELOPE *env, BODY *attach,
   if (env->in_reply_to)
   {
     fputs ("In-Reply-To:", fp);
-    write_references (env->in_reply_to, fp);
+    mutt_write_references (env->in_reply_to, fp, 1);
     fputc ('\n', fp);
   }