Introduce a dedicated structure for mailbox operations: struct mx_ops.
Move the open and close operations into that structure.
Assign this structure to the context in mx_open_mailbox. This is
currently based on the "magic" for the mailbox type, but may be
refactored in the future.
Add a stub mbox_close_mailbox function. This function does nothing,
the main purpose is to introduce a mx_ops structure for mbox, so its
usage is similar to mh/imap/pop. We reuse the name that was made
available by the previous commmit. Note that the actual closing of
the descriptor is done in mx.c.
To be more consistent with other mailboxes, introduce functions
mh_open_mailbox and maildir_open_mailbox, and create a dedicated
structure for mmdf.
return s;
}
-int imap_open_mailbox (CONTEXT* ctx)
+static int imap_open_mailbox (CONTEXT* ctx)
{
IMAP_DATA *idata;
IMAP_STATUS* status;
/* 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));
return -1;
}
+
+struct mx_ops mx_imap_ops = {
+ .open = imap_open_mailbox,
+ .close = imap_close_mailbox,
+};
int imap_access (const char*, int);
int imap_check_mailbox (CONTEXT *ctx, int *index_hint, int force);
int imap_delete_mailbox (CONTEXT* idata, IMAP_MBOX mx);
-int imap_open_mailbox (CONTEXT *ctx);
int imap_open_mailbox_append (CONTEXT *ctx);
int imap_sync_mailbox (CONTEXT *ctx, int expunge, int *index_hint);
int imap_close_mailbox (CONTEXT *ctx);
void imap_allow_reopen (CONTEXT *ctx);
void imap_disallow_reopen (CONTEXT *ctx);
+extern struct mx_ops mx_imap_ops;
+
/* browse.c */
int imap_browse (char* path, struct browser_state* state);
int imap_mailbox_state (const char* path, struct mailbox_state* state);
#undef PREV
/* open a mbox or mmdf style mailbox */
-int mbox_open_mailbox (CONTEXT *ctx)
+static int mbox_open_mailbox (CONTEXT *ctx)
{
int rc;
return (rc);
}
+static int mbox_close_mailbox (CONTEXT *ctx)
+{
+ return 0;
+}
+
/* return 1 if address lists are strictly identical */
static int strict_addrcmp (const ADDRESS *a, const ADDRESS *b)
{
return ((st.st_size == 0));
}
+
+struct mx_ops mx_mbox_ops = {
+ .open = mbox_open_mailbox,
+ .close = mbox_close_mailbox,
+};
+
+struct mx_ops mx_mmdf_ops = {
+ .open = mbox_open_mailbox,
+ .close = mbox_close_mailbox,
+};
* subdir [IN] NULL for MH mailboxes, otherwise the subdir of the
* maildir mailbox to read from
*/
-int mh_read_dir (CONTEXT * ctx, const char *subdir)
+static int mh_read_dir (CONTEXT * ctx, const char *subdir)
{
struct maildir *md;
struct mh_sequences mhs;
if (!ctx->data)
{
ctx->data = safe_calloc(sizeof (struct mh_data), 1);
- ctx->mx_close = mh_close_mailbox;
}
data = mh_data (ctx);
}
/* read a maildir style mailbox */
-int maildir_read_dir (CONTEXT * ctx)
+static int maildir_read_dir (CONTEXT * ctx)
{
/* maildir looks sort of like MH, except that there are two subdirectories
* of the main folder path from which to read messages
return 0;
}
+static int maildir_open_mailbox (CONTEXT *ctx)
+{
+ return maildir_read_dir (ctx);
+}
+
+static int mh_open_mailbox (CONTEXT *ctx)
+{
+ return mh_read_dir (ctx, NULL);
+}
+
/*
* Open a new (temporary) message in an MH folder.
*/
return 0;
}
+
+struct mx_ops mx_maildir_ops = {
+ .open = maildir_open_mailbox,
+ .close = mh_close_mailbox,
+};
+
+struct mx_ops mx_mh_ops = {
+ .open = mh_open_mailbox,
+ .close = mh_close_mailbox,
+};
RIGHTSMAX
};
+struct _context;
+
+struct mx_ops
+{
+ int (*open)(struct _context *);
+ int (*close)(struct _context *);
+};
+
typedef struct _context
{
char *path;
/* driver hooks */
void *data; /* driver specific data */
- int (*mx_close)(struct _context *);
+ struct mx_ops *mx_ops;
} CONTEXT;
typedef struct
#include <ctype.h>
#include <utime.h>
+static struct mx_ops* mx_get_ops (int magic)
+{
+ switch (magic)
+ {
+#ifdef USE_IMAP
+ case MUTT_IMAP:
+ return &mx_imap_ops;
+#endif
+ case MUTT_MAILDIR:
+ return &mx_maildir_ops;
+ case MUTT_MBOX:
+ return &mx_mbox_ops;
+ case MUTT_MH:
+ return &mx_mh_ops;
+ case MUTT_MMDF:
+ return &mx_mmdf_ops;
+#ifdef USE_POP
+ case MUTT_POP:
+ return &mx_pop_ops;
+#endif
+ default:
+ return NULL;
+ }
+}
#define mutt_is_spool(s) (mutt_strcmp (Spoolfile, s) == 0)
}
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);
if (!ctx->quiet)
mutt_message (_("Reading %s..."), ctx->path);
- switch (ctx->magic)
- {
- case MUTT_MH:
- rc = mh_read_dir (ctx, NULL);
- break;
-
- case MUTT_MAILDIR:
- rc = maildir_read_dir (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)
{
* 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);
#define MAXLOCKATTEMPT 5
int mbox_sync_mailbox (CONTEXT *, int *);
-int mbox_open_mailbox (CONTEXT *);
int mbox_check_mailbox (CONTEXT *, int *);
int mbox_lock_mailbox (CONTEXT *, int, int);
int mbox_parse_mailbox (CONTEXT *);
int mbox_check_empty (const char *);
void mbox_reset_atime (CONTEXT *, struct stat *);
-int mh_read_dir (CONTEXT *, const char *);
int mh_sync_mailbox (CONTEXT *, int *);
int mh_check_mailbox (CONTEXT *, int *);
int mh_check_empty (const char *);
-int maildir_read_dir (CONTEXT *);
int maildir_check_mailbox (CONTEXT *, int *);
int maildir_check_empty (const char *);
int mx_lock_file (const char *, int, int, int, int);
int mx_unlock_file (const char *path, int fd, int dot);
+extern struct mx_ops mx_maildir_ops;
+extern struct mx_ops mx_mbox_ops;
+extern struct mx_ops mx_mh_ops;
+extern struct mx_ops mx_mmdf_ops;
#endif
}
/* open POP mailbox - fetch only headers */
-int pop_open_mailbox (CONTEXT *ctx)
+static int pop_open_mailbox (CONTEXT *ctx)
{
int ret;
char buf[LONG_STRING];
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;
mutt_socket_close (conn);
FREE (&pop_data);
}
+
+struct mx_ops mx_pop_ops = {
+ .open = pop_open_mailbox,
+ .close = pop_close_mailbox,
+};
/* pop.c */
int pop_check_mailbox (CONTEXT *, int *);
-int pop_open_mailbox (CONTEXT *);
int pop_sync_mailbox (CONTEXT *, int *);
int pop_fetch_message (MESSAGE *, CONTEXT *, int);
int pop_close_mailbox (CONTEXT *);
void pop_fetch_mail (void);
+extern struct mx_ops mx_pop_ops;
+
#endif