]> granicus.if.org Git - neomutt/commitdiff
postpone: Don't reopen Postponed context
authorMehdi Abaakouk <sileht@sileht.net>
Wed, 21 Nov 2018 11:32:24 +0000 (12:32 +0100)
committerRichard Russon <rich@flatcap.org>
Thu, 29 Nov 2018 13:17:02 +0000 (13:17 +0000)
If the selected Mailbox is already the Postponed one, no need to open a
new context.

This change reuse the current context.

postpone.c

index 2994a06d52c4ee73e38d4eebe5d0226c44613451..0c84f5949720bccb08a8c7246a3d9ff1ccc7b90b 100644 (file)
@@ -287,7 +287,12 @@ int mutt_get_postponed(struct Context *ctx, struct Email *hdr,
   if (!Postponed)
     return -1;
 
-  PostContext = mx_mbox_open(NULL, Postponed, MUTT_NOSORT);
+  struct Mailbox *m = mx_mbox_find2(Postponed);
+  if (ctx->mailbox == m)
+    PostContext = ctx;
+  else
+    PostContext = mx_mbox_open(m, Postponed, MUTT_NOSORT);
+
   if (!PostContext)
   {
     PostCount = 0;
@@ -298,7 +303,10 @@ int mutt_get_postponed(struct Context *ctx, struct Email *hdr,
   if (!PostContext->mailbox->msg_count)
   {
     PostCount = 0;
-    mx_mbox_close(&PostContext, NULL);
+    if (PostContext == ctx)
+      PostContext = NULL;
+    else
+      mx_mbox_close(&PostContext, NULL);
     mutt_error(_("No postponed messages"));
     return -1;
   }
@@ -310,14 +318,20 @@ int mutt_get_postponed(struct Context *ctx, struct Email *hdr,
   }
   else if (!(e = select_msg()))
   {
-    mx_mbox_close(&PostContext, NULL);
+    if (PostContext == ctx)
+      PostContext = NULL;
+    else
+      mx_mbox_close(&PostContext, NULL);
     return -1;
   }
 
   if (mutt_prepare_template(NULL, PostContext->mailbox, hdr, e, false) < 0)
   {
-    mx_fastclose_mailbox(PostContext);
-    FREE(&PostContext);
+    if (PostContext != ctx)
+    {
+      mx_fastclose_mailbox(PostContext);
+      FREE(&PostContext);
+    }
     return -1;
   }
 
@@ -331,7 +345,10 @@ int mutt_get_postponed(struct Context *ctx, struct Email *hdr,
   /* avoid the "purge deleted messages" prompt */
   opt_delete = Delete;
   Delete = MUTT_YES;
-  mx_mbox_close(&PostContext, NULL);
+  if (PostContext == ctx)
+    PostContext = NULL;
+  else
+    mx_mbox_close(&PostContext, NULL);
   Delete = opt_delete;
 
   struct ListNode *np, *tmp;