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

[PATCH 3 of 3] Fix three bugs handling flags in mutt_copy_header



# HG changeset patch
# User Aron Griffis <agriffis@xxxxxxxxx>
# Date 1215697105 14400
# Branch HEAD
# Node ID 95485bbbeea33e82dec544c4d007194390a3b109
# Parent  73431d86627a2ccb24218c0f1f3b6b399860067e
Fix three bugs handling flags in mutt_copy_header

1. mutt_copy_header incorrectly tests CH_UPDATE to determine whether to write
   the In-Reply-To and References headers.  CH_UPDATE refers only to Status: and
   X-Status:

2. mutt_copy_header ignores CH_NOSTATUS which is supposed to indicate that the
   mailbox type doesn't use those headers.

3. mutt_copy_header tests h->env->irt_changed and h->env->refs_changed when it
   should be testing CH_UPDATE_IRT and CH_UPDATE_REFS, respectively.  Early in
   the function this happens:

    if (h->env)
      flags |= (h->env->irt_changed ? CH_UPDATE_IRT : 0)
        | (h->env->refs_changed ? CH_UPDATE_REFS : 0);

   This means that for most callers, the result is the same, but
   mutt_copy_header should be testing the flags because the caller might have
   set them explicitly without setting irt_changed/refs_changed.

Signed-off-by: Aron Griffis <agriffis@xxxxxxxxx>

diff -r 73431d86627a -r 95485bbbeea3 copy.c
--- a/copy.c    Thu Jul 10 09:38:25 2008 -0400
+++ b/copy.c    Thu Jul 10 09:38:25 2008 -0400
@@ -362,49 +362,46 @@
     fputc('\n', out);
   }
 
-  if (flags & CH_UPDATE)
+  if ((flags & CH_UPDATE_IRT) && h->env->in_reply_to)
   {
-    if ((flags & CH_NOSTATUS) == 0)
+    LIST *listp = h->env->in_reply_to;
+    fputs ("In-Reply-To:", out);
+    for (; listp; listp = listp->next)
     {
-      if (h->env->irt_changed && h->env->in_reply_to)
-      {
-       LIST *listp = h->env->in_reply_to;
-       fputs ("In-Reply-To:", out);
-       for (; listp; listp = listp->next)
-       {
-         fputc (' ', out);
-         fputs (listp->data, out);
-       }
-       fputc ('\n', out);
-      }
+      fputc (' ', out);
+      fputs (listp->data, out);
+    }
+    fputc ('\n', out);
+  }
 
-      if (h->env->refs_changed && h->env->references)
-      {
-       LIST *listp = h->env->references, *refs = NULL, *t;
-       fputs ("References:", out);
-       mutt_write_references (h->env->references, out, 0);
-       fputc ('\n', out);
-      }
+  if ((flags & CH_UPDATE_REFS) && h->env->references)
+  {
+    LIST *listp = h->env->references, *refs = NULL, *t;
+    fputs ("References:", out);
+    mutt_write_references (h->env->references, out, 0);
+    fputc ('\n', out);
+  }
 
-      if (h->old || h->read)
-      {
-       fputs ("Status: ", out);
-       if (h->read)
-         fputs ("RO", out);
-       else if (h->old)
-         fputc ('O', out);
-       fputc ('\n', out);
-      }
+  if ((flags & CH_UPDATE) && (flags & CH_NOSTATUS) == 0)
+  {
+    if (h->old || h->read)
+    {
+      fputs ("Status: ", out);
+      if (h->read)
+       fputs ("RO", out);
+      else if (h->old)
+       fputc ('O', out);
+      fputc ('\n', out);
+    }
 
-      if (h->flagged || h->replied)
-      {
-       fputs ("X-Status: ", out);
-       if (h->replied)
-         fputc ('A', out);
-       if (h->flagged)
-         fputc ('F', out);
-       fputc ('\n', out);
-      }
+    if (h->flagged || h->replied)
+    {
+      fputs ("X-Status: ", out);
+      if (h->replied)
+       fputc ('A', out);
+      if (h->flagged)
+       fputc ('F', out);
+      fputc ('\n', out);
     }
   }