]> granicus.if.org Git - neomutt/commitdiff
fix ev_message()
authorRichard Russon <rich@flatcap.org>
Mon, 1 Apr 2019 14:09:14 +0000 (14:09 +0000)
committerRichard Russon <rich@flatcap.org>
Tue, 9 Apr 2019 13:16:04 +0000 (14:16 +0100)
Prevent a crash when reopening a Mailbox.

> How exactly do these changes prevent the crash from occurring?

It's all about how mx_mbox_open() handles flags.  These four examples
are where we have a Mailbox open in 'normal' mode and try to open it
again in 'append' mode.

'Append' mode only makes sense for 'mbox' and 'compress', but the flag
affects mx_mbox_open(). It causes the function to create a duplicate
Mailbox, which is then used and discarded. The original Mailbox is now
out of sync.

The workaround, simply hides the flag for mx_mbox_open(), but
temporarily sets the internal bool append. This means that we work with
one Mailbox.

editmsg.c

index 063fb4f781f5c2a5afec14b8f0c03b725b28a536..835d16234e77f16ef11fe4d1356c4ca3db120ca8 100644 (file)
--- a/editmsg.c
+++ b/editmsg.c
@@ -63,6 +63,7 @@ static int ev_message(enum EvMessage action, struct Mailbox *m, struct Email *e)
   char buf[256];
   int rc;
   struct stat sb;
+  bool old_append = m->append;
 
   mutt_mktemp(fname, sizeof(fname));
 
@@ -173,7 +174,7 @@ static int ev_message(enum EvMessage action, struct Mailbox *m, struct Email *e)
     goto bail;
   }
 
-  struct Context *ctx_app = mx_mbox_open(m, MUTT_APPEND);
+  struct Context *ctx_app = mx_mbox_open(m, MUTT_OPEN_NO_FLAGS);
   if (!ctx_app)
   {
     rc = -1;
@@ -182,6 +183,9 @@ static int ev_message(enum EvMessage action, struct Mailbox *m, struct Email *e)
     goto bail;
   }
 
+  old_append = m->append;
+  m->append = true;
+
   MsgOpenFlags of = MUTT_MSG_NO_FLAGS;
   CopyHeaderFlags cf =
       (((ctx_app->mailbox->magic == MUTT_MBOX) || (ctx_app->mailbox->magic == MUTT_MMDF)) ?
@@ -244,6 +248,7 @@ bail:
   else if (rc == -1)
     mutt_message(_("Error. Preserving temporary file: %s"), fname);
 
+  m->append = old_append;
   return rc;
 }