]> git.cworth.org Git - notmuch/blob - test/T220-reply.sh
Merge tag '0.33.2'
[notmuch] / test / T220-reply.sh
1 #!/usr/bin/env bash
2 test_description="\"notmuch reply\" in several variations"
3 . $(dirname "$0")/test-lib.sh || exit 1
4
5 add_message '[from]="Sender <sender@example.com>"' \
6              [to]=test_suite@notmuchmail.org \
7              [subject]=notmuch-reply-test \
8             '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
9             '[body]="basic reply test"'
10
11 cat <<EOF > basic.expected
12 From: Notmuch Test Suite <test_suite@notmuchmail.org>
13 Subject: Re: notmuch-reply-test
14 To: Sender <sender@example.com>
15 In-Reply-To: <${gen_msg_id}>
16 References: <${gen_msg_id}>
17
18 On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
19 > basic reply test
20 OK
21 EOF
22
23 test_begin_subtest "Basic reply"
24 notmuch reply id:${gen_msg_id} >OUTPUT 2>&1 && echo OK >> OUTPUT
25 test_expect_equal_file basic.expected OUTPUT
26
27 if [ $NOTMUCH_HAVE_SFSEXP -eq 1 ]; then
28
29     test_begin_subtest "Basic reply (query=sexp)"
30     notmuch reply --query=sexp "(id ${gen_msg_id})" >OUTPUT 2>&1 && echo OK >> OUTPUT
31     test_expect_equal_file basic.expected OUTPUT
32 fi
33
34 test_begin_subtest "Multiple recipients"
35 add_message '[from]="Sender <sender@example.com>"' \
36             '[to]="test_suite@notmuchmail.org, Someone Else <someone@example.com>"' \
37              [subject]=notmuch-reply-test \
38             '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
39             '[body]="Multiple recipients"'
40
41 output=$(notmuch reply id:${gen_msg_id} 2>&1 && echo OK)
42 test_expect_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
43 Subject: Re: notmuch-reply-test
44 To: Sender <sender@example.com>, Someone Else <someone@example.com>
45 In-Reply-To: <${gen_msg_id}>
46 References: <${gen_msg_id}>
47
48 On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
49 > Multiple recipients
50 OK"
51
52 test_begin_subtest "Reply with CC"
53 add_message '[from]="Sender <sender@example.com>"' \
54              [to]=test_suite@notmuchmail.org \
55             '[cc]="Other Parties <cc@example.com>"' \
56              [subject]=notmuch-reply-test \
57             '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
58             '[body]="reply with CC"'
59
60 output=$(notmuch reply id:${gen_msg_id} 2>&1 && echo OK)
61 test_expect_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
62 Subject: Re: notmuch-reply-test
63 To: Sender <sender@example.com>
64 Cc: Other Parties <cc@example.com>
65 In-Reply-To: <${gen_msg_id}>
66 References: <${gen_msg_id}>
67
68 On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
69 > reply with CC
70 OK"
71
72 test_begin_subtest "Reply from alternate address"
73 add_message '[from]="Sender <sender@example.com>"' \
74              [to]=test_suite_other@notmuchmail.org \
75              [subject]=notmuch-reply-test \
76             '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
77             '[body]="reply from alternate address"'
78
79 output=$(notmuch reply id:${gen_msg_id} 2>&1 && echo OK)
80 test_expect_equal "$output" "From: Notmuch Test Suite <test_suite_other@notmuchmail.org>
81 Subject: Re: notmuch-reply-test
82 To: Sender <sender@example.com>
83 In-Reply-To: <${gen_msg_id}>
84 References: <${gen_msg_id}>
85
86 On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
87 > reply from alternate address
88 OK"
89
90 test_begin_subtest "Reply from address in named group list"
91 add_message '[from]="Sender <sender@example.com>"' \
92             '[to]=group:test_suite@notmuchmail.org,someone@example.com\;' \
93              [cc]=test_suite_other@notmuchmail.org \
94              [subject]=notmuch-reply-test \
95             '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
96             '[body]="Reply from address in named group list"'
97
98 output=$(notmuch reply id:${gen_msg_id} 2>&1 && echo OK)
99 test_expect_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
100 Subject: Re: notmuch-reply-test
101 To: Sender <sender@example.com>, someone@example.com
102 In-Reply-To: <${gen_msg_id}>
103 References: <${gen_msg_id}>
104
105 On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
106 > Reply from address in named group list
107 OK"
108
109 test_begin_subtest "Support for Reply-To"
110 add_message '[from]="Sender <sender@example.com>"' \
111              [to]=test_suite@notmuchmail.org \
112              [subject]=notmuch-reply-test \
113             '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
114             '[body]="support for reply-to"' \
115             '[reply-to]="Sender <elsewhere@example.com>"'
116
117 output=$(notmuch reply id:${gen_msg_id} 2>&1 && echo OK)
118 test_expect_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
119 Subject: Re: notmuch-reply-test
120 To: Sender <elsewhere@example.com>
121 In-Reply-To: <${gen_msg_id}>
122 References: <${gen_msg_id}>
123
124 On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
125 > support for reply-to
126 OK"
127
128 test_begin_subtest "Un-munging Reply-To"
129 add_message '[from]="Sender <sender@example.com>"' \
130             '[to]="Some List <list@example.com>"' \
131              [subject]=notmuch-reply-test \
132             '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
133             '[body]="Un-munging Reply-To"' \
134             '[reply-to]="Evil Munging List <list@example.com>"'
135
136 output=$(notmuch reply id:${gen_msg_id} 2>&1 && echo OK)
137 test_expect_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
138 Subject: Re: notmuch-reply-test
139 To: Sender <sender@example.com>, Some List <list@example.com>
140 In-Reply-To: <${gen_msg_id}>
141 References: <${gen_msg_id}>
142
143 On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
144 > Un-munging Reply-To
145 OK"
146
147 test_begin_subtest "Un-munging Reply-To With Exact Match"
148 add_message '[from]="Sender <sender@example.com>"' \
149             '[to]="Some List <list@example.com>"' \
150              [subject]=notmuch-reply-test \
151             '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
152             '[body]="Un-munging Reply-To"' \
153             '[reply-to]="Some List <list@example.com>"'
154
155 output=$(notmuch reply id:${gen_msg_id} 2>&1 && echo OK)
156 test_expect_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
157 Subject: Re: notmuch-reply-test
158 To: Sender <sender@example.com>, Some List <list@example.com>
159 In-Reply-To: <${gen_msg_id}>
160 References: <${gen_msg_id}>
161
162 On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
163 > Un-munging Reply-To
164 OK"
165
166 test_begin_subtest "Un-munging Reply-To With Raw addr-spec"
167 add_message '[from]="Sender <sender@example.com>"' \
168             '[to]="Some List <list@example.com>"' \
169              [subject]=notmuch-reply-test \
170             '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
171             '[body]="Un-munging Reply-To"' \
172             '[reply-to]="list@example.com"'
173
174 output=$(notmuch reply id:${gen_msg_id} 2>&1 && echo OK)
175 test_expect_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
176 Subject: Re: notmuch-reply-test
177 To: Sender <sender@example.com>, Some List <list@example.com>
178 In-Reply-To: <${gen_msg_id}>
179 References: <${gen_msg_id}>
180
181 On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
182 > Un-munging Reply-To
183 OK"
184
185 test_begin_subtest "Message with header of exactly 200 bytes"
186 add_message '[subject]="This subject is exactly 200 bytes in length. Other than its length there is not much of note here. Note that the length of 200 bytes includes the Subject: and Re: prefixes with two spaces"' \
187             '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
188             '[body]="200-byte header"'
189 output=$(notmuch reply id:${gen_msg_id} 2>&1 && echo OK)
190 test_expect_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
191 Subject: Re: This subject is exactly 200 bytes in length. Other than its
192  length there is not much of note here. Note that the length of 200 bytes
193  includes the Subject: and Re: prefixes with two spaces
194 To: test_suite@notmuchmail.org
195 In-Reply-To: <${gen_msg_id}>
196 References: <${gen_msg_id}>
197
198 On Tue, 05 Jan 2010 15:43:56 -0000, Notmuch Test Suite <test_suite@notmuchmail.org> wrote:
199 > 200-byte header
200 OK"
201
202 test_begin_subtest "From guessing: Envelope-To"
203 add_message '[from]="Sender <sender@example.com>"' \
204             '[to]="Recipient <recipient@example.com>"' \
205             '[subject]="From guessing"' \
206             '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
207             '[body]="From guessing"' \
208             '[header]="Envelope-To: test_suite_other@notmuchmail.org"'
209
210 output=$(notmuch reply id:${gen_msg_id} 2>&1 && echo OK)
211 test_expect_equal "$output" "From: Notmuch Test Suite <test_suite_other@notmuchmail.org>
212 Subject: Re: From guessing
213 To: Sender <sender@example.com>, Recipient <recipient@example.com>
214 In-Reply-To: <${gen_msg_id}>
215 References: <${gen_msg_id}>
216
217 On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
218 > From guessing
219 OK"
220
221 test_begin_subtest "From guessing: X-Original-To"
222 add_message '[from]="Sender <sender@example.com>"' \
223             '[to]="Recipient <recipient@example.com>"' \
224             '[subject]="From guessing"' \
225             '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
226             '[body]="From guessing"' \
227             '[header]="X-Original-To: test_suite@otherdomain.org"'
228
229 output=$(notmuch reply id:${gen_msg_id} 2>&1 && echo OK)
230 test_expect_equal "$output" "From: Notmuch Test Suite <test_suite@otherdomain.org>
231 Subject: Re: From guessing
232 To: Sender <sender@example.com>, Recipient <recipient@example.com>
233 In-Reply-To: <${gen_msg_id}>
234 References: <${gen_msg_id}>
235
236 On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
237 > From guessing
238 OK"
239
240 test_begin_subtest "From guessing: Delivered-To"
241 add_message '[from]="Sender <sender@example.com>"' \
242             '[to]="Recipient <recipient@example.com>"' \
243             '[subject]="From guessing"' \
244             '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
245             '[body]="From guessing"' \
246             '[header]="Delivered-To: test_suite_other@notmuchmail.org"'
247
248 output=$(notmuch reply id:${gen_msg_id} 2>&1 && echo OK)
249 test_expect_equal "$output" "From: Notmuch Test Suite <test_suite_other@notmuchmail.org>
250 Subject: Re: From guessing
251 To: Sender <sender@example.com>, Recipient <recipient@example.com>
252 In-Reply-To: <${gen_msg_id}>
253 References: <${gen_msg_id}>
254
255 On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
256 > From guessing
257 OK"
258
259 test_begin_subtest "From guessing: multiple Delivered-To"
260 add_message '[from]="Sender <sender@example.com>"' \
261             '[to]="Recipient <recipient@example.com>"' \
262             '[subject]="From guessing"' \
263             '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
264             '[body]="From guessing"' \
265             '[header]="Delivered-To: test_suite_other@notmuchmail.org
266 Delivered-To: test_suite@notmuchmail.org"'
267
268 output=$(notmuch reply id:${gen_msg_id} 2>&1 && echo OK)
269 test_expect_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
270 Subject: Re: From guessing
271 To: Sender <sender@example.com>, Recipient <recipient@example.com>
272 In-Reply-To: <${gen_msg_id}>
273 References: <${gen_msg_id}>
274
275 On Tue, 05 Jan 2010 15:43:56 -0000, Sender <sender@example.com> wrote:
276 > From guessing
277 OK"
278
279 test_begin_subtest "Reply with RFC 2047-encoded headers"
280 add_message '[subject]="=?iso-8859-1?q?=e0=df=e7?="' \
281             '[from]="=?utf-8?q?=e2=98=83?= <snowman@example.com>"' \
282             '[date]="Tue, 05 Jan 2010 15:43:56 -0000"' \
283             '[body]="Encoding"'
284
285 # GMime happens to change from Q- to B-encoding.  We canonicalize the
286 # case of the encoding and charset because different versions of GMime
287 # capitalize the encoding differently.
288 output=$( (notmuch reply id:${gen_msg_id} 2>&1 && echo OK) | perl -pe 's/=\?[^?]+\?[bB]\?/lc($&)/ge')
289 test_expect_equal "$output" "\
290 From: Notmuch Test Suite <test_suite@notmuchmail.org>
291 Subject: Re: =?iso-8859-1?b?4N/n?=
292 To: =?utf-8?b?4piD?= <snowman@example.com>
293 In-Reply-To: <${gen_msg_id}>
294 References: <${gen_msg_id}>
295
296 On Tue, 05 Jan 2010 15:43:56 -0000, ☃ <snowman@example.com> wrote:
297 > Encoding
298 OK"
299
300 test_begin_subtest "Reply with RFC 2047-encoded headers (JSON)"
301 output=$(echo '{"answer":' && notmuch reply --format=json id:${gen_msg_id} 2>&1 && echo ', "success": "OK"}')
302 test_expect_equal_json "$output" '
303 {  "answer": {
304     "original": {
305         "body": [
306             {
307                 "content": "Encoding\n",
308                 "content-type": "text/plain",
309                 "id": 1
310             }
311         ],
312         "crypto": {},
313         "date_relative": "2010-01-05",
314         "excluded": false,
315         "filename": ["'${MAIL_DIR}'/msg-015"],
316         "headers": {
317             "Date": "Tue, 05 Jan 2010 15:43:56 +0000",
318             "From": "\u2603 <snowman@example.com>",
319             "Subject": "\u00e0\u00df\u00e7",
320             "To": "Notmuch Test Suite <test_suite@notmuchmail.org>"
321         },
322         "id": "'${gen_msg_id}'",
323         "match": false,
324         "tags": [
325             "inbox",
326             "unread"
327         ],
328         "timestamp": 1262706236
329     },
330     "reply-headers": {
331         "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
332         "In-reply-to": "<'${gen_msg_id}'>",
333         "References": "<'${gen_msg_id}'>",
334         "Subject": "Re: \u00e0\u00df\u00e7",
335         "To": "\u2603 <snowman@example.com>"
336     }
337   },
338   "success": "OK"
339 }'
340
341 test_begin_subtest "Reply to a message with multiple Cc headers"
342 add_email_corpus broken
343 output=$(notmuch reply id:multiple-cc@example.org 2>&1 && echo OK)
344 test_expect_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
345 Subject: Re: wowsers!
346 To: Alice <alice@example.org>, Daniel <daniel@example.org>
347 Cc: Bob <bob@example.org>, Charles <charles@example.org>
348 In-Reply-To: <multiple-cc@example.org>
349 References: <multiple-cc@example.org>
350
351 On Thu, 16 Jun 2016 22:14:41 -0400, Alice <alice@example.org> wrote:
352 > Note the Cc: and cc: headers.
353 OK"
354
355 test_done