Slowly inch towards function pointers instead of switch statements.
/* 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));
RIGHTSMAX
};
-typedef struct
+typedef struct _context
{
char *path;
FILE *fp;
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 */
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
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)
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;