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.
#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 */
{
char tmp[_POSIX_PATH_MAX];
- if (flags & MUTT_NEWFOLDER)
+ if (flags & MUTT_APPENDNEW)
{
if (mkdir (ctx->path, S_IRWXU))
{
char tmp[_POSIX_PATH_MAX];
int i;
- if (flags & MUTT_NEWFOLDER)
+ if (flags & MUTT_APPENDNEW)
{
if (mkdir (ctx->path, S_IRWXU))
{
if (errno == ENOENT)
{
ctx->magic = DefaultMagic;
- flags |= MUTT_NEWFOLDER;
+ flags |= MUTT_APPENDNEW;
}
else
{