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