changeset: 6653:63cb99b46c34 user: Damien Riegel <[email protected]> date: Wed May 25 15:53:07 2016 -0700 link: http://dev.mutt.org/hg/mutt/rev/63cb99b46c34
add open_new_msg operation to struct mx_ops The code was already using a function pointer to do this operation. This commit moves this function pointer to the mx_ops structure and the open_new_message functions to their respective source files if it needs to. changeset: 6654:261939e71d80 user: Kevin McCarthy <[email protected]> date: Wed May 25 15:58:04 2016 -0700 link: http://dev.mutt.org/hg/mutt/rev/261939e71d80 Add a TODO to mx_open_new_message() to use mx_ops in the future. We can't use it until mx_open_mailbox_append() is converted to set mx_ops. diffs (228 lines): diff -r 79c379cb0c21 -r 261939e71d80 imap/imap.c --- a/imap/imap.c Tue May 24 12:45:21 2016 -0700 +++ b/imap/imap.c Wed May 25 15:58:04 2016 -0700 @@ -828,6 +828,20 @@ imap_free_idata (idata); } +static int imap_open_new_message (MESSAGE *msg, CONTEXT *dest, HEADER *hdr) +{ + char tmp[_POSIX_PATH_MAX]; + + mutt_mktemp (tmp, sizeof (tmp)); + if ((msg->fp = safe_fopen (tmp, "w")) == NULL) + { + mutt_perror (tmp); + return (-1); + } + msg->path = safe_strdup(tmp); + return 0; +} + /* imap_set_flag: append str to flags if we currently have permission * according to aclbit */ static void imap_set_flag (IMAP_DATA* idata, int aclbit, int flag, @@ -2041,4 +2055,5 @@ struct mx_ops mx_imap_ops = { .open = imap_open_mailbox, .close = imap_close_mailbox, + .open_new_msg = imap_open_new_message, }; diff -r 79c379cb0c21 -r 261939e71d80 mailbox.h --- a/mailbox.h Tue May 24 12:45:21 2016 -0700 +++ b/mailbox.h Wed May 25 15:58:04 2016 -0700 @@ -41,7 +41,7 @@ MUTT_FLAGS /* nondestructive flags change (IMAP) */ }; -typedef struct +typedef struct _message { FILE *fp; /* pointer to the message data */ char *path; /* path to temp file */ diff -r 79c379cb0c21 -r 261939e71d80 mbox.c --- a/mbox.c Tue May 24 12:45:21 2016 -0700 +++ b/mbox.c Wed May 25 15:58:04 2016 -0700 @@ -445,6 +445,12 @@ return 0; } +static int mbox_open_new_message (MESSAGE *msg, CONTEXT *dest, HEADER *hdr) +{ + msg->fp = dest->fp; + return 0; +} + /* return 1 if address lists are strictly identical */ static int strict_addrcmp (const ADDRESS *a, const ADDRESS *b) { @@ -1266,9 +1272,11 @@ struct mx_ops mx_mbox_ops = { .open = mbox_open_mailbox, .close = mbox_close_mailbox, + .open_new_msg = mbox_open_new_message, }; struct mx_ops mx_mmdf_ops = { .open = mbox_open_mailbox, .close = mbox_close_mailbox, + .open_new_msg = mbox_open_new_message, }; diff -r 79c379cb0c21 -r 261939e71d80 mh.c --- a/mh.c Tue May 24 12:45:21 2016 -0700 +++ b/mh.c Wed May 25 15:58:04 2016 -0700 @@ -1248,7 +1248,7 @@ * Open a new (temporary) message in an MH folder. */ -int mh_open_new_message (MESSAGE * msg, CONTEXT * dest, HEADER * hdr) +static int mh_open_new_message (MESSAGE * msg, CONTEXT * dest, HEADER * hdr) { return mh_mkstemp (dest, &msg->fp, &msg->path); } @@ -1294,7 +1294,7 @@ * */ -int maildir_open_new_message (MESSAGE * msg, CONTEXT * dest, HEADER * hdr) +static int maildir_open_new_message (MESSAGE * msg, CONTEXT * dest, HEADER * hdr) { int fd; char path[_POSIX_PATH_MAX]; @@ -2361,9 +2361,11 @@ struct mx_ops mx_maildir_ops = { .open = maildir_open_mailbox, .close = mh_close_mailbox, + .open_new_msg = maildir_open_new_message, }; struct mx_ops mx_mh_ops = { .open = mh_open_mailbox, .close = mh_close_mailbox, + .open_new_msg = mh_open_new_message, }; diff -r 79c379cb0c21 -r 261939e71d80 mutt.h --- a/mutt.h Tue May 24 12:45:21 2016 -0700 +++ b/mutt.h Wed May 25 15:58:04 2016 -0700 @@ -869,11 +869,22 @@ }; struct _context; +struct _message; +/* + * struct mx_ops - a structure to store operations on a mailbox + * The following operations are mandatory: + * - open + * - close + * + * Optional operations + * - open_new_msg + */ struct mx_ops { int (*open)(struct _context *); int (*close)(struct _context *); + int (*open_new_msg) (struct _message *, struct _context *, HEADER *); }; typedef struct _context diff -r 79c379cb0c21 -r 261939e71d80 mx.c --- a/mx.c Tue May 24 12:45:21 2016 -0700 +++ b/mx.c Wed May 25 15:58:04 2016 -0700 @@ -1197,31 +1197,6 @@ return (rc); } - -/* {maildir,mh}_open_new_message are in mh.c. */ - -static int mbox_open_new_message (MESSAGE *msg, CONTEXT *dest, HEADER *hdr) -{ - msg->fp = dest->fp; - return 0; -} - -#ifdef USE_IMAP -static int imap_open_new_message (MESSAGE *msg, CONTEXT *dest, HEADER *hdr) -{ - char tmp[_POSIX_PATH_MAX]; - - mutt_mktemp (tmp, sizeof (tmp)); - if ((msg->fp = safe_fopen (tmp, "w")) == NULL) - { - mutt_perror (tmp); - return (-1); - } - msg->path = safe_strdup(tmp); - return 0; -} -#endif - /* args: * dest destination mailbox * hdr message being copied (required for maildir support, because @@ -1229,31 +1204,18 @@ */ MESSAGE *mx_open_new_message (CONTEXT *dest, HEADER *hdr, int flags) { + /* TODO: Convert this to use dest->mx_ops after + * mx_open_mailbox_append() is changed to set mx_ops. + */ + struct mx_ops *ops = mx_get_ops (dest->magic); + ADDRESS *p = NULL; MESSAGE *msg; - int (*func) (MESSAGE *, CONTEXT *, HEADER *); - ADDRESS *p = NULL; - switch (dest->magic) + if (!ops || !ops->open_new_msg) { - case MUTT_MMDF: - case MUTT_MBOX: - func = mbox_open_new_message; - break; - case MUTT_MAILDIR: - func = maildir_open_new_message; - break; - case MUTT_MH: - func = mh_open_new_message; - break; -#ifdef USE_IMAP - case MUTT_IMAP: - func = imap_open_new_message; - break; -#endif - default: dprint (1, (debugfile, "mx_open_new_message(): function unimplemented for mailbox type %d.\n", - dest->magic)); - return (NULL); + dest->magic)); + return NULL; } msg = safe_calloc (1, sizeof (MESSAGE)); @@ -1271,8 +1233,8 @@ if(msg->received == 0) time(&msg->received); - - if (func (msg, dest, hdr) == 0) + + if (ops->open_new_msg (msg, dest, hdr) == 0) { if (dest->magic == MUTT_MMDF) fputs (MMDF_SEP, msg->fp); diff -r 79c379cb0c21 -r 261939e71d80 mx.h --- a/mx.h Tue May 24 12:45:21 2016 -0700 +++ b/mx.h Wed May 25 15:58:04 2016 -0700 @@ -62,9 +62,6 @@ int maildir_commit_message (CONTEXT *, MESSAGE *, HEADER *); int mh_commit_message (CONTEXT *, MESSAGE *, HEADER *); -int maildir_open_new_message (MESSAGE *, CONTEXT *, HEADER *); -int mh_open_new_message (MESSAGE *, CONTEXT *, HEADER *); - FILE *maildir_open_find_message (const char *, const char *); int mbox_strict_cmp_headers (const HEADER *, const HEADER *);
