]> granicus.if.org Git - neomutt/commitdiff
Don't fopen mail folders in append mode where we should safe_fopen()
authorThomas Roessler <roessler@does-not-exist.org>
Wed, 13 Mar 2002 23:34:58 +0000 (23:34 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Wed, 13 Mar 2002 23:34:58 +0000 (23:34 +0000)
them in write mode.  Debian bug #138200, noted by Colin Philipps
<cph@cph.demon.co.uk>.

NEEDS BACKPORTING.

attach.c
editmsg.c
mailbox.h
mx.c

index 5921ddf209d264e0c8a2581c49ce2501baed3af6..3d78708e582463e487772bd016574b38abd6229e 100644 (file)
--- 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)
       {
index 50cc42b2b37b58668ec73b96f11deced46647d5c..19c4a2ebea14cbeedcf9f8e77b48ba5ae41ec048 100644 (file)
--- 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;
 
index ed59440a74c31620533cbb49ecac72c85fa7c1a9..0d6ce84386650f4a819306d285cc9c8a5d8a250a 100644 (file)
--- 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 111014cc6e77bfd4f04cdce0c5be05a170654d16..d270c0e13252ed1ecc1a6c352140a30f5662d187 100644 (file)
--- 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)