}
/**
- * mutt_comp_sync - Save changes to the compressed mailbox file
+ * sync_mailbox - Save changes to the compressed mailbox file
* @ctx: Mailbox to sync
*
- * Changes in Mutt only affect the tmp file. Calling mutt_comp_sync()
+ * Changes in Mutt only affect the tmp file. Calling sync_mailbox()
* will commit them to the compressed file.
*
* Returns:
* 0: Success
* -1: Failure
*/
-int
-mutt_comp_sync (CONTEXT *ctx)
+static int
+sync_mailbox (CONTEXT *ctx, int *index_hint)
{
if (!ctx)
return -1;
return -1;
}
- /* TODO: need to refactor sync so we can lock around the
- * path sync as well as the compress operation */
+ struct mx_ops *ops = ci->child_ops;
+ if (!ops)
+ return -1;
+
if (!lock_realpath (ctx, 1))
{
mutt_error (_("Unable to lock mailbox!"));
return -1;
}
- int rc = execute_command (ctx, ci->close, _("Compressing %s"));
+ /* TODO: check if mailbox changed first! */
+
+ int rc = ops->sync (ctx, index_hint);
+ if (rc != 0)
+ {
+ unlock_realpath (ctx);
+ return rc;
+ }
+
+ rc = execute_command (ctx, ci->close, _("Compressing %s"));
if (rc == 0)
+ {
+ unlock_realpath (ctx);
return -1;
-
- unlock_realpath (ctx);
+ }
store_size (ctx);
+ unlock_realpath (ctx);
+
return 0;
}
.open_append = open_append_mailbox,
.close = close_mailbox,
.check = check_mailbox,
+ .sync = sync_mailbox,
.open_msg = open_message,
.close_msg = close_message,
.commit_msg = commit_message,
int mutt_comp_can_append (CONTEXT *ctx);
int mutt_comp_can_read (const char *path);
-int mutt_comp_sync (CONTEXT *ctx);
int mutt_comp_valid_command (const char *cmd);
extern struct mx_ops mx_comp_ops;
.commit_msg = imap_commit_message,
.open_new_msg = imap_open_new_message,
.check = imap_check_mailbox_reopen,
+ .sync = NULL, /* imap syncing is handled by imap_sync_mailbox */
};
* 0 success
* -1 failure
*/
-int mbox_sync_mailbox (CONTEXT *ctx, int *index_hint)
+static int mbox_sync_mailbox (CONTEXT *ctx, int *index_hint)
{
char tempfile[_POSIX_PATH_MAX];
char buf[32];
FILE *fp = NULL;
progress_t progress;
char msgbuf[STRING];
+ BUFFY *tmp = NULL;
/* sort message by their position in the mailbox on disk */
if (Sort != SORT_ORDER)
unlink (tempfile); /* remove partial copy of the mailbox */
mutt_unblock_signals ();
+ if (option(OPTCHECKMBOXSIZE))
+ {
+ tmp = mutt_find_mailbox (ctx->path);
+ if (tmp && tmp->new == 0)
+ mutt_update_mailbox (tmp);
+ }
+
return (0); /* signal success */
bail: /* Come here in case of disaster */
.commit_msg = mbox_commit_message,
.open_new_msg = mbox_open_new_message,
.check = mbox_check_mailbox,
+ .sync = mbox_sync_mailbox,
};
struct mx_ops mx_mmdf_ops = {
.commit_msg = mmdf_commit_message,
.open_new_msg = mbox_open_new_message,
.check = mbox_check_mailbox,
+ .sync = mbox_sync_mailbox,
};
.commit_msg = maildir_commit_message,
.open_new_msg = maildir_open_new_message,
.check = maildir_check_mailbox,
+ .sync = mh_sync_mailbox,
};
struct mx_ops mx_mh_ops = {
.commit_msg = mh_commit_message,
.open_new_msg = mh_open_new_message,
.check = mh_check_mailbox,
+ .sync = mh_sync_mailbox,
};
int (*open_append) (struct _context *, int flags);
int (*close) (struct _context *);
int (*check) (struct _context *ctx, int *index_hint);
+ int (*sync) (struct _context *ctx, int *index_hint);
int (*open_msg) (struct _context *, struct _message *, int msgno);
int (*close_msg) (struct _context *, struct _message *);
int (*commit_msg) (struct _context *, struct _message *);
/* save changes to disk */
static int sync_mailbox (CONTEXT *ctx, int *index_hint)
{
- BUFFY *tmp = NULL;
- int rc = -1;
+ if (!ctx->mx_ops || !ctx->mx_ops->sync)
+ return -1;
if (!ctx->quiet)
mutt_message (_("Writing %s..."), ctx->path);
- switch (ctx->magic)
- {
- case MUTT_MBOX:
- case MUTT_MMDF:
- rc = mbox_sync_mailbox (ctx, index_hint);
- if (option(OPTCHECKMBOXSIZE))
- tmp = mutt_find_mailbox (ctx->path);
- break;
-
- case MUTT_MH:
- case MUTT_MAILDIR:
- rc = mh_sync_mailbox (ctx, index_hint);
- break;
-
-#ifdef USE_IMAP
- case MUTT_IMAP:
- /* extra argument means EXPUNGE */
- rc = imap_sync_mailbox (ctx, 1, index_hint);
- break;
-#endif /* USE_IMAP */
-
-#ifdef USE_POP
- case MUTT_POP:
- rc = pop_sync_mailbox (ctx, index_hint);
- break;
-#endif /* USE_POP */
- }
-
-#if 0
- if (!ctx->quiet && !ctx->shutup && rc == -1)
- mutt_error ( _("Could not synchronize mailbox %s!"), ctx->path);
-#endif
-
- if (tmp && tmp->new == 0)
- mutt_update_mailbox (tmp);
-
-#ifdef USE_COMPRESSED
- /* If everything went well, the mbox handler saved the changes to our
- * temporary file. Next, mutt_comp_sync() will compress the temporary file. */
- if ((rc == 0) && ctx->compress_info)
- return mutt_comp_sync (ctx);
-#endif
-
- return rc;
+ return ctx->mx_ops->sync (ctx, index_hint);
}
/* move deleted mails to the trash folder */
#define MMDF_SEP "\001\001\001\001\n"
#define MAXLOCKATTEMPT 5
-int mbox_sync_mailbox (CONTEXT *, int *);
int mbox_lock_mailbox (CONTEXT *, int, int);
int mbox_parse_mailbox (CONTEXT *);
int mmdf_parse_mailbox (CONTEXT *);
int mbox_check_empty (const char *);
void mbox_reset_atime (CONTEXT *, struct stat *);
-int mh_sync_mailbox (CONTEXT *, int *);
int mh_check_empty (const char *);
int maildir_check_empty (const char *);
}
/* update POP mailbox - delete messages from server */
-int pop_sync_mailbox (CONTEXT *ctx, int *index_hint)
+static int pop_sync_mailbox (CONTEXT *ctx, int *index_hint)
{
int i, j, ret = 0;
char buf[LONG_STRING];
.check = pop_check_mailbox,
.commit_msg = NULL,
.open_new_msg = NULL,
+ .sync = pop_sync_mailbox,
};
void pop_error (POP_DATA *, char *);
/* pop.c */
-int pop_sync_mailbox (CONTEXT *, int *);
int pop_close_mailbox (CONTEXT *);
void pop_fetch_mail (void);