]> git.cworth.org Git - notmuch/blob - test/T670-duplicate-mid.sh
debian: changelog for 0.36~rc0-1
[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 test_require_external_prereq xapian-delve
6
7 add_message '[id]="duplicate"' '[subject]="message 1" [filename]=copy1'
8 add_message '[id]="duplicate"' '[subject]="message 2" [filename]=copy2'
9
10 add_message '[id]="duplicate"' '[subject]="message 0" [filename]=copy0'
11
12 test_begin_subtest 'at most 1 thread-id per xapian document'
13 db=${MAIL_DIR}/.notmuch/xapian
14 for doc in $(xapian-delve -1 -t '' "$db" | grep '^[1-9]'); do
15     xapian-delve -1 -r "$doc" "$db" | grep -c '^G'
16 done > OUTPUT.raw
17 sort -u < OUTPUT.raw > OUTPUT
18 cat <<EOF > EXPECTED
19 0
20 1
21 EOF
22 test_expect_equal_file EXPECTED OUTPUT
23
24 test_begin_subtest 'search: first indexed subject preserved'
25 cat <<EOF > EXPECTED
26 thread:XXX   2001-01-05 [1/1(3)] Notmuch Test Suite; message 1 (inbox unread)
27 EOF
28 notmuch search id:duplicate | notmuch_search_sanitize > OUTPUT
29 test_expect_equal_file EXPECTED OUTPUT
30
31 test_begin_subtest 'First subject preserved in notmuch-show (json)'
32 test_subtest_known_broken
33 output=$(notmuch show --body=false --format=json id:duplicate | notmuch_json_show_sanitize)
34 expected='[[[{
35     "id": "XXXXX",
36     "match": true,
37     "excluded": false,
38     "filename": [
39         "'"${MAIL_DIR}"/copy0'",
40         "'"${MAIL_DIR}"/copy1'",
41         "'"${MAIL_DIR}"/copy2'"
42     ],
43     "timestamp": 42,
44     "date_relative": "2001-01-05",
45     "tags": ["inbox","unread"],
46     "headers": {
47         "Subject": "message 1",
48         "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
49         "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
50         "Date": "GENERATED_DATE"
51     }
52  },
53 []]]]'
54 test_expect_equal_json "$output" "$expected"
55
56 test_begin_subtest 'Search for second subject'
57 cat <<EOF >EXPECTED
58 MAIL_DIR/copy0
59 MAIL_DIR/copy1
60 MAIL_DIR/copy2
61 EOF
62 notmuch search --output=files subject:'"message 2"' | notmuch_dir_sanitize > OUTPUT
63 test_expect_equal_file EXPECTED OUTPUT
64
65 test_begin_subtest 'Regexp search for second subject'
66 test_subtest_known_broken
67 cat <<EOF >EXPECTED
68 MAIL_DIR/copy0
69 MAIL_DIR/copy1
70 MAIL_DIR/copy2
71 EOF
72 notmuch search --output=files 'subject:"/message 2/"' | notmuch_dir_sanitize > OUTPUT
73 test_expect_equal_file EXPECTED OUTPUT
74
75 add_message '[id]="duplicate"' '[body]="sekrit" [filename]=copy3'
76 test_begin_subtest 'search for body in duplicate file'
77 cat <<EOF >EXPECTED
78 MAIL_DIR/copy0
79 MAIL_DIR/copy1
80 MAIL_DIR/copy2
81 MAIL_DIR/copy3
82 EOF
83 notmuch search --output=files "sekrit" | notmuch_dir_sanitize > OUTPUT
84 test_expect_equal_file EXPECTED OUTPUT
85
86 rm ${MAIL_DIR}/copy3
87 test_begin_subtest 'reindex drops terms in duplicate file'
88 cp /dev/null EXPECTED
89 notmuch reindex '*'
90 notmuch search --output=files "sekrit" | notmuch_dir_sanitize > OUTPUT
91 test_expect_equal_file EXPECTED OUTPUT
92
93 test_begin_subtest 'reindex choses subject from first filename'
94 cat <<EOF > EXPECTED
95 thread:XXX   2001-01-05 [1/1(3)] Notmuch Test Suite; message 0 (inbox unread)
96 EOF
97 notmuch search id:duplicate | notmuch_search_sanitize > OUTPUT
98 test_expect_equal_file EXPECTED OUTPUT
99
100 rm ${MAIL_DIR}/copy0
101 test_begin_subtest 'Deleted first duplicate file does not stop notmuch show from working'
102 output=$(notmuch show --body=false --format=json id:duplicate |
103              notmuch_json_show_sanitize | sed 's/message [0-9]/A_SUBJECT/')
104 expected='[[[{
105     "id": "XXXXX",
106     "crypto": {},
107     "match": true,
108     "excluded": false,
109     "filename": [
110         "'"${MAIL_DIR}"/copy0'",
111         "'"${MAIL_DIR}"/copy1'",
112         "'"${MAIL_DIR}"/copy2'"
113     ],
114     "timestamp": 42,
115     "date_relative": "2001-01-05",
116     "tags": ["inbox","unread"],
117     "headers": {
118         "Subject": "A_SUBJECT",
119         "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
120         "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
121         "Date": "GENERATED_DATE"
122     }
123  },
124 []]]]'
125
126 test_expect_equal_json "$output" "$expected"
127
128 test_done