# HG changeset patch
# User Damien Riegel <[email protected]>
# Date 1462483716 14400
# Thu May 05 17:28:36 2016 -0400
# Node ID b2855b043213ffb71abe13a14671c7e842d71924
# Parent fcacda156d724b1d56a4b2a218cd07ad7ee39fd7
open a mailbox using mx_ops callback
Now that the probe and open callbacks have been introduced, and that
there is a list of supported mailboxes, there is no need to use a switch
case to find the open function.
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.
diff -r fcacda156d72 -r b2855b043213 imap/imap.c
--- a/imap/imap.c Thu May 05 17:18:13 2016 -0400
+++ b/imap/imap.c Thu May 05 17:28:36 2016 -0400
@@ -589,7 +589,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 fcacda156d72 -r b2855b043213 mbox.c
--- a/mbox.c Thu May 05 17:18:13 2016 -0400
+++ b/mbox.c Thu May 05 17:28:36 2016 -0400
@@ -462,8 +462,6 @@
else
rc = -1;
- ctx->mx_ops = &mx_mbox_ops;
-
mbox_unlock_mailbox (ctx);
mutt_unblock_signals ();
return (rc);
diff -r fcacda156d72 -r b2855b043213 mh.c
--- a/mh.c Thu May 05 17:18:13 2016 -0400
+++ b/mh.c Thu May 05 17:28:36 2016 -0400
@@ -1190,8 +1190,6 @@
if (rc)
return rc;
- ctx->mx_ops = &mx_mh_ops;
-
return 0;
}
@@ -1202,8 +1200,6 @@
if (rc)
return rc;
- ctx->mx_ops = &mx_mh_ops;
-
return 0;
}
diff -r fcacda156d72 -r b2855b043213 mx.c
--- a/mx.c Thu May 05 17:18:13 2016 -0400
+++ b/mx.c Thu May 05 17:28:36 2016 -0400
@@ -719,17 +719,18 @@
}
mx_register_all();
+ ctx->mx_ops = mx_probe(path);
ctx->magic = mx_get_magic (path);
-
- if(ctx->magic == 0)
- mutt_error (_("%s is not a mailbox."), path);
- if(ctx->magic == -1)
- mutt_perror(path);
-
- if(ctx->magic <= 0)
+ if (ctx->magic <= 0 || !ctx->mx_ops)
{
- mx_fastclose_mailbox (ctx);
+ 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);
return (NULL);
@@ -745,37 +746,7 @@
if (!ctx->quiet)
mutt_message (_("Reading %s..."), ctx->path);
- switch (ctx->magic)
- {
- case M_MH:
- rc = mh_open_mailbox (ctx);
- break;
-
- case M_MAILDIR:
- rc = maildir_open_mailbox (ctx);
- break;
-
- case M_MMDF:
- case M_MBOX:
- rc = mbox_open_mailbox (ctx);
- break;
-
-#ifdef USE_IMAP
- case M_IMAP:
- rc = imap_open_mailbox (ctx);
- break;
-#endif /* USE_IMAP */
-
-#ifdef USE_POP
- case M_POP:
- rc = pop_open_mailbox (ctx);
- break;
-#endif /* USE_POP */
-
- default:
- rc = -1;
- break;
- }
+ rc = ctx->mx_ops->open(ctx);
if (rc == 0)
{
@@ -792,7 +763,7 @@
}
else
{
- mx_fastclose_mailbox (ctx);
+ __mx_fastclose_mailbox(ctx);
if (!pctx)
FREE (&ctx);
}
diff -r fcacda156d72 -r b2855b043213 pop.c
--- a/pop.c Thu May 05 17:18:13 2016 -0400
+++ b/pop.c Thu May 05 17:28:36 2016 -0400
@@ -437,7 +437,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;