From: Damien Riegel Date: Sat, 18 Jun 2016 19:41:45 +0000 (-0700) Subject: add close_msg to struct mx_ops X-Git-Tag: neomutt-20160822~111 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=591fafb36a3fef31d0128ba33870c0bfaaf6d04a;p=neomutt add close_msg to struct mx_ops --- diff --git a/imap/imap.c b/imap/imap.c index 87a9ed59e..ef9c46855 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -2075,6 +2075,7 @@ struct mx_ops mx_imap_ops = { .open = imap_open_mailbox, .close = imap_close_mailbox, .open_msg = imap_fetch_message, + .close_msg = imap_close_message, .open_new_msg = imap_open_new_message, .check = imap_check_mailbox_reopen, }; diff --git a/imap/imap_private.h b/imap/imap_private.h index f5dd83f30..8cd610adf 100644 --- a/imap/imap_private.h +++ b/imap/imap_private.h @@ -269,6 +269,7 @@ int imap_cache_del (IMAP_DATA* idata, HEADER* h); int imap_cache_clean (IMAP_DATA* idata); int imap_fetch_message (CONTEXT *ctx, MESSAGE *msg, int msgno); +int imap_close_message (CONTEXT *ctx, MESSAGE *msg); /* util.c */ #ifdef USE_HCACHE diff --git a/imap/message.c b/imap/message.c index f63161715..917e98773 100644 --- a/imap/message.c +++ b/imap/message.c @@ -595,6 +595,11 @@ bail: return -1; } +int imap_close_message (CONTEXT *ctx, MESSAGE *msg) +{ + return safe_fclose (&msg->fp); +} + int imap_append_message (CONTEXT *ctx, MESSAGE *msg) { IMAP_DATA* idata; diff --git a/mbox.c b/mbox.c index 5d9235fb2..e0b79a1ae 100644 --- a/mbox.c +++ b/mbox.c @@ -454,6 +454,13 @@ static int mbox_open_message (CONTEXT *ctx, MESSAGE *msg, int msgno) return 0; } +static int mbox_close_message (CONTEXT *ctx, MESSAGE *msg) +{ + msg->fp = NULL; + + return 0; +} + static int mbox_open_new_message (MESSAGE *msg, CONTEXT *dest, HEADER *hdr) { msg->fp = dest->fp; @@ -1282,6 +1289,7 @@ struct mx_ops mx_mbox_ops = { .open = mbox_open_mailbox, .close = mbox_close_mailbox, .open_msg = mbox_open_message, + .close_msg = mbox_close_message, .open_new_msg = mbox_open_new_message, .check = mbox_check_mailbox, }; @@ -1290,6 +1298,7 @@ struct mx_ops mx_mmdf_ops = { .open = mbox_open_mailbox, .close = mbox_close_mailbox, .open_msg = mbox_open_message, + .close_msg = mbox_close_message, .open_new_msg = mbox_open_new_message, .check = mbox_check_mailbox, }; diff --git a/mh.c b/mh.c index 45496508e..417957134 100644 --- a/mh.c +++ b/mh.c @@ -1369,6 +1369,11 @@ static int mh_open_message (CONTEXT *ctx, MESSAGE *msg, int msgno) return maildir_mh_open_message (ctx, msg, msgno, 0); } +static int mh_close_message (CONTEXT *ctx, MESSAGE *msg) +{ + return safe_fclose (&msg->fp); +} + /* * Open a new (temporary) message in a maildir folder. * @@ -2445,6 +2450,7 @@ struct mx_ops mx_maildir_ops = { .open = maildir_open_mailbox, .close = mh_close_mailbox, .open_msg = maildir_open_message, + .close_msg = mh_close_message, .open_new_msg = maildir_open_new_message, .check = maildir_check_mailbox, }; @@ -2453,6 +2459,7 @@ struct mx_ops mx_mh_ops = { .open = mh_open_mailbox, .close = mh_close_mailbox, .open_msg = mh_open_message, + .close_msg = mh_close_message, .open_new_msg = mh_open_new_message, .check = mh_check_mailbox, }; diff --git a/mutt.h b/mutt.h index 74cede325..8b2d9eae3 100644 --- a/mutt.h +++ b/mutt.h @@ -895,6 +895,7 @@ struct mx_ops int (*close)(struct _context *); int (*check) (struct _context *ctx, int *index_hint); int (*open_msg) (struct _context *, struct _message *, int msgno); + int (*close_msg) (struct _context *, struct _message *); int (*open_new_msg) (struct _message *, struct _context *, HEADER *); }; diff --git a/mx.c b/mx.c index e6760a768..01ac627e7 100644 --- a/mx.c +++ b/mx.c @@ -1389,20 +1389,16 @@ int mx_commit_message (MESSAGE *msg, CONTEXT *ctx) /* close a pointer to a message */ int mx_close_message (CONTEXT *ctx, MESSAGE **msg) { + struct mx_ops *ops = mx_get_ops (ctx->magic); int r = 0; - if (ctx->magic == MUTT_MH || ctx->magic == MUTT_MAILDIR - || ctx->magic == MUTT_IMAP || ctx->magic == MUTT_POP) - { - r = safe_fclose (&(*msg)->fp); - } - else - (*msg)->fp = NULL; + if (ops && ops->close_msg) + r = ops->close_msg (ctx, *msg); if ((*msg)->path) { dprint (1, (debugfile, "mx_close_message (): unlinking %s\n", - (*msg)->path)); + (*msg)->path)); unlink ((*msg)->path); FREE (&(*msg)->path); } diff --git a/pop.c b/pop.c index bccdc9b90..9e0a14597 100644 --- a/pop.c +++ b/pop.c @@ -656,6 +656,11 @@ static int pop_fetch_message (CONTEXT* ctx, MESSAGE* msg, int msgno) return 0; } +static int pop_close_message (CONTEXT *ctx, MESSAGE *msg) +{ + return safe_fclose (&msg->fp); +} + /* update POP mailbox - delete messages from server */ int pop_sync_mailbox (CONTEXT *ctx, int *index_hint) { @@ -932,5 +937,6 @@ struct mx_ops mx_pop_ops = { .open = pop_open_mailbox, .close = pop_close_mailbox, .open_msg = pop_fetch_message, + .close_msg = pop_close_message, .check = pop_check_mailbox, };