]> granicus.if.org Git - neomutt/commitdiff
mx_fastclose_mailbox: factor out Context
authorRichard Russon <rich@flatcap.org>
Sun, 23 Dec 2018 00:06:32 +0000 (00:06 +0000)
committerRichard Russon <rich@flatcap.org>
Sat, 5 Jan 2019 14:44:35 +0000 (14:44 +0000)
compose.c
imap/command.c
index.c
mbox/mbox.c
mx.c
mx.h
postpone.c

index 365982a584c8216395aa26736703a63e3458afce..d93b2a4e91bdf03460b6e3b6317929d4e0206459 100644 (file)
--- a/compose.c
+++ b/compose.c
@@ -1507,7 +1507,7 @@ int mutt_compose_menu(struct Email *msg, char *fcc, size_t fcclen, struct Email
           mx_mbox_close(&Context, NULL);
         else
         {
-          mx_fastclose_mailbox(Context);
+          mx_fastclose_mailbox(Context->mailbox);
           mutt_context_free(&Context);
         }
 
index c1e26f81dc83d68d6e133f09107bec89556bda43..ce724f3ceb673706eafcd75dd8065c081a6cbe74 100644 (file)
@@ -165,7 +165,7 @@ static void cmd_handle_fatal(struct ImapAccountData *adata)
 
   if (adata->state >= IMAP_SELECTED && (mdata->reopen & IMAP_REOPEN_ALLOW))
   {
-    mx_fastclose_mailbox(mdata->ctx);
+    mx_fastclose_mailbox(adata->mailbox);
     mutt_socket_close(adata->conn);
     mutt_error(_("Mailbox %s@%s closed"), adata->conn->account.user,
                adata->conn->account.host);
diff --git a/index.c b/index.c
index 071b24ebd1a69064981bc298beb0341259c96cb6..5f9b0eef923527987df494d2ec692a41a7c1c929 100644 (file)
--- a/index.c
+++ b/index.c
@@ -2331,7 +2331,7 @@ int mutt_index_menu(void)
         {
           if (Context)
           {
-            mx_fastclose_mailbox(Context);
+            mx_fastclose_mailbox(Context->mailbox);
             mutt_context_free(&Context);
           }
           done = true;
index 1860582dd2249df54c1b880baee00cd1a418a7e5..3f1f749951f7d23d81f810aaba02b2933cf8edaa 100644 (file)
@@ -1124,7 +1124,7 @@ static int mbox_mbox_check(struct Context *ctx, int *index_hint)
   /* fatal error */
 
   mbox_unlock_mailbox(m);
-  mx_fastclose_mailbox(ctx);
+  mx_fastclose_mailbox(m);
   mutt_sig_unblock();
   mutt_error(_("Mailbox was corrupted"));
   return -1;
@@ -1175,7 +1175,7 @@ static int mbox_mbox_sync(struct Context *ctx, int *index_hint)
   adata->fp = freopen(m->path, "r+", adata->fp);
   if (!adata->fp)
   {
-    mx_fastclose_mailbox(ctx);
+    mx_fastclose_mailbox(m);
     mutt_error(_("Fatal error!  Could not reopen mailbox!"));
     return -1;
   }
@@ -1353,7 +1353,7 @@ static int mbox_mbox_sync(struct Context *ctx, int *index_hint)
   if (!fp)
   {
     mutt_sig_unblock();
-    mx_fastclose_mailbox(ctx);
+    mx_fastclose_mailbox(m);
     mutt_debug(1, "unable to reopen temp copy of mailbox!\n");
     mutt_perror(tempfile);
     FREE(&new_offset);
@@ -1417,7 +1417,7 @@ static int mbox_mbox_sync(struct Context *ctx, int *index_hint)
              NONULL(Username), NONULL(ShortHostname), (unsigned int) getpid());
     rename(tempfile, savefile);
     mutt_sig_unblock();
-    mx_fastclose_mailbox(ctx);
+    mx_fastclose_mailbox(m);
     mutt_pretty_mailbox(savefile, sizeof(savefile));
     mutt_error(_("Write failed!  Saved partial mailbox to %s"), savefile);
     FREE(&new_offset);
@@ -1434,7 +1434,7 @@ static int mbox_mbox_sync(struct Context *ctx, int *index_hint)
   {
     unlink(tempfile);
     mutt_sig_unblock();
-    mx_fastclose_mailbox(ctx);
+    mx_fastclose_mailbox(m);
     mutt_error(_("Fatal error!  Could not reopen mailbox!"));
     FREE(&new_offset);
     FREE(&old_offset);
@@ -1494,7 +1494,7 @@ bail: /* Come here in case of disaster */
   if (!adata->fp)
   {
     mutt_error(_("Could not reopen mailbox"));
-    mx_fastclose_mailbox(ctx);
+    mx_fastclose_mailbox(m);
     return -1;
   }
 
diff --git a/mx.c b/mx.c
index 20e9e0ec700b834d0956838f2519914c168ad3b7..f5d559421a77784c564b48fa7795e84a3b7db919 100644 (file)
--- a/mx.c
+++ b/mx.c
@@ -355,7 +355,7 @@ struct Context *mx_mbox_open(struct Mailbox *m, const char *path, int flags)
   {
     if (mx_open_mailbox_append(ctx->mailbox, flags) != 0)
     {
-      mx_fastclose_mailbox(ctx);
+      mx_fastclose_mailbox(m);
       mutt_context_free(&ctx);
       return NULL;
     }
@@ -378,7 +378,7 @@ struct Context *mx_mbox_open(struct Mailbox *m, const char *path, int flags)
     else if (m->magic == MUTT_UNKNOWN || !m->mx_ops)
       mutt_error(_("%s is not a mailbox"), path);
 
-    mx_fastclose_mailbox(ctx);
+    mx_fastclose_mailbox(m);
     mutt_context_free(&ctx);
     return NULL;
   }
@@ -417,7 +417,7 @@ struct Context *mx_mbox_open(struct Mailbox *m, const char *path, int flags)
   }
   else
   {
-    mx_fastclose_mailbox(ctx);
+    mx_fastclose_mailbox(m);
     mutt_context_free(&ctx);
   }
 
@@ -427,15 +427,13 @@ struct Context *mx_mbox_open(struct Mailbox *m, const char *path, int flags)
 
 /**
  * mx_fastclose_mailbox - free up memory associated with the mailbox context
- * @param ctx Mailbox
+ * @param m Mailbox
  */
-void mx_fastclose_mailbox(struct Context *ctx)
+void mx_fastclose_mailbox(struct Mailbox *m)
 {
-  if (!ctx || !ctx->mailbox)
+  if (!m)
     return;
 
-  struct Mailbox *m = ctx->mailbox;
-
   m->opened--;
   if (m->opened != 0)
     return;
@@ -611,7 +609,7 @@ int mx_mbox_close(struct Context **pctx, int *index_hint)
 
   if (m->readonly || m->dontwrite || m->append)
   {
-    mx_fastclose_mailbox(ctx);
+    mx_fastclose_mailbox(m);
     FREE(pctx);
     return 0;
   }
@@ -765,7 +763,7 @@ int mx_mbox_close(struct Context **pctx, int *index_hint)
       mutt_message(_("Mailbox is unchanged"));
     if (m->magic == MUTT_MBOX || m->magic == MUTT_MMDF)
       mbox_reset_atime(m, NULL);
-    mx_fastclose_mailbox(ctx);
+    mx_fastclose_mailbox(m);
     FREE(pctx);
     return 0;
   }
@@ -840,7 +838,7 @@ int mx_mbox_close(struct Context **pctx, int *index_hint)
   }
 #endif
 
-  mx_fastclose_mailbox(ctx);
+  mx_fastclose_mailbox(m);
   FREE(pctx);
 
   return 0;
@@ -1049,7 +1047,7 @@ int mx_mbox_sync(struct Context *ctx, int *index_hint)
         !mutt_is_spool(m->path) && !SaveEmpty)
     {
       unlink(m->path);
-      mx_fastclose_mailbox(ctx);
+      mx_fastclose_mailbox(m);
       return 0;
     }
 
diff --git a/mx.h b/mx.h
index aa3608a6df3e223d2589e703c665e5c508145fce..2224767c7b3084160d085df2a13089db42d3c49f 100644 (file)
--- a/mx.h
+++ b/mx.h
@@ -288,7 +288,7 @@ int             mx_ac_remove (struct Mailbox *m);
 int                 mx_access           (const char *path, int flags);
 void                mx_alloc_memory     (struct Mailbox *m);
 int                 mx_check_empty      (const char *path);
-void                mx_fastclose_mailbox(struct Context *ctx);
+void                mx_fastclose_mailbox(struct Mailbox *m);
 const struct MxOps *mx_get_ops          (enum MailboxType magic);
 bool                mx_tags_is_supported(struct Mailbox *m);
 void                mx_update_context   (struct Context *ctx);
index 49d8bcd6dc0a6e6cdfed3010c5716b62152ccd29..e5ba3792a35756ce77f1aea503137c92a7bb9001 100644 (file)
@@ -175,7 +175,7 @@ int mutt_num_postponed(struct Mailbox *m, bool force)
       PostCount = 0;
     else
       PostCount = ctx->mailbox->msg_count;
-    mx_fastclose_mailbox(ctx);
+    mx_fastclose_mailbox(ctx->mailbox);
     mutt_context_free(&ctx);
 #ifdef USE_NNTP
     if (optnews)
@@ -337,7 +337,7 @@ int mutt_get_postponed(struct Context *ctx, struct Email *hdr,
   {
     if (PostContext != ctx)
     {
-      mx_fastclose_mailbox(PostContext);
+      mx_fastclose_mailbox(PostContext->mailbox);
       FREE(&PostContext);
     }
     return -1;