]> granicus.if.org Git - neomutt/commitdiff
add check operation to struct mx_ops
authorDamien Riegel <damien@riegel.io>
Thu, 26 May 2016 21:05:42 +0000 (14:05 -0700)
committerDamien Riegel <damien@riegel.io>
Thu, 26 May 2016 21:05:42 +0000 (14:05 -0700)
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.

imap/imap.c
imap/imap.h
mbox.c
mh.c
mutt.h
mx.c
mx.h
pop.c
pop.h

index d565ad8d08db5e2b51a850238bcadd924d58b08c..c334c441a1e4a97294892aba02946044e14bacf8 100644 (file)
@@ -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,
 };
index 1defdd47cb6db1048c7ee6ef9c6e52cc8f15b07c..132ae2b9ba342ef2141284f7d0cc71caffd75c53 100644 (file)
@@ -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 823c8e9c2a355ecaea2a73f9ff7bae3f46ab0f91..da69210084ec3a62ef006e102255c0fca350b5d2 100644 (file)
--- 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 1bca8ddd4dd1eede0dfcf54f6eca455b9f1d3399..c33745a20ca1c0f73ed4bc47e1215d5ee34b8d09 100644 (file)
--- 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 00529624d150ecdf744e06cc76c599d0e96ccf19..4e6fe39beba729f64ca3f3147a25318d5af78a37 100644 (file)
--- 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 f8d27aba4d6d4764c95659f97cf6c989d59921f9..d15fba372187d28cbdae436528c9710336320f61 100644 (file)
--- 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 bb6a3a3548e5eea380bb7289439acfecbbab1ae9..ef83595131016bdde7dc035245dfb94c3a9191e5 100644 (file)
--- 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 f45c2fec0f27a857c9d7dd476359b63add0b1608..4f0124abce2096747dd94a8138ed041da0dd0474 100644 (file)
--- 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 88671890933fe973f53d1b114027fea2aa7e486a..edc1ed19cee7982ca5a0f81f469731079e046afb 100644 (file)
--- 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 *);