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