fseek (fp, m->offset, 0);
if (fgets (buf, sizeof (buf), fp) == NULL)
return -1;
- if (mx_open_mailbox(path, M_APPEND | M_QUIET, &ctx) == NULL)
+ if (mx_open_mailbox (path, (flags == M_SAVE_APPEND ? M_APPEND : M_NEW) | M_QUIET, &ctx) == NULL)
return -1;
if ((msg = mx_open_new_message (&ctx, hn, is_from (buf, NULL, 0, NULL) ? 0 : M_ADD_FROM)) == NULL)
{
omagic = DefaultMagic;
DefaultMagic = M_MBOX;
- rc = (mx_open_mailbox (tmp, M_APPEND, &tmpctx) == NULL) ? -1 : 0;
+ rc = (mx_open_mailbox (tmp, M_NEW, &tmpctx) == NULL) ? -1 : 0;
DefaultMagic = omagic;
#define M_APPEND (1<<1) /* open mailbox for appending messages */
#define M_READONLY (1<<2) /* open in read-only mode */
#define M_QUIET (1<<3) /* do not print any messages */
+#define M_NEW (1<<4) /* create a new folder - same as M_APPEND, but uses
+ * safe_fopen() for mbox-style folders.
+ */
/* mx_open_new_message() */
#define M_ADD_FROM 1 /* add a From_ line */
return access (path, flags);
}
-static int mx_open_mailbox_append (CONTEXT *ctx)
+static int mx_open_mailbox_append (CONTEXT *ctx, int flags)
{
struct stat sb;
{
case M_MBOX:
case M_MMDF:
- if ((ctx->fp = fopen (ctx->path, "a")) == NULL ||
+ if ((ctx->fp = safe_fopen (ctx->path, flags & M_NEW ? "w" : "a")) == NULL ||
mbox_lock_mailbox (ctx, 1, 1) != 0)
{
if (!ctx->fp)
if (flags & M_READONLY)
ctx->readonly = 1;
- if (flags & M_APPEND)
+ if (flags & (M_APPEND|M_NEW))
{
- if (mx_open_mailbox_append (ctx) != 0)
+ if (mx_open_mailbox_append (ctx, flags) != 0)
{
mx_fastclose_mailbox (ctx);
if (!pctx)