]> git.notmuchmail.org Git - notmuch/blob - test/T510-thread-replies.sh
util: unreference objects referenced by the returned stream obj
[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
14 test_begin_subtest "Use References when In-Reply-To is broken"
15 add_message '[id]="foo@one.com"' \
16     '[subject]=one'
17 add_message '[in-reply-to]="mumble"' \
18     '[references]="<foo@one.com>"' \
19     '[subject]="Re: one"'
20 output=$(notmuch show --format=json 'subject:one' | notmuch_json_show_sanitize)
21 expected='[[[{"id": "foo@one.com",
22  "crypto": {},
23  "match": true,
24  "excluded": false,
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"},
33  "body": [{"id": 1,
34  "content-type": "text/plain",
35  "content": "This is just a test message (#1)\n"}]},
36  [[{"id": "msg-002@notmuch-test-suite",
37  "crypto": {},
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"
49
50 test_begin_subtest "Prefer References to dodgy In-Reply-To"
51 add_message '[id]="foo@two.com"' \
52     '[subject]=two'
53 add_message '[in-reply-to]="Your message of December 31 1999 <bar@baz.com>"' \
54     '[references]="<foo@two.com>"' \
55     '[subject]="Re: two"'
56 output=$(notmuch show --format=json 'subject:two' | notmuch_json_show_sanitize)
57 expected='[[[{"id": "foo@two.com",
58  "crypto": {},
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,
69  "crypto": {},
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"},
76  "body": [{"id": 1,
77  "content-type": "text/plain", "content": "This is just a test message (#4)\n"}]},
78  []]]]]]'
79 expected=`echo "$expected" | notmuch_json_show_sanitize`
80 test_expect_equal_json "$output" "$expected"
81
82 test_begin_subtest "Use In-Reply-To when no References"
83 add_message '[id]="foo@three.com"' \
84     '[subject]="three"'
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,
89  "crypto": {},
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,
98  "crypto": {},
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"}]},
106  []]]]]]'
107 expected=`echo "$expected" | notmuch_json_show_sanitize`
108 test_expect_equal_json "$output" "$expected"
109
110 test_begin_subtest "Use last Reference when In-Reply-To is dodgy"
111 add_message '[id]="foo@four.com"' \
112     '[subject]="four"'
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,
120  "crypto": {},
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,
129  "crypto": {},
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,
138  "crypto": {},
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"
148
149 test_begin_subtest "Ignore garbage at the end of References"
150 add_message '[id]="foo@five.com"' \
151     '[subject]="five"'
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,
157  "crypto": {},
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,
166  "crypto": {},
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"
177
178 add_email_corpus threading
179
180 test_begin_subtest "reply to ghost"
181 notmuch show --entire-thread=true id:000-real-root@example.org | grep ^Subject: | head -1  > OUTPUT
182 cat <<EOF > EXPECTED
183 Subject: root message
184 EOF
185 test_expect_equal_file EXPECTED OUTPUT
186
187 test_begin_subtest "reply to ghost (tree view)"
188 test_emacs '(notmuch-tree "id:000-real-root@example.org")
189             (notmuch-test-wait)
190             (test-output)
191             (delete-other-windows)'
192 cat <<EOF > EXPECTED
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.
200 EOF
201 test_expect_equal_file EXPECTED OUTPUT
202
203 test_begin_subtest "reply to ghost (RT)"
204 notmuch show --entire-thread=true id:87bmc6lp3h.fsf@len.workgroup | grep ^Subject: | head -1  > OUTPUT
205 cat <<EOF > EXPECTED
206 Subject: FYI: xxxx  xxxxxxx  xxxxxxxxxxxx xxx
207 EOF
208 test_expect_equal_file EXPECTED OUTPUT
209
210 test_begin_subtest "reply to ghost (RT/tree view)"
211 test_emacs '(notmuch-tree "id:87bmc6lp3h.fsf@len.workgroup")
212             (notmuch-test-wait)
213             (test-output)
214             (delete-other-windows)'
215 cat <<EOF > EXPECTED
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.
220 EOF
221 test_expect_equal_file EXPECTED OUTPUT
222
223 test_begin_subtest "trusting reply-to (tree view)"
224 test_emacs '(notmuch-tree "id:B00-root@example.org")
225             (notmuch-test-wait)
226             (test-output)
227             (delete-other-windows)'
228 cat <<EOF > EXPECTED
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.
233 EOF
234 test_expect_equal_file EXPECTED OUTPUT
235
236 test_done