int app = 0;
char buf[PATH_MAX];
const char *prompt = NULL;
- struct Context ctx;
+ struct Context *savectx = NULL;
struct stat st;
if (delete)
}
#endif
- if (mx_mbox_open(buf, MUTT_APPEND, &ctx))
+ savectx = mx_mbox_open(buf, MUTT_APPEND, NULL);
+ if (savectx)
{
#ifdef USE_COMPRESSED
/* If we're saving to a compressed mailbox, the stats won't be updated
* until the next open. Until then, improvise. */
struct Mailbox *cm = NULL;
- if (ctx.compress_info)
- cm = mutt_find_mailbox(ctx.realpath);
+ if (savectx->compress_info)
+ cm = mutt_find_mailbox(savectx->realpath);
/* We probably haven't been opened yet */
if (cm && (cm->msg_count == 0))
cm = NULL;
#endif
if (h)
{
- if (mutt_save_message_ctx(h, delete, decode, decrypt, &ctx) != 0)
+ if (mutt_save_message_ctx(h, delete, decode, decrypt, savectx) != 0)
{
- mx_mbox_close(&ctx, NULL);
+ mx_mbox_close(savectx, NULL);
+ FREE(&savectx);
return -1;
}
#ifdef USE_COMPRESSED
continue;
mutt_message_hook(Context, Context->hdrs[i], MUTT_MESSAGE_HOOK);
- rc = mutt_save_message_ctx(Context->hdrs[i], delete, decode, decrypt, &ctx);
+ rc = mutt_save_message_ctx(Context->hdrs[i], delete, decode, decrypt, savectx);
if (rc != 0)
break;
#ifdef USE_COMPRESSED
#endif
if (rc != 0)
{
- mx_mbox_close(&ctx, NULL);
+ mx_mbox_close(savectx, NULL);
+ FREE(&savectx);
return -1;
}
}
- const int need_mailbox_cleanup = (ctx.magic == MUTT_MBOX || ctx.magic == MUTT_MMDF);
+ const bool need_mailbox_cleanup = ((savectx->magic == MUTT_MBOX) || (savectx->magic == MUTT_MMDF));
- mx_mbox_close(&ctx, NULL);
+ mx_mbox_close(savectx, NULL);
+ FREE(&savectx);
if (need_mailbox_cleanup)
mutt_mailbox_cleanup(buf, &st);
* switch statement would need to be run. */
mutt_folder_hook(buf);
- Context = mx_mbox_open(
- buf, (ReadOnly || (op == OP_MAIN_CHANGE_FOLDER_READONLY)) ? MUTT_READONLY : 0, NULL);
+ const int flags = (ReadOnly || (op == OP_MAIN_CHANGE_FOLDER_READONLY)) ? MUTT_READONLY : 0;
+ Context = mx_mbox_open(buf, flags, NULL);
if (Context)
{
menu->current = ci_first_message();
int of, cf;
- struct Context tmpctx;
+ struct Context *tmpctx = NULL;
struct Message *msg = NULL;
FILE *fp = NULL;
omagic = MboxType;
MboxType = MUTT_MBOX;
- rc = mx_mbox_open(tmp, MUTT_NEWFOLDER, &tmpctx) ? 0 : -1;
+ tmpctx = mx_mbox_open(tmp, MUTT_NEWFOLDER, NULL);
MboxType = omagic;
- if (rc == -1)
+ if (!tmpctx)
{
mutt_error(_("could not create temporary folder: %s"), strerror(errno));
return -1;
}
- rc = mutt_append_message(
- &tmpctx, ctx, cur, 0,
- CH_NOLEN | ((ctx->magic == MUTT_MBOX || ctx->magic == MUTT_MMDF) ? 0 : CH_NOSTATUS));
+ const int chflags = CH_NOLEN | ((ctx->magic == MUTT_MBOX || ctx->magic == MUTT_MMDF) ? 0 : CH_NOSTATUS);
+ rc = mutt_append_message(tmpctx, ctx, cur, 0, chflags);
oerrno = errno;
- mx_mbox_close(&tmpctx, NULL);
+ mx_mbox_close(tmpctx, NULL);
+ FREE(&tmpctx);
if (rc == -1)
{
goto bail;
}
- if (!mx_mbox_open(ctx->path, MUTT_APPEND, &tmpctx))
+ tmpctx = mx_mbox_open(ctx->path, MUTT_APPEND, NULL);
+ if (!tmpctx)
{
rc = -1;
/* L10N: %s is from strerror(errno) */
}
of = 0;
- cf = ((tmpctx.magic == MUTT_MBOX || tmpctx.magic == MUTT_MMDF) ? 0 : CH_NOSTATUS);
+ cf = (((tmpctx->magic == MUTT_MBOX) || (tmpctx->magic == MUTT_MMDF)) ? 0 : CH_NOSTATUS);
if (fgets(buf, sizeof(buf), fp) && is_from(buf, NULL, 0, NULL))
{
- if (tmpctx.magic == MUTT_MBOX || tmpctx.magic == MUTT_MMDF)
+ if ((tmpctx->magic == MUTT_MBOX) || (tmpctx->magic == MUTT_MMDF))
cf = CH_FROM | CH_FORCE_FROM;
}
else
o_old = cur->old;
cur->read = false;
cur->old = false;
- msg = mx_msg_open_new(&tmpctx, cur, of);
+ msg = mx_msg_open_new(tmpctx, cur, of);
cur->read = o_read;
cur->old = o_old;
if (!msg)
{
mutt_error(_("Can't append to folder: %s"), strerror(errno));
- mx_mbox_close(&tmpctx, NULL);
+ mx_mbox_close(tmpctx, NULL);
+ FREE(&tmpctx);
goto bail;
}
mutt_file_copy_stream(fp, msg->fp);
}
- rc = mx_msg_commit(&tmpctx, msg);
- mx_msg_close(&tmpctx, &msg);
+ rc = mx_msg_commit(tmpctx, msg);
+ mx_msg_close(tmpctx, &msg);
- mx_mbox_close(&tmpctx, NULL);
+ mx_mbox_close(tmpctx, NULL);
+ FREE(&tmpctx);
bail:
if (fp)
static int mailbox_mbox_check(struct Mailbox *mailbox, struct stat *sb, bool check_stats)
{
int rc = 0;
- int new_or_changed;
- struct Context ctx;
+ bool new_or_changed;
if (CheckMboxSize)
- new_or_changed = sb->st_size > mailbox->size;
+ new_or_changed = (sb->st_size > mailbox->size);
else
{
- new_or_changed = sb->st_mtime > sb->st_atime ||
- (mailbox->newly_created && sb->st_ctime == sb->st_mtime &&
- sb->st_ctime == sb->st_atime);
+ new_or_changed = (sb->st_mtime > sb->st_atime) ||
+ (mailbox->newly_created && (sb->st_ctime == sb->st_mtime) &&
+ (sb->st_ctime == sb->st_atime));
}
if (new_or_changed)
if (check_stats && (mailbox->stats_last_checked < sb->st_mtime))
{
- if (mx_mbox_open(mailbox->path, MUTT_READONLY | MUTT_QUIET | MUTT_NOSORT | MUTT_PEEK,
- &ctx))
+ struct Context *ctx = mx_mbox_open(mailbox->path, MUTT_READONLY | MUTT_QUIET | MUTT_NOSORT | MUTT_PEEK, NULL);
+ if (ctx)
{
- mailbox->msg_count = ctx.msgcount;
- mailbox->msg_unread = ctx.unread;
- mailbox->msg_flagged = ctx.flagged;
- mailbox->stats_last_checked = ctx.mtime;
- mx_mbox_close(&ctx, 0);
+ mailbox->msg_count = ctx->msgcount;
+ mailbox->msg_unread = ctx->unread;
+ mailbox->msg_flagged = ctx->flagged;
+ mailbox->stats_last_checked = ctx->mtime;
+ mx_mbox_close(ctx, NULL);
+ FREE(&ctx);
}
}
/* message type attachments are written to mail folders. */
char buf[HUGE_STRING];
- struct Context ctx;
struct Message *msg = NULL;
int chflags = 0;
int r = -1;
return -1;
if (!fgets(buf, sizeof(buf), fp))
return -1;
- if (!mx_mbox_open(path, MUTT_APPEND | MUTT_QUIET, &ctx))
+ struct Context *ctx = mx_mbox_open(path, MUTT_APPEND | MUTT_QUIET, NULL);
+ if (!ctx)
return -1;
- msg = mx_msg_open_new(&ctx, hn, is_from(buf, NULL, 0, NULL) ? 0 : MUTT_ADD_FROM);
+ msg = mx_msg_open_new(ctx, hn, is_from(buf, NULL, 0, NULL) ? 0 : MUTT_ADD_FROM);
if (!msg)
{
- mx_mbox_close(&ctx, NULL);
+ mx_mbox_close(ctx, NULL);
+ FREE(&ctx);
return -1;
}
- if (ctx.magic == MUTT_MBOX || ctx.magic == MUTT_MMDF)
+ if ((ctx->magic == MUTT_MBOX) || (ctx->magic == MUTT_MMDF))
chflags = CH_FROM | CH_UPDATE_LEN;
- chflags |= (ctx.magic == MUTT_MAILDIR ? CH_NOSTATUS : CH_UPDATE);
- if (mutt_copy_message_fp(msg->fp, fp, hn, 0, chflags) == 0 &&
- mx_msg_commit(&ctx, msg) == 0)
+ chflags |= (ctx->magic == MUTT_MAILDIR ? CH_NOSTATUS : CH_UPDATE);
+ if ((mutt_copy_message_fp(msg->fp, fp, hn, 0, chflags) == 0) &&
+ (mx_msg_commit(ctx, msg) == 0))
{
r = 0;
}
r = -1;
}
- mx_msg_close(&ctx, &msg);
- mx_mbox_close(&ctx, NULL);
+ mx_msg_close(ctx, &msg);
+ mx_mbox_close(ctx, NULL);
+ FREE(&ctx);
return r;
}
else
*/
static int trash_append(struct Context *ctx)
{
- struct Context ctx_trash;
int i;
struct stat st, stc;
int opt_confappend, rc;
}
#endif
- if (mx_mbox_open(Trash, MUTT_APPEND, &ctx_trash))
+ struct Context *ctx_trash = mx_mbox_open(Trash, MUTT_APPEND, NULL);
+ if (ctx_trash)
{
/* continue from initial scan above */
for (i = first_del; i < ctx->msgcount; i++)
{
if (ctx->hdrs[i]->deleted && (!ctx->hdrs[i]->purge))
{
- if (mutt_append_message(&ctx_trash, ctx, ctx->hdrs[i], 0, 0) == -1)
+ if (mutt_append_message(ctx_trash, ctx, ctx->hdrs[i], 0, 0) == -1)
{
- mx_mbox_close(&ctx_trash, NULL);
+ mx_mbox_close(ctx_trash, NULL);
+ FREE(&ctx_trash);
return -1;
}
}
}
- mx_mbox_close(&ctx_trash, NULL);
+ mx_mbox_close(ctx_trash, NULL);
+ FREE(&ctx_trash);
}
else
{
int mx_mbox_close(struct Context *ctx, int *index_hint)
{
int i, move_messages = 0, purge = 1, read_msgs = 0;
- struct Context f;
char mbox[PATH_MAX];
char buf[PATH_MAX + 64];
else /* use regular append-copy mode */
#endif
{
- if (!mx_mbox_open(mbox, MUTT_APPEND, &f))
+ struct Context *f = mx_mbox_open(mbox, MUTT_APPEND, NULL);
+ if (!f)
{
ctx->closing = false;
return -1;
if (ctx->hdrs[i]->read && !ctx->hdrs[i]->deleted &&
!(ctx->hdrs[i]->flagged && KeepFlagged))
{
- if (mutt_append_message(&f, ctx, ctx->hdrs[i], 0, CH_UPDATE_LEN) == 0)
+ if (mutt_append_message(f, ctx, ctx->hdrs[i], 0, CH_UPDATE_LEN) == 0)
{
mutt_set_flag(ctx, ctx->hdrs[i], MUTT_DELETE, 1);
mutt_set_flag(ctx, ctx->hdrs[i], MUTT_PURGE, 1);
}
else
{
- mx_mbox_close(&f, NULL);
+ mx_mbox_close(f, NULL);
+ FREE(&f);
ctx->closing = false;
return -1;
}
}
}
- mx_mbox_close(&f, NULL);
+ mx_mbox_close(f, NULL);
+ FREE(&f);
}
}
else if (!ctx->changed && ctx->deleted == 0)
struct Header;
struct Context;
+struct Mailbox;
struct stat;
/* These Config Variables are only used in mx.c */
char *url = NULL, *p = NULL;
int delanswer, last = 0, msgs, bytes, rset = 0, ret;
struct Connection *conn = NULL;
- struct Context ctx;
struct Message *msg = NULL;
struct Account acct;
struct PopData *pop_data = NULL;
goto finish;
}
- if (!mx_mbox_open(Spoolfile, MUTT_APPEND, &ctx))
+ struct Context *ctx = mx_mbox_open(Spoolfile, MUTT_APPEND, NULL);
+ if (!ctx)
goto finish;
delanswer = query_quadoption(PopDelete, _("Delete messages from server?"));
for (int i = last + 1; i <= msgs; i++)
{
- msg = mx_msg_open_new(&ctx, NULL, MUTT_ADD_FROM);
+ msg = mx_msg_open_new(ctx, NULL, MUTT_ADD_FROM);
if (!msg)
ret = -3;
else
if (ret == -3)
rset = 1;
- if (ret == 0 && mx_msg_commit(&ctx, msg) != 0)
+ if (ret == 0 && mx_msg_commit(ctx, msg) != 0)
{
rset = 1;
ret = -3;
}
- mx_msg_close(&ctx, &msg);
+ mx_msg_close(ctx, &msg);
}
if (ret == 0 && delanswer == MUTT_YES)
if (ret == -1)
{
- mx_mbox_close(&ctx, NULL);
+ mx_mbox_close(ctx, NULL);
+ FREE(&ctx);
goto fail;
}
if (ret == -2)
msgbuf, i - last, msgs - last);
}
- mx_mbox_close(&ctx, NULL);
+ mx_mbox_close(ctx, NULL);
+ FREE(&ctx);
if (rset)
{
int mutt_num_postponed(bool force)
{
struct stat st;
- struct Context ctx;
static time_t LastModify = 0;
static char *OldPostponed = NULL;
if (optnews)
OptNews = false;
#endif
- if (!mx_mbox_open(Postponed, MUTT_NOSORT | MUTT_QUIET, &ctx))
+ struct Context *ctx = mx_mbox_open(Postponed, MUTT_NOSORT | MUTT_QUIET, NULL);
+ if (!ctx)
PostCount = 0;
else
- PostCount = ctx.msgcount;
- mx_fastclose_mailbox(&ctx);
+ PostCount = ctx->msgcount;
+ mx_fastclose_mailbox(ctx);
+ FREE(&ctx);
#ifdef USE_NNTP
if (optnews)
OptNews = true;
int mutt_write_fcc(const char *path, struct Header *hdr, const char *msgid,
bool post, char *fcc, char **finalpath)
{
- struct Context f;
struct Message *msg = NULL;
char tempfile[PATH_MAX];
FILE *tempfp = NULL;
#ifdef RECORD_FOLDER_HOOK
mutt_folder_hook(path);
#endif
- if (!mx_mbox_open(path, MUTT_APPEND | MUTT_QUIET, &f))
+ struct Context *f = mx_mbox_open(path, MUTT_APPEND | MUTT_QUIET, NULL);
+ if (!f)
{
mutt_debug(1, "unable to open mailbox %s in append-mode, aborting.\n", path);
goto done;
/* We need to add a Content-Length field to avoid problems where a line in
* the message body begins with "From "
*/
- if (f.magic == MUTT_MMDF || f.magic == MUTT_MBOX)
+ if ((f->magic == MUTT_MMDF) || (f->magic == MUTT_MBOX))
{
mutt_mktemp(tempfile, sizeof(tempfile));
tempfp = mutt_file_fopen(tempfile, "w+");
if (!tempfp)
{
mutt_perror(tempfile);
- mx_mbox_close(&f, NULL);
+ mx_mbox_close(f, NULL);
+ FREE(&f);
goto done;
}
/* remember new mail status before appending message */
onm_flags = MUTT_ADD_FROM;
if (post)
onm_flags |= MUTT_SET_DRAFT;
- msg = mx_msg_open_new(&f, hdr, onm_flags);
+ msg = mx_msg_open_new(f, hdr, onm_flags);
if (!msg)
{
mutt_file_fclose(&tempfp);
- mx_mbox_close(&f, NULL);
+ mx_mbox_close(f, NULL);
+ FREE(&f);
goto done;
}
if (post && fcc)
fprintf(msg->fp, "X-Mutt-Fcc: %s\n", fcc);
- if (f.magic == MUTT_MMDF || f.magic == MUTT_MBOX)
+ if ((f->magic == MUTT_MMDF) || (f->magic == MUTT_MBOX))
fprintf(msg->fp, "Status: RO\n");
/* mutt_rfc822_write_header() only writes out a Date: header with
mutt_debug(1, "%s: write failed.\n", tempfile);
mutt_file_fclose(&tempfp);
unlink(tempfile);
- mx_msg_commit(&f, msg); /* XXX really? */
- mx_msg_close(&f, &msg);
- mx_mbox_close(&f, NULL);
+ mx_msg_commit(f, msg); /* XXX really? */
+ mx_msg_close(f, &msg);
+ mx_mbox_close(f, NULL);
+ FREE(&f);
goto done;
}
rc = mutt_write_mime_body(hdr->content, msg->fp);
}
- if (mx_msg_commit(&f, msg) != 0)
+ if (mx_msg_commit(f, msg) != 0)
rc = -1;
else if (finalpath)
*finalpath = mutt_str_strdup(msg->committed_path);
- mx_msg_close(&f, &msg);
- mx_mbox_close(&f, NULL);
+ mx_msg_close(f, &msg);
+ mx_mbox_close(f, NULL);
+ FREE(&f);
if (!post && need_mailbox_cleanup)
mutt_mailbox_cleanup(path, &st);