]> git.cworth.org Git - notmuch/blob - test/T670-duplicate-mid.sh
prepare upload for stretch-backports
[notmuch] / test / T670-duplicate-mid.sh
1 #!/usr/bin/env bash
2 test_description="duplicate message ids"
3 . $(dirname "$0")/test-lib.sh || exit 1
4
5 add_message '[id]="duplicate"' '[subject]="message 1" [filename]=copy1'
6 add_message '[id]="duplicate"' '[subject]="message 2" [filename]=copy2'
7
8 add_message '[id]="duplicate"' '[subject]="message 0" [filename]=copy0'
9 test_begin_subtest 'search: first indexed subject preserved'
10 cat <<EOF > EXPECTED
11 thread:XXX   2001-01-05 [1/1(3)] Notmuch Test Suite; message 1 (inbox unread)
12 EOF
13 notmuch search id:duplicate | notmuch_search_sanitize > OUTPUT
14 test_expect_equal_file EXPECTED OUTPUT
15
16 test_begin_subtest 'First subject preserved in notmuch-show (json)'
17 test_subtest_known_broken
18 output=$(notmuch show --body=false --format=json id:duplicate | notmuch_json_show_sanitize)
19 expected='[[[{
20     "id": "XXXXX",
21     "match": true,
22     "excluded": false,
23     "filename": [
24         "'"${MAIL_DIR}"/copy0'",
25         "'"${MAIL_DIR}"/copy1'",
26         "'"${MAIL_DIR}"/copy2'"
27     ],
28     "timestamp": 42,
29     "date_relative": "2001-01-05",
30     "tags": ["inbox","unread"],
31     "headers": {
32         "Subject": "message 1",
33         "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
34         "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
35         "Date": "GENERATED_DATE"
36     }
37  },
38 []]]]'
39 test_expect_equal_json "$output" "$expected"
40
41 test_begin_subtest 'Search for second subject'
42 cat <<EOF >EXPECTED
43 MAIL_DIR/copy0
44 MAIL_DIR/copy1
45 MAIL_DIR/copy2
46 EOF
47 notmuch search --output=files subject:'"message 2"' | notmuch_dir_sanitize > OUTPUT
48 test_expect_equal_file EXPECTED OUTPUT
49
50 add_message '[id]="duplicate"' '[body]="sekrit" [filename]=copy3'
51 test_begin_subtest 'search for body in duplicate file'
52 cat <<EOF >EXPECTED
53 MAIL_DIR/copy0
54 MAIL_DIR/copy1
55 MAIL_DIR/copy2
56 MAIL_DIR/copy3
57 EOF
58 notmuch search --output=files "sekrit" | notmuch_dir_sanitize > OUTPUT
59 test_expect_equal_file EXPECTED OUTPUT
60
61 rm ${MAIL_DIR}/copy3
62 test_begin_subtest 'reindex drops terms in duplicate file'
63 cp /dev/null EXPECTED
64 notmuch reindex '*'
65 notmuch search --output=files "sekrit" | notmuch_dir_sanitize > OUTPUT
66 test_expect_equal_file EXPECTED OUTPUT
67
68 test_begin_subtest 'reindex choses subject from first filename'
69 cat <<EOF > EXPECTED
70 thread:XXX   2001-01-05 [1/1(3)] Notmuch Test Suite; message 0 (inbox unread)
71 EOF
72 notmuch search id:duplicate | notmuch_search_sanitize > OUTPUT
73 test_expect_equal_file EXPECTED OUTPUT
74
75 rm ${MAIL_DIR}/copy0
76 test_begin_subtest 'Deleted first duplicate file does not stop notmuch show from working'
77 output=$(notmuch show --body=false --format=json id:duplicate |
78              notmuch_json_show_sanitize | sed 's/message [0-9]/A_SUBJECT/')
79 expected='[[[{
80     "id": "XXXXX",
81     "match": true,
82     "excluded": false,
83     "filename": [
84         "'"${MAIL_DIR}"/copy0'",
85         "'"${MAIL_DIR}"/copy1'",
86         "'"${MAIL_DIR}"/copy2'"
87     ],
88     "timestamp": 42,
89     "date_relative": "2001-01-05",
90     "tags": ["inbox","unread"],
91     "headers": {
92         "Subject": "A_SUBJECT",
93         "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
94         "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
95         "Date": "GENERATED_DATE"
96     }
97  },
98 []]]]'
99
100 test_expect_equal_json "$output" "$expected"
101
102 test_done