t/README: Document GIT_TEST_INSTALLED and GIT_TEST_EXEC_PATH
[git] / t / t9001-send-email.sh
1 #!/bin/sh
2
3 test_description='git send-email'
4 . ./test-lib.sh
5
6 if ! test_have_prereq PERL; then
7         say 'skipping git send-email tests, perl not available'
8         test_done
9 fi
10
11 PROG='git send-email'
12 test_expect_success \
13     'prepare reference tree' \
14     'echo "1A quick brown fox jumps over the" >file &&
15      echo "lazy dog" >>file &&
16      git add file &&
17      GIT_AUTHOR_NAME="A" git commit -a -m "Initial."'
18
19 test_expect_success \
20     'Setup helper tool' \
21     '(echo "#!$SHELL_PATH"
22       echo shift
23       echo output=1
24       echo "while test -f commandline\$output; do output=\$((\$output+1)); done"
25       echo for a
26       echo do
27       echo "  echo \"!\$a!\""
28       echo "done >commandline\$output"
29       echo "cat > msgtxt\$output"
30       ) >fake.sendmail &&
31      chmod +x ./fake.sendmail &&
32      git add fake.sendmail &&
33      GIT_AUTHOR_NAME="A" git commit -a -m "Second."'
34
35 clean_fake_sendmail() {
36         rm -f commandline* msgtxt*
37 }
38
39 test_expect_success 'Extract patches' '
40     patches=`git format-patch -s --cc="One <one@example.com>" --cc=two@example.com -n HEAD^1`
41 '
42
43 # Test no confirm early to ensure remaining tests will not hang
44 test_no_confirm () {
45         rm -f no_confirm_okay
46         echo n | \
47                 GIT_SEND_EMAIL_NOTTY=1 \
48                 git send-email \
49                 --from="Example <from@example.com>" \
50                 --to=nobody@example.com \
51                 --smtp-server="$(pwd)/fake.sendmail" \
52                 $@ \
53                 $patches > stdout &&
54                 test_must_fail grep "Send this email" stdout &&
55                 > no_confirm_okay
56 }
57
58 # Exit immediately to prevent hang if a no-confirm test fails
59 check_no_confirm () {
60         test -f no_confirm_okay || {
61                 say 'No confirm test failed; skipping remaining tests to prevent hanging'
62                 test_done
63         }
64 }
65
66 test_expect_success 'No confirm with --suppress-cc' '
67         test_no_confirm --suppress-cc=sob
68 '
69 check_no_confirm
70
71 test_expect_success 'No confirm with --confirm=never' '
72         test_no_confirm --confirm=never
73 '
74 check_no_confirm
75
76 # leave sendemail.confirm set to never after this so that none of the
77 # remaining tests prompt unintentionally.
78 test_expect_success 'No confirm with sendemail.confirm=never' '
79         git config sendemail.confirm never &&
80         test_no_confirm --compose --subject=foo
81 '
82 check_no_confirm
83
84 test_expect_success 'Send patches' '
85      git send-email --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
86 '
87
88 cat >expected <<\EOF
89 !nobody@example.com!
90 !author@example.com!
91 !one@example.com!
92 !two@example.com!
93 EOF
94 test_expect_success \
95     'Verify commandline' \
96     'test_cmp expected commandline1'
97
98 cat >expected-show-all-headers <<\EOF
99 0001-Second.patch
100 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
101 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
102 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
103 Dry-OK. Log says:
104 Server: relay.example.com
105 MAIL FROM:<from@example.com>
106 RCPT TO:<to@example.com>
107 RCPT TO:<cc@example.com>
108 RCPT TO:<author@example.com>
109 RCPT TO:<one@example.com>
110 RCPT TO:<two@example.com>
111 RCPT TO:<bcc@example.com>
112 From: Example <from@example.com>
113 To: to@example.com
114 Cc: cc@example.com,
115         A <author@example.com>,
116         One <one@example.com>,
117         two@example.com
118 Subject: [PATCH 1/1] Second.
119 Date: DATE-STRING
120 Message-Id: MESSAGE-ID-STRING
121 X-Mailer: X-MAILER-STRING
122 In-Reply-To: <unique-message-id@example.com>
123 References: <unique-message-id@example.com>
124
125 Result: OK
126 EOF
127
128 test_expect_success 'Show all headers' '
129         git send-email \
130                 --dry-run \
131                 --suppress-cc=sob \
132                 --from="Example <from@example.com>" \
133                 --to=to@example.com \
134                 --cc=cc@example.com \
135                 --bcc=bcc@example.com \
136                 --in-reply-to="<unique-message-id@example.com>" \
137                 --smtp-server relay.example.com \
138                 $patches |
139         sed     -e "s/^\(Date:\).*/\1 DATE-STRING/" \
140                 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
141                 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
142                 >actual-show-all-headers &&
143         test_cmp expected-show-all-headers actual-show-all-headers
144 '
145
146 test_expect_success 'Prompting works' '
147         clean_fake_sendmail &&
148         (echo "Example <from@example.com>"
149          echo "to@example.com"
150          echo ""
151         ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
152                 --smtp-server="$(pwd)/fake.sendmail" \
153                 $patches \
154                 2>errors &&
155                 grep "^From: Example <from@example.com>$" msgtxt1 &&
156                 grep "^To: to@example.com$" msgtxt1
157 '
158
159 test_expect_success 'cccmd works' '
160         clean_fake_sendmail &&
161         cp $patches cccmd.patch &&
162         echo cccmd--cccmd@example.com >>cccmd.patch &&
163         {
164           echo "#!$SHELL_PATH"
165           echo sed -n -e s/^cccmd--//p \"\$1\"
166         } > cccmd-sed &&
167         chmod +x cccmd-sed &&
168         git send-email \
169                 --from="Example <nobody@example.com>" \
170                 --to=nobody@example.com \
171                 --cc-cmd=./cccmd-sed \
172                 --smtp-server="$(pwd)/fake.sendmail" \
173                 cccmd.patch \
174                 &&
175         grep "^ cccmd@example.com" msgtxt1
176 '
177
178 z8=zzzzzzzz
179 z64=$z8$z8$z8$z8$z8$z8$z8$z8
180 z512=$z64$z64$z64$z64$z64$z64$z64$z64
181 test_expect_success 'reject long lines' '
182         clean_fake_sendmail &&
183         cp $patches longline.patch &&
184         echo $z512$z512 >>longline.patch &&
185         test_must_fail git send-email \
186                 --from="Example <nobody@example.com>" \
187                 --to=nobody@example.com \
188                 --smtp-server="$(pwd)/fake.sendmail" \
189                 $patches longline.patch \
190                 2>errors &&
191         grep longline.patch errors
192 '
193
194 test_expect_success 'no patch was sent' '
195         ! test -e commandline1
196 '
197
198 test_expect_success 'Author From: in message body' '
199         clean_fake_sendmail &&
200         git send-email \
201                 --from="Example <nobody@example.com>" \
202                 --to=nobody@example.com \
203                 --smtp-server="$(pwd)/fake.sendmail" \
204                 $patches &&
205         sed "1,/^$/d" < msgtxt1 > msgbody1
206         grep "From: A <author@example.com>" msgbody1
207 '
208
209 test_expect_success 'Author From: not in message body' '
210         clean_fake_sendmail &&
211         git send-email \
212                 --from="A <author@example.com>" \
213                 --to=nobody@example.com \
214                 --smtp-server="$(pwd)/fake.sendmail" \
215                 $patches &&
216         sed "1,/^$/d" < msgtxt1 > msgbody1
217         ! grep "From: A <author@example.com>" msgbody1
218 '
219
220 test_expect_success 'allow long lines with --no-validate' '
221         git send-email \
222                 --from="Example <nobody@example.com>" \
223                 --to=nobody@example.com \
224                 --smtp-server="$(pwd)/fake.sendmail" \
225                 --novalidate \
226                 $patches longline.patch \
227                 2>errors
228 '
229
230 test_expect_success 'Invalid In-Reply-To' '
231         clean_fake_sendmail &&
232         git send-email \
233                 --from="Example <nobody@example.com>" \
234                 --to=nobody@example.com \
235                 --in-reply-to=" " \
236                 --smtp-server="$(pwd)/fake.sendmail" \
237                 $patches
238                 2>errors
239         ! grep "^In-Reply-To: < *>" msgtxt1
240 '
241
242 test_expect_success 'Valid In-Reply-To when prompting' '
243         clean_fake_sendmail &&
244         (echo "From Example <from@example.com>"
245          echo "To Example <to@example.com>"
246          echo ""
247         ) | env GIT_SEND_EMAIL_NOTTY=1 git send-email \
248                 --smtp-server="$(pwd)/fake.sendmail" \
249                 $patches 2>errors &&
250         ! grep "^In-Reply-To: < *>" msgtxt1
251 '
252
253 test_expect_success 'setup fake editor' '
254         (echo "#!$SHELL_PATH" &&
255          echo "echo fake edit >>\"\$1\""
256         ) >fake-editor &&
257         chmod +x fake-editor
258 '
259
260 test_set_editor "$(pwd)/fake-editor"
261
262 test_expect_success '--compose works' '
263         clean_fake_sendmail &&
264         git send-email \
265         --compose --subject foo \
266         --from="Example <nobody@example.com>" \
267         --to=nobody@example.com \
268         --smtp-server="$(pwd)/fake.sendmail" \
269         $patches \
270         2>errors
271 '
272
273 test_expect_success 'first message is compose text' '
274         grep "^fake edit" msgtxt1
275 '
276
277 test_expect_success 'second message is patch' '
278         grep "Subject:.*Second" msgtxt2
279 '
280
281 cat >expected-suppress-sob <<\EOF
282 0001-Second.patch
283 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
284 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
285 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
286 Dry-OK. Log says:
287 Server: relay.example.com
288 MAIL FROM:<from@example.com>
289 RCPT TO:<to@example.com>
290 RCPT TO:<cc@example.com>
291 RCPT TO:<author@example.com>
292 RCPT TO:<one@example.com>
293 RCPT TO:<two@example.com>
294 From: Example <from@example.com>
295 To: to@example.com
296 Cc: cc@example.com,
297         A <author@example.com>,
298         One <one@example.com>,
299         two@example.com
300 Subject: [PATCH 1/1] Second.
301 Date: DATE-STRING
302 Message-Id: MESSAGE-ID-STRING
303 X-Mailer: X-MAILER-STRING
304
305 Result: OK
306 EOF
307
308 test_suppression () {
309         git send-email \
310                 --dry-run \
311                 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
312                 --from="Example <from@example.com>" \
313                 --to=to@example.com \
314                 --smtp-server relay.example.com \
315                 $patches |
316         sed     -e "s/^\(Date:\).*/\1 DATE-STRING/" \
317                 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
318                 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
319                 >actual-suppress-$1${2+"-$2"} &&
320         test_cmp expected-suppress-$1${2+"-$2"} actual-suppress-$1${2+"-$2"}
321 }
322
323 test_expect_success 'sendemail.cc set' '
324         git config sendemail.cc cc@example.com &&
325         test_suppression sob
326 '
327
328 cat >expected-suppress-sob <<\EOF
329 0001-Second.patch
330 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
331 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
332 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
333 Dry-OK. Log says:
334 Server: relay.example.com
335 MAIL FROM:<from@example.com>
336 RCPT TO:<to@example.com>
337 RCPT TO:<author@example.com>
338 RCPT TO:<one@example.com>
339 RCPT TO:<two@example.com>
340 From: Example <from@example.com>
341 To: to@example.com
342 Cc: A <author@example.com>,
343         One <one@example.com>,
344         two@example.com
345 Subject: [PATCH 1/1] Second.
346 Date: DATE-STRING
347 Message-Id: MESSAGE-ID-STRING
348 X-Mailer: X-MAILER-STRING
349
350 Result: OK
351 EOF
352
353 test_expect_success 'sendemail.cc unset' '
354         git config --unset sendemail.cc &&
355         test_suppression sob
356 '
357
358 cat >expected-suppress-cccmd <<\EOF
359 0001-Second.patch
360 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
361 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
362 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
363 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
364 Dry-OK. Log says:
365 Server: relay.example.com
366 MAIL FROM:<from@example.com>
367 RCPT TO:<to@example.com>
368 RCPT TO:<author@example.com>
369 RCPT TO:<one@example.com>
370 RCPT TO:<two@example.com>
371 RCPT TO:<committer@example.com>
372 From: Example <from@example.com>
373 To: to@example.com
374 Cc: A <author@example.com>,
375         One <one@example.com>,
376         two@example.com,
377         C O Mitter <committer@example.com>
378 Subject: [PATCH 1/1] Second.
379 Date: DATE-STRING
380 Message-Id: MESSAGE-ID-STRING
381 X-Mailer: X-MAILER-STRING
382
383 Result: OK
384 EOF
385
386 test_expect_success 'sendemail.cccmd' '
387         echo echo cc-cmd@example.com > cccmd &&
388         chmod +x cccmd &&
389         git config sendemail.cccmd ./cccmd &&
390         test_suppression cccmd
391 '
392
393 cat >expected-suppress-all <<\EOF
394 0001-Second.patch
395 Dry-OK. Log says:
396 Server: relay.example.com
397 MAIL FROM:<from@example.com>
398 RCPT TO:<to@example.com>
399 From: Example <from@example.com>
400 To: to@example.com
401 Subject: [PATCH 1/1] Second.
402 Date: DATE-STRING
403 Message-Id: MESSAGE-ID-STRING
404 X-Mailer: X-MAILER-STRING
405
406 Result: OK
407 EOF
408
409 test_expect_success '--suppress-cc=all' '
410         test_suppression all
411 '
412
413 cat >expected-suppress-body <<\EOF
414 0001-Second.patch
415 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
416 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
417 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
418 (cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
419 Dry-OK. Log says:
420 Server: relay.example.com
421 MAIL FROM:<from@example.com>
422 RCPT TO:<to@example.com>
423 RCPT TO:<author@example.com>
424 RCPT TO:<one@example.com>
425 RCPT TO:<two@example.com>
426 RCPT TO:<cc-cmd@example.com>
427 From: Example <from@example.com>
428 To: to@example.com
429 Cc: A <author@example.com>,
430         One <one@example.com>,
431         two@example.com,
432         cc-cmd@example.com
433 Subject: [PATCH 1/1] Second.
434 Date: DATE-STRING
435 Message-Id: MESSAGE-ID-STRING
436 X-Mailer: X-MAILER-STRING
437
438 Result: OK
439 EOF
440
441 test_expect_success '--suppress-cc=body' '
442         test_suppression body
443 '
444
445 cat >expected-suppress-body-cccmd <<\EOF
446 0001-Second.patch
447 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
448 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
449 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
450 Dry-OK. Log says:
451 Server: relay.example.com
452 MAIL FROM:<from@example.com>
453 RCPT TO:<to@example.com>
454 RCPT TO:<author@example.com>
455 RCPT TO:<one@example.com>
456 RCPT TO:<two@example.com>
457 From: Example <from@example.com>
458 To: to@example.com
459 Cc: A <author@example.com>,
460         One <one@example.com>,
461         two@example.com
462 Subject: [PATCH 1/1] Second.
463 Date: DATE-STRING
464 Message-Id: MESSAGE-ID-STRING
465 X-Mailer: X-MAILER-STRING
466
467 Result: OK
468 EOF
469
470 test_expect_success '--suppress-cc=body --suppress-cc=cccmd' '
471         test_suppression body cccmd
472 '
473
474 cat >expected-suppress-sob <<\EOF
475 0001-Second.patch
476 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
477 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
478 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
479 Dry-OK. Log says:
480 Server: relay.example.com
481 MAIL FROM:<from@example.com>
482 RCPT TO:<to@example.com>
483 RCPT TO:<author@example.com>
484 RCPT TO:<one@example.com>
485 RCPT TO:<two@example.com>
486 From: Example <from@example.com>
487 To: to@example.com
488 Cc: A <author@example.com>,
489         One <one@example.com>,
490         two@example.com
491 Subject: [PATCH 1/1] Second.
492 Date: DATE-STRING
493 Message-Id: MESSAGE-ID-STRING
494 X-Mailer: X-MAILER-STRING
495
496 Result: OK
497 EOF
498
499 test_expect_success '--suppress-cc=sob' '
500         git config --unset sendemail.cccmd
501         test_suppression sob
502 '
503
504 cat >expected-suppress-bodycc <<\EOF
505 0001-Second.patch
506 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
507 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
508 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
509 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
510 Dry-OK. Log says:
511 Server: relay.example.com
512 MAIL FROM:<from@example.com>
513 RCPT TO:<to@example.com>
514 RCPT TO:<author@example.com>
515 RCPT TO:<one@example.com>
516 RCPT TO:<two@example.com>
517 RCPT TO:<committer@example.com>
518 From: Example <from@example.com>
519 To: to@example.com
520 Cc: A <author@example.com>,
521         One <one@example.com>,
522         two@example.com,
523         C O Mitter <committer@example.com>
524 Subject: [PATCH 1/1] Second.
525 Date: DATE-STRING
526 Message-Id: MESSAGE-ID-STRING
527 X-Mailer: X-MAILER-STRING
528
529 Result: OK
530 EOF
531
532 test_expect_success '--suppress-cc=bodycc' '
533         test_suppression bodycc
534 '
535
536 cat >expected-suppress-cc <<\EOF
537 0001-Second.patch
538 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
539 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
540 Dry-OK. Log says:
541 Server: relay.example.com
542 MAIL FROM:<from@example.com>
543 RCPT TO:<to@example.com>
544 RCPT TO:<author@example.com>
545 RCPT TO:<committer@example.com>
546 From: Example <from@example.com>
547 To: to@example.com
548 Cc: A <author@example.com>,
549         C O Mitter <committer@example.com>
550 Subject: [PATCH 1/1] Second.
551 Date: DATE-STRING
552 Message-Id: MESSAGE-ID-STRING
553 X-Mailer: X-MAILER-STRING
554
555 Result: OK
556 EOF
557
558 test_expect_success '--suppress-cc=cc' '
559         test_suppression cc
560 '
561
562 test_confirm () {
563         echo y | \
564                 GIT_SEND_EMAIL_NOTTY=1 \
565                 git send-email \
566                 --from="Example <nobody@example.com>" \
567                 --to=nobody@example.com \
568                 --smtp-server="$(pwd)/fake.sendmail" \
569                 $@ $patches > stdout &&
570         grep "Send this email" stdout
571 }
572
573 test_expect_success '--confirm=always' '
574         test_confirm --confirm=always --suppress-cc=all
575 '
576
577 test_expect_success '--confirm=auto' '
578         test_confirm --confirm=auto
579 '
580
581 test_expect_success '--confirm=cc' '
582         test_confirm --confirm=cc
583 '
584
585 test_expect_success '--confirm=compose' '
586         test_confirm --confirm=compose --compose
587 '
588
589 test_expect_success 'confirm by default (due to cc)' '
590         CONFIRM=$(git config --get sendemail.confirm) &&
591         git config --unset sendemail.confirm &&
592         test_confirm
593         ret="$?"
594         git config sendemail.confirm ${CONFIRM:-never}
595         test $ret = "0"
596 '
597
598 test_expect_success 'confirm by default (due to --compose)' '
599         CONFIRM=$(git config --get sendemail.confirm) &&
600         git config --unset sendemail.confirm &&
601         test_confirm --suppress-cc=all --compose
602         ret="$?"
603         git config sendemail.confirm ${CONFIRM:-never}
604         test $ret = "0"
605 '
606
607 test_expect_success 'confirm detects EOF (inform assumes y)' '
608         CONFIRM=$(git config --get sendemail.confirm) &&
609         git config --unset sendemail.confirm &&
610         rm -fr outdir &&
611         git format-patch -2 -o outdir &&
612         GIT_SEND_EMAIL_NOTTY=1 \
613                 git send-email \
614                         --from="Example <nobody@example.com>" \
615                         --to=nobody@example.com \
616                         --smtp-server="$(pwd)/fake.sendmail" \
617                         outdir/*.patch < /dev/null
618         ret="$?"
619         git config sendemail.confirm ${CONFIRM:-never}
620         test $ret = "0"
621 '
622
623 test_expect_success 'confirm detects EOF (auto causes failure)' '
624         CONFIRM=$(git config --get sendemail.confirm) &&
625         git config sendemail.confirm auto &&
626         GIT_SEND_EMAIL_NOTTY=1 &&
627         export GIT_SEND_EMAIL_NOTTY &&
628                 test_must_fail git send-email \
629                         --from="Example <nobody@example.com>" \
630                         --to=nobody@example.com \
631                         --smtp-server="$(pwd)/fake.sendmail" \
632                         $patches < /dev/null
633         ret="$?"
634         git config sendemail.confirm ${CONFIRM:-never}
635         test $ret = "0"
636 '
637
638 test_expect_success 'confirm doesnt loop forever' '
639         CONFIRM=$(git config --get sendemail.confirm) &&
640         git config sendemail.confirm auto &&
641         GIT_SEND_EMAIL_NOTTY=1 &&
642         export GIT_SEND_EMAIL_NOTTY &&
643                 yes "bogus" | test_must_fail git send-email \
644                         --from="Example <nobody@example.com>" \
645                         --to=nobody@example.com \
646                         --smtp-server="$(pwd)/fake.sendmail" \
647                         $patches
648         ret="$?"
649         git config sendemail.confirm ${CONFIRM:-never}
650         test $ret = "0"
651 '
652
653 test_expect_success 'utf8 Cc is rfc2047 encoded' '
654         clean_fake_sendmail &&
655         rm -fr outdir &&
656         git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
657         git send-email \
658         --from="Example <nobody@example.com>" \
659         --to=nobody@example.com \
660         --smtp-server="$(pwd)/fake.sendmail" \
661         outdir/*.patch &&
662         grep "^ " msgtxt1 |
663         grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
664 '
665
666 test_expect_success '--compose adds MIME for utf8 body' '
667         clean_fake_sendmail &&
668         (echo "#!$SHELL_PATH" &&
669          echo "echo utf8 body: àéìöú >>\"\$1\""
670         ) >fake-editor-utf8 &&
671         chmod +x fake-editor-utf8 &&
672           GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
673           git send-email \
674           --compose --subject foo \
675           --from="Example <nobody@example.com>" \
676           --to=nobody@example.com \
677           --smtp-server="$(pwd)/fake.sendmail" \
678           $patches &&
679         grep "^utf8 body" msgtxt1 &&
680         grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
681 '
682
683 test_expect_success '--compose respects user mime type' '
684         clean_fake_sendmail &&
685         (echo "#!$SHELL_PATH" &&
686          echo "(echo MIME-Version: 1.0"
687          echo " echo Content-Type: text/plain\\; charset=iso-8859-1"
688          echo " echo Content-Transfer-Encoding: 8bit"
689          echo " echo Subject: foo"
690          echo " echo "
691          echo " echo utf8 body: àéìöú) >\"\$1\""
692         ) >fake-editor-utf8-mime &&
693         chmod +x fake-editor-utf8-mime &&
694           GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
695           git send-email \
696           --compose --subject foo \
697           --from="Example <nobody@example.com>" \
698           --to=nobody@example.com \
699           --smtp-server="$(pwd)/fake.sendmail" \
700           $patches &&
701         grep "^utf8 body" msgtxt1 &&
702         grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
703         ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
704 '
705
706 test_expect_success '--compose adds MIME for utf8 subject' '
707         clean_fake_sendmail &&
708           GIT_EDITOR="\"$(pwd)/fake-editor\"" \
709           git send-email \
710           --compose --subject utf8-sübjëct \
711           --from="Example <nobody@example.com>" \
712           --to=nobody@example.com \
713           --smtp-server="$(pwd)/fake.sendmail" \
714           $patches &&
715         grep "^fake edit" msgtxt1 &&
716         grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
717 '
718
719 test_expect_success 'detects ambiguous reference/file conflict' '
720         echo master > master &&
721         git add master &&
722         git commit -m"add master" &&
723         test_must_fail git send-email --dry-run master 2>errors &&
724         grep disambiguate errors
725 '
726
727 test_expect_success 'feed two files' '
728         rm -fr outdir &&
729         git format-patch -2 -o outdir &&
730         git send-email \
731         --dry-run \
732         --from="Example <nobody@example.com>" \
733         --to=nobody@example.com \
734         outdir/000?-*.patch 2>errors >out &&
735         grep "^Subject: " out >subjects &&
736         test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
737         test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"
738 '
739
740 test_expect_success 'in-reply-to but no threading' '
741         git send-email \
742                 --dry-run \
743                 --from="Example <nobody@example.com>" \
744                 --to=nobody@example.com \
745                 --in-reply-to="<in-reply-id@example.com>" \
746                 --nothread \
747                 $patches |
748         grep "In-Reply-To: <in-reply-id@example.com>"
749 '
750
751 test_expect_success 'no in-reply-to and no threading' '
752         git send-email \
753                 --dry-run \
754                 --from="Example <nobody@example.com>" \
755                 --to=nobody@example.com \
756                 --nothread \
757                 $patches $patches >stdout &&
758         ! grep "In-Reply-To: " stdout
759 '
760
761 test_expect_success 'threading but no chain-reply-to' '
762         git send-email \
763                 --dry-run \
764                 --from="Example <nobody@example.com>" \
765                 --to=nobody@example.com \
766                 --thread \
767                 --nochain-reply-to \
768                 $patches $patches >stdout &&
769         grep "In-Reply-To: " stdout
770 '
771
772 test_done