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,
struct mx_ops mx_imap_ops = {
.open = imap_open_mailbox,
.close = imap_close_mailbox,
+ .open_new_msg = imap_open_new_message,
};
MUTT_FLAGS /* nondestructive flags change (IMAP) */
};
-typedef struct
+typedef struct _message
{
FILE *fp; /* pointer to the message data */
char *path; /* path to temp file */
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)
{
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,
};
* 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);
}
*
*/
-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];
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,
};
};
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
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
*/
MESSAGE *mx_open_new_message (CONTEXT *dest, HEADER *hdr, int flags)
{
- MESSAGE *msg;
- int (*func) (MESSAGE *, CONTEXT *, HEADER *);
+ struct mx_ops *ops = mx_get_ops (dest->magic);
ADDRESS *p = NULL;
+ MESSAGE *msg;
- 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));
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);
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 *);