changeset: 6655:0ae29df8a81a user: Damien Riegel <dam...@riegel.io> date: Thu May 26 14:05:36 2016 -0700 link: http://dev.mutt.org/hg/mutt/rev/0ae29df8a81a
add function imap_check_mailbox_reopen In mx_check_mailbox, imap mailbox is the only function with a different prototype: it has an extra force argument. In order to move the check operation to the mx_ops structure, we need that all mailboxes have the same prototype. To do so, a new function imap_check_mailbox_reopen is added. changeset: 6656:a28ed1c725c6 user: Damien Riegel <dam...@riegel.io> date: Thu May 26 14:05:39 2016 -0700 link: http://dev.mutt.org/hg/mutt/rev/a28ed1c725c6 mx_check_mailbox: remove lock argument in function call This function is only called in one place with lock = 0. Basically, all code under if (lock) is dead code, so we can remove it, making the function simpler to factorize. changeset: 6657:2821e77c1a54 user: Damien Riegel <dam...@riegel.io> date: Thu May 26 14:05:42 2016 -0700 link: http://dev.mutt.org/hg/mutt/rev/2821e77c1a54 add check operation to struct mx_ops In mx_check_mailbox switch case, we simply call <mailbox>_check_mailbox, so this operation can be move into the mx_ops structure pretty easily. This commit adds a mandatory "check" operation to struct mx_ops and change all mailboxes to use it. Check functions are made static as they are only used in their respective source files now. diffs (267 lines): diff -r 261939e71d80 -r 2821e77c1a54 curs_main.c --- a/curs_main.c Wed May 25 15:58:04 2016 -0700 +++ b/curs_main.c Thu May 26 14:05:42 2016 -0700 @@ -549,7 +549,7 @@ index_hint = (Context->vcount && menu->current >= 0 && menu->current < Context->vcount) ? CURHDR->index : 0; - if ((check = mx_check_mailbox (Context, &index_hint, 0)) < 0) + if ((check = mx_check_mailbox (Context, &index_hint)) < 0) { if (!Context->path) { diff -r 261939e71d80 -r 2821e77c1a54 imap/imap.c --- a/imap/imap.c Wed May 25 15:58:04 2016 -0700 +++ b/imap/imap.c Thu May 26 14:05:42 2016 -0700 @@ -1464,6 +1464,17 @@ return result; } +static int imap_check_mailbox_reopen (CONTEXT *ctx, int *index_hint) +{ + int rc; + + imap_allow_reopen (ctx); + rc = imap_check_mailbox (ctx, index_hint, 0); + imap_disallow_reopen (ctx); + + return rc; +} + /* split path into (idata,mailbox name) */ static int imap_get_mailbox (const char* path, IMAP_DATA** hidata, char* buf, size_t blen) { @@ -2056,4 +2067,5 @@ .open = imap_open_mailbox, .close = imap_close_mailbox, .open_new_msg = imap_open_new_message, + .check = imap_check_mailbox_reopen, }; diff -r 261939e71d80 -r 2821e77c1a54 mailbox.h --- a/mailbox.h Wed May 25 15:58:04 2016 -0700 +++ b/mailbox.h Thu May 26 14:05:42 2016 -0700 @@ -69,7 +69,7 @@ int mx_close_message (MESSAGE **); int mx_get_magic (const char *); int mx_set_magic (const char *); -int mx_check_mailbox (CONTEXT *, int *, int); +int mx_check_mailbox (CONTEXT *, int *); #ifdef USE_IMAP int mx_is_imap (const char *); #endif diff -r 261939e71d80 -r 2821e77c1a54 mbox.c --- a/mbox.c Wed May 25 15:58:04 2016 -0700 +++ b/mbox.c Thu May 26 14:05:42 2016 -0700 @@ -577,7 +577,7 @@ * 0 no change * -1 error */ -int mbox_check_mailbox (CONTEXT *ctx, int *index_hint) +static int mbox_check_mailbox (CONTEXT *ctx, int *index_hint) { struct stat st; char buffer[LONG_STRING]; @@ -1273,10 +1273,12 @@ .open = mbox_open_mailbox, .close = mbox_close_mailbox, .open_new_msg = mbox_open_new_message, + .check = mbox_check_mailbox, }; struct mx_ops mx_mmdf_ops = { .open = mbox_open_mailbox, .close = mbox_close_mailbox, .open_new_msg = mbox_open_new_message, + .check = mbox_check_mailbox, }; diff -r 261939e71d80 -r 2821e77c1a54 mh.c --- a/mh.c Wed May 25 15:58:04 2016 -0700 +++ b/mh.c Thu May 26 14:05:42 2016 -0700 @@ -58,6 +58,9 @@ #define INS_SORT_THRESHOLD 6 +static int maildir_check_mailbox (CONTEXT * ctx, int *index_hint); +static int mh_check_mailbox (CONTEXT * ctx, int *index_hint); + struct maildir { HEADER *h; @@ -1905,7 +1908,7 @@ * either subdirectory differently, as mail could be copied directly into * the cur directory from another agent. */ -int maildir_check_mailbox (CONTEXT * ctx, int *index_hint) +static int maildir_check_mailbox (CONTEXT * ctx, int *index_hint) { struct stat st_new; /* status of the "new" subdirectory */ struct stat st_cur; /* status of the "cur" subdirectory */ @@ -2051,7 +2054,7 @@ * */ -int mh_check_mailbox (CONTEXT * ctx, int *index_hint) +static int mh_check_mailbox (CONTEXT * ctx, int *index_hint) { char buf[_POSIX_PATH_MAX]; struct stat st, st_cur; @@ -2362,10 +2365,12 @@ .open = maildir_open_mailbox, .close = mh_close_mailbox, .open_new_msg = maildir_open_new_message, + .check = maildir_check_mailbox, }; struct mx_ops mx_mh_ops = { .open = mh_open_mailbox, .close = mh_close_mailbox, .open_new_msg = mh_open_new_message, + .check = mh_check_mailbox, }; diff -r 261939e71d80 -r 2821e77c1a54 mutt.h --- a/mutt.h Wed May 25 15:58:04 2016 -0700 +++ b/mutt.h Thu May 26 14:05:42 2016 -0700 @@ -876,6 +876,7 @@ * The following operations are mandatory: * - open * - close + * - check * * Optional operations * - open_new_msg @@ -884,6 +885,7 @@ { int (*open)(struct _context *); int (*close)(struct _context *); + int (*check) (struct _context *ctx, int *index_hint); int (*open_new_msg) (struct _message *, struct _context *, HEADER *); }; diff -r 261939e71d80 -r 2821e77c1a54 mx.c --- a/mx.c Wed May 25 15:58:04 2016 -0700 +++ b/mx.c Thu May 26 14:05:42 2016 -0700 @@ -1262,63 +1262,21 @@ } /* check for new mail */ -int mx_check_mailbox (CONTEXT *ctx, int *index_hint, int lock) +int mx_check_mailbox (CONTEXT *ctx, int *index_hint) { - int rc; + struct mx_ops *ops; - if (ctx) + if (!ctx) { - if (ctx->locked) lock = 0; - - switch (ctx->magic) - { - case MUTT_MBOX: - case MUTT_MMDF: - - if (lock) - { - mutt_block_signals (); - if (mbox_lock_mailbox (ctx, 0, 0) == -1) - { - mutt_unblock_signals (); - return MUTT_LOCKED; - } - } - - rc = mbox_check_mailbox (ctx, index_hint); - - if (lock) - { - mutt_unblock_signals (); - mbox_unlock_mailbox (ctx); - } - - return rc; - - - case MUTT_MH: - return (mh_check_mailbox (ctx, index_hint)); - case MUTT_MAILDIR: - return (maildir_check_mailbox (ctx, index_hint)); - -#ifdef USE_IMAP - case MUTT_IMAP: - /* caller expects that mailbox may change */ - imap_allow_reopen (ctx); - rc = imap_check_mailbox (ctx, index_hint, 0); - imap_disallow_reopen (ctx); - return rc; -#endif /* USE_IMAP */ - -#ifdef USE_POP - case MUTT_POP: - return (pop_check_mailbox (ctx, index_hint)); -#endif /* USE_POP */ - } + dprint (1, (debugfile, "mx_check_mailbox: null or invalid context.\n")); + return -1; } - dprint (1, (debugfile, "mx_check_mailbox: null or invalid context.\n")); - return (-1); + ops = mx_get_ops (ctx->magic); + if (!ops) + return -1; + + return ops->check (ctx, index_hint); } /* return a stream pointer for a message */ diff -r 261939e71d80 -r 2821e77c1a54 mx.h --- a/mx.h Wed May 25 15:58:04 2016 -0700 +++ b/mx.h Thu May 26 14:05:42 2016 -0700 @@ -44,7 +44,6 @@ #define MAXLOCKATTEMPT 5 int mbox_sync_mailbox (CONTEXT *, int *); -int mbox_check_mailbox (CONTEXT *, int *); int mbox_lock_mailbox (CONTEXT *, int, int); int mbox_parse_mailbox (CONTEXT *); int mmdf_parse_mailbox (CONTEXT *); @@ -53,10 +52,8 @@ void mbox_reset_atime (CONTEXT *, struct stat *); int mh_sync_mailbox (CONTEXT *, int *); -int mh_check_mailbox (CONTEXT *, int *); int mh_check_empty (const char *); -int maildir_check_mailbox (CONTEXT *, int *); int maildir_check_empty (const char *); int maildir_commit_message (CONTEXT *, MESSAGE *, HEADER *); diff -r 261939e71d80 -r 2821e77c1a54 pop.c --- a/pop.c Wed May 25 15:58:04 2016 -0700 +++ b/pop.c Thu May 26 14:05:42 2016 -0700 @@ -735,7 +735,7 @@ } /* Check for new messages and fetch headers */ -int pop_check_mailbox (CONTEXT *ctx, int *index_hint) +static int pop_check_mailbox (CONTEXT *ctx, int *index_hint) { int ret; POP_DATA *pop_data = (POP_DATA *)ctx->data; @@ -931,4 +931,5 @@ struct mx_ops mx_pop_ops = { .open = pop_open_mailbox, .close = pop_close_mailbox, + .check = pop_check_mailbox, }; diff -r 261939e71d80 -r 2821e77c1a54 pop.h --- a/pop.h Wed May 25 15:58:04 2016 -0700 +++ b/pop.h Thu May 26 14:05:42 2016 -0700 @@ -105,7 +105,6 @@ void pop_error (POP_DATA *, char *); /* pop.c */ -int pop_check_mailbox (CONTEXT *, int *); int pop_sync_mailbox (CONTEXT *, int *); int pop_fetch_message (MESSAGE *, CONTEXT *, int); int pop_close_mailbox (CONTEXT *);