# HG changeset patch
# User Damien Riegel <damien.rie...@gmail.com>
# Date 1462391862 14400
#      Wed May 04 15:57:42 2016 -0400
# Node ID 743eb0278f8f1c4c6dab79979fa6095430808247
# Parent  b74dfb9fa90123a76772541f270a424485ac4d71
create a dedicated structure for mx operations

This commit introduces a dedicated structure for mailbox operations. The
point is to avoid to clobber the context structure with additional
callbacks, and to allow each kind of mailboxes to define its own
structure.

diff -r b74dfb9fa901 -r 743eb0278f8f imap/imap.c
--- a/imap/imap.c       Tue May 03 13:21:41 2016 -0700
+++ b/imap/imap.c       Wed May 04 15:57:42 2016 -0400
@@ -554,6 +554,10 @@
   return s;
 }
 
+struct mx_ops mx_imap_ops = {
+  .close = imap_close_mailbox,
+};
+
 int imap_open_mailbox (CONTEXT* ctx)
 {
   IMAP_DATA *idata;
@@ -578,7 +582,7 @@
 
   /* once again the context is new */
   ctx->data = idata;
-  ctx->mx_close = imap_close_mailbox;
+  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 b74dfb9fa901 -r 743eb0278f8f mh.c
--- a/mh.c      Tue May 03 13:21:41 2016 -0700
+++ b/mh.c      Wed May 04 15:57:42 2016 -0400
@@ -1161,6 +1161,10 @@
   return 0;
 }
 
+struct mx_ops mx_mh_ops = {
+  .close = mh_close_mailbox,
+};
+
 /* Read a MH/maildir style mailbox.
  *
  * args:
@@ -1188,7 +1192,7 @@
   if (!ctx->data)
   {
     ctx->data = safe_calloc(sizeof (struct mh_data), 1);
-    ctx->mx_close = mh_close_mailbox;
+    ctx->mx_ops = &mx_mh_ops;
   }
   data = mh_data (ctx);
 
diff -r b74dfb9fa901 -r 743eb0278f8f mutt.h
--- a/mutt.h    Tue May 03 13:21:41 2016 -0700
+++ b/mutt.h    Wed May 04 15:57:42 2016 -0400
@@ -868,6 +868,13 @@
   RIGHTSMAX
 };
 
+struct _context;
+
+struct mx_ops {
+  int (*close)(struct _context *);
+
+};
+
 typedef struct _context
 {
   char *path;
@@ -909,7 +916,7 @@
 
   /* driver hooks */
   void *data;                  /* driver specific data */
-  int (*mx_close)(struct _context *);
+  struct mx_ops *mx_ops;
 } CONTEXT;
 
 typedef struct
diff -r b74dfb9fa901 -r 743eb0278f8f mx.c
--- a/mx.c      Tue May 03 13:21:41 2016 -0700
+++ b/mx.c      Wed May 04 15:57:42 2016 -0400
@@ -709,8 +709,8 @@
    * XXX: really belongs in mx_close_mailbox, but this is a nice hook point */
   mutt_buffy_setnotified(ctx->path);
 
-  if (ctx->mx_close)
-    ctx->mx_close (ctx);
+  if (ctx->mx_ops)
+    ctx->mx_ops->close (ctx);
 
   if (ctx->subj_hash)
     hash_destroy (&ctx->subj_hash, NULL);
diff -r b74dfb9fa901 -r 743eb0278f8f pop.c
--- a/pop.c     Tue May 03 13:21:41 2016 -0700
+++ b/pop.c     Wed May 04 15:57:42 2016 -0400
@@ -396,6 +396,10 @@
   return (new_count - old_count);
 }
 
+struct mx_ops mx_pop_ops = {
+  .close = pop_close_mailbox,
+};
+
 /* open POP mailbox - fetch only headers */
 int pop_open_mailbox (CONTEXT *ctx)
 {
@@ -426,7 +430,7 @@
   pop_data = safe_calloc (1, sizeof (POP_DATA));
   pop_data->conn = conn;
   ctx->data = pop_data;
-  ctx->mx_close = pop_close_mailbox;
+  ctx->mx_ops = &mx_pop_ops;
 
   if (pop_open_connection (pop_data) < 0)
     return -1;

Reply via email to