changeset: 6685:3ec6c133641c user: Damien Riegel <damien.rie...@gmail.com> date: Sat Jun 18 12:41:42 2016 -0700 link: http://dev.mutt.org/hg/mutt/rev/3ec6c133641c
pass context in mx_close_message The mx_close_message is one of the few mx_* functions that don't have a context as parameter. To make them more consistent, pass the context. changeset: 6686:4bab14a24dbe user: Damien Riegel <damien.rie...@gmail.com> date: Sat Jun 18 12:41:43 2016 -0700 link: http://dev.mutt.org/hg/mutt/rev/4bab14a24dbe Remove magic member in MESSAGE structure The "magic" was copied from the context to the message structure to be able to determine which close function had to be called in mx_close_message. Now that this function is context aware, there is no need to store the magic in the MESSAGE structure and it can be safely removed. changeset: 6687:ce2e5caf4339 user: Damien Riegel <damien.rie...@gmail.com> date: Sat Jun 18 12:41:45 2016 -0700 link: http://dev.mutt.org/hg/mutt/rev/ce2e5caf4339 add close_msg to struct mx_ops diffs (426 lines): diff -r 70eb7e0dbb58 -r ce2e5caf4339 attach.c --- a/attach.c Fri Jun 17 19:01:31 2016 -0700 +++ b/attach.c Sat Jun 18 12:41:45 2016 -0700 @@ -745,7 +745,7 @@ else r = -1; - mx_close_message (&msg); + mx_close_message (&ctx, &msg); mx_close_mailbox (&ctx, NULL); return r; } diff -r 70eb7e0dbb58 -r ce2e5caf4339 commands.c --- a/commands.c Fri Jun 17 19:01:31 2016 -0700 +++ b/commands.c Sat Jun 18 12:41:45 2016 -0700 @@ -993,7 +993,7 @@ } h->security |= PGP_TRADITIONAL_CHECKED; - mx_close_message (&msg); + mx_close_message (Context, &msg); return rv; } diff -r 70eb7e0dbb58 -r ce2e5caf4339 copy.c --- a/copy.c Fri Jun 17 19:01:31 2016 -0700 +++ b/copy.c Sat Jun 18 12:41:45 2016 -0700 @@ -692,7 +692,7 @@ dprint (1, (debugfile, "_mutt_copy_message failed to detect EOF!\n")); r = -1; } - mx_close_message (&msg); + mx_close_message (src, &msg); return r; } @@ -728,7 +728,7 @@ if (mx_commit_message (msg, dest) != 0) r = -1; - mx_close_message (&msg); + mx_close_message (dest, &msg); return r; } @@ -742,7 +742,7 @@ if ((msg = mx_open_message (src, hdr->msgno)) == NULL) return -1; r = _mutt_append_message (dest, msg->fp, src, hdr, hdr->content, cmflags, chflags); - mx_close_message (&msg); + mx_close_message (src, &msg); return r; } diff -r 70eb7e0dbb58 -r ce2e5caf4339 editmsg.c --- a/editmsg.c Fri Jun 17 19:01:31 2016 -0700 +++ b/editmsg.c Sat Jun 18 12:41:45 2016 -0700 @@ -187,7 +187,7 @@ } rc = mx_commit_message (msg, &tmpctx); - mx_close_message (&msg); + mx_close_message (&tmpctx, &msg); mx_close_mailbox (&tmpctx, NULL); diff -r 70eb7e0dbb58 -r ce2e5caf4339 imap/imap.c --- a/imap/imap.c Fri Jun 17 19:01:31 2016 -0700 +++ b/imap/imap.c Sat Jun 18 12:41:45 2016 -0700 @@ -2075,6 +2075,7 @@ .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 -r 70eb7e0dbb58 -r ce2e5caf4339 imap/imap_private.h --- a/imap/imap_private.h Fri Jun 17 19:01:31 2016 -0700 +++ b/imap/imap_private.h Sat Jun 18 12:41:45 2016 -0700 @@ -269,6 +269,7 @@ 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 -r 70eb7e0dbb58 -r ce2e5caf4339 imap/message.c --- a/imap/message.c Fri Jun 17 19:01:31 2016 -0700 +++ b/imap/message.c Sat Jun 18 12:41:45 2016 -0700 @@ -595,6 +595,11 @@ 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 -r 70eb7e0dbb58 -r ce2e5caf4339 mailbox.h --- a/mailbox.h Fri Jun 17 19:01:31 2016 -0700 +++ b/mailbox.h Sat Jun 18 12:41:45 2016 -0700 @@ -45,7 +45,6 @@ { FILE *fp; /* pointer to the message data */ char *path; /* path to temp file */ - short magic; /* type of mailbox this message belongs to */ short write; /* nonzero if message is open for writing */ struct { unsigned read : 1; @@ -66,7 +65,7 @@ int mx_close_mailbox (CONTEXT *, int *); int mx_sync_mailbox (CONTEXT *, int *); int mx_commit_message (MESSAGE *, CONTEXT *); -int mx_close_message (MESSAGE **); +int mx_close_message (CONTEXT *, MESSAGE **); int mx_get_magic (const char *); int mx_set_magic (const char *); int mx_check_mailbox (CONTEXT *, int *); diff -r 70eb7e0dbb58 -r ce2e5caf4339 mbox.c --- a/mbox.c Fri Jun 17 19:01:31 2016 -0700 +++ b/mbox.c Sat Jun 18 12:41:45 2016 -0700 @@ -454,6 +454,13 @@ 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 @@ .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 @@ .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 -r 70eb7e0dbb58 -r ce2e5caf4339 mh.c --- a/mh.c Fri Jun 17 19:01:31 2016 -0700 +++ b/mh.c Sat Jun 18 12:41:45 2016 -0700 @@ -1369,6 +1369,11 @@ 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. * @@ -1656,7 +1661,7 @@ else rc = _mh_commit_message (ctx, dest, h, 0); - mx_close_message (&dest); + mx_close_message (ctx, &dest); if (rc == 0) { @@ -1687,7 +1692,7 @@ } } else - mx_close_message (&dest); + mx_close_message (ctx, &dest); if (rc == -1 && restore) { @@ -2445,6 +2450,7 @@ .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 @@ .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 -r 70eb7e0dbb58 -r ce2e5caf4339 mutt.h --- a/mutt.h Fri Jun 17 19:01:31 2016 -0700 +++ b/mutt.h Sat Jun 18 12:41:45 2016 -0700 @@ -895,6 +895,7 @@ 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 -r 70eb7e0dbb58 -r ce2e5caf4339 mx.c --- a/mx.c Fri Jun 17 19:01:31 2016 -0700 +++ b/mx.c Sat Jun 18 12:41:45 2016 -0700 @@ -1245,7 +1245,6 @@ } msg = safe_calloc (1, sizeof (MESSAGE)); - msg->magic = dest->magic; msg->write = 1; if (hdr) @@ -1265,7 +1264,7 @@ if (dest->magic == MUTT_MMDF) fputs (MMDF_SEP, msg->fp); - if ((msg->magic == MUTT_MBOX || msg->magic == MUTT_MMDF) && + if ((dest->magic == MUTT_MBOX || dest->magic == MUTT_MMDF) && flags & MUTT_ADD_FROM) { if (hdr) @@ -1319,7 +1318,6 @@ } msg = safe_calloc (1, sizeof (MESSAGE)); - msg->magic = ctx->magic; ret = ops->open_msg (ctx, msg, msgno); if (ret) FREE (&msg); @@ -1340,7 +1338,7 @@ return -1; } - switch (msg->magic) + switch (ctx->magic) { case MUTT_MMDF: { @@ -1389,22 +1387,18 @@ } /* close a pointer to a message */ -int mx_close_message (MESSAGE **msg) +int mx_close_message (CONTEXT *ctx, MESSAGE **msg) { + struct mx_ops *ops = mx_get_ops (ctx->magic); int r = 0; - if ((*msg)->magic == MUTT_MH || (*msg)->magic == MUTT_MAILDIR - || (*msg)->magic == MUTT_IMAP || (*msg)->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 -r 70eb7e0dbb58 -r ce2e5caf4339 parse.c --- a/parse.c Fri Jun 17 19:01:31 2016 -0700 +++ b/parse.c Sat Jun 18 12:41:45 2016 -0700 @@ -969,7 +969,7 @@ if (WithCrypto) cur->security = crypt_query (cur->content); - mx_close_message (&msg); + mx_close_message (ctx, &msg); } } while (0); diff -r 70eb7e0dbb58 -r ce2e5caf4339 pattern.c --- a/pattern.c Fri Jun 17 19:01:31 2016 -0700 +++ b/pattern.c Sat Jun 18 12:41:45 2016 -0700 @@ -180,7 +180,7 @@ if (WithCrypto && (h->security & ENCRYPT) && !crypt_valid_passphrase(h->security)) { - mx_close_message (&msg); + mx_close_message (ctx, &msg); if (s.fpout) { safe_fclose (&s.fpout); @@ -239,7 +239,7 @@ FREE (&buf); - mx_close_message (&msg); + mx_close_message (ctx, &msg); if (option (OPTTHOROUGHSRC)) { diff -r 70eb7e0dbb58 -r ce2e5caf4339 pop.c --- a/pop.c Fri Jun 17 19:01:31 2016 -0700 +++ b/pop.c Sat Jun 18 12:41:45 2016 -0700 @@ -656,6 +656,11 @@ 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) { @@ -874,7 +879,7 @@ ret = -3; } - mx_close_message (&msg); + mx_close_message (&ctx, &msg); } if (ret == 0 && delanswer == MUTT_YES) @@ -932,5 +937,6 @@ .open = pop_open_mailbox, .close = pop_close_mailbox, .open_msg = pop_fetch_message, + .close_msg = pop_close_message, .check = pop_check_mailbox, }; diff -r 70eb7e0dbb58 -r ce2e5caf4339 postpone.c --- a/postpone.c Fri Jun 17 19:01:31 2016 -0700 +++ b/postpone.c Sat Jun 18 12:41:45 2016 -0700 @@ -586,7 +586,7 @@ || b == NULL) { err: - mx_close_message (&msg); + mx_close_message (ctx, &msg); mutt_free_envelope (&newhdr->env); mutt_free_body (&newhdr->content); mutt_error _("Decryption failed."); @@ -735,7 +735,7 @@ /* that's it. */ if (bfp != fp) safe_fclose (&bfp); - if (msg) mx_close_message (&msg); + if (msg) mx_close_message (ctx, &msg); if (rv == -1) { diff -r 70eb7e0dbb58 -r ce2e5caf4339 recvattach.c --- a/recvattach.c Fri Jun 17 19:01:31 2016 -0700 +++ b/recvattach.c Sat Jun 18 12:41:45 2016 -0700 @@ -966,7 +966,7 @@ if ((hdr->security & ENCRYPT) && !crypt_valid_passphrase(hdr->security)) { - mx_close_message (&msg); + mx_close_message (Context, &msg); return; } if ((WithCrypto & APPLICATION_SMIME) && (hdr->security & APPLICATION_SMIME)) @@ -1006,7 +1006,7 @@ if (need_secured && !secured) { - mx_close_message (&msg); + mx_close_message (Context, &msg); mutt_error _("Can't decrypt encrypted message!"); return; } @@ -1239,7 +1239,7 @@ break; case OP_EXIT: - mx_close_message (&msg); + mx_close_message (Context, &msg); hdr->attach_del = 0; while (idxmax-- > 0) { diff -r 70eb7e0dbb58 -r ce2e5caf4339 sendlib.c --- a/sendlib.c Fri Jun 17 19:01:31 2016 -0700 +++ b/sendlib.c Sat Jun 18 12:41:45 2016 -0700 @@ -2573,7 +2573,7 @@ } if (msg) - mx_close_message (&msg); + mx_close_message (Context, &msg); return ret; } @@ -2847,7 +2847,7 @@ safe_fclose (&tempfp); unlink (tempfile); mx_commit_message (msg, &f); /* XXX - really? */ - mx_close_message (&msg); + mx_close_message (&f, &msg); mx_close_mailbox (&f, NULL); return -1; } @@ -2876,7 +2876,7 @@ if (mx_commit_message (msg, &f) != 0) r = -1; - mx_close_message (&msg); + mx_close_message (&f, &msg); mx_close_mailbox (&f, NULL); if (!post && need_buffy_cleanup)