]> granicus.if.org Git - neomutt/commitdiff
fix: maildir creation 639/head
authorChristopher John CZETTEL <chris@christopher-czettel.net>
Mon, 19 Jun 2017 01:54:33 +0000 (03:54 +0200)
committerRichard Russon <rich@flatcap.org>
Sat, 24 Jun 2017 10:29:59 +0000 (11:29 +0100)
- added missing recursive directory creation after user prompt
- checked for trailing '/' when saving mbox

commands.c
muttlib.c

index 9002f0d15dbe790e93feb82fde050a4aa5feb50d..bd740b736c41e94de8b2d6b847f60070776a6551 100644 (file)
@@ -801,6 +801,15 @@ int mutt_save_message(struct Header *h, int delete, int decode, int decrypt)
   else
     strfcpy(LastSaveFolder, buf, sizeof(LastSaveFolder));
 
+  /* check if path is a filename by comparing last character
+   * (mboxes need filenames, not directories)
+   */
+  if (DefaultMagic == MUTT_MBOX && buf[strlen(buf) - 1] == '/')
+  {
+    mutt_error(_("'%s' is a directory, need a filename for mbox."), buf);
+    return -1;
+  }
+
   mutt_expand_path(buf, sizeof(buf));
 
   /* check to make sure that this file is really the one the user wants */
index 3942e72ee1b962edd8c7e0822b54f5ada9d17a67..40608929f122782b7ac10ae6f19cb75305ef4b98 100644 (file)
--- a/muttlib.c
+++ b/muttlib.c
@@ -21,6 +21,7 @@
 #include <ctype.h>
 #include <errno.h>
 #include <inttypes.h>
+#include <libgen.h>
 #include <libintl.h>
 #include <limits.h>
 #include <pwd.h>
@@ -1865,6 +1866,7 @@ int mutt_save_confirm(const char *s, struct stat *st)
     st->st_mtime = 0;
     st->st_atime = 0;
 
+    /* pathname does not exist */
     if (errno == ENOENT)
     {
       if (option(OPTCONFIRMCREATE))
@@ -1875,6 +1877,20 @@ int mutt_save_confirm(const char *s, struct stat *st)
         else if (rc == MUTT_ABORT)
           ret = -1;
       }
+
+      /* user confirmed with MUTT_YES or set OPTCONFIRMCREATE */
+      if (ret == 0)
+      {
+        strncpy(tmp, s, sizeof(tmp) - 1);
+
+        /* create dir recursively */
+        if (mutt_mkdir(dirname(tmp), S_IRWXU) == -1)
+        {
+          /* report failure & abort */
+          mutt_perror(s);
+          return 1;
+        }
+      }
     }
     else
     {