]> git.notmuchmail.org Git - notmuch/blob - test/T510-thread-replies.sh
emacs: Add new option notmuch-search-hide-excluded
[notmuch] / test / T510-thread-replies.sh
1 #!/usr/bin/env bash
2 #
3 # Copyright (c) 2013 Aaron Ecay
4 #
5
6 test_description='test of proper handling of in-reply-to and references headers'
7
8 # This test makes sure that the thread structure in the notmuch
9 # database is constructed properly, even in the presence of
10 # non-RFC-compliant headers'
11
12 . $(dirname "$0")/test-lib.sh || exit 1
13 . $NOTMUCH_SRCDIR/test/test-lib-emacs.sh || exit 1
14
15 test_begin_subtest "Use References when In-Reply-To is broken"
16 add_message '[id]="foo@one.com"' \
17     '[subject]=one'
18 add_message '[in-reply-to]="mumble"' \
19     '[references]="<foo@one.com>"' \
20     '[subject]="Re: one"'
21 output=$(notmuch show --format=json 'subject:one' | notmuch_json_show_sanitize)
22 expected='[[[{"id": "foo@one.com",
23  "crypto": {},
24  "match": true,
25  "excluded": false,
26  "filename": ["YYYYY"],
27  "timestamp": 978709437,
28  "date_relative": "2001-01-05",
29  "tags": ["inbox", "unread"],
30  "headers": {"Subject": "one",
31  "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
32  "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
33  "Date": "Fri, 05 Jan 2001 15:43:57 +0000"},
34  "body": [{"id": 1,
35  "content-type": "text/plain",
36  "content": "This is just a test message (#1)\n"}]},
37  [[{"id": "msg-002@notmuch-test-suite",
38  "crypto": {},
39  "match": true, "excluded": false,
40  "filename": ["YYYYY"],
41  "timestamp": 978709437, "date_relative": "2001-01-05",
42  "tags": ["inbox", "unread"], "headers": {"Subject": "Re: one",
43  "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
44  "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
45  "Date": "Fri, 05 Jan 2001 15:43:57 +0000"},
46  "body": [{"id": 1, "content-type": "text/plain",
47  "content": "This is just a test message (#2)\n"}]}, []]]]]]'
48 expected=`echo "$expected" | notmuch_json_show_sanitize`
49 test_expect_equal_json "$output" "$expected"
50
51 test_begin_subtest "Prefer References to dodgy In-Reply-To"
52 add_message '[id]="foo@two.com"' \
53     '[subject]=two'
54 add_message '[in-reply-to]="Your message of December 31 1999 <bar@baz.com>"' \
55     '[references]="<foo@two.com>"' \
56     '[subject]="Re: two"'
57 output=$(notmuch show --format=json 'subject:two' | notmuch_json_show_sanitize)
58 expected='[[[{"id": "foo@two.com",
59  "crypto": {},
60  "match": true, "excluded": false,
61  "filename": ["YYYYY"],
62  "timestamp": 978709437, "date_relative": "2001-01-05", "tags": ["inbox", "unread"],
63  "headers": {"Subject": "two",
64  "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
65  "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
66  "Date": "Fri, 05 Jan 2001 15:43:57 +0000"},
67  "body": [{"id": 1, "content-type": "text/plain",
68  "content": "This is just a test message (#3)\n"}]},
69  [[{"id": "msg-004@notmuch-test-suite", "match": true, "excluded": false,
70  "crypto": {},
71  "filename": ["YYYYY"],
72  "timestamp": 978709437, "date_relative": "2001-01-05", "tags": ["inbox", "unread"],
73  "headers": {"Subject": "Re: two",
74  "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
75  "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
76  "Date": "Fri, 05 Jan 2001 15:43:57 +0000"},
77  "body": [{"id": 1,
78  "content-type": "text/plain", "content": "This is just a test message (#4)\n"}]},
79  []]]]]]'
80 expected=`echo "$expected" | notmuch_json_show_sanitize`
81 test_expect_equal_json "$output" "$expected"
82
83 test_begin_subtest "Use In-Reply-To when no References"
84 add_message '[id]="foo@three.com"' \
85     '[subject]="three"'
86 add_message '[in-reply-to]="<foo@three.com>"' \
87     '[subject]="Re: three"'
88 output=$(notmuch show --format=json 'subject:three' | notmuch_json_show_sanitize)
89 expected='[[[{"id": "foo@three.com", "match": true, "excluded": false,
90  "crypto": {},
91  "filename": ["YYYYY"],
92  "timestamp": 978709437, "date_relative": "2001-01-05", "tags": ["inbox", "unread"],
93  "headers": {"Subject": "three",
94  "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
95  "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
96  "Date": "Fri, 05 Jan 2001 15:43:57 +0000"}, "body": [{"id": 1,
97  "content-type": "text/plain", "content": "This is just a test message (#5)\n"}]},
98  [[{"id": "msg-006@notmuch-test-suite", "match": true, "excluded": false,
99  "crypto": {},
100  "filename": ["YYYYY"],
101  "timestamp": 978709437, "date_relative": "2001-01-05", "tags": ["inbox", "unread"],
102  "headers": {"Subject": "Re: three",
103  "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
104  "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
105  "Date": "Fri, 05 Jan 2001 15:43:57 +0000"}, "body": [{"id": 1,
106  "content-type": "text/plain", "content": "This is just a test message (#6)\n"}]},
107  []]]]]]'
108 expected=`echo "$expected" | notmuch_json_show_sanitize`
109 test_expect_equal_json "$output" "$expected"
110
111 test_begin_subtest "Use last Reference when In-Reply-To is dodgy"
112 add_message '[id]="foo@four.com"' \
113     '[subject]="four"'
114 add_message '[id]="bar@four.com"' \
115     '[subject]="not-four"'
116 add_message '[in-reply-to]="<baz@four.com> (RFC822 4lyfe)"' \
117     '[references]="<baz@four.com> <foo@four.com>"' \
118     '[subject]="neither"'
119 output=$(notmuch show --format=json 'subject:four' | notmuch_json_show_sanitize)
120 expected='[[[{"id": "foo@four.com", "match": true, "excluded": false,
121  "crypto": {},
122  "filename": ["YYYYY"],
123  "timestamp": 978709437, "date_relative": "2001-01-05", "tags": ["inbox", "unread"],
124  "headers": {"Subject": "four",
125  "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
126  "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
127  "Date": "Fri, 05 Jan 2001 15:43:57 +0000"}, "body": [{"id": 1,
128  "content-type": "text/plain", "content": "This is just a test message (#7)\n"}]},
129  [[{"id": "msg-009@notmuch-test-suite", "match": false, "excluded": false,
130  "crypto": {},
131  "filename": ["YYYYY"],
132  "timestamp": 978709437, "date_relative": "2001-01-05", "tags": ["inbox", "unread"],
133  "headers": {"Subject": "neither",
134  "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
135  "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
136  "Date": "Fri, 05 Jan 2001 15:43:57 +0000"}, "body": [{"id": 1,
137  "content-type": "text/plain", "content": "This is just a test message (#9)\n"}]},
138  []]]]], [[{"id": "bar@four.com", "match": true, "excluded": false,
139  "crypto": {},
140  "filename": ["YYYYY"],
141  "timestamp": 978709437, "date_relative": "2001-01-05", "tags": ["inbox", "unread"],
142  "headers": {"Subject": "not-four",
143  "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
144  "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
145  "Date": "Fri, 05 Jan 2001 15:43:57 +0000"}, "body": [{"id": 1,
146  "content-type": "text/plain", "content": "This is just a test message (#8)\n"}]}, []]]]'
147 expected=`echo "$expected" | notmuch_json_show_sanitize`
148 test_expect_equal_json "$output" "$expected"
149
150 test_begin_subtest "Ignore garbage at the end of References"
151 add_message '[id]="foo@five.com"' \
152     '[subject]="five"'
153 add_message '[id]="bar@five.com"' \
154     '[references]="<foo@five.com> (garbage)"' \
155     '[subject]="not-five"'
156 output=$(notmuch show --format=json 'subject:five' | notmuch_json_show_sanitize)
157 expected='[[[{"id": "XXXXX", "match": true, "excluded": false,
158  "crypto": {},
159  "filename": ["YYYYY"], "timestamp": 42, "date_relative": "2001-01-05",
160  "tags": ["inbox", "unread"], "headers": {"Subject": "five",
161  "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
162  "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
163  "Date": "GENERATED_DATE"}, "body": [{"id": 1,
164  "content-type": "text/plain",
165  "content": "This is just a test message (#10)\n"}]},
166  [[{"id": "XXXXX", "match": true, "excluded": false,
167  "crypto": {},
168  "filename": ["YYYYY"], "timestamp": 42, "date_relative": "2001-01-05",
169  "tags": ["inbox", "unread"],
170  "headers": {"Subject": "not-five",
171  "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
172  "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
173  "Date": "GENERATED_DATE"},
174  "body": [{"id": 1, "content-type": "text/plain",
175  "content": "This is just a test message (#11)\n"}]}, []]]]]]'
176 expected=`echo "$expected" | notmuch_json_show_sanitize`
177 test_expect_equal_json "$output" "$expected"
178
179 add_email_corpus threading
180
181 test_begin_subtest "reply to ghost"
182 notmuch show --entire-thread=true id:000-real-root@example.org | grep ^Subject: | head -1 > OUTPUT
183 cat <<EOF > EXPECTED
184 Subject: root message
185 EOF
186 test_expect_equal_file EXPECTED OUTPUT
187
188 test_begin_subtest "reply to ghost (tree view)"
189 test_emacs '(notmuch-tree "id:000-real-root@example.org")
190             (notmuch-test-wait)
191             (test-output)
192             (delete-other-windows)'
193 cat <<EOF > EXPECTED
194   2016-06-17  Alice                 ┬►root message                                        (inbox unread)
195   2016-06-18  Alice                 ╰┬►child message                                      (inbox unread)
196   2016-06-17  Mallory                ├─►fake root message                                 (inbox unread)
197   2016-06-18  Alice                  ├┬►grand-child message                               (inbox unread)
198   2016-06-18  Alice                  │╰─►great grand-child message                        (inbox unread)
199   2016-06-18  Daniel                 ╰─►grand-child message 2                             (inbox unread)
200 End of search results.
201 EOF
202 test_expect_equal_file EXPECTED OUTPUT
203
204 test_begin_subtest "reply to ghost (RT)"
205 notmuch show --entire-thread=true id:87bmc6lp3h.fsf@len.workgroup | grep ^Subject: | head -1  > OUTPUT
206 cat <<EOF > EXPECTED
207 Subject: FYI: xxxx  xxxxxxx  xxxxxxxxxxxx xxx
208 EOF
209 test_expect_equal_file EXPECTED OUTPUT
210
211 test_begin_subtest "reply to ghost (RT/tree view)"
212 test_emacs '(notmuch-tree "id:87bmc6lp3h.fsf@len.workgroup")
213             (notmuch-test-wait)
214             (test-output)
215             (delete-other-windows)'
216 cat <<EOF > EXPECTED
217   2016-06-19  Gregor Zattler       ┬┬►FYI: xxxx  xxxxxxx  xxxxxxxxxxxx xxx                (inbox unread)
218   2016-06-19   via RT              │╰─►[support.xxxxxxxxxxx-xxxxxxxxx-xxxxxxxxx.de #33575] AutoReply: FYI: xxxx  xxxxxxx  xxxxxxxxxxxx xxx (inbox unread)
219   2016-06-26   via RT              ╰─►[support.xxxxxxxxxxx-xxxxxxxxx-xxxxxxxxx.de #33575] Resolved: FYI: xxxx  xxxxxxx  xxxxxxxxxxxx xxx (inbox unread)
220 End of search results.
221 EOF
222 test_expect_equal_file EXPECTED OUTPUT
223
224 test_begin_subtest "trusting reply-to (tree view)"
225 test_emacs '(notmuch-tree "id:B00-root@example.org")
226             (notmuch-test-wait)
227             (test-output)
228             (delete-other-windows)'
229 cat <<EOF > EXPECTED
230   2016-06-17  Alice                 ┬►root message                                        (inbox unread)
231   2016-06-18  Alice                 ╰┬►child message                                      (inbox unread)
232   2016-06-18  Alice                  ╰─►grand-child message                               (inbox unread)
233 End of search results.
234 EOF
235 test_expect_equal_file EXPECTED OUTPUT
236
237 test_done