]> granicus.if.org Git - neomutt/commitdiff
fix pop_fetch_mail()
authorRichard Russon <rich@flatcap.org>
Tue, 2 Apr 2019 12:47:27 +0000 (12:47 +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.

pop/pop.c

index 84430e59641bb018d440feeafeaae30e038bca16..e6101acec9a1354ceb375953a66bc5384d544b1b 100644 (file)
--- a/pop/pop.c
+++ b/pop/pop.c
@@ -648,13 +648,16 @@ void pop_fetch_mail(void)
   }
 
   struct Mailbox *m_spool = mx_path_resolve(C_Spoolfile);
-  struct Context *ctx = mx_mbox_open(m_spool, MUTT_APPEND);
+  struct Context *ctx = mx_mbox_open(m_spool, MUTT_OPEN_NO_FLAGS);
   if (!ctx)
   {
     mailbox_free(&m_spool);
     goto finish;
   }
 
+  bool old_append = m_spool->append;
+  m_spool->append = true;
+
   enum QuadOption delanswer =
       query_quadoption(C_PopDelete, _("Delete messages from server?"));
 
@@ -694,6 +697,7 @@ void pop_fetch_mail(void)
 
     if (ret == -1)
     {
+      m_spool->append = old_append;
       mx_mbox_close(&ctx);
       goto fail;
     }
@@ -715,6 +719,7 @@ void pop_fetch_mail(void)
                  msgbuf, i - last, msgs - last);
   }
 
+  m_spool->append = old_append;
   mx_mbox_close(&ctx);
 
   if (rset)