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

[PATCH 2 of 3] Unify mutt_write_references



# HG changeset patch
# User Aron Griffis <agriffis@xxxxxxxxx>
# Date 1215697105 14400
# Branch HEAD
# Node ID 73431d86627a2ccb24218c0f1f3b6b399860067e
# Parent  f005e1a25900d3df40963adcee04e384ac33b29b
Unify mutt_write_references

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@xxxxxxxxx>

diff -r f005e1a25900 -r 73431d86627a copy.c
--- a/copy.c    Thu Jul 10 09:38:25 2008 -0400
+++ b/copy.c    Thu Jul 10 09:38:25 2008 -0400
@@ -369,11 +369,11 @@
       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)
        {
+         fputc (' ', out);
          fputs (listp->data, out);
-         fputc (' ', out);
        }
        fputc ('\n', out);
       }
@@ -381,27 +381,8 @@
       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);
       }
 
diff -r f005e1a25900 -r 73431d86627a protos.h
--- a/protos.h  Thu Jul 10 09:38:25 2008 -0400
+++ b/protos.h  Thu Jul 10 09:38:25 2008 -0400
@@ -371,6 +371,7 @@
 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);
diff -r f005e1a25900 -r 73431d86627a sendlib.c
--- a/sendlib.c Thu Jul 10 09:38:25 2008 -0400
+++ b/sendlib.c Thu Jul 10 09:38:25 2008 -0400
@@ -1520,17 +1520,15 @@
 /* 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 @@
     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 @@
   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);
   }