# HG changeset patch
# User Damien Riegel <[email protected]>
# Date 1462483716 14400
# Thu May 05 17:28:36 2016 -0400
# Node ID b69d57c51a51d9e875dd0ac813d5d699f62a3697
# Parent 2007ebda7ccc4acce3c9492bfa75440fe16a4123
open a mailbox using mx_ops callback
The assignment of ctx->mx_ops is now done in mx_open_mailbox, so this
commit also cleans that in other parts of the code. It also removes
prototypes for open functions and change them to static as they are not
used outside of their files anymore.
diff -r 2007ebda7ccc -r b69d57c51a51 imap/imap.c
--- a/imap/imap.c Thu May 05 14:40:15 2016 -0400
+++ b/imap/imap.c Thu May 05 17:28:36 2016 -0400
@@ -554,7 +554,7 @@
return s;
}
-int imap_open_mailbox (CONTEXT* ctx)
+static int imap_open_mailbox (CONTEXT* ctx)
{
IMAP_DATA *idata;
IMAP_STATUS* status;
@@ -578,7 +578,6 @@
/* once again the context is new */
ctx->data = idata;
- ctx->mx_ops = &mx_imap_ops;
/* Clean up path and replace the one in the ctx */
imap_fix_path (idata, mx.mbox, buf, sizeof (buf));
diff -r 2007ebda7ccc -r b69d57c51a51 imap/imap.h
--- a/imap/imap.h Thu May 05 14:40:15 2016 -0400
+++ b/imap/imap.h Thu May 05 17:28:36 2016 -0400
@@ -35,7 +35,6 @@
int imap_access (const char*, int);
int imap_check_mailbox (CONTEXT *ctx, int *index_hint, int force);
int imap_delete_mailbox (CONTEXT* idata, IMAP_MBOX mx);
-int imap_open_mailbox (CONTEXT *ctx);
int imap_open_mailbox_append (CONTEXT *ctx);
int imap_sync_mailbox (CONTEXT *ctx, int expunge, int *index_hint);
int imap_close_mailbox (CONTEXT *ctx);
diff -r 2007ebda7ccc -r b69d57c51a51 mbox.c
--- a/mbox.c Thu May 05 14:40:15 2016 -0400
+++ b/mbox.c Thu May 05 17:28:36 2016 -0400
@@ -412,7 +412,7 @@
#undef PREV
/* open a mbox or mmdf style mailbox */
-int mbox_open_mailbox (CONTEXT *ctx)
+static int mbox_open_mailbox (CONTEXT *ctx)
{
int rc;
@@ -435,8 +435,6 @@
else
rc = -1;
- ctx->mx_ops = &mx_mbox_ops;
-
mbox_unlock_mailbox (ctx);
mutt_unblock_signals ();
return (rc);
diff -r 2007ebda7ccc -r b69d57c51a51 mh.c
--- a/mh.c Thu May 05 14:40:15 2016 -0400
+++ b/mh.c Thu May 05 17:28:36 2016 -0400
@@ -1234,22 +1234,14 @@
return 0;
}
-int maildir_open_mailbox (CONTEXT *ctx)
+static int maildir_open_mailbox (CONTEXT *ctx)
{
- int rc = maildir_read_dir (ctx);
-
- ctx->mx_ops = &mx_maildir_ops;
-
- return rc;
+ return maildir_read_dir (ctx);
}
-int mh_open_mailbox (CONTEXT *ctx)
+static int mh_open_mailbox (CONTEXT *ctx)
{
- int rc = mh_read_dir (ctx, NULL);
-
- ctx->mx_ops = &mx_mh_ops;
-
- return rc;
+ return mh_read_dir (ctx, NULL);
}
/*
diff -r 2007ebda7ccc -r b69d57c51a51 mx.c
--- a/mx.c Thu May 05 14:40:15 2016 -0400
+++ b/mx.c Thu May 05 17:28:36 2016 -0400
@@ -57,6 +57,30 @@
#include <ctype.h>
#include <utime.h>
+static struct mx_ops* mx_get_ops (int magic)
+{
+ switch (magic)
+ {
+#ifdef USE_IMAP
+ case MUTT_IMAP:
+ return &mx_imap_ops;
+#endif
+ case MUTT_MAILDIR:
+ return &mx_maildir_ops;
+ case MUTT_MBOX:
+ return &mx_mbox_ops;
+ case MUTT_MH:
+ return &mx_mh_ops;
+ case MUTT_MMDF:
+ return &mx_mmdf_ops;
+#ifdef USE_POP
+ case MUTT_POP:
+ return &mx_pop_ops;
+#endif
+ default:
+ return NULL;
+ }
+}
#define mutt_is_spool(s) (mutt_strcmp (Spoolfile, s) == 0)
@@ -625,15 +649,15 @@
}
ctx->magic = mx_get_magic (path);
-
- if(ctx->magic == 0)
- mutt_error (_("%s is not a mailbox."), path);
+ ctx->mx_ops = mx_get_ops (ctx->magic);
- if(ctx->magic == -1)
- mutt_perror(path);
-
- if(ctx->magic <= 0)
+ if (ctx->magic <= 0 || !ctx->mx_ops)
{
+ if (ctx->magic == 0 || !ctx->mx_ops)
+ mutt_error (_("%s is not a mailbox."), path);
+ else if (ctx->magic == -1)
+ mutt_perror(path);
+
mx_fastclose_mailbox (ctx);
if (!pctx)
FREE (&ctx);
@@ -650,37 +674,7 @@
if (!ctx->quiet)
mutt_message (_("Reading %s..."), ctx->path);
- switch (ctx->magic)
- {
- case MUTT_MH:
- rc = mh_open_mailbox (ctx);
- break;
-
- case MUTT_MAILDIR:
- rc = maildir_open_mailbox (ctx);
- break;
-
- case MUTT_MMDF:
- case MUTT_MBOX:
- rc = mbox_open_mailbox (ctx);
- break;
-
-#ifdef USE_IMAP
- case MUTT_IMAP:
- rc = imap_open_mailbox (ctx);
- break;
-#endif /* USE_IMAP */
-
-#ifdef USE_POP
- case MUTT_POP:
- rc = pop_open_mailbox (ctx);
- break;
-#endif /* USE_POP */
-
- default:
- rc = -1;
- break;
- }
+ rc = ctx->mx_ops->open(ctx);
if (rc == 0)
{
diff -r 2007ebda7ccc -r b69d57c51a51 mx.h
--- a/mx.h Thu May 05 14:40:15 2016 -0400
+++ b/mx.h Thu May 05 17:28:36 2016 -0400
@@ -44,7 +44,6 @@
#define MAXLOCKATTEMPT 5
int mbox_sync_mailbox (CONTEXT *, int *);
-int mbox_open_mailbox (CONTEXT *);
int mbox_check_mailbox (CONTEXT *, int *);
int mbox_lock_mailbox (CONTEXT *, int, int);
int mbox_parse_mailbox (CONTEXT *);
@@ -53,12 +52,10 @@
int mbox_check_empty (const char *);
void mbox_reset_atime (CONTEXT *, struct stat *);
-int mh_open_mailbox (CONTEXT *);
int mh_sync_mailbox (CONTEXT *, int *);
int mh_check_mailbox (CONTEXT *, int *);
int mh_check_empty (const char *);
-int maildir_open_mailbox (CONTEXT *);
int maildir_check_mailbox (CONTEXT *, int *);
int maildir_check_empty (const char *);
diff -r 2007ebda7ccc -r b69d57c51a51 pop.c
--- a/pop.c Thu May 05 14:40:15 2016 -0400
+++ b/pop.c Thu May 05 17:28:36 2016 -0400
@@ -397,7 +397,7 @@
}
/* open POP mailbox - fetch only headers */
-int pop_open_mailbox (CONTEXT *ctx)
+static int pop_open_mailbox (CONTEXT *ctx)
{
int ret;
char buf[LONG_STRING];
@@ -426,7 +426,6 @@
pop_data = safe_calloc (1, sizeof (POP_DATA));
pop_data->conn = conn;
ctx->data = pop_data;
- ctx->mx_ops = &mx_pop_ops;
if (pop_open_connection (pop_data) < 0)
return -1;
diff -r 2007ebda7ccc -r b69d57c51a51 pop.h
--- a/pop.h Thu May 05 14:40:15 2016 -0400
+++ b/pop.h Thu May 05 17:28:36 2016 -0400
@@ -106,7 +106,6 @@
/* pop.c */
int pop_check_mailbox (CONTEXT *, int *);
-int pop_open_mailbox (CONTEXT *);
int pop_sync_mailbox (CONTEXT *, int *);
int pop_fetch_message (MESSAGE *, CONTEXT *, int);
int pop_close_mailbox (CONTEXT *);