3 test_description='git send-email'
6 # May be altered later in the test
9 test_expect_success $PREREQ \
10 'prepare reference tree' \
11 'echo "1A quick brown fox jumps over the" >file &&
12 echo "lazy dog" >>file &&
14 GIT_AUTHOR_NAME="A" git commit -a -m "Initial."'
16 test_expect_success $PREREQ \
18 '(echo "#!$SHELL_PATH"
21 echo "while test -f commandline\$output; do output=\$((\$output+1)); done"
24 echo " echo \"!\$a!\""
25 echo "done >commandline\$output"
26 echo "cat > msgtxt\$output"
28 chmod +x ./fake.sendmail &&
29 git add fake.sendmail &&
30 GIT_AUTHOR_NAME="A" git commit -a -m "Second."'
32 clean_fake_sendmail() {
33 rm -f commandline* msgtxt*
36 test_expect_success $PREREQ 'Extract patches' '
37 patches=`git format-patch -s --cc="One <one@example.com>" --cc=two@example.com -n HEAD^1`
40 # Test no confirm early to ensure remaining tests will not hang
44 GIT_SEND_EMAIL_NOTTY=1 \
46 --from="Example <from@example.com>" \
47 --to=nobody@example.com \
48 --smtp-server="$(pwd)/fake.sendmail" \
51 test_must_fail grep "Send this email" stdout &&
55 # Exit immediately to prevent hang if a no-confirm test fails
57 if ! test -f no_confirm_okay
59 say 'confirm test failed; skipping remaining tests to prevent hanging'
60 PREREQ="$PREREQ,CHECK_NO_CONFIRM"
65 test_expect_success $PREREQ 'No confirm with --suppress-cc' '
66 test_no_confirm --suppress-cc=sob &&
71 test_expect_success $PREREQ 'No confirm with --confirm=never' '
72 test_no_confirm --confirm=never &&
76 # leave sendemail.confirm set to never after this so that none of the
77 # remaining tests prompt unintentionally.
78 test_expect_success $PREREQ 'No confirm with sendemail.confirm=never' '
79 git config sendemail.confirm never &&
80 test_no_confirm --compose --subject=foo &&
84 test_expect_success $PREREQ 'Send patches' '
85 git send-email --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
88 test_expect_success $PREREQ 'setup expect' '
97 test_expect_success $PREREQ \
98 'Verify commandline' \
99 'test_cmp expected commandline1'
101 test_expect_success $PREREQ 'Send patches with --envelope-sender' '
102 clean_fake_sendmail &&
103 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
106 test_expect_success $PREREQ 'setup expect' '
117 test_expect_success $PREREQ \
118 'Verify commandline' \
119 'test_cmp expected commandline1'
121 test_expect_success $PREREQ 'Send patches with --envelope-sender=auto' '
122 clean_fake_sendmail &&
123 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
126 test_expect_success $PREREQ 'setup expect' '
137 test_expect_success $PREREQ \
138 'Verify commandline' \
139 'test_cmp expected commandline1'
141 test_expect_success $PREREQ 'setup expect' "
142 cat >expected-show-all-headers <<\EOF
144 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
145 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
146 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
148 Server: relay.example.com
149 MAIL FROM:<from@example.com>
150 RCPT TO:<to@example.com>
151 RCPT TO:<cc@example.com>
152 RCPT TO:<author@example.com>
153 RCPT TO:<one@example.com>
154 RCPT TO:<two@example.com>
155 RCPT TO:<bcc@example.com>
156 From: Example <from@example.com>
159 A <author@example.com>,
160 One <one@example.com>,
162 Subject: [PATCH 1/1] Second.
164 Message-Id: MESSAGE-ID-STRING
165 X-Mailer: X-MAILER-STRING
166 In-Reply-To: <unique-message-id@example.com>
167 References: <unique-message-id@example.com>
173 test_suppress_self () {
175 test_when_finished "git reset --hard HEAD^" &&
177 write_script cccmd-sed <<-EOF &&
178 sed -n -e s/^cccmd--//p "\$1"
181 git commit --amend --author="$1 <$2>" -F - &&
182 clean_fake_sendmail &&
183 git format-patch --stdout -1 >"suppress-self-$3.patch" &&
185 git send-email --from="$1 <$2>" \
186 --to=nobody@example.com \
187 --cc-cmd=./cccmd-sed \
189 --smtp-server="$(pwd)/fake.sendmail" \
190 suppress-self-$3.patch &&
192 mv msgtxt1 msgtxt1-$3 &&
193 sed -e '/^$/q' msgtxt1-$3 >"msghdr1-$3" &&
194 >"expected-no-cc-$3" &&
196 (grep '^Cc:' msghdr1-$3 >"actual-no-cc-$3";
197 test_cmp expected-no-cc-$3 actual-no-cc-$3)
200 test_suppress_self_unquoted () {
201 test_suppress_self "$1" "$2" "unquoted-$3" <<-EOF
202 test suppress-cc.self unquoted-$3 with name $1 email $2
209 Signed-off-by: $1 <$2>
213 test_suppress_self_quoted () {
214 test_suppress_self "$1" "$2" "quoted-$3" <<-EOF
215 test suppress-cc.self quoted-$3 with name $1 email $2
223 Signed-off-by: $1 <$2>
224 Signed-off-by: "$1" <$2>
228 test_expect_success $PREREQ 'self name is suppressed' "
229 test_suppress_self_unquoted 'A U Thor' 'author@example.com' \
230 'self_name_suppressed'
233 test_expect_success $PREREQ 'self name with dot is suppressed' "
234 test_suppress_self_quoted 'A U. Thor' 'author@example.com' \
235 'self_name_dot_suppressed'
238 test_expect_success $PREREQ 'non-ascii self name is suppressed' "
239 test_suppress_self_quoted 'Füñný Nâmé' 'odd_?=mail@example.com' \
240 'non_ascii_self_suppressed'
243 test_expect_success $PREREQ 'sanitized self name is suppressed' "
244 test_suppress_self_unquoted '\"A U. Thor\"' 'author@example.com' \
245 'self_name_sanitized_suppressed'
248 test_expect_success $PREREQ 'Show all headers' '
252 --from="Example <from@example.com>" \
253 --to=to@example.com \
254 --cc=cc@example.com \
255 --bcc=bcc@example.com \
256 --in-reply-to="<unique-message-id@example.com>" \
257 --smtp-server relay.example.com \
259 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
260 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
261 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
262 >actual-show-all-headers &&
263 test_cmp expected-show-all-headers actual-show-all-headers
266 test_expect_success $PREREQ 'Prompting works' '
267 clean_fake_sendmail &&
268 (echo "to@example.com"
270 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
271 --smtp-server="$(pwd)/fake.sendmail" \
274 grep "^From: A U Thor <author@example.com>\$" msgtxt1 &&
275 grep "^To: to@example.com\$" msgtxt1
278 test_expect_success $PREREQ,AUTOIDENT 'implicit ident is allowed' '
279 clean_fake_sendmail &&
280 (sane_unset GIT_AUTHOR_NAME &&
281 sane_unset GIT_AUTHOR_EMAIL &&
282 sane_unset GIT_COMMITTER_NAME &&
283 sane_unset GIT_COMMITTER_EMAIL &&
284 GIT_SEND_EMAIL_NOTTY=1 git send-email \
285 --smtp-server="$(pwd)/fake.sendmail" \
286 --to=to@example.com \
287 $patches </dev/null 2>errors
291 test_expect_success $PREREQ,!AUTOIDENT 'broken implicit ident aborts send-email' '
292 clean_fake_sendmail &&
293 (sane_unset GIT_AUTHOR_NAME &&
294 sane_unset GIT_AUTHOR_EMAIL &&
295 sane_unset GIT_COMMITTER_NAME &&
296 sane_unset GIT_COMMITTER_EMAIL &&
297 GIT_SEND_EMAIL_NOTTY=1 && export GIT_SEND_EMAIL_NOTTY &&
298 test_must_fail git send-email \
299 --smtp-server="$(pwd)/fake.sendmail" \
300 --to=to@example.com \
301 $patches </dev/null 2>errors &&
302 test_i18ngrep "tell me who you are" errors
306 test_expect_success $PREREQ 'tocmd works' '
307 clean_fake_sendmail &&
308 cp $patches tocmd.patch &&
309 echo tocmd--tocmd@example.com >>tocmd.patch &&
312 echo sed -n -e s/^tocmd--//p \"\$1\"
314 chmod +x tocmd-sed &&
316 --from="Example <nobody@example.com>" \
317 --to-cmd=./tocmd-sed \
318 --smtp-server="$(pwd)/fake.sendmail" \
321 grep "^To: tocmd@example.com" msgtxt1
324 test_expect_success $PREREQ 'cccmd works' '
325 clean_fake_sendmail &&
326 cp $patches cccmd.patch &&
327 echo "cccmd-- cccmd@example.com" >>cccmd.patch &&
330 echo sed -n -e s/^cccmd--//p \"\$1\"
332 chmod +x cccmd-sed &&
334 --from="Example <nobody@example.com>" \
335 --to=nobody@example.com \
336 --cc-cmd=./cccmd-sed \
337 --smtp-server="$(pwd)/fake.sendmail" \
340 grep "^ cccmd@example.com" msgtxt1
343 test_expect_success $PREREQ 'reject long lines' '
345 z64=$z8$z8$z8$z8$z8$z8$z8$z8 &&
346 z512=$z64$z64$z64$z64$z64$z64$z64$z64 &&
347 clean_fake_sendmail &&
348 cp $patches longline.patch &&
349 echo $z512$z512 >>longline.patch &&
350 test_must_fail git send-email \
351 --from="Example <nobody@example.com>" \
352 --to=nobody@example.com \
353 --smtp-server="$(pwd)/fake.sendmail" \
354 $patches longline.patch \
356 grep longline.patch errors
359 test_expect_success $PREREQ 'no patch was sent' '
360 ! test -e commandline1
363 test_expect_success $PREREQ 'Author From: in message body' '
364 clean_fake_sendmail &&
366 --from="Example <nobody@example.com>" \
367 --to=nobody@example.com \
368 --smtp-server="$(pwd)/fake.sendmail" \
370 sed "1,/^\$/d" < msgtxt1 > msgbody1 &&
371 grep "From: A <author@example.com>" msgbody1
374 test_expect_success $PREREQ 'Author From: not in message body' '
375 clean_fake_sendmail &&
377 --from="A <author@example.com>" \
378 --to=nobody@example.com \
379 --smtp-server="$(pwd)/fake.sendmail" \
381 sed "1,/^\$/d" < msgtxt1 > msgbody1 &&
382 ! grep "From: A <author@example.com>" msgbody1
385 test_expect_success $PREREQ 'allow long lines with --no-validate' '
387 --from="Example <nobody@example.com>" \
388 --to=nobody@example.com \
389 --smtp-server="$(pwd)/fake.sendmail" \
391 $patches longline.patch \
395 test_expect_success $PREREQ 'Invalid In-Reply-To' '
396 clean_fake_sendmail &&
398 --from="Example <nobody@example.com>" \
399 --to=nobody@example.com \
401 --smtp-server="$(pwd)/fake.sendmail" \
404 ! grep "^In-Reply-To: < *>" msgtxt1
407 test_expect_success $PREREQ 'Valid In-Reply-To when prompting' '
408 clean_fake_sendmail &&
409 (echo "From Example <from@example.com>"
410 echo "To Example <to@example.com>"
412 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
413 --smtp-server="$(pwd)/fake.sendmail" \
415 ! grep "^In-Reply-To: < *>" msgtxt1
418 test_expect_success $PREREQ 'In-Reply-To without --chain-reply-to' '
419 clean_fake_sendmail &&
420 echo "<unique-message-id@example.com>" >expect &&
422 --from="Example <nobody@example.com>" \
423 --to=nobody@example.com \
425 --in-reply-to="$(cat expect)" \
426 --smtp-server="$(pwd)/fake.sendmail" \
427 $patches $patches $patches \
429 # The first message is a reply to --in-reply-to
430 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
431 test_cmp expect actual &&
432 # Second and subsequent messages are replies to the first one
433 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
434 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
435 test_cmp expect actual &&
436 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
437 test_cmp expect actual
440 test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' '
441 clean_fake_sendmail &&
442 echo "<unique-message-id@example.com>" >expect &&
444 --from="Example <nobody@example.com>" \
445 --to=nobody@example.com \
447 --in-reply-to="$(cat expect)" \
448 --smtp-server="$(pwd)/fake.sendmail" \
449 $patches $patches $patches \
451 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
452 test_cmp expect actual &&
453 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
454 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
455 test_cmp expect actual &&
456 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt2 >expect &&
457 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
458 test_cmp expect actual
461 test_expect_success $PREREQ 'setup fake editor' '
462 (echo "#!$SHELL_PATH" &&
463 echo "echo fake edit >>\"\$1\""
468 test_set_editor "$(pwd)/fake-editor"
470 test_expect_success $PREREQ '--compose works' '
471 clean_fake_sendmail &&
473 --compose --subject foo \
474 --from="Example <nobody@example.com>" \
475 --to=nobody@example.com \
476 --smtp-server="$(pwd)/fake.sendmail" \
481 test_expect_success $PREREQ 'first message is compose text' '
482 grep "^fake edit" msgtxt1
485 test_expect_success $PREREQ 'second message is patch' '
486 grep "Subject:.*Second" msgtxt2
489 test_expect_success $PREREQ 'setup expect' "
490 cat >expected-suppress-sob <<\EOF
492 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
493 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
494 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
496 Server: relay.example.com
497 MAIL FROM:<from@example.com>
498 RCPT TO:<to@example.com>
499 RCPT TO:<cc@example.com>
500 RCPT TO:<author@example.com>
501 RCPT TO:<one@example.com>
502 RCPT TO:<two@example.com>
503 From: Example <from@example.com>
506 A <author@example.com>,
507 One <one@example.com>,
509 Subject: [PATCH 1/1] Second.
511 Message-Id: MESSAGE-ID-STRING
512 X-Mailer: X-MAILER-STRING
518 test_suppression () {
521 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
522 --from="Example <from@example.com>" \
523 --to=to@example.com \
524 --smtp-server relay.example.com \
526 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
527 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
528 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
529 >actual-suppress-$1${2+"-$2"} &&
530 test_cmp expected-suppress-$1${2+"-$2"} actual-suppress-$1${2+"-$2"}
533 test_expect_success $PREREQ 'sendemail.cc set' '
534 git config sendemail.cc cc@example.com &&
538 test_expect_success $PREREQ 'setup expect' "
539 cat >expected-suppress-sob <<\EOF
541 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
542 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
543 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
545 Server: relay.example.com
546 MAIL FROM:<from@example.com>
547 RCPT TO:<to@example.com>
548 RCPT TO:<author@example.com>
549 RCPT TO:<one@example.com>
550 RCPT TO:<two@example.com>
551 From: Example <from@example.com>
553 Cc: A <author@example.com>,
554 One <one@example.com>,
556 Subject: [PATCH 1/1] Second.
558 Message-Id: MESSAGE-ID-STRING
559 X-Mailer: X-MAILER-STRING
565 test_expect_success $PREREQ 'sendemail.cc unset' '
566 git config --unset sendemail.cc &&
570 test_expect_success $PREREQ 'setup expect' "
571 cat >expected-suppress-cccmd <<\EOF
573 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
574 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
575 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
576 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
578 Server: relay.example.com
579 MAIL FROM:<from@example.com>
580 RCPT TO:<to@example.com>
581 RCPT TO:<author@example.com>
582 RCPT TO:<one@example.com>
583 RCPT TO:<two@example.com>
584 RCPT TO:<committer@example.com>
585 From: Example <from@example.com>
587 Cc: A <author@example.com>,
588 One <one@example.com>,
590 C O Mitter <committer@example.com>
591 Subject: [PATCH 1/1] Second.
593 Message-Id: MESSAGE-ID-STRING
594 X-Mailer: X-MAILER-STRING
600 test_expect_success $PREREQ 'sendemail.cccmd' '
601 echo echo cc-cmd@example.com > cccmd &&
603 git config sendemail.cccmd ./cccmd &&
604 test_suppression cccmd
607 test_expect_success $PREREQ 'setup expect' '
608 cat >expected-suppress-all <<\EOF
611 Server: relay.example.com
612 MAIL FROM:<from@example.com>
613 RCPT TO:<to@example.com>
614 From: Example <from@example.com>
616 Subject: [PATCH 1/1] Second.
618 Message-Id: MESSAGE-ID-STRING
619 X-Mailer: X-MAILER-STRING
625 test_expect_success $PREREQ '--suppress-cc=all' '
629 test_expect_success $PREREQ 'setup expect' "
630 cat >expected-suppress-body <<\EOF
632 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
633 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
634 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
635 (cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
637 Server: relay.example.com
638 MAIL FROM:<from@example.com>
639 RCPT TO:<to@example.com>
640 RCPT TO:<author@example.com>
641 RCPT TO:<one@example.com>
642 RCPT TO:<two@example.com>
643 RCPT TO:<cc-cmd@example.com>
644 From: Example <from@example.com>
646 Cc: A <author@example.com>,
647 One <one@example.com>,
650 Subject: [PATCH 1/1] Second.
652 Message-Id: MESSAGE-ID-STRING
653 X-Mailer: X-MAILER-STRING
659 test_expect_success $PREREQ '--suppress-cc=body' '
660 test_suppression body
663 test_expect_success $PREREQ 'setup expect' "
664 cat >expected-suppress-body-cccmd <<\EOF
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'
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>
678 Cc: A <author@example.com>,
679 One <one@example.com>,
681 Subject: [PATCH 1/1] Second.
683 Message-Id: MESSAGE-ID-STRING
684 X-Mailer: X-MAILER-STRING
690 test_expect_success $PREREQ '--suppress-cc=body --suppress-cc=cccmd' '
691 test_suppression body cccmd
694 test_expect_success $PREREQ 'setup expect' "
695 cat >expected-suppress-sob <<\EOF
697 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
698 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
699 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
701 Server: relay.example.com
702 MAIL FROM:<from@example.com>
703 RCPT TO:<to@example.com>
704 RCPT TO:<author@example.com>
705 RCPT TO:<one@example.com>
706 RCPT TO:<two@example.com>
707 From: Example <from@example.com>
709 Cc: A <author@example.com>,
710 One <one@example.com>,
712 Subject: [PATCH 1/1] Second.
714 Message-Id: MESSAGE-ID-STRING
715 X-Mailer: X-MAILER-STRING
721 test_expect_success $PREREQ '--suppress-cc=sob' '
722 test_might_fail git config --unset sendemail.cccmd &&
726 test_expect_success $PREREQ 'setup expect' "
727 cat >expected-suppress-bodycc <<\EOF
729 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
730 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
731 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
732 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
734 Server: relay.example.com
735 MAIL FROM:<from@example.com>
736 RCPT TO:<to@example.com>
737 RCPT TO:<author@example.com>
738 RCPT TO:<one@example.com>
739 RCPT TO:<two@example.com>
740 RCPT TO:<committer@example.com>
741 From: Example <from@example.com>
743 Cc: A <author@example.com>,
744 One <one@example.com>,
746 C O Mitter <committer@example.com>
747 Subject: [PATCH 1/1] Second.
749 Message-Id: MESSAGE-ID-STRING
750 X-Mailer: X-MAILER-STRING
756 test_expect_success $PREREQ '--suppress-cc=bodycc' '
757 test_suppression bodycc
760 test_expect_success $PREREQ 'setup expect' "
761 cat >expected-suppress-cc <<\EOF
763 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
764 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
766 Server: relay.example.com
767 MAIL FROM:<from@example.com>
768 RCPT TO:<to@example.com>
769 RCPT TO:<author@example.com>
770 RCPT TO:<committer@example.com>
771 From: Example <from@example.com>
773 Cc: A <author@example.com>,
774 C O Mitter <committer@example.com>
775 Subject: [PATCH 1/1] Second.
777 Message-Id: MESSAGE-ID-STRING
778 X-Mailer: X-MAILER-STRING
784 test_expect_success $PREREQ '--suppress-cc=cc' '
790 GIT_SEND_EMAIL_NOTTY=1 \
792 --from="Example <nobody@example.com>" \
793 --to=nobody@example.com \
794 --smtp-server="$(pwd)/fake.sendmail" \
795 $@ $patches > stdout &&
796 grep "Send this email" stdout
799 test_expect_success $PREREQ '--confirm=always' '
800 test_confirm --confirm=always --suppress-cc=all
803 test_expect_success $PREREQ '--confirm=auto' '
804 test_confirm --confirm=auto
807 test_expect_success $PREREQ '--confirm=cc' '
808 test_confirm --confirm=cc
811 test_expect_success $PREREQ '--confirm=compose' '
812 test_confirm --confirm=compose --compose
815 test_expect_success $PREREQ 'confirm by default (due to cc)' '
816 CONFIRM=$(git config --get sendemail.confirm) &&
817 git config --unset sendemail.confirm &&
820 git config sendemail.confirm ${CONFIRM:-never}
824 test_expect_success $PREREQ 'confirm by default (due to --compose)' '
825 CONFIRM=$(git config --get sendemail.confirm) &&
826 git config --unset sendemail.confirm &&
827 test_confirm --suppress-cc=all --compose
829 git config sendemail.confirm ${CONFIRM:-never}
833 test_expect_success $PREREQ 'confirm detects EOF (inform assumes y)' '
834 CONFIRM=$(git config --get sendemail.confirm) &&
835 git config --unset sendemail.confirm &&
837 git format-patch -2 -o outdir &&
838 GIT_SEND_EMAIL_NOTTY=1 \
840 --from="Example <nobody@example.com>" \
841 --to=nobody@example.com \
842 --smtp-server="$(pwd)/fake.sendmail" \
843 outdir/*.patch < /dev/null
845 git config sendemail.confirm ${CONFIRM:-never}
849 test_expect_success $PREREQ 'confirm detects EOF (auto causes failure)' '
850 CONFIRM=$(git config --get sendemail.confirm) &&
851 git config sendemail.confirm auto &&
852 GIT_SEND_EMAIL_NOTTY=1 &&
853 export GIT_SEND_EMAIL_NOTTY &&
854 test_must_fail git send-email \
855 --from="Example <nobody@example.com>" \
856 --to=nobody@example.com \
857 --smtp-server="$(pwd)/fake.sendmail" \
860 git config sendemail.confirm ${CONFIRM:-never}
864 test_expect_success $PREREQ 'confirm does not loop forever' '
865 CONFIRM=$(git config --get sendemail.confirm) &&
866 git config sendemail.confirm auto &&
867 GIT_SEND_EMAIL_NOTTY=1 &&
868 export GIT_SEND_EMAIL_NOTTY &&
869 yes "bogus" | test_must_fail git send-email \
870 --from="Example <nobody@example.com>" \
871 --to=nobody@example.com \
872 --smtp-server="$(pwd)/fake.sendmail" \
875 git config sendemail.confirm ${CONFIRM:-never}
879 test_expect_success $PREREQ 'utf8 Cc is rfc2047 encoded' '
880 clean_fake_sendmail &&
882 git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
884 --from="Example <nobody@example.com>" \
885 --to=nobody@example.com \
886 --smtp-server="$(pwd)/fake.sendmail" \
889 grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
892 test_expect_success $PREREQ '--compose adds MIME for utf8 body' '
893 clean_fake_sendmail &&
894 (echo "#!$SHELL_PATH" &&
895 echo "echo utf8 body: àéìöú >>\"\$1\""
896 ) >fake-editor-utf8 &&
897 chmod +x fake-editor-utf8 &&
898 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
900 --compose --subject foo \
901 --from="Example <nobody@example.com>" \
902 --to=nobody@example.com \
903 --smtp-server="$(pwd)/fake.sendmail" \
905 grep "^utf8 body" msgtxt1 &&
906 grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
909 test_expect_success $PREREQ '--compose respects user mime type' '
910 clean_fake_sendmail &&
911 (echo "#!$SHELL_PATH" &&
912 echo "(echo MIME-Version: 1.0"
913 echo " echo Content-Type: text/plain\\; charset=iso-8859-1"
914 echo " echo Content-Transfer-Encoding: 8bit"
915 echo " echo Subject: foo"
917 echo " echo utf8 body: àéìöú) >\"\$1\""
918 ) >fake-editor-utf8-mime &&
919 chmod +x fake-editor-utf8-mime &&
920 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
922 --compose --subject foo \
923 --from="Example <nobody@example.com>" \
924 --to=nobody@example.com \
925 --smtp-server="$(pwd)/fake.sendmail" \
927 grep "^utf8 body" msgtxt1 &&
928 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
929 ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
932 test_expect_success $PREREQ '--compose adds MIME for utf8 subject' '
933 clean_fake_sendmail &&
934 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
936 --compose --subject utf8-sübjëct \
937 --from="Example <nobody@example.com>" \
938 --to=nobody@example.com \
939 --smtp-server="$(pwd)/fake.sendmail" \
941 grep "^fake edit" msgtxt1 &&
942 grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
945 test_expect_success $PREREQ 'utf8 author is correctly passed on' '
946 clean_fake_sendmail &&
947 test_commit weird_author &&
948 test_when_finished "git reset --hard HEAD^" &&
949 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
950 git format-patch --stdout -1 >funny_name.patch &&
951 git send-email --from="Example <nobody@example.com>" \
952 --to=nobody@example.com \
953 --smtp-server="$(pwd)/fake.sendmail" \
955 grep "^From: Füñný Nâmé <odd_?=mail@example.com>" msgtxt1
958 test_expect_success $PREREQ 'utf8 sender is not duplicated' '
959 clean_fake_sendmail &&
960 test_commit weird_sender &&
961 test_when_finished "git reset --hard HEAD^" &&
962 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
963 git format-patch --stdout -1 >funny_name.patch &&
964 git send-email --from="Füñný Nâmé <odd_?=mail@example.com>" \
965 --to=nobody@example.com \
966 --smtp-server="$(pwd)/fake.sendmail" \
968 grep "^From: " msgtxt1 >msgfrom &&
969 test_line_count = 1 msgfrom
972 test_expect_success $PREREQ 'sendemail.composeencoding works' '
973 clean_fake_sendmail &&
974 git config sendemail.composeencoding iso-8859-1 &&
975 (echo "#!$SHELL_PATH" &&
976 echo "echo utf8 body: àéìöú >>\"\$1\""
977 ) >fake-editor-utf8 &&
978 chmod +x fake-editor-utf8 &&
979 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
981 --compose --subject foo \
982 --from="Example <nobody@example.com>" \
983 --to=nobody@example.com \
984 --smtp-server="$(pwd)/fake.sendmail" \
986 grep "^utf8 body" msgtxt1 &&
987 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
990 test_expect_success $PREREQ '--compose-encoding works' '
991 clean_fake_sendmail &&
992 (echo "#!$SHELL_PATH" &&
993 echo "echo utf8 body: àéìöú >>\"\$1\""
994 ) >fake-editor-utf8 &&
995 chmod +x fake-editor-utf8 &&
996 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
998 --compose-encoding iso-8859-1 \
999 --compose --subject foo \
1000 --from="Example <nobody@example.com>" \
1001 --to=nobody@example.com \
1002 --smtp-server="$(pwd)/fake.sendmail" \
1004 grep "^utf8 body" msgtxt1 &&
1005 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1008 test_expect_success $PREREQ '--compose-encoding overrides sendemail.composeencoding' '
1009 clean_fake_sendmail &&
1010 git config sendemail.composeencoding iso-8859-1 &&
1011 (echo "#!$SHELL_PATH" &&
1012 echo "echo utf8 body: àéìöú >>\"\$1\""
1013 ) >fake-editor-utf8 &&
1014 chmod +x fake-editor-utf8 &&
1015 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1017 --compose-encoding iso-8859-2 \
1018 --compose --subject foo \
1019 --from="Example <nobody@example.com>" \
1020 --to=nobody@example.com \
1021 --smtp-server="$(pwd)/fake.sendmail" \
1023 grep "^utf8 body" msgtxt1 &&
1024 grep "^Content-Type: text/plain; charset=iso-8859-2" msgtxt1
1027 test_expect_success $PREREQ '--compose-encoding adds correct MIME for subject' '
1028 clean_fake_sendmail &&
1029 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
1031 --compose-encoding iso-8859-2 \
1032 --compose --subject utf8-sübjëct \
1033 --from="Example <nobody@example.com>" \
1034 --to=nobody@example.com \
1035 --smtp-server="$(pwd)/fake.sendmail" \
1037 grep "^fake edit" msgtxt1 &&
1038 grep "^Subject: =?iso-8859-2?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
1041 test_expect_success $PREREQ 'detects ambiguous reference/file conflict' '
1042 echo master > master &&
1044 git commit -m"add master" &&
1045 test_must_fail git send-email --dry-run master 2>errors &&
1046 grep disambiguate errors
1049 test_expect_success $PREREQ 'feed two files' '
1051 git format-patch -2 -o outdir &&
1054 --from="Example <nobody@example.com>" \
1055 --to=nobody@example.com \
1056 outdir/000?-*.patch 2>errors >out &&
1057 grep "^Subject: " out >subjects &&
1058 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
1059 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"
1062 test_expect_success $PREREQ 'in-reply-to but no threading' '
1065 --from="Example <nobody@example.com>" \
1066 --to=nobody@example.com \
1067 --in-reply-to="<in-reply-id@example.com>" \
1070 grep "In-Reply-To: <in-reply-id@example.com>"
1073 test_expect_success $PREREQ 'no in-reply-to and no threading' '
1076 --from="Example <nobody@example.com>" \
1077 --to=nobody@example.com \
1079 $patches $patches >stdout &&
1080 ! grep "In-Reply-To: " stdout
1083 test_expect_success $PREREQ 'threading but no chain-reply-to' '
1086 --from="Example <nobody@example.com>" \
1087 --to=nobody@example.com \
1089 --nochain-reply-to \
1090 $patches $patches >stdout &&
1091 grep "In-Reply-To: " stdout
1094 test_expect_success $PREREQ 'sendemail.to works' '
1095 git config --replace-all sendemail.to "Somebody <somebody@ex.com>" &&
1098 --from="Example <nobody@example.com>" \
1099 $patches $patches >stdout &&
1100 grep "To: Somebody <somebody@ex.com>" stdout
1103 test_expect_success $PREREQ '--no-to overrides sendemail.to' '
1106 --from="Example <nobody@example.com>" \
1108 --to=nobody@example.com \
1109 $patches $patches >stdout &&
1110 grep "To: nobody@example.com" stdout &&
1111 ! grep "To: Somebody <somebody@ex.com>" stdout
1114 test_expect_success $PREREQ 'sendemail.cc works' '
1115 git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" &&
1118 --from="Example <nobody@example.com>" \
1119 --to=nobody@example.com \
1120 $patches $patches >stdout &&
1121 grep "Cc: Somebody <somebody@ex.com>" stdout
1124 test_expect_success $PREREQ '--no-cc overrides sendemail.cc' '
1127 --from="Example <nobody@example.com>" \
1129 --cc=bodies@example.com \
1130 --to=nobody@example.com \
1131 $patches $patches >stdout &&
1132 grep "Cc: bodies@example.com" stdout &&
1133 ! grep "Cc: Somebody <somebody@ex.com>" stdout
1136 test_expect_success $PREREQ 'sendemail.bcc works' '
1137 git config --replace-all sendemail.bcc "Other <other@ex.com>" &&
1140 --from="Example <nobody@example.com>" \
1141 --to=nobody@example.com \
1142 --smtp-server relay.example.com \
1143 $patches $patches >stdout &&
1144 grep "RCPT TO:<other@ex.com>" stdout
1147 test_expect_success $PREREQ '--no-bcc overrides sendemail.bcc' '
1150 --from="Example <nobody@example.com>" \
1152 --bcc=bodies@example.com \
1153 --to=nobody@example.com \
1154 --smtp-server relay.example.com \
1155 $patches $patches >stdout &&
1156 grep "RCPT TO:<bodies@example.com>" stdout &&
1157 ! grep "RCPT TO:<other@ex.com>" stdout
1160 test_expect_success $PREREQ 'patches To headers are used by default' '
1161 patch=`git format-patch -1 --to="bodies@example.com"` &&
1162 test_when_finished "rm $patch" &&
1165 --from="Example <nobody@example.com>" \
1166 --smtp-server relay.example.com \
1168 grep "RCPT TO:<bodies@example.com>" stdout
1171 test_expect_success $PREREQ 'patches To headers are appended to' '
1172 patch=`git format-patch -1 --to="bodies@example.com"` &&
1173 test_when_finished "rm $patch" &&
1176 --from="Example <nobody@example.com>" \
1177 --to=nobody@example.com \
1178 --smtp-server relay.example.com \
1180 grep "RCPT TO:<bodies@example.com>" stdout &&
1181 grep "RCPT TO:<nobody@example.com>" stdout
1184 test_expect_success $PREREQ 'To headers from files reset each patch' '
1185 patch1=`git format-patch -1 --to="bodies@example.com"` &&
1186 patch2=`git format-patch -1 --to="other@example.com" HEAD~` &&
1187 test_when_finished "rm $patch1 && rm $patch2" &&
1190 --from="Example <nobody@example.com>" \
1191 --to="nobody@example.com" \
1192 --smtp-server relay.example.com \
1193 $patch1 $patch2 >stdout &&
1194 test $(grep -c "RCPT TO:<bodies@example.com>" stdout) = 1 &&
1195 test $(grep -c "RCPT TO:<nobody@example.com>" stdout) = 2 &&
1196 test $(grep -c "RCPT TO:<other@example.com>" stdout) = 1
1199 test_expect_success $PREREQ 'setup expect' '
1200 cat >email-using-8bit <<EOF
1201 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1202 Message-Id: <bogus-message-id@example.com>
1203 From: author@example.com
1204 Date: Sat, 12 Jun 2010 15:53:58 +0200
1205 Subject: subject goes here
1207 Dieser deutsche Text enthält einen Umlaut!
1211 test_expect_success $PREREQ 'setup expect' '
1213 Subject: subject goes here
1217 test_expect_success $PREREQ 'ASCII subject is not RFC2047 quoted' '
1218 clean_fake_sendmail &&
1220 git send-email --from=author@example.com --to=nobody@example.com \
1221 --smtp-server="$(pwd)/fake.sendmail" \
1222 --8bit-encoding=UTF-8 \
1223 email-using-8bit >stdout &&
1224 grep "Subject" msgtxt1 >actual &&
1225 test_cmp expected actual
1228 test_expect_success $PREREQ 'setup expect' '
1229 cat >content-type-decl <<EOF
1231 Content-Type: text/plain; charset=UTF-8
1232 Content-Transfer-Encoding: 8bit
1236 test_expect_success $PREREQ 'asks about and fixes 8bit encodings' '
1237 clean_fake_sendmail &&
1239 git send-email --from=author@example.com --to=nobody@example.com \
1240 --smtp-server="$(pwd)/fake.sendmail" \
1241 email-using-8bit >stdout &&
1242 grep "do not declare a Content-Transfer-Encoding" stdout &&
1243 grep email-using-8bit stdout &&
1244 grep "Which 8bit encoding" stdout &&
1245 egrep "Content|MIME" msgtxt1 >actual &&
1246 test_cmp actual content-type-decl
1249 test_expect_success $PREREQ 'sendemail.8bitEncoding works' '
1250 clean_fake_sendmail &&
1251 git config sendemail.assume8bitEncoding UTF-8 &&
1253 git send-email --from=author@example.com --to=nobody@example.com \
1254 --smtp-server="$(pwd)/fake.sendmail" \
1255 email-using-8bit >stdout &&
1256 egrep "Content|MIME" msgtxt1 >actual &&
1257 test_cmp actual content-type-decl
1260 test_expect_success $PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
1261 clean_fake_sendmail &&
1262 git config sendemail.assume8bitEncoding "bogus too" &&
1264 git send-email --from=author@example.com --to=nobody@example.com \
1265 --smtp-server="$(pwd)/fake.sendmail" \
1266 --8bit-encoding=UTF-8 \
1267 email-using-8bit >stdout &&
1268 egrep "Content|MIME" msgtxt1 >actual &&
1269 test_cmp actual content-type-decl
1272 test_expect_success $PREREQ 'setup expect' '
1273 cat >email-using-8bit <<EOF
1274 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1275 Message-Id: <bogus-message-id@example.com>
1276 From: author@example.com
1277 Date: Sat, 12 Jun 2010 15:53:58 +0200
1278 Subject: Dieser Betreff enthält auch einen Umlaut!
1280 Nothing to see here.
1284 test_expect_success $PREREQ 'setup expect' '
1286 Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
1290 test_expect_success $PREREQ '--8bit-encoding also treats subject' '
1291 clean_fake_sendmail &&
1293 git send-email --from=author@example.com --to=nobody@example.com \
1294 --smtp-server="$(pwd)/fake.sendmail" \
1295 --8bit-encoding=UTF-8 \
1296 email-using-8bit >stdout &&
1297 grep "Subject" msgtxt1 >actual &&
1298 test_cmp expected actual
1301 # Note that the patches in this test are deliberately out of order; we
1302 # want to make sure it works even if the cover-letter is not in the
1304 test_expect_success $PREREQ 'refusing to send cover letter template' '
1305 clean_fake_sendmail &&
1307 git format-patch --cover-letter -2 -o outdir &&
1308 test_must_fail git send-email \
1309 --from="Example <nobody@example.com>" \
1310 --to=nobody@example.com \
1311 --smtp-server="$(pwd)/fake.sendmail" \
1312 outdir/0002-*.patch \
1313 outdir/0000-*.patch \
1314 outdir/0001-*.patch \
1316 grep "SUBJECT HERE" errors &&
1317 test -z "$(ls msgtxt*)"
1320 test_expect_success $PREREQ '--force sends cover letter template anyway' '
1321 clean_fake_sendmail &&
1323 git format-patch --cover-letter -2 -o outdir &&
1326 --from="Example <nobody@example.com>" \
1327 --to=nobody@example.com \
1328 --smtp-server="$(pwd)/fake.sendmail" \
1329 outdir/0002-*.patch \
1330 outdir/0000-*.patch \
1331 outdir/0001-*.patch \
1333 ! grep "SUBJECT HERE" errors &&
1334 test -n "$(ls msgtxt*)"
1337 test_cover_addresses () {
1340 clean_fake_sendmail &&
1342 git format-patch --cover-letter -2 -o outdir &&
1343 cover=`echo outdir/0000-*.patch` &&
1344 mv $cover cover-to-edit.patch &&
1345 perl -pe "s/^From:/$header: extra\@address.com\nFrom:/" cover-to-edit.patch >"$cover" &&
1348 --from="Example <nobody@example.com>" \
1351 --smtp-server="$(pwd)/fake.sendmail" \
1352 outdir/0000-*.patch \
1353 outdir/0001-*.patch \
1354 outdir/0002-*.patch \
1356 grep "^$header: extra@address.com" msgtxt1 >to1 &&
1357 grep "^$header: extra@address.com" msgtxt2 >to2 &&
1358 grep "^$header: extra@address.com" msgtxt3 >to3 &&
1359 test_line_count = 1 to1 &&
1360 test_line_count = 1 to2 &&
1361 test_line_count = 1 to3
1364 test_expect_success $PREREQ 'to-cover adds To to all mail' '
1365 test_cover_addresses "To" --to-cover
1368 test_expect_success $PREREQ 'cc-cover adds Cc to all mail' '
1369 test_cover_addresses "Cc" --cc-cover
1372 test_expect_success $PREREQ 'tocover adds To to all mail' '
1373 test_config sendemail.tocover true &&
1374 test_cover_addresses "To"
1377 test_expect_success $PREREQ 'cccover adds Cc to all mail' '
1378 test_config sendemail.cccover true &&
1379 test_cover_addresses "Cc"
1382 test_expect_success $PREREQ 'sendemail.aliasfiletype=mailrc' '
1383 clean_fake_sendmail &&
1384 echo "alias sbd somebody@example.org" >.mailrc &&
1385 git config --replace-all sendemail.aliasesfile "$(pwd)/.mailrc" &&
1386 git config sendemail.aliasfiletype mailrc &&
1388 --from="Example <nobody@example.com>" \
1390 --smtp-server="$(pwd)/fake.sendmail" \
1391 outdir/0001-*.patch \
1393 grep "^!somebody@example\.org!$" commandline1
1396 test_expect_success $PREREQ 'sendemail.aliasfile=~/.mailrc' '
1397 clean_fake_sendmail &&
1398 echo "alias sbd someone@example.org" >~/.mailrc &&
1399 git config --replace-all sendemail.aliasesfile "~/.mailrc" &&
1400 git config sendemail.aliasfiletype mailrc &&
1402 --from="Example <nobody@example.com>" \
1404 --smtp-server="$(pwd)/fake.sendmail" \
1405 outdir/0001-*.patch \
1407 grep "^!someone@example\.org!$" commandline1