]> granicus.if.org Git - neomutt/commitdiff
Add function pointer for close hook in Context.
authorBrendan Cully <brendan@kublai.com>
Sat, 31 Mar 2007 02:22:55 +0000 (19:22 -0700)
committerBrendan Cully <brendan@kublai.com>
Sat, 31 Mar 2007 02:22:55 +0000 (19:22 -0700)
Slowly inch towards function pointers instead of switch statements.

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

index 87b5eb4a7ca7cb0f118d1f0511dcb569aae1d196..a4ad726acc9ccd8315769104e6ade68f56c19e7a 100644 (file)
@@ -569,6 +569,7 @@ int imap_open_mailbox (CONTEXT* ctx)
 
   /* once again the context is new */
   ctx->data = idata;
+  ctx->mx_close = imap_close_mailbox;
 
   /* Clean up path and replace the one in the ctx */
   imap_fix_path (idata, mx.mbox, buf, sizeof (buf));
diff --git a/mutt.h b/mutt.h
index 02df3c485f9a75cfa22ef43d61d8d9b401faa465..51f80d903ef59f10b3137c4a4b15501e853df70d 100644 (file)
--- a/mutt.h
+++ b/mutt.h
@@ -856,7 +856,7 @@ enum
   RIGHTSMAX
 };
 
-typedef struct
+typedef struct _context
 {
   char *path;
   FILE *fp;
@@ -882,9 +882,6 @@ typedef struct
   int deleted;                 /* how many deleted messages */
   int flagged;                 /* how many flagged messages */
   int msgnotreadyet;           /* which msg "new" in pager, -1 if none */
-#if defined USE_POP || defined USE_IMAP
-  void *data;                  /* driver specific data */
-#endif /* USE_IMAP */
 
   short magic;                 /* mailbox type */
 
@@ -898,6 +895,10 @@ typedef struct
   unsigned int quiet : 1;      /* inhibit status messages? */
   unsigned int collapsed : 1;   /* are all threads collapsed? */
   unsigned int closing : 1;    /* mailbox is being closed */
+
+  /* driver hooks */
+  void *data;                  /* driver specific data */
+  int (*mx_close)(struct _context *);
 } CONTEXT;
 
 typedef struct
diff --git a/mx.c b/mx.c
index ec621c0b83549e814eef0a711062b9393a0b0836..afa68431f54089d6a1ade8c5fbc766b181bececd 100644 (file)
--- a/mx.c
+++ b/mx.c
@@ -740,15 +740,10 @@ void mx_fastclose_mailbox (CONTEXT *ctx)
 
   if(!ctx) 
     return;
-  
-#ifdef USE_IMAP
-  if (ctx->magic == M_IMAP)
-    imap_close_mailbox (ctx);
-#endif /* USE_IMAP */
-#ifdef USE_POP
-  if (ctx->magic == M_POP)
-    pop_close_mailbox (ctx);
-#endif /* USE_POP */
+
+  if (ctx->mx_close)
+    ctx->mx_close (ctx);
+
   if (ctx->subj_hash)
     hash_destroy (&ctx->subj_hash, NULL);
   if (ctx->id_hash)
diff --git a/pop.c b/pop.c
index ba2841f106d9bd7e5ab8a8c63ecb1d6305fd2c90..f84ec80c6402f4107f2623acb5be17ef66c87f94 100644 (file)
--- a/pop.c
+++ b/pop.c
@@ -372,6 +372,7 @@ int pop_open_mailbox (CONTEXT *ctx)
   pop_data = safe_calloc (1, sizeof (POP_DATA));
   pop_data->conn = conn;
   ctx->data = pop_data;
+  ctx->mx_close = pop_close_mailbox;
 
   if (pop_open_connection (pop_data) < 0)
     return -1;