From 1dd7f017d2e5b86a69feeec4d144d3e9bc8edac1 Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Tue, 2 Apr 2019 12:47:27 +0000 Subject: [PATCH] fix pop_fetch_mail() 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 | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pop/pop.c b/pop/pop.c index 84430e596..e6101acec 100644 --- 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) -- 2.50.0