changeset: 6747:e778db6e693c
user:      Kevin McCarthy <[email protected]>
date:      Mon Aug 01 18:25:28 2016 -0700
link:      http://dev.mutt.org/hg/mutt/rev/e778db6e693c

Use a different flag in mx_open_mailbox_append() when mailbox doesn't exist.

The previous commit re-used MUTT_NEWFOLDER, but the meaning of that
flag is slightly different: it causes mbox to use fopen with mode "w",
and is used only for the case of a brand-new mktemp-generated mbox.

Setting it for other non-existing mbox files leads to a race condition
between the stat and the fopen/lock, and so could end up truncating an
existing mailbox created in-between!

Create a different flag, MUTT_APPENDNEW to notify the open_append()
functions that the mailbox doesn't exist.  Change maildir and mh to
check for that flag to create their directory structures.

diffs (49 lines):

diff -r 2b9d6165b8b7 -r e778db6e693c mailbox.h
--- a/mailbox.h Mon Aug 01 15:04:45 2016 -0700
+++ b/mailbox.h Mon Aug 01 18:25:28 2016 -0700
@@ -25,8 +25,11 @@
 #define MUTT_READONLY   (1<<2) /* open in read-only mode */
 #define MUTT_QUIET      (1<<3) /* do not print any messages */
 #define MUTT_NEWFOLDER  (1<<4) /* create a new folder - same as MUTT_APPEND, 
but uses
-                                * safe_fopen() for mbox-style folders. */
+                                * safe_fopen() with mode "w" for mbox-style 
folders.
+                                * This will truncate an existing file. */
 #define MUTT_PEEK       (1<<5) /* revert atime back after taking a look (if 
applicable) */
+#define MUTT_APPENDNEW  (1<<6) /* set in mx_open_mailbox_append if the mailbox 
doesn't
+                                * exist. used by maildir/mh to create the 
mailbox. */
 
 /* mx_open_new_message() */
 #define MUTT_ADD_FROM   (1<<0)  /* add a From_ line */
diff -r 2b9d6165b8b7 -r e778db6e693c mh.c
--- a/mh.c      Mon Aug 01 15:04:45 2016 -0700
+++ b/mh.c      Mon Aug 01 18:25:28 2016 -0700
@@ -1294,7 +1294,7 @@
 {
   char tmp[_POSIX_PATH_MAX];
 
-  if (flags & MUTT_NEWFOLDER)
+  if (flags & MUTT_APPENDNEW)
   {
     if (mkdir (ctx->path, S_IRWXU))
     {
@@ -1346,7 +1346,7 @@
   char tmp[_POSIX_PATH_MAX];
   int i;
 
-  if (flags & MUTT_NEWFOLDER)
+  if (flags & MUTT_APPENDNEW)
   {
     if (mkdir (ctx->path, S_IRWXU))
     {
diff -r 2b9d6165b8b7 -r e778db6e693c mx.c
--- a/mx.c      Mon Aug 01 15:04:45 2016 -0700
+++ b/mx.c      Mon Aug 01 18:25:28 2016 -0700
@@ -495,7 +495,7 @@
       if (errno == ENOENT)
       {
         ctx->magic = DefaultMagic;
-        flags |= MUTT_NEWFOLDER;
+        flags |= MUTT_APPENDNEW;
       }
       else
       {

Reply via email to