From: Damien Riegel Date: Thu, 26 May 2016 21:05:42 +0000 (-0700) Subject: add check operation to struct mx_ops X-Git-Tag: neomutt-20160822~141 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8921ed4212fef5423da4daa391f1b4a49117f240;p=neomutt add check operation to struct mx_ops In mx_check_mailbox switch case, we simply call _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. --- diff --git a/imap/imap.c b/imap/imap.c index d565ad8d0..c334c441a 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -1464,7 +1464,7 @@ int imap_check_mailbox (CONTEXT *ctx, int *index_hint, int force) return result; } -int imap_check_mailbox_reopen (CONTEXT *ctx, int *index_hint) +static int imap_check_mailbox_reopen (CONTEXT *ctx, int *index_hint) { int rc; @@ -2067,4 +2067,5 @@ struct mx_ops mx_imap_ops = { .open = imap_open_mailbox, .close = imap_close_mailbox, .open_new_msg = imap_open_new_message, + .check = imap_check_mailbox_reopen, }; diff --git a/imap/imap.h b/imap/imap.h index 1defdd47c..132ae2b9b 100644 --- a/imap/imap.h +++ b/imap/imap.h @@ -34,7 +34,6 @@ typedef struct /* imap.c */ int imap_access (const char*, int); int imap_check_mailbox (CONTEXT *ctx, int *index_hint, int force); -int imap_check_mailbox_reopen (CONTEXT *ctx, int *index_hint); int imap_delete_mailbox (CONTEXT* idata, IMAP_MBOX mx); int imap_open_mailbox_append (CONTEXT *ctx); int imap_sync_mailbox (CONTEXT *ctx, int expunge, int *index_hint); diff --git a/mbox.c b/mbox.c index 823c8e9c2..da6921008 100644 --- a/mbox.c +++ b/mbox.c @@ -577,7 +577,7 @@ int mbox_strict_cmp_headers (const HEADER *h1, const HEADER *h2) * 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 @@ struct mx_ops mx_mbox_ops = { .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 --git a/mh.c b/mh.c index 1bca8ddd4..c33745a20 100644 --- a/mh.c +++ b/mh.c @@ -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 @@ static void maildir_update_flags (CONTEXT *ctx, HEADER *o, HEADER *n) * 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 maildir_check_mailbox (CONTEXT * ctx, int *index_hint) * */ -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 @@ struct mx_ops mx_maildir_ops = { .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 --git a/mutt.h b/mutt.h index 00529624d..4e6fe39be 100644 --- a/mutt.h +++ b/mutt.h @@ -876,6 +876,7 @@ struct _message; * The following operations are mandatory: * - open * - close + * - check * * Optional operations * - open_new_msg @@ -884,6 +885,7 @@ struct mx_ops { 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 --git a/mx.c b/mx.c index f8d27aba4..d15fba372 100644 --- a/mx.c +++ b/mx.c @@ -1264,32 +1264,19 @@ MESSAGE *mx_open_new_message (CONTEXT *dest, HEADER *hdr, int flags) /* check for new mail */ int mx_check_mailbox (CONTEXT *ctx, int *index_hint) { - if (ctx) - { - switch (ctx->magic) - { - case MUTT_MBOX: - case MUTT_MMDF: - return mbox_check_mailbox (ctx, index_hint); - case MUTT_MH: - return (mh_check_mailbox (ctx, index_hint)); - case MUTT_MAILDIR: - return (maildir_check_mailbox (ctx, index_hint)); + struct mx_ops *ops; -#ifdef USE_IMAP - case MUTT_IMAP: - return imap_check_mailbox_reopen (ctx, index_hint); -#endif /* USE_IMAP */ - -#ifdef USE_POP - case MUTT_POP: - return (pop_check_mailbox (ctx, index_hint)); -#endif /* USE_POP */ - } + if (!ctx) + { + 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 --git a/mx.h b/mx.h index bb6a3a354..ef8359513 100644 --- a/mx.h +++ b/mx.h @@ -44,7 +44,6 @@ WHERE short DefaultMagic INITVAL (MUTT_MBOX); #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 @@ int mbox_check_empty (const char *); 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 --git a/pop.c b/pop.c index f45c2fec0..4f0124abc 100644 --- a/pop.c +++ b/pop.c @@ -735,7 +735,7 @@ int pop_sync_mailbox (CONTEXT *ctx, int *index_hint) } /* 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 @@ fail: struct mx_ops mx_pop_ops = { .open = pop_open_mailbox, .close = pop_close_mailbox, + .check = pop_check_mailbox, }; diff --git a/pop.h b/pop.h index 886718909..edc1ed19c 100644 --- a/pop.h +++ b/pop.h @@ -105,7 +105,6 @@ void pop_logout (CONTEXT *); 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 *);