]> git.cworth.org Git - notmuch/commitdiff
insert: strip trailing / in folder path
authorYuri Volchkov <yuri.volchkov@gmail.com>
Mon, 21 Aug 2017 15:44:46 +0000 (17:44 +0200)
committerDavid Bremner <david@tethera.net>
Tue, 22 Aug 2017 21:48:09 +0000 (18:48 -0300)
This patch fixes the "Insert message into folder with trailing /"
test. The problem was insufficient path canonization.

From database's point of view, "Sent" and "Sent/" are different
folders. If user runs (note the last '/'):

    notmuch insert --folder=maildir/Sent/ < test.msg

notmuch will create an extra XDIRECTORY record for the folder
'Sent/'. This means that database will have _TWO_ records for _ONE_
physical folder: 'Sent' and 'Sent/'. However, the 'notmuch new'
command will update only records related to the first one (the correct
one).

Now, if user moved the email file (e.g. from 'Sent/new' to
'Sent/cur'), 'notmuch new' will add a record about the new file, but
will not delete the old record.

Signed-off-by: Yuri Volchkov <yuri.volchkov@gmail.com>
notmuch-insert.c
test/T070-insert.sh

index bc96af0e881c4ec2b2dac8130bf9aea22588fb81..2590e836e3fed337838602fb474dc8b4fe435216 100644 (file)
@@ -27,6 +27,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include "string-util.h"
 
 static volatile sig_atomic_t interrupted;
 
@@ -451,7 +452,7 @@ 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;
-    const char *folder = NULL;
+    char *folder = NULL;
     notmuch_bool_t create_folder = FALSE;
     notmuch_bool_t keep = FALSE;
     notmuch_bool_t no_hooks = FALSE;
@@ -511,6 +512,7 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])
     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;
index 187dfd377b1560e95d3c4eb165bfd95fc8210ac5..380934a63d10383067ea45172110ec75da186f56 100755 (executable)
@@ -133,7 +133,6 @@ dirname=$(dirname "$output")
 test_expect_equal "$dirname" "$MAIL_DIR/Drafts/new"
 
 test_begin_subtest "Insert message into folder with trailing /"
-test_subtest_known_broken
 gen_insert_msg
 notmuch insert --folder=Drafts/ < "$gen_msg_filename"
 output=$(notmuch search --output=files id:${gen_msg_id})