# HG changeset patch
# User Damien Riegel <[email protected]>
# Date 1464136614 14400
# Tue May 24 20:36:54 2016 -0400
# Node ID ba6f48fd6a5658a26b5f941b0a4f5f8bd1e38c14
# Parent d18efeecb6d3bf1d176cad8a14071a0aefadcd41
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.
diff -r d18efeecb6d3 -r ba6f48fd6a56 imap/imap.c
--- a/imap/imap.c Tue May 24 20:24:09 2016 -0400
+++ b/imap/imap.c Tue May 24 20:36:54 2016 -0400
@@ -1464,7 +1464,7 @@
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 @@
.open = imap_open_mailbox,
.close = imap_close_mailbox,
.open_new_msg = imap_open_new_message,
+ .check = imap_check_mailbox_reopen,
};
diff -r d18efeecb6d3 -r ba6f48fd6a56 imap/imap.h
--- a/imap/imap.h Tue May 24 20:24:09 2016 -0400
+++ b/imap/imap.h Tue May 24 20:36:54 2016 -0400
@@ -34,7 +34,6 @@
/* 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 -r d18efeecb6d3 -r ba6f48fd6a56 mbox.c
--- a/mbox.c Tue May 24 20:24:09 2016 -0400
+++ b/mbox.c Tue May 24 20:36:54 2016 -0400
@@ -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 d18efeecb6d3 -r ba6f48fd6a56 mh.c
--- a/mh.c Tue May 24 20:24:09 2016 -0400
+++ b/mh.c Tue May 24 20:36:54 2016 -0400
@@ -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 d18efeecb6d3 -r ba6f48fd6a56 mutt.h
--- a/mutt.h Tue May 24 20:24:09 2016 -0400
+++ b/mutt.h Tue May 24 20:36:54 2016 -0400
@@ -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 d18efeecb6d3 -r ba6f48fd6a56 mx.c
--- a/mx.c Tue May 24 20:24:09 2016 -0400
+++ b/mx.c Tue May 24 20:36:54 2016 -0400
@@ -1261,32 +1261,19 @@
/* check for new mail */
int mx_check_mailbox (CONTEXT *ctx, int *index_hint)
{
- if (ctx)
+ struct mx_ops *ops;
+
+ 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));
-
-#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 */
- }
+ 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 d18efeecb6d3 -r ba6f48fd6a56 mx.h
--- a/mx.h Tue May 24 20:24:09 2016 -0400
+++ b/mx.h Tue May 24 20:36:54 2016 -0400
@@ -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 d18efeecb6d3 -r ba6f48fd6a56 pop.c
--- a/pop.c Tue May 24 20:24:09 2016 -0400
+++ b/pop.c Tue May 24 20:36:54 2016 -0400
@@ -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 d18efeecb6d3 -r ba6f48fd6a56 pop.h
--- a/pop.h Tue May 24 20:24:09 2016 -0400
+++ b/pop.h Tue May 24 20:36:54 2016 -0400
@@ -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 *);