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"