From 956541d5b7d2e422a8204bee44d593788b6b9fcc Mon Sep 17 00:00:00 2001 From: Brendan Cully Date: Fri, 30 Mar 2007 19:22:55 -0700 Subject: [PATCH] Add function pointer for close hook in Context. Slowly inch towards function pointers instead of switch statements. --- imap/imap.c | 1 + mutt.h | 9 +++++---- mx.c | 13 ++++--------- pop.c | 1 + 4 files changed, 11 insertions(+), 13 deletions(-) diff --git a/imap/imap.c b/imap/imap.c index 87b5eb4a7..a4ad726ac 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -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 02df3c485..51f80d903 100644 --- 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 ec621c0b8..afa68431f 100644 --- 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 ba2841f10..f84ec80c6 100644 --- 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; -- 2.40.0