3 # Copyright (c) 2013 Aaron Ecay
6 test_description='test of proper handling of in-reply-to and references headers'
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'
12 . $(dirname "$0")/test-lib.sh || exit 1
13 . $NOTMUCH_SRCDIR/test/test-lib-emacs.sh || exit 1
15 test_begin_subtest "Use References when In-Reply-To is broken"
16 add_message '[id]="foo@one.com"' \
18 add_message '[in-reply-to]="mumble"' \
19 '[references]="<foo@one.com>"' \
21 output=$(notmuch show --format=json 'subject:one' | notmuch_json_show_sanitize)
22 expected='[[[{"id": "foo@one.com",
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"},
35 "content-type": "text/plain",
36 "content": "This is just a test message (#1)\n"}]},
37 [[{"id": "msg-002@notmuch-test-suite",
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"
51 test_begin_subtest "Prefer References to dodgy In-Reply-To"
52 add_message '[id]="foo@two.com"' \
54 add_message '[in-reply-to]="Your message of December 31 1999 <bar@baz.com>"' \
55 '[references]="<foo@two.com>"' \
57 output=$(notmuch show --format=json 'subject:two' | notmuch_json_show_sanitize)
58 expected='[[[{"id": "foo@two.com",
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,
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"},
78 "content-type": "text/plain", "content": "This is just a test message (#4)\n"}]},
80 expected=`echo "$expected" | notmuch_json_show_sanitize`
81 test_expect_equal_json "$output" "$expected"
83 test_begin_subtest "Use In-Reply-To when no References"
84 add_message '[id]="foo@three.com"' \
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,
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,
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"}]},
108 expected=`echo "$expected" | notmuch_json_show_sanitize`
109 test_expect_equal_json "$output" "$expected"
111 test_begin_subtest "Use last Reference when In-Reply-To is dodgy"
112 add_message '[id]="foo@four.com"' \
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,
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,
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,
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"
150 test_begin_subtest "Ignore garbage at the end of References"
151 add_message '[id]="foo@five.com"' \
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,
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,
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"
179 add_email_corpus threading
181 test_begin_subtest "reply to ghost"
182 notmuch show --entire-thread=true id:000-real-root@example.org | grep ^Subject: | head -1 > OUTPUT
184 Subject: root message
186 test_expect_equal_file EXPECTED OUTPUT
188 test_begin_subtest "reply to ghost (tree view)"
189 test_emacs '(notmuch-tree "id:000-real-root@example.org")
192 (delete-other-windows)'
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.
202 test_expect_equal_file EXPECTED OUTPUT
204 test_begin_subtest "reply to ghost (RT)"
205 notmuch show --entire-thread=true id:87bmc6lp3h.fsf@len.workgroup | grep ^Subject: | head -1 > OUTPUT
207 Subject: FYI: xxxx xxxxxxx xxxxxxxxxxxx xxx
209 test_expect_equal_file EXPECTED OUTPUT
211 test_begin_subtest "reply to ghost (RT/tree view)"
212 test_emacs '(notmuch-tree "id:87bmc6lp3h.fsf@len.workgroup")
215 (delete-other-windows)'
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.
222 test_expect_equal_file EXPECTED OUTPUT
224 test_begin_subtest "trusting reply-to (tree view)"
225 test_emacs '(notmuch-tree "id:B00-root@example.org")
228 (delete-other-windows)'
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.
235 test_expect_equal_file EXPECTED OUTPUT