return;
if (ctx == idata->ctx) {
- if (idata->state = IMAP_SELECTED) {
+ if (idata->state == IMAP_SELECTED) {
/* mx_close_mailbox won't sync if there are no deleted messages
* and the mailbox is unchanged, so we may have to close here */
if (idata->status != IMAP_FATAL && !ctx->deleted &&
return (imap_check_mailbox (ctx, index_hint, 0));
}
+static int imap_commit_message (MESSAGE* msg, CONTEXT* ctx) {
+ int r = 0;
+
+ if ((r = safe_fclose (&msg->fp)) == 0)
+ r = imap_append_message (ctx, msg);
+ return (r);
+}
+
mx_t* imap_reg_mx (void) {
mx_t* fmt = safe_calloc (1, sizeof (mx_t));
fmt->mx_fastclose_mailbox = imap_close_mailbox;
fmt->mx_sync_mailbox = imap_sync_mailbox;
fmt->mx_check_mailbox = _imap_check_mailbox;
+ fmt->mx_commit_message = imap_commit_message;
return (fmt);
}
return (magic);
}
+static int commit_message (MESSAGE* msg, CONTEXT* ctx, int mbox) {
+ if ((mbox && fputc ('\n', msg->fp) == EOF) ||
+ (!mbox && fputs (MMDF_SEP, msg->fp) == EOF))
+ return (-1);
+ if ((fflush (msg->fp) == EOF || fsync (fileno (msg->fp)) == -1)) {
+ mutt_perror (_("Can't write message"));
+ return (-1);
+ }
+ return (0);
+}
+
+static int mbox_commit_message (MESSAGE* msg, CONTEXT* ctx) {
+ return (commit_message (msg, ctx, 1));
+}
+
+static int mmdf_commit_message (MESSAGE* msg, CONTEXT* ctx) {
+ return (commit_message (msg, ctx, 0));
+}
+
static mx_t* reg_mx (void) {
mx_t* fmt = safe_calloc (1, sizeof (mx_t));
fmt->local = 1;
mx_t* mbox_reg_mx (void) {
mx_t* fmt = reg_mx ();
fmt->type = M_MBOX;
+ fmt->mx_commit_message = mbox_commit_message;
return (fmt);
}
mx_t* mmdf_reg_mx (void) {
mx_t* fmt = reg_mx ();
fmt->type = M_MMDF;
+ fmt->mx_commit_message = mmdf_commit_message;
return (fmt);
}
*
*/
-int maildir_commit_message (CONTEXT * ctx, MESSAGE * msg, HEADER * hdr)
+static int maildir_commit_message (MESSAGE * msg, CONTEXT * ctx, HEADER * hdr)
{
char subdir[4];
char suffix[16];
*/
-static int _mh_commit_message (CONTEXT * ctx, MESSAGE * msg, HEADER * hdr,
+static int _mh_commit_message (MESSAGE * msg, CONTEXT * ctx, HEADER * hdr,
short updseq)
{
DIR *dirp;
return 0;
}
-int mh_commit_message (CONTEXT * ctx, MESSAGE * msg, HEADER * hdr)
-{
- return _mh_commit_message (ctx, msg, hdr, 1);
+static int mh_commit_message (MESSAGE * msg, CONTEXT * ctx, HEADER * hdr) {
+ return _mh_commit_message (msg, ctx, hdr, 1);
}
-
/* Sync a message in an MH folder.
*
* This code is also used for attachment deletion in maildir
strfcpy (partpath, h->path, _POSIX_PATH_MAX);
if (ctx->magic == M_MAILDIR)
- rc = maildir_commit_message (ctx, dest, h);
+ rc = maildir_commit_message (dest, ctx, h);
else
- rc = _mh_commit_message (ctx, dest, h, 0);
+ rc = _mh_commit_message (dest, ctx, h, 0);
mx_close_message (&dest);
return (fmt);
}
+static int mh_commit (MESSAGE* msg, CONTEXT* ctx) {
+ return (mh_commit_message (msg, ctx, NULL));
+}
+
+static int maildir_commit (MESSAGE* msg, CONTEXT* ctx) {
+ return (maildir_commit_message (msg, ctx, NULL));
+}
+
mx_t* mh_reg_mx (void) {
mx_t* fmt = reg_mx ();
fmt->type = M_MH;
fmt->mx_open_mailbox = mh_read_dir;
fmt->mx_open_new_message = mh_open_new_message;
fmt->mx_check_mailbox = mh_check_mailbox;
+ fmt->mx_commit_message = mh_commit;
return (fmt);
}
fmt->mx_open_mailbox = maildir_read_dir;
fmt->mx_open_new_message = maildir_open_new_message;
fmt->mx_check_mailbox = maildir_check_mailbox;
+ fmt->mx_commit_message = maildir_commit;
return (fmt);
}
/* TODO all of these must disappear to achieve good information hiding */
int mh_buffy (const char *);
-int mh_commit_message (CONTEXT *, MESSAGE *, HEADER *);
-
-int maildir_commit_message (CONTEXT *, MESSAGE *, HEADER *);
FILE *maildir_open_find_message (const char *, const char *);
+/* these are the only publicly visible for usage */
+
mx_t* maildir_reg_mx (void);
mx_t* mh_reg_mx (void);
/* commit a message to a folder */
-int mx_commit_message (MESSAGE * msg, CONTEXT * ctx)
-{
- int r = 0;
-
+int mx_commit_message (MESSAGE * msg, CONTEXT * ctx) {
if (!(msg->write && ctx->append)) {
debug_print (1, ("msg->write = %d, ctx->append = %d\n", msg->write, ctx->append));
return -1;
}
-
- switch (msg->magic) {
- case M_MMDF:
- {
- if (fputs (MMDF_SEP, msg->fp) == EOF)
- r = -1;
- break;
- }
-
- case M_MBOX:
- {
- if (fputc ('\n', msg->fp) == EOF)
- r = -1;
- break;
- }
-
-#ifdef USE_IMAP
- case M_IMAP:
- {
- if ((r = safe_fclose (&msg->fp)) == 0)
- r = imap_append_message (ctx, msg);
- break;
- }
-#endif
-
- case M_MAILDIR:
- {
- r = maildir_commit_message (ctx, msg, NULL);
- break;
- }
-
- case M_MH:
- {
- r = mh_commit_message (ctx, msg, NULL);
- break;
- }
- }
-
- if (r == 0 && (ctx->magic == M_MBOX || ctx->magic == M_MMDF)
- && (fflush (msg->fp) == EOF || fsync (fileno (msg->fp)) == -1)) {
- mutt_perror (_("Can't write message"));
-
- r = -1;
- }
-
- return r;
+ if (!ctx || !MX_IDX(ctx->magic-1) || !MX_COMMAND(ctx->magic-1,mx_commit_message))
+ return (-1);
+ return (MX_COMMAND(ctx->magic-1,mx_commit_message) (msg, ctx));
}
/* close a pointer to a message */
void (*mx_fastclose_mailbox) (CONTEXT*);
/* write out changes */
int (*mx_sync_mailbox) (CONTEXT*, int, int*);
+ /* commit a message to a folder */
+ int (*mx_commit_message) (MESSAGE*, CONTEXT*);
} mx_t;
/* called from main: init all folder types */