2 test_description='"notmuch insert"'
5 # Create directories and database before inserting.
6 mkdir -p "$MAIL_DIR"/{cur,new,tmp}
7 mkdir -p "$MAIL_DIR"/Drafts/{cur,new,tmp}
8 notmuch new > /dev/null
10 # We use generate_message to create the temporary message files.
11 # They happen to be in the mail directory already but that is okay
12 # since we do not call notmuch new hereafter.
16 "[subject]=\"insert-subject\"" \
17 "[date]=\"Sat, 01 Jan 2000 12:00:00 -0000\"" \
18 "[body]=\"insert-message\""
21 test_expect_code 1 "Insert zero-length file" \
22 "notmuch insert < /dev/null"
24 # This test is a proxy for other errors that may occur while trying to
25 # add a message to the notmuch database, e.g. database locked.
26 test_expect_code 0 "Insert non-message" \
27 "echo bad_message | notmuch insert"
29 test_begin_subtest "Database empty so far"
30 test_expect_equal "0" "`notmuch count --output=messages '*'`"
32 test_begin_subtest "Insert message"
34 notmuch insert < "$gen_msg_filename"
35 cur_msg_filename=$(notmuch search --output=files "subject:insert-subject")
36 test_expect_equal_file "$cur_msg_filename" "$gen_msg_filename"
38 test_begin_subtest "Insert message adds default tags"
39 output=$(notmuch show --format=json "subject:insert-subject")
41 "id": "'"${gen_msg_id}"'",
44 "filename": "'"${cur_msg_filename}"'",
45 "timestamp": 946728000,
46 "date_relative": "2000-01-01",
47 "tags": ["inbox","unread"],
49 "Subject": "insert-subject",
50 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
51 "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
52 "Date": "Sat, 01 Jan 2000 12:00:00 +0000"},
54 "content-type": "text/plain",
55 "content": "insert-message\n"}]},
57 test_expect_equal_json "$output" "$expected"
59 test_begin_subtest "Insert duplicate message"
60 notmuch insert +duptag -unread < "$gen_msg_filename"
61 output=$(notmuch search --output=files "subject:insert-subject" | wc -l)
62 test_expect_equal "$output" 2
64 test_begin_subtest "Duplicate message does not change tags"
65 output=$(notmuch search --format=json --output=tags "subject:insert-subject")
66 test_expect_equal_json "$output" '["inbox", "unread"]'
68 test_begin_subtest "Insert message, add tag"
70 notmuch insert +custom < "$gen_msg_filename"
71 output=$(notmuch count tag:custom)
72 test_expect_equal "$output" "1"
74 test_begin_subtest "Insert message, add/remove tags"
76 notmuch insert +custom -unread < "$gen_msg_filename"
77 output=$(notmuch count tag:custom NOT tag:unread)
78 test_expect_equal "$output" "1"
80 test_begin_subtest "Insert message into folder"
82 notmuch insert --folder=Drafts < "$gen_msg_filename"
83 output=$(notmuch search --output=files folder:Drafts)
84 dirname=$(dirname "$output")
85 test_expect_equal "$dirname" "$MAIL_DIR/Drafts/cur"
87 test_begin_subtest "Insert message into folder, add/remove tags"
89 notmuch insert --folder=Drafts +draft -unread < "$gen_msg_filename"
90 output=$(notmuch count folder:Drafts tag:draft NOT tag:unread)
91 test_expect_equal "$output" "1"
94 test_expect_code 1 "Insert message into non-existent folder" \
95 "notmuch insert --folder=nonesuch < $gen_msg_filename"
97 test_begin_subtest "Insert message, create folder"
99 notmuch insert --folder=F --create-folder +folder < "$gen_msg_filename"
100 output=$(notmuch search --output=files folder:F tag:folder)
101 basename=$(basename "$output")
102 test_expect_equal_file "$gen_msg_filename" "$MAIL_DIR/F/cur/${basename}"
104 test_begin_subtest "Insert message, create subfolder"
106 notmuch insert --folder=F/G/H/I/J --create-folder +folder < "$gen_msg_filename"
107 output=$(notmuch search --output=files folder:F/G/H/I/J tag:folder)
108 basename=$(basename "$output")
109 test_expect_equal_file "$gen_msg_filename" "${MAIL_DIR}/F/G/H/I/J/cur/${basename}"
111 test_begin_subtest "Insert message, create existing subfolder"
113 notmuch insert --folder=F/G/H/I/J --create-folder +folder < "$gen_msg_filename"
114 output=$(notmuch count folder:F/G/H/I/J tag:folder)
115 test_expect_equal "$output" "2"
118 test_expect_code 1 "Insert message, create invalid subfolder" \
119 "notmuch insert --folder=../G --create-folder $gen_msg_filename"