Several subtle interconnected changes here: - If the folder name passed as argument is the empty string "" or slash "/", the final maildir path would end up having "//" in it. We should strip the final maildir path, not folder. - The folder variable should really be const char *, another reason not to modify it. - The maildir variable is only const to let us point it at db_path directly. To be able to strip the maildir variable, always allocate it. Default folder to the empty string "", and don't treat folder not being present on the command line as anything special. As a side effect, we also create the cur/new/tmp in the top level directory if they're not there and --create-folder is given. --- notmuch-insert.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/notmuch-insert.c b/notmuch-insert.c index 648bd944a7b1..040b6aa0de3b 100644 --- a/notmuch-insert.c +++ b/notmuch-insert.c @@ -452,12 +452,12 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[]) size_t new_tags_length; tag_op_list_t *tag_ops; char *query_string = NULL; - char *folder = NULL; + const char *folder = ""; notmuch_bool_t create_folder = FALSE; notmuch_bool_t keep = FALSE; notmuch_bool_t no_hooks = FALSE; notmuch_bool_t synchronize_flags; - const char *maildir; + char *maildir; char *newpath; int opt_index; unsigned int i; @@ -509,23 +509,21 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[]) return EXIT_FAILURE; } - if (folder == NULL) { - maildir = db_path; - } else { - strip_trailing (folder, '/'); - if (! is_valid_folder_name (folder)) { - fprintf (stderr, "Error: invalid folder name: '%s'\n", folder); - return EXIT_FAILURE; - } - maildir = talloc_asprintf (config, "%s/%s", db_path, folder); - if (! maildir) { - fprintf (stderr, "Out of memory\n"); - return EXIT_FAILURE; - } - if (create_folder && ! maildir_create_folder (config, maildir)) - return EXIT_FAILURE; + if (! is_valid_folder_name (folder)) { + fprintf (stderr, "Error: invalid folder name: '%s'\n", folder); + return EXIT_FAILURE; + } + + maildir = talloc_asprintf (config, "%s/%s", db_path, folder); + if (! maildir) { + fprintf (stderr, "Out of memory\n"); + return EXIT_FAILURE; } + strip_trailing (maildir, '/'); + if (create_folder && ! maildir_create_folder (config, maildir)) + return EXIT_FAILURE; + /* Set up our handler for SIGINT. We do not set SA_RESTART so that copying * from standard input may be interrupted. */ memset (&action, 0, sizeof (struct sigaction)); -- 2.11.0 _______________________________________________ notmuch mailing list notmuch@notmuchmail.org https://notmuchmail.org/mailman/listinfo/notmuch