From c9dd74b97f5e7c48af384adb7d645a7184a639b4 Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Mon, 1 Apr 2019 14:09:14 +0000 Subject: [PATCH] fix ev_message() 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 | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/editmsg.c b/editmsg.c index 063fb4f78..835d16234 100644 --- 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; } -- 2.40.0