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
14 test_begin_subtest "Use References when In-Reply-To is broken"
15 add_message '[id]="foo@one.com"' \
17 add_message '[in-reply-to]="mumble"' \
18 '[references]="<foo@one.com>"' \
20 output=$(notmuch show --format=json 'subject:one' | notmuch_json_show_sanitize)
21 expected='[[[{"id": "foo@one.com",
25 "filename": ["YYYYY"],
26 "timestamp": 978709437,
27 "date_relative": "2001-01-05",
28 "tags": ["inbox", "unread"],
29 "headers": {"Subject": "one",
30 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
31 "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
32 "Date": "Fri, 05 Jan 2001 15:43:57 +0000"},
34 "content-type": "text/plain",
35 "content": "This is just a test message (#1)\n"}]},
36 [[{"id": "msg-002@notmuch-test-suite",
38 "match": true, "excluded": false,
39 "filename": ["YYYYY"],
40 "timestamp": 978709437, "date_relative": "2001-01-05",
41 "tags": ["inbox", "unread"], "headers": {"Subject": "Re: one",
42 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
43 "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
44 "Date": "Fri, 05 Jan 2001 15:43:57 +0000"},
45 "body": [{"id": 1, "content-type": "text/plain",
46 "content": "This is just a test message (#2)\n"}]}, []]]]]]'
47 expected=`echo "$expected" | notmuch_json_show_sanitize`
48 test_expect_equal_json "$output" "$expected"
50 test_begin_subtest "Prefer References to dodgy In-Reply-To"
51 add_message '[id]="foo@two.com"' \
53 add_message '[in-reply-to]="Your message of December 31 1999 <bar@baz.com>"' \
54 '[references]="<foo@two.com>"' \
56 output=$(notmuch show --format=json 'subject:two' | notmuch_json_show_sanitize)
57 expected='[[[{"id": "foo@two.com",
59 "match": true, "excluded": false,
60 "filename": ["YYYYY"],
61 "timestamp": 978709437, "date_relative": "2001-01-05", "tags": ["inbox", "unread"],
62 "headers": {"Subject": "two",
63 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
64 "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
65 "Date": "Fri, 05 Jan 2001 15:43:57 +0000"},
66 "body": [{"id": 1, "content-type": "text/plain",
67 "content": "This is just a test message (#3)\n"}]},
68 [[{"id": "msg-004@notmuch-test-suite", "match": true, "excluded": false,
70 "filename": ["YYYYY"],
71 "timestamp": 978709437, "date_relative": "2001-01-05", "tags": ["inbox", "unread"],
72 "headers": {"Subject": "Re: two",
73 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
74 "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
75 "Date": "Fri, 05 Jan 2001 15:43:57 +0000"},
77 "content-type": "text/plain", "content": "This is just a test message (#4)\n"}]},
79 expected=`echo "$expected" | notmuch_json_show_sanitize`
80 test_expect_equal_json "$output" "$expected"
82 test_begin_subtest "Use In-Reply-To when no References"
83 add_message '[id]="foo@three.com"' \
85 add_message '[in-reply-to]="<foo@three.com>"' \
86 '[subject]="Re: three"'
87 output=$(notmuch show --format=json 'subject:three' | notmuch_json_show_sanitize)
88 expected='[[[{"id": "foo@three.com", "match": true, "excluded": false,
90 "filename": ["YYYYY"],
91 "timestamp": 978709437, "date_relative": "2001-01-05", "tags": ["inbox", "unread"],
92 "headers": {"Subject": "three",
93 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
94 "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
95 "Date": "Fri, 05 Jan 2001 15:43:57 +0000"}, "body": [{"id": 1,
96 "content-type": "text/plain", "content": "This is just a test message (#5)\n"}]},
97 [[{"id": "msg-006@notmuch-test-suite", "match": true, "excluded": false,
99 "filename": ["YYYYY"],
100 "timestamp": 978709437, "date_relative": "2001-01-05", "tags": ["inbox", "unread"],
101 "headers": {"Subject": "Re: three",
102 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
103 "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
104 "Date": "Fri, 05 Jan 2001 15:43:57 +0000"}, "body": [{"id": 1,
105 "content-type": "text/plain", "content": "This is just a test message (#6)\n"}]},
107 expected=`echo "$expected" | notmuch_json_show_sanitize`
108 test_expect_equal_json "$output" "$expected"
110 test_begin_subtest "Use last Reference when In-Reply-To is dodgy"
111 add_message '[id]="foo@four.com"' \
113 add_message '[id]="bar@four.com"' \
114 '[subject]="not-four"'
115 add_message '[in-reply-to]="<baz@four.com> (RFC822 4lyfe)"' \
116 '[references]="<baz@four.com> <foo@four.com>"' \
117 '[subject]="neither"'
118 output=$(notmuch show --format=json 'subject:four' | notmuch_json_show_sanitize)
119 expected='[[[{"id": "foo@four.com", "match": true, "excluded": false,
121 "filename": ["YYYYY"],
122 "timestamp": 978709437, "date_relative": "2001-01-05", "tags": ["inbox", "unread"],
123 "headers": {"Subject": "four",
124 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
125 "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
126 "Date": "Fri, 05 Jan 2001 15:43:57 +0000"}, "body": [{"id": 1,
127 "content-type": "text/plain", "content": "This is just a test message (#7)\n"}]},
128 [[{"id": "msg-009@notmuch-test-suite", "match": false, "excluded": false,
130 "filename": ["YYYYY"],
131 "timestamp": 978709437, "date_relative": "2001-01-05", "tags": ["inbox", "unread"],
132 "headers": {"Subject": "neither",
133 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
134 "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
135 "Date": "Fri, 05 Jan 2001 15:43:57 +0000"}, "body": [{"id": 1,
136 "content-type": "text/plain", "content": "This is just a test message (#9)\n"}]},
137 []]]]], [[{"id": "bar@four.com", "match": true, "excluded": false,
139 "filename": ["YYYYY"],
140 "timestamp": 978709437, "date_relative": "2001-01-05", "tags": ["inbox", "unread"],
141 "headers": {"Subject": "not-four",
142 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
143 "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
144 "Date": "Fri, 05 Jan 2001 15:43:57 +0000"}, "body": [{"id": 1,
145 "content-type": "text/plain", "content": "This is just a test message (#8)\n"}]}, []]]]'
146 expected=`echo "$expected" | notmuch_json_show_sanitize`
147 test_expect_equal_json "$output" "$expected"
149 test_begin_subtest "Ignore garbage at the end of References"
150 add_message '[id]="foo@five.com"' \
152 add_message '[id]="bar@five.com"' \
153 '[references]="<foo@five.com> (garbage)"' \
154 '[subject]="not-five"'
155 output=$(notmuch show --format=json 'subject:five' | notmuch_json_show_sanitize)
156 expected='[[[{"id": "XXXXX", "match": true, "excluded": false,
158 "filename": ["YYYYY"], "timestamp": 42, "date_relative": "2001-01-05",
159 "tags": ["inbox", "unread"], "headers": {"Subject": "five",
160 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
161 "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
162 "Date": "GENERATED_DATE"}, "body": [{"id": 1,
163 "content-type": "text/plain",
164 "content": "This is just a test message (#10)\n"}]},
165 [[{"id": "XXXXX", "match": true, "excluded": false,
167 "filename": ["YYYYY"], "timestamp": 42, "date_relative": "2001-01-05",
168 "tags": ["inbox", "unread"],
169 "headers": {"Subject": "not-five",
170 "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
171 "To": "Notmuch Test Suite <test_suite@notmuchmail.org>",
172 "Date": "GENERATED_DATE"},
173 "body": [{"id": 1, "content-type": "text/plain",
174 "content": "This is just a test message (#11)\n"}]}, []]]]]]'
175 expected=`echo "$expected" | notmuch_json_show_sanitize`
176 test_expect_equal_json "$output" "$expected"
178 add_email_corpus threading
180 test_begin_subtest "reply to ghost"
181 notmuch show --entire-thread=true id:000-real-root@example.org | grep ^Subject: | head -1 > OUTPUT
183 Subject: root message
185 test_expect_equal_file EXPECTED OUTPUT
187 test_begin_subtest "reply to ghost (tree view)"
188 test_emacs '(notmuch-tree "id:000-real-root@example.org")
191 (delete-other-windows)'
193 2016-06-17 Alice ┬►root message (inbox unread)
194 2016-06-18 Alice ╰┬►child message (inbox unread)
195 2016-06-17 Mallory ├─►fake root message (inbox unread)
196 2016-06-18 Alice ├┬►grand-child message (inbox unread)
197 2016-06-18 Alice │╰─►great grand-child message (inbox unread)
198 2016-06-18 Daniel ╰─►grand-child message 2 (inbox unread)
199 End of search results.
201 test_expect_equal_file EXPECTED OUTPUT
203 test_begin_subtest "reply to ghost (RT)"
204 notmuch show --entire-thread=true id:87bmc6lp3h.fsf@len.workgroup | grep ^Subject: | head -1 > OUTPUT
206 Subject: FYI: xxxx xxxxxxx xxxxxxxxxxxx xxx
208 test_expect_equal_file EXPECTED OUTPUT
210 test_begin_subtest "reply to ghost (RT/tree view)"
211 test_emacs '(notmuch-tree "id:87bmc6lp3h.fsf@len.workgroup")
214 (delete-other-windows)'
216 2016-06-19 Gregor Zattler ┬┬►FYI: xxxx xxxxxxx xxxxxxxxxxxx xxx (inbox unread)
217 2016-06-19 via RT │╰─►[support.xxxxxxxxxxx-xxxxxxxxx-xxxxxxxxx.de #33575] AutoReply: FYI: xxxx xxxxxxx xxxxxxxxxxxx xxx (inbox unread)
218 2016-06-26 via RT ╰─►[support.xxxxxxxxxxx-xxxxxxxxx-xxxxxxxxx.de #33575] Resolved: FYI: xxxx xxxxxxx xxxxxxxxxxxx xxx (inbox unread)
219 End of search results.
221 test_expect_equal_file EXPECTED OUTPUT
223 test_begin_subtest "trusting reply-to (tree view)"
224 test_emacs '(notmuch-tree "id:B00-root@example.org")
227 (delete-other-windows)'
229 2016-06-17 Alice ┬►root message (inbox unread)
230 2016-06-18 Alice ╰┬►child message (inbox unread)
231 2016-06-18 Alice ╰─►grand-child message (inbox unread)
232 End of search results.
234 test_expect_equal_file EXPECTED OUTPUT