]> granicus.if.org Git - neomutt/commitdiff
Create envelope->changed to mark all field changes
authorKevin McCarthy <kevin@8t8.us>
Wed, 26 Dec 2018 03:24:08 +0000 (19:24 -0800)
committerRichard Russon <rich@flatcap.org>
Mon, 7 Jan 2019 15:09:41 +0000 (15:09 +0000)
In subsequent commits, we're going to add the x-label and subject
headers changed flags into the envelope.  To avoid the list of checks
exploding everywhere, just use a single field to check and reset those
values.

Several places in the code are checking for a null header->env.  I
wasn't aware this was possible, so I've added todo notes to track down
when this occurs.

Co-authored-by: Richard Russon <rich@flatcap.org>
context.c
copy.c
email/envelope.c
email/envelope.h
email/thread.c
imap/imap.c
maildir/maildir.c
maildir/mh.c
mutt_thread.c

index 41cdd8351c282e62b5c6295355395659c0b0c844..5872db76b84d7d217ded5800d3a56e795a708a86 100644 (file)
--- a/context.c
+++ b/context.c
@@ -199,7 +199,10 @@ void ctx_update_tables(struct Context *ctx, bool committing)
       }
 
       if (committing)
+      {
         m->emails[j]->changed = false;
+        m->emails[j]->env->changed = false;
+      }
       else if (m->emails[j]->changed)
         m->changed = true;
 
diff --git a/copy.c b/copy.c
index e32b929fd1e5141f3e1f8f729ab990a9f0a496bd..7b1131f186bc0eae962d2cdb7353b9d296660ac2 100644 (file)
--- a/copy.c
+++ b/copy.c
@@ -409,8 +409,8 @@ int mutt_copy_header(FILE *in, struct Email *e, FILE *out, int flags, const char
 
   if (e->env)
   {
-    flags |= (e->env->irt_changed ? CH_UPDATE_IRT : 0) |
-             (e->env->refs_changed ? CH_UPDATE_REFS : 0);
+    flags |= ((e->env->changed & MUTT_ENV_CHANGED_IRT) ? CH_UPDATE_IRT : 0) |
+             ((e->env->changed & MUTT_ENV_CHANGED_REFS) ? CH_UPDATE_REFS : 0);
   }
 
   if (mutt_copy_hdr(in, out, e->offset, e->content->offset, flags, prefix) == -1)
index be45696e55f649d110520a57f9a2e20eb8b8db46..8b0abad2832f880b4f57fb65e324df5b94248ff0 100644 (file)
@@ -128,11 +128,11 @@ void mutt_env_merge(struct Envelope *base, struct Envelope **extra)
   MOVE_ELEM(date);
   MOVE_ELEM(x_label);
   MOVE_ELEM(x_original_to);
-  if (!base->refs_changed)
+  if (!(base->changed & MUTT_ENV_CHANGED_REFS))
   {
     MOVE_STAILQ(references);
   }
-  if (!base->irt_changed)
+  if (!(base->changed & MUTT_ENV_CHANGED_IRT))
   {
     MOVE_STAILQ(in_reply_to);
   }
index c0f2e6353229ad2bc2224c8903daf7a16b86a31a..f64f482643ab7d5ddcac52870694d70e4ea800ce 100644 (file)
@@ -26,6 +26,9 @@
 #include <stdbool.h>
 #include "mutt/mutt.h"
 
+#define MUTT_ENV_CHANGED_IRT   (1<<0)  /* In-Reply-To changed to link/break threads */
+#define MUTT_ENV_CHANGED_REFS  (1<<1)  /* References changed to break thread */
+
 /**
  * struct Envelope - The header of an email
  */
@@ -60,8 +63,8 @@ struct Envelope
   struct ListHead in_reply_to; /**< in-reply-to header content */
   struct ListHead userhdrs;    /**< user defined headers */
 
-  bool irt_changed : 1;  /**< In-Reply-To changed to link/break threads */
-  bool refs_changed : 1; /**< References changed to break thread */
+  unsigned char changed;       /* The MUTT_ENV_CHANGED_* flags specify which
+                                * fields are modified */
 };
 
 bool             mutt_env_cmp_strict(const struct Envelope *e1, const struct Envelope *e2);
index 2b4443cd326f1814a710f69f843d3860e1068347..2e332c17cefee4dd48e65fe67e3ea20c93068fe8 100644 (file)
@@ -204,8 +204,8 @@ void clean_references(struct MuttThread *brk, struct MuttThread *cur)
         FREE(&np);
       }
 
-      e->env->refs_changed = true;
       e->changed = true;
+      e->env->changed |= MUTT_ENV_CHANGED_REFS;
     }
   }
 }
@@ -218,9 +218,8 @@ void mutt_break_thread(struct Email *e)
 {
   mutt_list_free(&e->env->in_reply_to);
   mutt_list_free(&e->env->references);
-  e->env->irt_changed = true;
-  e->env->refs_changed = true;
   e->changed = true;
+  e->env->changed |= (MUTT_ENV_CHANGED_IRT | MUTT_ENV_CHANGED_REFS);
 
   clean_references(e->thread, e->thread->child);
 }
index e18324c8b60134961e4c48c55f6207022c6a1466..a6cdb20b65c1bbe879a18fc3954701ce8634f890 100644 (file)
@@ -1696,14 +1696,16 @@ int imap_sync_mailbox(struct Mailbox *m, bool expunge, bool close)
       /* if the message has been rethreaded or attachments have been deleted
        * we delete the message and reupload it.
        * This works better if we're expunging, of course. */
-      if ((e->env && (e->env->refs_changed || e->env->irt_changed)) ||
-          e->attach_del || e->xlabel_changed)
+      if ((e->env && e->env->changed) || e->attach_del || e->xlabel_changed)
       {
         /* L10N: The plural is choosen by the last %d, i.e. the total number */
         mutt_message(ngettext("Saving changed message... [%d/%d]",
                               "Saving changed messages... [%d/%d]", m->msg_count),
                      i + 1, m->msg_count);
         mutt_save_message_ctx(e, true, false, false, m);
+        /* TODO: why the check for h->env?  Is this possible? */
+        if (e->env)
+          e->env->changed = 0;
         e->xlabel_changed = false;
       }
     }
index 6532eb73d7471ef257c60306b9de54f3733abdf2..3da89811ec826eae2d428d61e7d9260fbf04d277 100644 (file)
@@ -222,12 +222,15 @@ int maildir_sync_message(struct Mailbox *m, int msgno)
   char suffix[16];
   int rc = 0;
 
-  if (e->attach_del || e->xlabel_changed ||
-      (e->env && (e->env->refs_changed || e->env->irt_changed)))
+  /* TODO: why the h->env check? */
+  if (e->attach_del || e->xlabel_changed || (e->env && e->env->changed))
   {
     /* when doing attachment deletion/rethreading, fall back to the MH case. */
     if (mh_rewrite_message(m, msgno) != 0)
       return -1;
+    /* TODO: why the env check? */
+    if (e->env)
+      e->env->changed = 0;
   }
   else
   {
index 2f4a6bf75ac93cb3a2669c1430eec7bf8881a96c..88602232704a1977510f0876db5052a8fbadba4b 100644 (file)
@@ -528,11 +528,14 @@ int mh_sync_message(struct Mailbox *m, int msgno)
 
   struct Email *e = m->emails[msgno];
 
-  if (e->attach_del || e->xlabel_changed ||
-      (e->env && (e->env->refs_changed || e->env->irt_changed)))
+  /* TODO: why the e->env check? */
+  if (e->attach_del || e->xlabel_changed || (e->env && e->env->changed))
   {
     if (mh_rewrite_message(m, msgno) != 0)
       return -1;
+    /* TODO: why the env check? */
+    if (e->env)
+      e->env->changed = 0;
   }
 
   return 0;
index d61bd0f0462f3b5e282cf10662a1dfb7e8ef810c..5478e1522f76618ee018bf29d362b361a20d264e 100644 (file)
@@ -1465,8 +1465,8 @@ static bool link_threads(struct Email *parent, struct Email *child, struct Mailb
   mutt_list_insert_head(&child->env->in_reply_to, mutt_str_strdup(parent->env->message_id));
   mutt_set_flag(m, child, MUTT_TAG, 0);
 
-  child->env->irt_changed = true;
   child->changed = true;
+  child->env->changed |= MUTT_ENV_CHANGED_IRT;
   return true;
 }