From: pdmef Date: Thu, 28 Apr 2005 16:02:43 +0000 (+0000) Subject: Rocco Rutte: X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=commitdiff_plain;h=ce220f6dc8789ed75468c63adce953fbdfed11a8 Rocco Rutte: modularize mx_open_new_message() git-svn-id: svn://svn.berlios.de/mutt-ng/trunk@277 e385b8ad-14ed-0310-8656-cc95a2468c6d --- diff --git a/imap/mx_imap.c b/imap/mx_imap.c index 2d3797b..cd6d71b 100644 --- a/imap/mx_imap.c +++ b/imap/mx_imap.c @@ -35,6 +35,17 @@ static int acl_check_imap (CONTEXT* ctx, int bit) { mutt_bit_isset (((IMAP_DATA*) ctx->data)->rights, bit)); } +static int imap_open_new_message (MESSAGE * msg, CONTEXT * dest, HEADER * hdr) +{ + char tmp[_POSIX_PATH_MAX]; + + mutt_mktemp (tmp); + if ((msg->fp = safe_fopen (tmp, "w")) == NULL) + return (-1); + msg->path = safe_strdup (tmp); + return 0; +} + mx_t* imap_reg_mx (void) { mx_t* fmt = safe_calloc (1, sizeof (mx_t)); @@ -43,6 +54,7 @@ mx_t* imap_reg_mx (void) { fmt->mx_is_magic = imap_is_magic; fmt->mx_access = imap_access; fmt->mx_open_mailbox = imap_open_mailbox; + fmt->mx_open_new_message = imap_open_new_message; fmt->mx_acl_check = acl_check_imap; fmt->mx_fastclose_mailbox = imap_close_mailbox; fmt->mx_sync_mailbox = imap_sync_mailbox; diff --git a/mbox.c b/mbox.c index b906bfe..2470bb3 100644 --- a/mbox.c +++ b/mbox.c @@ -47,7 +47,7 @@ struct m_update_t { }; -int mbox_open_new_message (MESSAGE * msg, CONTEXT * dest, HEADER * hdr) +static int mbox_open_new_message (MESSAGE * msg, CONTEXT * dest, HEADER * hdr) { msg->fp = dest->fp; return 0; @@ -1225,6 +1225,7 @@ static mx_t* reg_mx (void) { fmt->mx_is_magic = mbox_is_magic; fmt->mx_access = access; fmt->mx_open_mailbox = mbox_open_mailbox; + fmt->mx_open_new_message = mbox_open_new_message; fmt->mx_sync_mailbox = mbox_sync_mailbox; return (fmt); } diff --git a/mbox.h b/mbox.h index 8ea345a..5379c56 100644 --- a/mbox.h +++ b/mbox.h @@ -30,7 +30,6 @@ void mbox_unlock_mailbox (CONTEXT *); int mbox_check_empty (const char *); int mbox_is_magic (const char*, struct stat*); int mbox_strict_cmp_headers (const HEADER *, const HEADER *); -int mbox_open_new_message (MESSAGE * msg, CONTEXT * dest, HEADER * hdr); mx_t* mbox_reg_mx (void); mx_t* mmdf_reg_mx (void); diff --git a/mh.c b/mh.c index 17b1033..1c6483b 100644 --- a/mh.c +++ b/mh.c @@ -970,7 +970,7 @@ static int maildir_read_dir (CONTEXT * ctx) * 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); } @@ -1018,7 +1018,7 @@ static void maildir_flags (char *dest, size_t destlen, HEADER * hdr) * */ -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]; @@ -1993,6 +1993,7 @@ mx_t* mh_reg_mx (void) { fmt->mx_check_empty = mh_check_empty; fmt->mx_is_magic = mh_is_magic; fmt->mx_open_mailbox = mh_read_dir; + fmt->mx_open_new_message = mh_open_new_message; return (fmt); } @@ -2002,5 +2003,6 @@ mx_t* maildir_reg_mx (void) { fmt->mx_check_empty = maildir_check_empty; fmt->mx_is_magic = maildir_is_magic; fmt->mx_open_mailbox = maildir_read_dir; + fmt->mx_open_new_message = maildir_open_new_message; return (fmt); } diff --git a/mh.h b/mh.h index e395254..9e1089e 100644 --- a/mh.h +++ b/mh.h @@ -24,11 +24,9 @@ int mh_check_mailbox (CONTEXT *, int *); int mh_buffy (const char *); int mh_commit_message (CONTEXT *, MESSAGE *, HEADER *); -int mh_open_new_message (MESSAGE *, CONTEXT *, HEADER *); int maildir_check_mailbox (CONTEXT *, int *); int maildir_commit_message (CONTEXT *, MESSAGE *, HEADER *); -int maildir_open_new_message (MESSAGE *, CONTEXT *, HEADER *); FILE *maildir_open_find_message (const char *, const char *); mx_t* maildir_reg_mx (void); diff --git a/mx.c b/mx.c index 54548b0..5764a51 100644 --- a/mx.c +++ b/mx.c @@ -1094,19 +1094,6 @@ int mx_sync_mailbox (CONTEXT * ctx, int *index_hint) return (rc); } -#ifdef USE_IMAP -int imap_open_new_message (MESSAGE * msg, CONTEXT * dest, HEADER * hdr) -{ - char tmp[_POSIX_PATH_MAX]; - - mutt_mktemp (tmp); - if ((msg->fp = safe_fopen (tmp, "w")) == NULL) - return (-1); - msg->path = safe_strdup (tmp); - return 0; -} -#endif - /* args: * dest destintation mailbox * hdr message being copied (required for maildir support, because @@ -1115,30 +1102,11 @@ int imap_open_new_message (MESSAGE * msg, CONTEXT * dest, HEADER * hdr) MESSAGE *mx_open_new_message (CONTEXT * dest, HEADER * hdr, int flags) { MESSAGE *msg; - int (*func) (MESSAGE *, CONTEXT *, HEADER *); ADDRESS *p = NULL; - switch (dest->magic) { - case M_MMDF: - case M_MBOX: - func = mbox_open_new_message; - break; - case M_MAILDIR: - func = maildir_open_new_message; - break; - case M_MH: - func = mh_open_new_message; - break; -#ifdef USE_IMAP - case M_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)); + if (!MX_IDX(dest->magic-1)) { + dprint (1, (debugfile, "mx_open_new_message(): function " + "unimplemented for mailbox type %d.\n", dest->magic)); return (NULL); } @@ -1156,7 +1124,7 @@ MESSAGE *mx_open_new_message (CONTEXT * dest, HEADER * hdr, int flags) if (msg->received == 0) time (&msg->received); - if (func (msg, dest, hdr) == 0) { + if (MX_COMMAND(dest->magic-1,mx_open_new_message)(msg, dest, hdr) == 0) { if (dest->magic == M_MMDF) fputs (MMDF_SEP, msg->fp); diff --git a/mx.h b/mx.h index 57de519..cf032d4 100644 --- a/mx.h +++ b/mx.h @@ -65,6 +65,19 @@ enum { break; \ } +typedef struct { + FILE *fp; /* pointer to the message data */ + char *path; /* path to temp file */ + short magic; /* type of mailbox this message belongs to */ + short write; /* nonzero if message is open for writing */ + struct { + unsigned read:1; + unsigned flagged:1; + unsigned replied:1; + } flags; + time_t received; /* the time at which this message was received */ +} MESSAGE; + typedef struct { /* folder magic */ int type; @@ -78,6 +91,8 @@ typedef struct { int (*mx_access) (const char*, int); /* read mailbox into ctx structure */ int (*mx_open_mailbox) (CONTEXT*); + /* open new message */ + int (*mx_open_new_message) (MESSAGE*, CONTEXT*, HEADER*); /* check ACL flags; if not implemented, always assume granted * permissions */ int (*mx_acl_check) (CONTEXT*, int); @@ -113,19 +128,6 @@ enum { M_FLAGS /* nondestructive flags change (IMAP) */ }; -typedef struct { - FILE *fp; /* pointer to the message data */ - char *path; /* path to temp file */ - short magic; /* type of mailbox this message belongs to */ - short write; /* nonzero if message is open for writing */ - struct { - unsigned read:1; - unsigned flagged:1; - unsigned replied:1; - } flags; - time_t received; /* the time at which this message was received */ -} MESSAGE; - WHERE short DefaultMagic INITVAL (M_MBOX); /*