From 1b33e6c7073075f5613e4bb227aec76e0b2fefb4 Mon Sep 17 00:00:00 2001 From: Thomas Roessler Date: Wed, 13 Mar 2002 23:34:58 +0000 Subject: [PATCH] Don't fopen mail folders in append mode where we should safe_fopen() them in write mode. Debian bug #138200, noted by Colin Philipps . NEEDS BACKPORTING. --- attach.c | 2 +- editmsg.c | 2 +- mailbox.h | 3 +++ mx.c | 8 ++++---- 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/attach.c b/attach.c index 5921ddf20..3d78708e5 100644 --- a/attach.c +++ b/attach.c @@ -762,7 +762,7 @@ int mutt_save_attachment (FILE *fp, BODY *m, char *path, int flags, HEADER *hdr) 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) { diff --git a/editmsg.c b/editmsg.c index 50cc42b2b..19c4a2ebe 100644 --- a/editmsg.c +++ b/editmsg.c @@ -65,7 +65,7 @@ static int edit_one_message (CONTEXT *ctx, HEADER *cur) 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; diff --git a/mailbox.h b/mailbox.h index ed59440a7..0d6ce8438 100644 --- a/mailbox.h +++ b/mailbox.h @@ -24,6 +24,9 @@ #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 */ diff --git a/mx.c b/mx.c index 111014cc6..d270c0e13 100644 --- a/mx.c +++ b/mx.c @@ -489,7 +489,7 @@ int mx_access (const char* path, int flags) 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; @@ -585,7 +585,7 @@ static int mx_open_mailbox_append (CONTEXT *ctx) { 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) @@ -640,9 +640,9 @@ CONTEXT *mx_open_mailbox (const char *path, int flags, CONTEXT *pctx) 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) -- 2.40.0