Merge branch 'maint-1.8.2' into maint-1.8.3
[git] / t / t9001-send-email.sh
1 #!/bin/sh
2
3 test_description='git send-email'
4 . ./test-lib.sh
5
6 # May be altered later in the test
7 PREREQ="PERL"
8
9 test_expect_success $PREREQ \
10     'prepare reference tree' \
11     'echo "1A quick brown fox jumps over the" >file &&
12      echo "lazy dog" >>file &&
13      git add file &&
14      GIT_AUTHOR_NAME="A" git commit -a -m "Initial."'
15
16 test_expect_success $PREREQ \
17     'Setup helper tool' \
18     '(echo "#!$SHELL_PATH"
19       echo shift
20       echo output=1
21       echo "while test -f commandline\$output; do output=\$((\$output+1)); done"
22       echo for a
23       echo do
24       echo "  echo \"!\$a!\""
25       echo "done >commandline\$output"
26       test_have_prereq MINGW && echo "dos2unix commandline\$output"
27       echo "cat > msgtxt\$output"
28       ) >fake.sendmail &&
29      chmod +x ./fake.sendmail &&
30      git add fake.sendmail &&
31      GIT_AUTHOR_NAME="A" git commit -a -m "Second."'
32
33 clean_fake_sendmail() {
34         rm -f commandline* msgtxt*
35 }
36
37 test_expect_success $PREREQ 'Extract patches' '
38     patches=`git format-patch -s --cc="One <one@example.com>" --cc=two@example.com -n HEAD^1`
39 '
40
41 # Test no confirm early to ensure remaining tests will not hang
42 test_no_confirm () {
43         rm -f no_confirm_okay
44         echo n | \
45                 GIT_SEND_EMAIL_NOTTY=1 \
46                 git send-email \
47                 --from="Example <from@example.com>" \
48                 --to=nobody@example.com \
49                 --smtp-server="$(pwd)/fake.sendmail" \
50                 $@ \
51                 $patches > stdout &&
52                 test_must_fail grep "Send this email" stdout &&
53                 > no_confirm_okay
54 }
55
56 # Exit immediately to prevent hang if a no-confirm test fails
57 check_no_confirm () {
58         if ! test -f no_confirm_okay
59         then
60                 say 'confirm test failed; skipping remaining tests to prevent hanging'
61                 PREREQ="$PREREQ,CHECK_NO_CONFIRM"
62         fi
63         return 0
64 }
65
66 test_expect_success $PREREQ 'No confirm with --suppress-cc' '
67         test_no_confirm --suppress-cc=sob &&
68         check_no_confirm
69 '
70
71
72 test_expect_success $PREREQ 'No confirm with --confirm=never' '
73         test_no_confirm --confirm=never &&
74         check_no_confirm
75 '
76
77 # leave sendemail.confirm set to never after this so that none of the
78 # remaining tests prompt unintentionally.
79 test_expect_success $PREREQ 'No confirm with sendemail.confirm=never' '
80         git config sendemail.confirm never &&
81         test_no_confirm --compose --subject=foo &&
82         check_no_confirm
83 '
84
85 test_expect_success $PREREQ 'Send patches' '
86      git send-email --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
87 '
88
89 test_expect_success $PREREQ 'setup expect' '
90 cat >expected <<\EOF
91 !nobody@example.com!
92 !author@example.com!
93 !one@example.com!
94 !two@example.com!
95 EOF
96 '
97
98 test_expect_success $PREREQ \
99     'Verify commandline' \
100     'test_cmp expected commandline1'
101
102 test_expect_success $PREREQ 'Send patches with --envelope-sender' '
103     clean_fake_sendmail &&
104      git send-email --envelope-sender="Patch Contributor <patch@example.com>" --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
105 '
106
107 test_expect_success $PREREQ 'setup expect' '
108 cat >expected <<\EOF
109 !patch@example.com!
110 !-i!
111 !nobody@example.com!
112 !author@example.com!
113 !one@example.com!
114 !two@example.com!
115 EOF
116 '
117
118 test_expect_success $PREREQ \
119     'Verify commandline' \
120     'test_cmp expected commandline1'
121
122 test_expect_success $PREREQ 'Send patches with --envelope-sender=auto' '
123     clean_fake_sendmail &&
124      git send-email --envelope-sender=auto --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
125 '
126
127 test_expect_success $PREREQ 'setup expect' '
128 cat >expected <<\EOF
129 !nobody@example.com!
130 !-i!
131 !nobody@example.com!
132 !author@example.com!
133 !one@example.com!
134 !two@example.com!
135 EOF
136 '
137
138 test_expect_success $PREREQ \
139     'Verify commandline' \
140     'test_cmp expected commandline1'
141
142 test_expect_success $PREREQ 'setup expect' "
143 cat >expected-show-all-headers <<\EOF
144 0001-Second.patch
145 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
146 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
147 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
148 Dry-OK. Log says:
149 Server: relay.example.com
150 MAIL FROM:<from@example.com>
151 RCPT TO:<to@example.com>
152 RCPT TO:<cc@example.com>
153 RCPT TO:<author@example.com>
154 RCPT TO:<one@example.com>
155 RCPT TO:<two@example.com>
156 RCPT TO:<bcc@example.com>
157 From: Example <from@example.com>
158 To: to@example.com
159 Cc: cc@example.com,
160         A <author@example.com>,
161         One <one@example.com>,
162         two@example.com
163 Subject: [PATCH 1/1] Second.
164 Date: DATE-STRING
165 Message-Id: MESSAGE-ID-STRING
166 X-Mailer: X-MAILER-STRING
167 In-Reply-To: <unique-message-id@example.com>
168 References: <unique-message-id@example.com>
169
170 Result: OK
171 EOF
172 "
173
174 test_suppress_self () {
175         test_commit $3 &&
176         test_when_finished "git reset --hard HEAD^" &&
177
178         write_script cccmd-sed <<-EOF &&
179                 sed -n -e s/^cccmd--//p "\$1"
180         EOF
181
182         git commit --amend --author="$1 <$2>" -F - &&
183         clean_fake_sendmail &&
184         git format-patch --stdout -1 >"suppress-self-$3.patch" &&
185
186         git send-email --from="$1 <$2>" \
187                 --to=nobody@example.com \
188                 --cc-cmd=./cccmd-sed \
189                 --suppress-cc=self \
190                 --smtp-server="$(pwd)/fake.sendmail" \
191                 suppress-self-$3.patch &&
192
193         mv msgtxt1 msgtxt1-$3 &&
194         sed -e '/^$/q' msgtxt1-$3 >"msghdr1-$3" &&
195         >"expected-no-cc-$3" &&
196
197         (grep '^Cc:' msghdr1-$3 >"actual-no-cc-$3";
198          test_cmp expected-no-cc-$3 actual-no-cc-$3)
199 }
200
201 test_suppress_self_unquoted () {
202         test_suppress_self "$1" "$2" "unquoted-$3" <<-EOF
203                 test suppress-cc.self unquoted-$3 with name $1 email $2
204
205                 unquoted-$3
206
207                 cccmd--$1 <$2>
208
209                 Cc: $1 <$2>
210                 Signed-off-by: $1 <$2>
211         EOF
212 }
213
214 test_suppress_self_quoted () {
215         test_suppress_self "$1" "$2" "quoted-$3" <<-EOF
216                 test suppress-cc.self quoted-$3 with name $1 email $2
217
218                 quoted-$3
219
220                 cccmd--"$1" <$2>
221
222                 Cc: $1 <$2>
223                 Cc: "$1" <$2>
224                 Signed-off-by: $1 <$2>
225                 Signed-off-by: "$1" <$2>
226         EOF
227 }
228
229 test_expect_success $PREREQ 'self name is suppressed' "
230         test_suppress_self_unquoted 'A U Thor' 'author@example.com' \
231                 'self_name_suppressed'
232 "
233
234 test_expect_success $PREREQ 'self name with dot is suppressed' "
235         test_suppress_self_quoted 'A U. Thor' 'author@example.com' \
236                 'self_name_dot_suppressed'
237 "
238
239 test_expect_success $PREREQ 'non-ascii self name is suppressed' "
240         test_suppress_self_quoted 'Füñný Nâmé' 'odd_?=mail@example.com' \
241                 'non_ascii_self_suppressed'
242 "
243
244 test_expect_success $PREREQ 'sanitized self name is suppressed' "
245         test_suppress_self_unquoted '\"A U. Thor\"' 'author@example.com' \
246                 'self_name_sanitized_suppressed'
247 "
248
249 test_expect_success $PREREQ 'Show all headers' '
250         git send-email \
251                 --dry-run \
252                 --suppress-cc=sob \
253                 --from="Example <from@example.com>" \
254                 --to=to@example.com \
255                 --cc=cc@example.com \
256                 --bcc=bcc@example.com \
257                 --in-reply-to="<unique-message-id@example.com>" \
258                 --smtp-server relay.example.com \
259                 $patches |
260         sed     -e "s/^\(Date:\).*/\1 DATE-STRING/" \
261                 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
262                 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
263                 >actual-show-all-headers &&
264         test_cmp expected-show-all-headers actual-show-all-headers
265 '
266
267 test_expect_success $PREREQ 'Prompting works' '
268         clean_fake_sendmail &&
269         (echo "to@example.com"
270          echo ""
271         ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
272                 --smtp-server="$(pwd)/fake.sendmail" \
273                 $patches \
274                 2>errors &&
275                 grep "^From: A U Thor <author@example.com>\$" msgtxt1 &&
276                 grep "^To: to@example.com\$" msgtxt1
277 '
278
279 test_expect_success $PREREQ,AUTOIDENT 'implicit ident is allowed' '
280         clean_fake_sendmail &&
281         (sane_unset GIT_AUTHOR_NAME &&
282         sane_unset GIT_AUTHOR_EMAIL &&
283         sane_unset GIT_COMMITTER_NAME &&
284         sane_unset GIT_COMMITTER_EMAIL &&
285         GIT_SEND_EMAIL_NOTTY=1 git send-email \
286                 --smtp-server="$(pwd)/fake.sendmail" \
287                 --to=to@example.com \
288                 $patches </dev/null 2>errors
289         )
290 '
291
292 test_expect_success $PREREQ,!AUTOIDENT 'broken implicit ident aborts send-email' '
293         clean_fake_sendmail &&
294         (sane_unset GIT_AUTHOR_NAME &&
295         sane_unset GIT_AUTHOR_EMAIL &&
296         sane_unset GIT_COMMITTER_NAME &&
297         sane_unset GIT_COMMITTER_EMAIL &&
298         GIT_SEND_EMAIL_NOTTY=1 && export GIT_SEND_EMAIL_NOTTY &&
299         test_must_fail git send-email \
300                 --smtp-server="$(pwd)/fake.sendmail" \
301                 --to=to@example.com \
302                 $patches </dev/null 2>errors &&
303         test_i18ngrep "tell me who you are" errors
304         )
305 '
306
307 test_expect_success $PREREQ 'tocmd works' '
308         clean_fake_sendmail &&
309         cp $patches tocmd.patch &&
310         echo tocmd--tocmd@example.com >>tocmd.patch &&
311         {
312           echo "#!$SHELL_PATH"
313           echo sed -n -e s/^tocmd--//p \"\$1\"
314         } > tocmd-sed &&
315         chmod +x tocmd-sed &&
316         git send-email \
317                 --from="Example <nobody@example.com>" \
318                 --to-cmd=./tocmd-sed \
319                 --smtp-server="$(pwd)/fake.sendmail" \
320                 tocmd.patch \
321                 &&
322         grep "^To: tocmd@example.com" msgtxt1
323 '
324
325 test_expect_success $PREREQ 'cccmd works' '
326         clean_fake_sendmail &&
327         cp $patches cccmd.patch &&
328         echo "cccmd--  cccmd@example.com" >>cccmd.patch &&
329         {
330           echo "#!$SHELL_PATH"
331           echo sed -n -e s/^cccmd--//p \"\$1\"
332         } > cccmd-sed &&
333         chmod +x cccmd-sed &&
334         git send-email \
335                 --from="Example <nobody@example.com>" \
336                 --to=nobody@example.com \
337                 --cc-cmd=./cccmd-sed \
338                 --smtp-server="$(pwd)/fake.sendmail" \
339                 cccmd.patch \
340                 &&
341         grep "^ cccmd@example.com" msgtxt1
342 '
343
344 test_expect_success $PREREQ 'reject long lines' '
345         z8=zzzzzzzz &&
346         z64=$z8$z8$z8$z8$z8$z8$z8$z8 &&
347         z512=$z64$z64$z64$z64$z64$z64$z64$z64 &&
348         clean_fake_sendmail &&
349         cp $patches longline.patch &&
350         echo $z512$z512 >>longline.patch &&
351         test_must_fail git send-email \
352                 --from="Example <nobody@example.com>" \
353                 --to=nobody@example.com \
354                 --smtp-server="$(pwd)/fake.sendmail" \
355                 $patches longline.patch \
356                 2>errors &&
357         grep longline.patch errors
358 '
359
360 test_expect_success $PREREQ 'no patch was sent' '
361         ! test -e commandline1
362 '
363
364 test_expect_success $PREREQ 'Author From: in message body' '
365         clean_fake_sendmail &&
366         git send-email \
367                 --from="Example <nobody@example.com>" \
368                 --to=nobody@example.com \
369                 --smtp-server="$(pwd)/fake.sendmail" \
370                 $patches &&
371         sed "1,/^\$/d" < msgtxt1 > msgbody1 &&
372         grep "From: A <author@example.com>" msgbody1
373 '
374
375 test_expect_success $PREREQ 'Author From: not in message body' '
376         clean_fake_sendmail &&
377         git send-email \
378                 --from="A <author@example.com>" \
379                 --to=nobody@example.com \
380                 --smtp-server="$(pwd)/fake.sendmail" \
381                 $patches &&
382         sed "1,/^\$/d" < msgtxt1 > msgbody1 &&
383         ! grep "From: A <author@example.com>" msgbody1
384 '
385
386 test_expect_success $PREREQ 'allow long lines with --no-validate' '
387         git send-email \
388                 --from="Example <nobody@example.com>" \
389                 --to=nobody@example.com \
390                 --smtp-server="$(pwd)/fake.sendmail" \
391                 --novalidate \
392                 $patches longline.patch \
393                 2>errors
394 '
395
396 test_expect_success $PREREQ 'Invalid In-Reply-To' '
397         clean_fake_sendmail &&
398         git send-email \
399                 --from="Example <nobody@example.com>" \
400                 --to=nobody@example.com \
401                 --in-reply-to=" " \
402                 --smtp-server="$(pwd)/fake.sendmail" \
403                 $patches \
404                 2>errors &&
405         ! grep "^In-Reply-To: < *>" msgtxt1
406 '
407
408 test_expect_success $PREREQ 'Valid In-Reply-To when prompting' '
409         clean_fake_sendmail &&
410         (echo "From Example <from@example.com>"
411          echo "To Example <to@example.com>"
412          echo ""
413         ) | env GIT_SEND_EMAIL_NOTTY=1 git send-email \
414                 --smtp-server="$(pwd)/fake.sendmail" \
415                 $patches 2>errors &&
416         ! grep "^In-Reply-To: < *>" msgtxt1
417 '
418
419 test_expect_success $PREREQ 'In-Reply-To without --chain-reply-to' '
420         clean_fake_sendmail &&
421         echo "<unique-message-id@example.com>" >expect &&
422         git send-email \
423                 --from="Example <nobody@example.com>" \
424                 --to=nobody@example.com \
425                 --nochain-reply-to \
426                 --in-reply-to="$(cat expect)" \
427                 --smtp-server="$(pwd)/fake.sendmail" \
428                 $patches $patches $patches \
429                 2>errors &&
430         # The first message is a reply to --in-reply-to
431         sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
432         test_cmp expect actual &&
433         # Second and subsequent messages are replies to the first one
434         sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
435         sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
436         test_cmp expect actual &&
437         sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
438         test_cmp expect actual
439 '
440
441 test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' '
442         clean_fake_sendmail &&
443         echo "<unique-message-id@example.com>" >expect &&
444         git send-email \
445                 --from="Example <nobody@example.com>" \
446                 --to=nobody@example.com \
447                 --chain-reply-to \
448                 --in-reply-to="$(cat expect)" \
449                 --smtp-server="$(pwd)/fake.sendmail" \
450                 $patches $patches $patches \
451                 2>errors &&
452         sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
453         test_cmp expect actual &&
454         sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
455         sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
456         test_cmp expect actual &&
457         sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt2 >expect &&
458         sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
459         test_cmp expect actual
460 '
461
462 test_expect_success $PREREQ 'setup fake editor' '
463         (echo "#!$SHELL_PATH" &&
464          echo "echo fake edit >>\"\$1\""
465         ) >fake-editor &&
466         chmod +x fake-editor
467 '
468
469 test_set_editor "$(pwd)/fake-editor"
470
471 test_expect_success $PREREQ '--compose works' '
472         clean_fake_sendmail &&
473         git send-email \
474         --compose --subject foo \
475         --from="Example <nobody@example.com>" \
476         --to=nobody@example.com \
477         --smtp-server="$(pwd)/fake.sendmail" \
478         $patches \
479         2>errors
480 '
481
482 test_expect_success $PREREQ 'first message is compose text' '
483         grep "^fake edit" msgtxt1
484 '
485
486 test_expect_success $PREREQ 'second message is patch' '
487         grep "Subject:.*Second" msgtxt2
488 '
489
490 test_expect_success $PREREQ 'setup expect' "
491 cat >expected-suppress-sob <<\EOF
492 0001-Second.patch
493 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
494 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
495 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
496 Dry-OK. Log says:
497 Server: relay.example.com
498 MAIL FROM:<from@example.com>
499 RCPT TO:<to@example.com>
500 RCPT TO:<cc@example.com>
501 RCPT TO:<author@example.com>
502 RCPT TO:<one@example.com>
503 RCPT TO:<two@example.com>
504 From: Example <from@example.com>
505 To: to@example.com
506 Cc: cc@example.com,
507         A <author@example.com>,
508         One <one@example.com>,
509         two@example.com
510 Subject: [PATCH 1/1] Second.
511 Date: DATE-STRING
512 Message-Id: MESSAGE-ID-STRING
513 X-Mailer: X-MAILER-STRING
514
515 Result: OK
516 EOF
517 "
518
519 test_suppression () {
520         git send-email \
521                 --dry-run \
522                 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
523                 --from="Example <from@example.com>" \
524                 --to=to@example.com \
525                 --smtp-server relay.example.com \
526                 $patches |
527         sed     -e "s/^\(Date:\).*/\1 DATE-STRING/" \
528                 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
529                 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
530                 >actual-suppress-$1${2+"-$2"} &&
531         test_cmp expected-suppress-$1${2+"-$2"} actual-suppress-$1${2+"-$2"}
532 }
533
534 test_expect_success $PREREQ 'sendemail.cc set' '
535         git config sendemail.cc cc@example.com &&
536         test_suppression sob
537 '
538
539 test_expect_success $PREREQ 'setup expect' "
540 cat >expected-suppress-sob <<\EOF
541 0001-Second.patch
542 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
543 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
544 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
545 Dry-OK. Log says:
546 Server: relay.example.com
547 MAIL FROM:<from@example.com>
548 RCPT TO:<to@example.com>
549 RCPT TO:<author@example.com>
550 RCPT TO:<one@example.com>
551 RCPT TO:<two@example.com>
552 From: Example <from@example.com>
553 To: to@example.com
554 Cc: A <author@example.com>,
555         One <one@example.com>,
556         two@example.com
557 Subject: [PATCH 1/1] Second.
558 Date: DATE-STRING
559 Message-Id: MESSAGE-ID-STRING
560 X-Mailer: X-MAILER-STRING
561
562 Result: OK
563 EOF
564 "
565
566 test_expect_success $PREREQ 'sendemail.cc unset' '
567         git config --unset sendemail.cc &&
568         test_suppression sob
569 '
570
571 test_expect_success $PREREQ 'setup expect' "
572 cat >expected-suppress-cccmd <<\EOF
573 0001-Second.patch
574 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
575 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
576 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
577 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
578 Dry-OK. Log says:
579 Server: relay.example.com
580 MAIL FROM:<from@example.com>
581 RCPT TO:<to@example.com>
582 RCPT TO:<author@example.com>
583 RCPT TO:<one@example.com>
584 RCPT TO:<two@example.com>
585 RCPT TO:<committer@example.com>
586 From: Example <from@example.com>
587 To: to@example.com
588 Cc: A <author@example.com>,
589         One <one@example.com>,
590         two@example.com,
591         C O Mitter <committer@example.com>
592 Subject: [PATCH 1/1] Second.
593 Date: DATE-STRING
594 Message-Id: MESSAGE-ID-STRING
595 X-Mailer: X-MAILER-STRING
596
597 Result: OK
598 EOF
599 "
600
601 test_expect_success $PREREQ 'sendemail.cccmd' '
602         echo echo cc-cmd@example.com > cccmd &&
603         chmod +x cccmd &&
604         git config sendemail.cccmd ./cccmd &&
605         test_suppression cccmd
606 '
607
608 test_expect_success $PREREQ 'setup expect' '
609 cat >expected-suppress-all <<\EOF
610 0001-Second.patch
611 Dry-OK. Log says:
612 Server: relay.example.com
613 MAIL FROM:<from@example.com>
614 RCPT TO:<to@example.com>
615 From: Example <from@example.com>
616 To: to@example.com
617 Subject: [PATCH 1/1] Second.
618 Date: DATE-STRING
619 Message-Id: MESSAGE-ID-STRING
620 X-Mailer: X-MAILER-STRING
621
622 Result: OK
623 EOF
624 '
625
626 test_expect_success $PREREQ '--suppress-cc=all' '
627         test_suppression all
628 '
629
630 test_expect_success $PREREQ 'setup expect' "
631 cat >expected-suppress-body <<\EOF
632 0001-Second.patch
633 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
634 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
635 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
636 (cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
637 Dry-OK. Log says:
638 Server: relay.example.com
639 MAIL FROM:<from@example.com>
640 RCPT TO:<to@example.com>
641 RCPT TO:<author@example.com>
642 RCPT TO:<one@example.com>
643 RCPT TO:<two@example.com>
644 RCPT TO:<cc-cmd@example.com>
645 From: Example <from@example.com>
646 To: to@example.com
647 Cc: A <author@example.com>,
648         One <one@example.com>,
649         two@example.com,
650         cc-cmd@example.com
651 Subject: [PATCH 1/1] Second.
652 Date: DATE-STRING
653 Message-Id: MESSAGE-ID-STRING
654 X-Mailer: X-MAILER-STRING
655
656 Result: OK
657 EOF
658 "
659
660 test_expect_success $PREREQ '--suppress-cc=body' '
661         test_suppression body
662 '
663
664 test_expect_success $PREREQ 'setup expect' "
665 cat >expected-suppress-body-cccmd <<\EOF
666 0001-Second.patch
667 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
668 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
669 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
670 Dry-OK. Log says:
671 Server: relay.example.com
672 MAIL FROM:<from@example.com>
673 RCPT TO:<to@example.com>
674 RCPT TO:<author@example.com>
675 RCPT TO:<one@example.com>
676 RCPT TO:<two@example.com>
677 From: Example <from@example.com>
678 To: to@example.com
679 Cc: A <author@example.com>,
680         One <one@example.com>,
681         two@example.com
682 Subject: [PATCH 1/1] Second.
683 Date: DATE-STRING
684 Message-Id: MESSAGE-ID-STRING
685 X-Mailer: X-MAILER-STRING
686
687 Result: OK
688 EOF
689 "
690
691 test_expect_success $PREREQ '--suppress-cc=body --suppress-cc=cccmd' '
692         test_suppression body cccmd
693 '
694
695 test_expect_success $PREREQ 'setup expect' "
696 cat >expected-suppress-sob <<\EOF
697 0001-Second.patch
698 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
699 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
700 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
701 Dry-OK. Log says:
702 Server: relay.example.com
703 MAIL FROM:<from@example.com>
704 RCPT TO:<to@example.com>
705 RCPT TO:<author@example.com>
706 RCPT TO:<one@example.com>
707 RCPT TO:<two@example.com>
708 From: Example <from@example.com>
709 To: to@example.com
710 Cc: A <author@example.com>,
711         One <one@example.com>,
712         two@example.com
713 Subject: [PATCH 1/1] Second.
714 Date: DATE-STRING
715 Message-Id: MESSAGE-ID-STRING
716 X-Mailer: X-MAILER-STRING
717
718 Result: OK
719 EOF
720 "
721
722 test_expect_success $PREREQ '--suppress-cc=sob' '
723         test_might_fail git config --unset sendemail.cccmd &&
724         test_suppression sob
725 '
726
727 test_expect_success $PREREQ 'setup expect' "
728 cat >expected-suppress-bodycc <<\EOF
729 0001-Second.patch
730 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
731 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
732 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
733 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
734 Dry-OK. Log says:
735 Server: relay.example.com
736 MAIL FROM:<from@example.com>
737 RCPT TO:<to@example.com>
738 RCPT TO:<author@example.com>
739 RCPT TO:<one@example.com>
740 RCPT TO:<two@example.com>
741 RCPT TO:<committer@example.com>
742 From: Example <from@example.com>
743 To: to@example.com
744 Cc: A <author@example.com>,
745         One <one@example.com>,
746         two@example.com,
747         C O Mitter <committer@example.com>
748 Subject: [PATCH 1/1] Second.
749 Date: DATE-STRING
750 Message-Id: MESSAGE-ID-STRING
751 X-Mailer: X-MAILER-STRING
752
753 Result: OK
754 EOF
755 "
756
757 test_expect_success $PREREQ '--suppress-cc=bodycc' '
758         test_suppression bodycc
759 '
760
761 test_expect_success $PREREQ 'setup expect' "
762 cat >expected-suppress-cc <<\EOF
763 0001-Second.patch
764 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
765 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
766 Dry-OK. Log says:
767 Server: relay.example.com
768 MAIL FROM:<from@example.com>
769 RCPT TO:<to@example.com>
770 RCPT TO:<author@example.com>
771 RCPT TO:<committer@example.com>
772 From: Example <from@example.com>
773 To: to@example.com
774 Cc: A <author@example.com>,
775         C O Mitter <committer@example.com>
776 Subject: [PATCH 1/1] Second.
777 Date: DATE-STRING
778 Message-Id: MESSAGE-ID-STRING
779 X-Mailer: X-MAILER-STRING
780
781 Result: OK
782 EOF
783 "
784
785 test_expect_success $PREREQ '--suppress-cc=cc' '
786         test_suppression cc
787 '
788
789 test_confirm () {
790         echo y | \
791                 GIT_SEND_EMAIL_NOTTY=1 \
792                 git send-email \
793                 --from="Example <nobody@example.com>" \
794                 --to=nobody@example.com \
795                 --smtp-server="$(pwd)/fake.sendmail" \
796                 $@ $patches > stdout &&
797         grep "Send this email" stdout
798 }
799
800 test_expect_success $PREREQ '--confirm=always' '
801         test_confirm --confirm=always --suppress-cc=all
802 '
803
804 test_expect_success $PREREQ '--confirm=auto' '
805         test_confirm --confirm=auto
806 '
807
808 test_expect_success $PREREQ '--confirm=cc' '
809         test_confirm --confirm=cc
810 '
811
812 test_expect_success $PREREQ '--confirm=compose' '
813         test_confirm --confirm=compose --compose
814 '
815
816 test_expect_success $PREREQ 'confirm by default (due to cc)' '
817         CONFIRM=$(git config --get sendemail.confirm) &&
818         git config --unset sendemail.confirm &&
819         test_confirm
820         ret="$?"
821         git config sendemail.confirm ${CONFIRM:-never}
822         test $ret = "0"
823 '
824
825 test_expect_success $PREREQ 'confirm by default (due to --compose)' '
826         CONFIRM=$(git config --get sendemail.confirm) &&
827         git config --unset sendemail.confirm &&
828         test_confirm --suppress-cc=all --compose
829         ret="$?"
830         git config sendemail.confirm ${CONFIRM:-never}
831         test $ret = "0"
832 '
833
834 test_expect_success $PREREQ 'confirm detects EOF (inform assumes y)' '
835         CONFIRM=$(git config --get sendemail.confirm) &&
836         git config --unset sendemail.confirm &&
837         rm -fr outdir &&
838         git format-patch -2 -o outdir &&
839         GIT_SEND_EMAIL_NOTTY=1 \
840                 git send-email \
841                         --from="Example <nobody@example.com>" \
842                         --to=nobody@example.com \
843                         --smtp-server="$(pwd)/fake.sendmail" \
844                         outdir/*.patch < /dev/null
845         ret="$?"
846         git config sendemail.confirm ${CONFIRM:-never}
847         test $ret = "0"
848 '
849
850 test_expect_success $PREREQ 'confirm detects EOF (auto causes failure)' '
851         CONFIRM=$(git config --get sendemail.confirm) &&
852         git config sendemail.confirm auto &&
853         GIT_SEND_EMAIL_NOTTY=1 &&
854         export GIT_SEND_EMAIL_NOTTY &&
855                 test_must_fail git send-email \
856                         --from="Example <nobody@example.com>" \
857                         --to=nobody@example.com \
858                         --smtp-server="$(pwd)/fake.sendmail" \
859                         $patches < /dev/null
860         ret="$?"
861         git config sendemail.confirm ${CONFIRM:-never}
862         test $ret = "0"
863 '
864
865 test_expect_success $PREREQ 'confirm does not loop forever' '
866         CONFIRM=$(git config --get sendemail.confirm) &&
867         git config sendemail.confirm auto &&
868         GIT_SEND_EMAIL_NOTTY=1 &&
869         export GIT_SEND_EMAIL_NOTTY &&
870                 yes "bogus" | test_must_fail git send-email \
871                         --from="Example <nobody@example.com>" \
872                         --to=nobody@example.com \
873                         --smtp-server="$(pwd)/fake.sendmail" \
874                         $patches
875         ret="$?"
876         git config sendemail.confirm ${CONFIRM:-never}
877         test $ret = "0"
878 '
879
880 test_expect_success $PREREQ 'utf8 Cc is rfc2047 encoded' '
881         clean_fake_sendmail &&
882         rm -fr outdir &&
883         git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
884         git send-email \
885         --from="Example <nobody@example.com>" \
886         --to=nobody@example.com \
887         --smtp-server="$(pwd)/fake.sendmail" \
888         outdir/*.patch &&
889         grep "^ " msgtxt1 |
890         grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
891 '
892
893 test_expect_success $PREREQ '--compose adds MIME for utf8 body' '
894         clean_fake_sendmail &&
895         (echo "#!$SHELL_PATH" &&
896          echo "echo utf8 body: àéìöú >>\"\$1\""
897         ) >fake-editor-utf8 &&
898         chmod +x fake-editor-utf8 &&
899           GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
900           git send-email \
901           --compose --subject foo \
902           --from="Example <nobody@example.com>" \
903           --to=nobody@example.com \
904           --smtp-server="$(pwd)/fake.sendmail" \
905           $patches &&
906         grep "^utf8 body" msgtxt1 &&
907         grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
908 '
909
910 test_expect_success $PREREQ '--compose respects user mime type' '
911         clean_fake_sendmail &&
912         (echo "#!$SHELL_PATH" &&
913          echo "(echo MIME-Version: 1.0"
914          echo " echo Content-Type: text/plain\\; charset=iso-8859-1"
915          echo " echo Content-Transfer-Encoding: 8bit"
916          echo " echo Subject: foo"
917          echo " echo "
918          echo " echo utf8 body: àéìöú) >\"\$1\""
919         ) >fake-editor-utf8-mime &&
920         chmod +x fake-editor-utf8-mime &&
921           GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
922           git send-email \
923           --compose --subject foo \
924           --from="Example <nobody@example.com>" \
925           --to=nobody@example.com \
926           --smtp-server="$(pwd)/fake.sendmail" \
927           $patches &&
928         grep "^utf8 body" msgtxt1 &&
929         grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
930         ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
931 '
932
933 test_expect_success $PREREQ '--compose adds MIME for utf8 subject' '
934         clean_fake_sendmail &&
935           GIT_EDITOR="\"$(pwd)/fake-editor\"" \
936           git send-email \
937           --compose --subject utf8-sübjëct \
938           --from="Example <nobody@example.com>" \
939           --to=nobody@example.com \
940           --smtp-server="$(pwd)/fake.sendmail" \
941           $patches &&
942         grep "^fake edit" msgtxt1 &&
943         grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
944 '
945
946 test_expect_success $PREREQ 'utf8 author is correctly passed on' '
947         clean_fake_sendmail &&
948         test_commit weird_author &&
949         test_when_finished "git reset --hard HEAD^" &&
950         git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
951         git format-patch --stdout -1 >funny_name.patch &&
952         git send-email --from="Example <nobody@example.com>" \
953           --to=nobody@example.com \
954           --smtp-server="$(pwd)/fake.sendmail" \
955           funny_name.patch &&
956         grep "^From: Füñný Nâmé <odd_?=mail@example.com>" msgtxt1
957 '
958
959 test_expect_success $PREREQ 'utf8 sender is not duplicated' '
960         clean_fake_sendmail &&
961         test_commit weird_sender &&
962         test_when_finished "git reset --hard HEAD^" &&
963         git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
964         git format-patch --stdout -1 >funny_name.patch &&
965         git send-email --from="Füñný Nâmé <odd_?=mail@example.com>" \
966           --to=nobody@example.com \
967           --smtp-server="$(pwd)/fake.sendmail" \
968           funny_name.patch &&
969         grep "^From: " msgtxt1 >msgfrom &&
970         test_line_count = 1 msgfrom
971 '
972
973 test_expect_success $PREREQ 'sendemail.composeencoding works' '
974         clean_fake_sendmail &&
975         git config sendemail.composeencoding iso-8859-1 &&
976         (echo "#!$SHELL_PATH" &&
977          echo "echo utf8 body: àéìöú >>\"\$1\""
978         ) >fake-editor-utf8 &&
979         chmod +x fake-editor-utf8 &&
980           GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
981           git send-email \
982           --compose --subject foo \
983           --from="Example <nobody@example.com>" \
984           --to=nobody@example.com \
985           --smtp-server="$(pwd)/fake.sendmail" \
986           $patches &&
987         grep "^utf8 body" msgtxt1 &&
988         grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
989 '
990
991 test_expect_success $PREREQ '--compose-encoding works' '
992         clean_fake_sendmail &&
993         (echo "#!$SHELL_PATH" &&
994          echo "echo utf8 body: àéìöú >>\"\$1\""
995         ) >fake-editor-utf8 &&
996         chmod +x fake-editor-utf8 &&
997           GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
998           git send-email \
999           --compose-encoding iso-8859-1 \
1000           --compose --subject foo \
1001           --from="Example <nobody@example.com>" \
1002           --to=nobody@example.com \
1003           --smtp-server="$(pwd)/fake.sendmail" \
1004           $patches &&
1005         grep "^utf8 body" msgtxt1 &&
1006         grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1007 '
1008
1009 test_expect_success $PREREQ '--compose-encoding overrides sendemail.composeencoding' '
1010         clean_fake_sendmail &&
1011         git config sendemail.composeencoding iso-8859-1 &&
1012         (echo "#!$SHELL_PATH" &&
1013          echo "echo utf8 body: àéìöú >>\"\$1\""
1014         ) >fake-editor-utf8 &&
1015         chmod +x fake-editor-utf8 &&
1016           GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1017           git send-email \
1018           --compose-encoding iso-8859-2 \
1019           --compose --subject foo \
1020           --from="Example <nobody@example.com>" \
1021           --to=nobody@example.com \
1022           --smtp-server="$(pwd)/fake.sendmail" \
1023           $patches &&
1024         grep "^utf8 body" msgtxt1 &&
1025         grep "^Content-Type: text/plain; charset=iso-8859-2" msgtxt1
1026 '
1027
1028 test_expect_success $PREREQ '--compose-encoding adds correct MIME for subject' '
1029         clean_fake_sendmail &&
1030           GIT_EDITOR="\"$(pwd)/fake-editor\"" \
1031           git send-email \
1032           --compose-encoding iso-8859-2 \
1033           --compose --subject utf8-sübjëct \
1034           --from="Example <nobody@example.com>" \
1035           --to=nobody@example.com \
1036           --smtp-server="$(pwd)/fake.sendmail" \
1037           $patches &&
1038         grep "^fake edit" msgtxt1 &&
1039         grep "^Subject: =?iso-8859-2?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
1040 '
1041
1042 test_expect_success $PREREQ 'detects ambiguous reference/file conflict' '
1043         echo master > master &&
1044         git add master &&
1045         git commit -m"add master" &&
1046         test_must_fail git send-email --dry-run master 2>errors &&
1047         grep disambiguate errors
1048 '
1049
1050 test_expect_success $PREREQ 'feed two files' '
1051         rm -fr outdir &&
1052         git format-patch -2 -o outdir &&
1053         git send-email \
1054         --dry-run \
1055         --from="Example <nobody@example.com>" \
1056         --to=nobody@example.com \
1057         outdir/000?-*.patch 2>errors >out &&
1058         grep "^Subject: " out >subjects &&
1059         test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
1060         test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"
1061 '
1062
1063 test_expect_success $PREREQ 'in-reply-to but no threading' '
1064         git send-email \
1065                 --dry-run \
1066                 --from="Example <nobody@example.com>" \
1067                 --to=nobody@example.com \
1068                 --in-reply-to="<in-reply-id@example.com>" \
1069                 --nothread \
1070                 $patches |
1071         grep "In-Reply-To: <in-reply-id@example.com>"
1072 '
1073
1074 test_expect_success $PREREQ 'no in-reply-to and no threading' '
1075         git send-email \
1076                 --dry-run \
1077                 --from="Example <nobody@example.com>" \
1078                 --to=nobody@example.com \
1079                 --nothread \
1080                 $patches $patches >stdout &&
1081         ! grep "In-Reply-To: " stdout
1082 '
1083
1084 test_expect_success $PREREQ 'threading but no chain-reply-to' '
1085         git send-email \
1086                 --dry-run \
1087                 --from="Example <nobody@example.com>" \
1088                 --to=nobody@example.com \
1089                 --thread \
1090                 --nochain-reply-to \
1091                 $patches $patches >stdout &&
1092         grep "In-Reply-To: " stdout
1093 '
1094
1095 test_expect_success $PREREQ 'warning with an implicit --chain-reply-to' '
1096         git send-email \
1097         --dry-run \
1098         --from="Example <nobody@example.com>" \
1099         --to=nobody@example.com \
1100         outdir/000?-*.patch 2>errors >out &&
1101         grep "no-chain-reply-to" errors
1102 '
1103
1104 test_expect_success $PREREQ 'no warning with an explicit --chain-reply-to' '
1105         git send-email \
1106         --dry-run \
1107         --from="Example <nobody@example.com>" \
1108         --to=nobody@example.com \
1109         --chain-reply-to \
1110         outdir/000?-*.patch 2>errors >out &&
1111         ! grep "no-chain-reply-to" errors
1112 '
1113
1114 test_expect_success $PREREQ 'no warning with an explicit --no-chain-reply-to' '
1115         git send-email \
1116         --dry-run \
1117         --from="Example <nobody@example.com>" \
1118         --to=nobody@example.com \
1119         --nochain-reply-to \
1120         outdir/000?-*.patch 2>errors >out &&
1121         ! grep "no-chain-reply-to" errors
1122 '
1123
1124 test_expect_success $PREREQ 'no warning with sendemail.chainreplyto = false' '
1125         git config sendemail.chainreplyto false &&
1126         git send-email \
1127         --dry-run \
1128         --from="Example <nobody@example.com>" \
1129         --to=nobody@example.com \
1130         outdir/000?-*.patch 2>errors >out &&
1131         ! grep "no-chain-reply-to" errors
1132 '
1133
1134 test_expect_success $PREREQ 'no warning with sendemail.chainreplyto = true' '
1135         git config sendemail.chainreplyto true &&
1136         git send-email \
1137         --dry-run \
1138         --from="Example <nobody@example.com>" \
1139         --to=nobody@example.com \
1140         outdir/000?-*.patch 2>errors >out &&
1141         ! grep "no-chain-reply-to" errors
1142 '
1143
1144 test_expect_success $PREREQ 'sendemail.to works' '
1145         git config --replace-all sendemail.to "Somebody <somebody@ex.com>" &&
1146         git send-email \
1147                 --dry-run \
1148                 --from="Example <nobody@example.com>" \
1149                 $patches $patches >stdout &&
1150         grep "To: Somebody <somebody@ex.com>" stdout
1151 '
1152
1153 test_expect_success $PREREQ '--no-to overrides sendemail.to' '
1154         git send-email \
1155                 --dry-run \
1156                 --from="Example <nobody@example.com>" \
1157                 --no-to \
1158                 --to=nobody@example.com \
1159                 $patches $patches >stdout &&
1160         grep "To: nobody@example.com" stdout &&
1161         ! grep "To: Somebody <somebody@ex.com>" stdout
1162 '
1163
1164 test_expect_success $PREREQ 'sendemail.cc works' '
1165         git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" &&
1166         git send-email \
1167                 --dry-run \
1168                 --from="Example <nobody@example.com>" \
1169                 --to=nobody@example.com \
1170                 $patches $patches >stdout &&
1171         grep "Cc: Somebody <somebody@ex.com>" stdout
1172 '
1173
1174 test_expect_success $PREREQ '--no-cc overrides sendemail.cc' '
1175         git send-email \
1176                 --dry-run \
1177                 --from="Example <nobody@example.com>" \
1178                 --no-cc \
1179                 --cc=bodies@example.com \
1180                 --to=nobody@example.com \
1181                 $patches $patches >stdout &&
1182         grep "Cc: bodies@example.com" stdout &&
1183         ! grep "Cc: Somebody <somebody@ex.com>" stdout
1184 '
1185
1186 test_expect_success $PREREQ 'sendemail.bcc works' '
1187         git config --replace-all sendemail.bcc "Other <other@ex.com>" &&
1188         git send-email \
1189                 --dry-run \
1190                 --from="Example <nobody@example.com>" \
1191                 --to=nobody@example.com \
1192                 --smtp-server relay.example.com \
1193                 $patches $patches >stdout &&
1194         grep "RCPT TO:<other@ex.com>" stdout
1195 '
1196
1197 test_expect_success $PREREQ '--no-bcc overrides sendemail.bcc' '
1198         git send-email \
1199                 --dry-run \
1200                 --from="Example <nobody@example.com>" \
1201                 --no-bcc \
1202                 --bcc=bodies@example.com \
1203                 --to=nobody@example.com \
1204                 --smtp-server relay.example.com \
1205                 $patches $patches >stdout &&
1206         grep "RCPT TO:<bodies@example.com>" stdout &&
1207         ! grep "RCPT TO:<other@ex.com>" stdout
1208 '
1209
1210 test_expect_success $PREREQ 'patches To headers are used by default' '
1211         patch=`git format-patch -1 --to="bodies@example.com"` &&
1212         test_when_finished "rm $patch" &&
1213         git send-email \
1214                 --dry-run \
1215                 --from="Example <nobody@example.com>" \
1216                 --smtp-server relay.example.com \
1217                 $patch >stdout &&
1218         grep "RCPT TO:<bodies@example.com>" stdout
1219 '
1220
1221 test_expect_success $PREREQ 'patches To headers are appended to' '
1222         patch=`git format-patch -1 --to="bodies@example.com"` &&
1223         test_when_finished "rm $patch" &&
1224         git send-email \
1225                 --dry-run \
1226                 --from="Example <nobody@example.com>" \
1227                 --to=nobody@example.com \
1228                 --smtp-server relay.example.com \
1229                 $patch >stdout &&
1230         grep "RCPT TO:<bodies@example.com>" stdout &&
1231         grep "RCPT TO:<nobody@example.com>" stdout
1232 '
1233
1234 test_expect_success $PREREQ 'To headers from files reset each patch' '
1235         patch1=`git format-patch -1 --to="bodies@example.com"` &&
1236         patch2=`git format-patch -1 --to="other@example.com" HEAD~` &&
1237         test_when_finished "rm $patch1 && rm $patch2" &&
1238         git send-email \
1239                 --dry-run \
1240                 --from="Example <nobody@example.com>" \
1241                 --to="nobody@example.com" \
1242                 --smtp-server relay.example.com \
1243                 $patch1 $patch2 >stdout &&
1244         test $(grep -c "RCPT TO:<bodies@example.com>" stdout) = 1 &&
1245         test $(grep -c "RCPT TO:<nobody@example.com>" stdout) = 2 &&
1246         test $(grep -c "RCPT TO:<other@example.com>" stdout) = 1
1247 '
1248
1249 test_expect_success $PREREQ 'setup expect' '
1250 cat >email-using-8bit <<EOF
1251 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1252 Message-Id: <bogus-message-id@example.com>
1253 From: author@example.com
1254 Date: Sat, 12 Jun 2010 15:53:58 +0200
1255 Subject: subject goes here
1256
1257 Dieser deutsche Text enthält einen Umlaut!
1258 EOF
1259 '
1260
1261 test_expect_success $PREREQ 'setup expect' '
1262 cat >expected <<EOF
1263 Subject: subject goes here
1264 EOF
1265 '
1266
1267 test_expect_success $PREREQ 'ASCII subject is not RFC2047 quoted' '
1268         clean_fake_sendmail &&
1269         echo bogus |
1270         git send-email --from=author@example.com --to=nobody@example.com \
1271                         --smtp-server="$(pwd)/fake.sendmail" \
1272                         --8bit-encoding=UTF-8 \
1273                         email-using-8bit >stdout &&
1274         grep "Subject" msgtxt1 >actual &&
1275         test_cmp expected actual
1276 '
1277
1278 test_expect_success $PREREQ 'setup expect' '
1279 cat >content-type-decl <<EOF
1280 MIME-Version: 1.0
1281 Content-Type: text/plain; charset=UTF-8
1282 Content-Transfer-Encoding: 8bit
1283 EOF
1284 '
1285
1286 test_expect_success $PREREQ 'asks about and fixes 8bit encodings' '
1287         clean_fake_sendmail &&
1288         echo |
1289         git send-email --from=author@example.com --to=nobody@example.com \
1290                         --smtp-server="$(pwd)/fake.sendmail" \
1291                         email-using-8bit >stdout &&
1292         grep "do not declare a Content-Transfer-Encoding" stdout &&
1293         grep email-using-8bit stdout &&
1294         grep "Which 8bit encoding" stdout &&
1295         egrep "Content|MIME" msgtxt1 >actual &&
1296         test_cmp actual content-type-decl
1297 '
1298
1299 test_expect_success $PREREQ 'sendemail.8bitEncoding works' '
1300         clean_fake_sendmail &&
1301         git config sendemail.assume8bitEncoding UTF-8 &&
1302         echo bogus |
1303         git send-email --from=author@example.com --to=nobody@example.com \
1304                         --smtp-server="$(pwd)/fake.sendmail" \
1305                         email-using-8bit >stdout &&
1306         egrep "Content|MIME" msgtxt1 >actual &&
1307         test_cmp actual content-type-decl
1308 '
1309
1310 test_expect_success $PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
1311         clean_fake_sendmail &&
1312         git config sendemail.assume8bitEncoding "bogus too" &&
1313         echo bogus |
1314         git send-email --from=author@example.com --to=nobody@example.com \
1315                         --smtp-server="$(pwd)/fake.sendmail" \
1316                         --8bit-encoding=UTF-8 \
1317                         email-using-8bit >stdout &&
1318         egrep "Content|MIME" msgtxt1 >actual &&
1319         test_cmp actual content-type-decl
1320 '
1321
1322 test_expect_success $PREREQ 'setup expect' '
1323 cat >email-using-8bit <<EOF
1324 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1325 Message-Id: <bogus-message-id@example.com>
1326 From: author@example.com
1327 Date: Sat, 12 Jun 2010 15:53:58 +0200
1328 Subject: Dieser Betreff enthält auch einen Umlaut!
1329
1330 Nothing to see here.
1331 EOF
1332 '
1333
1334 test_expect_success $PREREQ 'setup expect' '
1335 cat >expected <<EOF
1336 Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
1337 EOF
1338 '
1339
1340 test_expect_success $PREREQ '--8bit-encoding also treats subject' '
1341         clean_fake_sendmail &&
1342         echo bogus |
1343         git send-email --from=author@example.com --to=nobody@example.com \
1344                         --smtp-server="$(pwd)/fake.sendmail" \
1345                         --8bit-encoding=UTF-8 \
1346                         email-using-8bit >stdout &&
1347         grep "Subject" msgtxt1 >actual &&
1348         test_cmp expected actual
1349 '
1350
1351 # Note that the patches in this test are deliberately out of order; we
1352 # want to make sure it works even if the cover-letter is not in the
1353 # first mail.
1354 test_expect_success $PREREQ 'refusing to send cover letter template' '
1355         clean_fake_sendmail &&
1356         rm -fr outdir &&
1357         git format-patch --cover-letter -2 -o outdir &&
1358         test_must_fail git send-email \
1359           --from="Example <nobody@example.com>" \
1360           --to=nobody@example.com \
1361           --smtp-server="$(pwd)/fake.sendmail" \
1362           outdir/0002-*.patch \
1363           outdir/0000-*.patch \
1364           outdir/0001-*.patch \
1365           2>errors >out &&
1366         grep "SUBJECT HERE" errors &&
1367         test -z "$(ls msgtxt*)"
1368 '
1369
1370 test_expect_success $PREREQ '--force sends cover letter template anyway' '
1371         clean_fake_sendmail &&
1372         rm -fr outdir &&
1373         git format-patch --cover-letter -2 -o outdir &&
1374         git send-email \
1375           --force \
1376           --from="Example <nobody@example.com>" \
1377           --to=nobody@example.com \
1378           --smtp-server="$(pwd)/fake.sendmail" \
1379           outdir/0002-*.patch \
1380           outdir/0000-*.patch \
1381           outdir/0001-*.patch \
1382           2>errors >out &&
1383         ! grep "SUBJECT HERE" errors &&
1384         test -n "$(ls msgtxt*)"
1385 '
1386
1387 test_expect_success $PREREQ 'sendemail.aliasfiletype=mailrc' '
1388         clean_fake_sendmail &&
1389         echo "alias sbd  somebody@example.org" >.mailrc &&
1390         git config --replace-all sendemail.aliasesfile "$(pwd)/.mailrc" &&
1391         git config sendemail.aliasfiletype mailrc &&
1392         git send-email \
1393           --from="Example <nobody@example.com>" \
1394           --to=sbd \
1395           --smtp-server="$(pwd)/fake.sendmail" \
1396           outdir/0001-*.patch \
1397           2>errors >out &&
1398         grep "^!somebody@example\.org!$" commandline1
1399 '
1400
1401 test_expect_success $PREREQ 'sendemail.aliasfile=~/.mailrc' '
1402         clean_fake_sendmail &&
1403         echo "alias sbd  someone@example.org" >~/.mailrc &&
1404         git config --replace-all sendemail.aliasesfile "~/.mailrc" &&
1405         git config sendemail.aliasfiletype mailrc &&
1406         git send-email \
1407           --from="Example <nobody@example.com>" \
1408           --to=sbd \
1409           --smtp-server="$(pwd)/fake.sendmail" \
1410           outdir/0001-*.patch \
1411           2>errors >out &&
1412         grep "^!someone@example\.org!$" commandline1
1413 '
1414
1415 test_done