]> git.cworth.org Git - notmuch-old/blob - test/T220-reply.sh
debian: update changelog for new build-depends
[notmuch-old] / 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 | notmuch_json_show_sanitize \
302          && echo ', "success": "OK"}')
303 test_expect_equal_json "$output" '
304 {  "answer": {
305     "original": {
306         "body": [
307             {
308                 "content": "Encoding\n",
309                 "content-type": "text/plain",
310                 "id": 1
311             }
312         ],
313         "crypto": {},
314         "date_relative": "2010-01-05",
315         "excluded": false,
316         "filename": ["YYYYY"],
317         "headers": {
318             "Date": "Tue, 05 Jan 2010 15:43:56 +0000",
319             "From": "\u2603 <snowman@example.com>",
320             "Subject": "\u00e0\u00df\u00e7",
321             "To": "Notmuch Test Suite <test_suite@notmuchmail.org>"
322         },
323         "id": "XXXXX",
324         "match": false,
325         "tags": [
326             "inbox",
327             "unread"
328         ],
329         "timestamp": 1262706236
330     },
331     "reply-headers": {
332         "From": "Notmuch Test Suite <test_suite@notmuchmail.org>",
333         "In-reply-to": "<'${gen_msg_id}'>",
334         "References": "<'${gen_msg_id}'>",
335         "Subject": "Re: \u00e0\u00df\u00e7",
336         "To": "\u2603 <snowman@example.com>"
337     }
338   },
339   "success": "OK"
340 }'
341
342 test_begin_subtest "Reply to a message with multiple Cc headers"
343 add_email_corpus broken
344 output=$(notmuch reply id:multiple-cc@example.org 2>&1 && echo OK)
345 test_expect_equal "$output" "From: Notmuch Test Suite <test_suite@notmuchmail.org>
346 Subject: Re: wowsers!
347 To: Alice <alice@example.org>, Daniel <daniel@example.org>
348 Cc: Bob <bob@example.org>, Charles <charles@example.org>
349 In-Reply-To: <multiple-cc@example.org>
350 References: <multiple-cc@example.org>
351
352 On Thu, 16 Jun 2016 22:14:41 -0400, Alice <alice@example.org> wrote:
353 > Note the Cc: and cc: headers.
354 OK"
355
356 add_email_corpus duplicate
357
358 ID1=debian/2.6.1.dfsg-4-1-g87ea161@87ea161e851dfb1ea324af00e4ecfccc18875e15
359
360 test_begin_subtest "format json, --duplicate=2, duplicate key"
361 output=$(notmuch reply --format=json --duplicate=2 id:${ID1})
362 test_json_nodes <<<"$output" "dup:['original']['duplicate']=2"
363
364 test_begin_subtest "format json, subject, --duplicate=1"
365 output=$(notmuch reply --format=json --duplicate=1 id:${ID1})
366 file=$(notmuch search --output=files id:${ID1} | head -n 1)
367 subject=$(sed -n 's/^Subject: \(.*\)$/\1/p' < $file)
368 test_json_nodes <<<"$output" "subject:['reply-headers']['Subject']=\"Re: $subject\""
369
370 test_begin_subtest "format json, subject, --duplicate=2"
371 output=$(notmuch reply --format=json --duplicate=2 id:${ID1})
372 file=$(notmuch search --output=files id:${ID1} | tail -n 1)
373 subject=$(sed -n 's/^Subject: \(.*\)$/\1/p' < $file)
374 test_json_nodes <<<"$output" "subject:['reply-headers']['Subject']=\"Re: $subject\""
375
376 ID2=87r2geywh9.fsf@tethera.net
377 for dup in {1..2}; do
378     test_begin_subtest "format json, body, --duplicate=${dup}"
379     output=$(notmuch reply --format=json --duplicate=${dup} id:${ID2} | \
380              $NOTMUCH_PYTHON -B "$NOTMUCH_SRCDIR"/test/json_check_nodes.py "body:['original']['body'][0]['content']" | \
381              grep '^# body')
382     test_expect_equal "$output" "# body ${dup}"
383 done
384
385 ID3=87r2ecrr6x.fsf@zephyr.silentflame.com
386 for dup in {1..5}; do
387     test_begin_subtest "format json, --duplicate=${dup}, 'duplicate' key"
388     output=$(notmuch reply --format=json --duplicate=${dup} id:${ID3})
389     test_json_nodes <<<"$output" "dup:['original']['duplicate']=${dup}"
390 done
391
392 test_done