# HG changeset patch
# User Damien Riegel <[email protected]>
# Date 1462483716 14400
#      Thu May 05 17:28:36 2016 -0400
# Node ID e61c9203ffa102a2c010c02b6e4c8dd467abce10
# Parent  742779f8f5116d86a0a73cc17a10d725f56664b6
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.

diff -r 742779f8f511 -r e61c9203ffa1 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
@@ -583,7 +583,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 742779f8f511 -r e61c9203ffa1 mbox.c
--- a/mbox.c    Thu May 05 14:40:15 2016 -0400
+++ b/mbox.c    Thu May 05 17:28:36 2016 -0400
@@ -450,8 +450,6 @@
   else
     rc = -1;
 
-  ctx->mx_ops = &mx_mbox_ops;
-
   mbox_unlock_mailbox (ctx);
   mutt_unblock_signals ();
   return (rc);
diff -r 742779f8f511 -r e61c9203ffa1 mh.c
--- a/mh.c      Thu May 05 14:40:15 2016 -0400
+++ b/mh.c      Thu May 05 17:28:36 2016 -0400
@@ -1173,20 +1173,12 @@
 
 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)
 {
-  int rc = mh_read_dir (ctx, NULL);
-
-  ctx->mx_ops = &mx_mh_ops;
-
-  return rc;
+  return mh_read_dir (ctx, NULL);
 }
 
 /* Read a MH/maildir style mailbox.
diff -r 742779f8f511 -r e61c9203ffa1 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,48 @@
 #include <ctype.h>
 #include <utime.h>
 
+static struct mx_ops* mx_get_ops (int magic)
+{
+  switch (magic)
+  {
+#ifdef USE_IMAP
+    case MUTT_IMAP:
+    {
+      extern struct mx_ops mx_imap_ops;
+      return &mx_imap_ops;
+    }
+#endif
+    case MUTT_MAILDIR:
+    {
+      extern struct mx_ops mx_maildir_ops;
+      return &mx_maildir_ops;
+    }
+    case MUTT_MBOX:
+    {
+      extern struct mx_ops mx_mbox_ops;
+      return &mx_mbox_ops;
+    }
+    case MUTT_MH:
+    {
+      extern struct mx_ops mx_mh_ops;
+      return &mx_mh_ops;
+    }
+    case MUTT_MMDF:
+    {
+      extern struct mx_ops mx_mmdf_ops;
+      return &mx_mmdf_ops;
+    }
+#ifdef USE_POP
+    case MUTT_POP:
+    {
+      extern struct mx_ops mx_pop_ops;
+      return &mx_pop_ops;
+    }
+#endif
+    default:
+      return NULL;
+  }
+}
 
 #define mutt_is_spool(s)  (mutt_strcmp (Spoolfile, s) == 0)
 
@@ -625,15 +667,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 +692,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 742779f8f511 -r e61c9203ffa1 pop.c
--- a/pop.c     Thu May 05 14:40:15 2016 -0400
+++ b/pop.c     Thu May 05 17:28:36 2016 -0400
@@ -431,7 +431,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;

Reply via email to