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 test_have_prereq MINGW && echo "dos2unix commandline\$output"
27 echo "cat > msgtxt\$output"
29 chmod +x ./fake.sendmail &&
30 git add fake.sendmail &&
31 GIT_AUTHOR_NAME="A" git commit -a -m "Second."'
33 clean_fake_sendmail() {
34 rm -f commandline* msgtxt*
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`
41 # Test no confirm early to ensure remaining tests will not hang
45 GIT_SEND_EMAIL_NOTTY=1 \
47 --from="Example <from@example.com>" \
48 --to=nobody@example.com \
49 --smtp-server="$(pwd)/fake.sendmail" \
52 test_must_fail grep "Send this email" stdout &&
56 # Exit immediately to prevent hang if a no-confirm test fails
58 if ! test -f no_confirm_okay
60 say 'confirm test failed; skipping remaining tests to prevent hanging'
61 PREREQ="$PREREQ,CHECK_NO_CONFIRM"
66 test_expect_success $PREREQ 'No confirm with --suppress-cc' '
67 test_no_confirm --suppress-cc=sob &&
72 test_expect_success $PREREQ 'No confirm with --confirm=never' '
73 test_no_confirm --confirm=never &&
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 &&
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
89 test_expect_success $PREREQ 'setup expect' '
98 test_expect_success $PREREQ \
99 'Verify commandline' \
100 'test_cmp expected commandline1'
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
107 test_expect_success $PREREQ 'setup expect' '
118 test_expect_success $PREREQ \
119 'Verify commandline' \
120 'test_cmp expected commandline1'
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
127 test_expect_success $PREREQ 'setup expect' '
138 test_expect_success $PREREQ \
139 'Verify commandline' \
140 'test_cmp expected commandline1'
142 test_expect_success $PREREQ 'setup expect' "
143 cat >expected-show-all-headers <<\EOF
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'
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>
160 A <author@example.com>,
161 One <one@example.com>,
163 Subject: [PATCH 1/1] Second.
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>
174 test_suppress_self () {
176 test_when_finished "git reset --hard HEAD^" &&
178 write_script cccmd-sed <<-EOF &&
179 sed -n -e s/^cccmd--//p "\$1"
182 git commit --amend --author="$1 <$2>" -F - &&
183 clean_fake_sendmail &&
184 git format-patch --stdout -1 >"suppress-self-$3.patch" &&
186 git send-email --from="$1 <$2>" \
187 --to=nobody@example.com \
188 --cc-cmd=./cccmd-sed \
190 --smtp-server="$(pwd)/fake.sendmail" \
191 suppress-self-$3.patch &&
193 mv msgtxt1 msgtxt1-$3 &&
194 sed -e '/^$/q' msgtxt1-$3 >"msghdr1-$3" &&
195 >"expected-no-cc-$3" &&
197 (grep '^Cc:' msghdr1-$3 >"actual-no-cc-$3";
198 test_cmp expected-no-cc-$3 actual-no-cc-$3)
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
210 Signed-off-by: $1 <$2>
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
224 Signed-off-by: $1 <$2>
225 Signed-off-by: "$1" <$2>
229 test_expect_success $PREREQ 'self name is suppressed' "
230 test_suppress_self_unquoted 'A U Thor' 'author@example.com' \
231 'self_name_suppressed'
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'
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'
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'
249 test_expect_success $PREREQ 'Show all headers' '
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 \
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
267 test_expect_success $PREREQ 'Prompting works' '
268 clean_fake_sendmail &&
269 (echo "to@example.com"
271 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
272 --smtp-server="$(pwd)/fake.sendmail" \
275 grep "^From: A U Thor <author@example.com>\$" msgtxt1 &&
276 grep "^To: to@example.com\$" msgtxt1
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
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
307 test_expect_success $PREREQ 'tocmd works' '
308 clean_fake_sendmail &&
309 cp $patches tocmd.patch &&
310 echo tocmd--tocmd@example.com >>tocmd.patch &&
313 echo sed -n -e s/^tocmd--//p \"\$1\"
315 chmod +x tocmd-sed &&
317 --from="Example <nobody@example.com>" \
318 --to-cmd=./tocmd-sed \
319 --smtp-server="$(pwd)/fake.sendmail" \
322 grep "^To: tocmd@example.com" msgtxt1
325 test_expect_success $PREREQ 'cccmd works' '
326 clean_fake_sendmail &&
327 cp $patches cccmd.patch &&
328 echo "cccmd-- cccmd@example.com" >>cccmd.patch &&
331 echo sed -n -e s/^cccmd--//p \"\$1\"
333 chmod +x cccmd-sed &&
335 --from="Example <nobody@example.com>" \
336 --to=nobody@example.com \
337 --cc-cmd=./cccmd-sed \
338 --smtp-server="$(pwd)/fake.sendmail" \
341 grep "^ cccmd@example.com" msgtxt1
344 test_expect_success $PREREQ 'reject long lines' '
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 \
357 grep longline.patch errors
360 test_expect_success $PREREQ 'no patch was sent' '
361 ! test -e commandline1
364 test_expect_success $PREREQ 'Author From: in message body' '
365 clean_fake_sendmail &&
367 --from="Example <nobody@example.com>" \
368 --to=nobody@example.com \
369 --smtp-server="$(pwd)/fake.sendmail" \
371 sed "1,/^\$/d" < msgtxt1 > msgbody1 &&
372 grep "From: A <author@example.com>" msgbody1
375 test_expect_success $PREREQ 'Author From: not in message body' '
376 clean_fake_sendmail &&
378 --from="A <author@example.com>" \
379 --to=nobody@example.com \
380 --smtp-server="$(pwd)/fake.sendmail" \
382 sed "1,/^\$/d" < msgtxt1 > msgbody1 &&
383 ! grep "From: A <author@example.com>" msgbody1
386 test_expect_success $PREREQ 'allow long lines with --no-validate' '
388 --from="Example <nobody@example.com>" \
389 --to=nobody@example.com \
390 --smtp-server="$(pwd)/fake.sendmail" \
392 $patches longline.patch \
396 test_expect_success $PREREQ 'Invalid In-Reply-To' '
397 clean_fake_sendmail &&
399 --from="Example <nobody@example.com>" \
400 --to=nobody@example.com \
402 --smtp-server="$(pwd)/fake.sendmail" \
405 ! grep "^In-Reply-To: < *>" msgtxt1
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>"
413 ) | env GIT_SEND_EMAIL_NOTTY=1 git send-email \
414 --smtp-server="$(pwd)/fake.sendmail" \
416 ! grep "^In-Reply-To: < *>" msgtxt1
419 test_expect_success $PREREQ 'In-Reply-To without --chain-reply-to' '
420 clean_fake_sendmail &&
421 echo "<unique-message-id@example.com>" >expect &&
423 --from="Example <nobody@example.com>" \
424 --to=nobody@example.com \
426 --in-reply-to="$(cat expect)" \
427 --smtp-server="$(pwd)/fake.sendmail" \
428 $patches $patches $patches \
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
441 test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' '
442 clean_fake_sendmail &&
443 echo "<unique-message-id@example.com>" >expect &&
445 --from="Example <nobody@example.com>" \
446 --to=nobody@example.com \
448 --in-reply-to="$(cat expect)" \
449 --smtp-server="$(pwd)/fake.sendmail" \
450 $patches $patches $patches \
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
462 test_expect_success $PREREQ 'setup fake editor' '
463 (echo "#!$SHELL_PATH" &&
464 echo "echo fake edit >>\"\$1\""
469 test_set_editor "$(pwd)/fake-editor"
471 test_expect_success $PREREQ '--compose works' '
472 clean_fake_sendmail &&
474 --compose --subject foo \
475 --from="Example <nobody@example.com>" \
476 --to=nobody@example.com \
477 --smtp-server="$(pwd)/fake.sendmail" \
482 test_expect_success $PREREQ 'first message is compose text' '
483 grep "^fake edit" msgtxt1
486 test_expect_success $PREREQ 'second message is patch' '
487 grep "Subject:.*Second" msgtxt2
490 test_expect_success $PREREQ 'setup expect' "
491 cat >expected-suppress-sob <<\EOF
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'
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>
507 A <author@example.com>,
508 One <one@example.com>,
510 Subject: [PATCH 1/1] Second.
512 Message-Id: MESSAGE-ID-STRING
513 X-Mailer: X-MAILER-STRING
519 test_suppression () {
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 \
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"}
534 test_expect_success $PREREQ 'sendemail.cc set' '
535 git config sendemail.cc cc@example.com &&
539 test_expect_success $PREREQ 'setup expect' "
540 cat >expected-suppress-sob <<\EOF
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'
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>
554 Cc: A <author@example.com>,
555 One <one@example.com>,
557 Subject: [PATCH 1/1] Second.
559 Message-Id: MESSAGE-ID-STRING
560 X-Mailer: X-MAILER-STRING
566 test_expect_success $PREREQ 'sendemail.cc unset' '
567 git config --unset sendemail.cc &&
571 test_expect_success $PREREQ 'setup expect' "
572 cat >expected-suppress-cccmd <<\EOF
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>'
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>
588 Cc: A <author@example.com>,
589 One <one@example.com>,
591 C O Mitter <committer@example.com>
592 Subject: [PATCH 1/1] Second.
594 Message-Id: MESSAGE-ID-STRING
595 X-Mailer: X-MAILER-STRING
601 test_expect_success $PREREQ 'sendemail.cccmd' '
602 echo echo cc-cmd@example.com > cccmd &&
604 git config sendemail.cccmd ./cccmd &&
605 test_suppression cccmd
608 test_expect_success $PREREQ 'setup expect' '
609 cat >expected-suppress-all <<\EOF
612 Server: relay.example.com
613 MAIL FROM:<from@example.com>
614 RCPT TO:<to@example.com>
615 From: Example <from@example.com>
617 Subject: [PATCH 1/1] Second.
619 Message-Id: MESSAGE-ID-STRING
620 X-Mailer: X-MAILER-STRING
626 test_expect_success $PREREQ '--suppress-cc=all' '
630 test_expect_success $PREREQ 'setup expect' "
631 cat >expected-suppress-body <<\EOF
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'
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>
647 Cc: A <author@example.com>,
648 One <one@example.com>,
651 Subject: [PATCH 1/1] Second.
653 Message-Id: MESSAGE-ID-STRING
654 X-Mailer: X-MAILER-STRING
660 test_expect_success $PREREQ '--suppress-cc=body' '
661 test_suppression body
664 test_expect_success $PREREQ 'setup expect' "
665 cat >expected-suppress-body-cccmd <<\EOF
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'
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>
679 Cc: A <author@example.com>,
680 One <one@example.com>,
682 Subject: [PATCH 1/1] Second.
684 Message-Id: MESSAGE-ID-STRING
685 X-Mailer: X-MAILER-STRING
691 test_expect_success $PREREQ '--suppress-cc=body --suppress-cc=cccmd' '
692 test_suppression body cccmd
695 test_expect_success $PREREQ 'setup expect' "
696 cat >expected-suppress-sob <<\EOF
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'
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>
710 Cc: A <author@example.com>,
711 One <one@example.com>,
713 Subject: [PATCH 1/1] Second.
715 Message-Id: MESSAGE-ID-STRING
716 X-Mailer: X-MAILER-STRING
722 test_expect_success $PREREQ '--suppress-cc=sob' '
723 test_might_fail git config --unset sendemail.cccmd &&
727 test_expect_success $PREREQ 'setup expect' "
728 cat >expected-suppress-bodycc <<\EOF
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>'
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>
744 Cc: A <author@example.com>,
745 One <one@example.com>,
747 C O Mitter <committer@example.com>
748 Subject: [PATCH 1/1] Second.
750 Message-Id: MESSAGE-ID-STRING
751 X-Mailer: X-MAILER-STRING
757 test_expect_success $PREREQ '--suppress-cc=bodycc' '
758 test_suppression bodycc
761 test_expect_success $PREREQ 'setup expect' "
762 cat >expected-suppress-cc <<\EOF
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>'
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>
774 Cc: A <author@example.com>,
775 C O Mitter <committer@example.com>
776 Subject: [PATCH 1/1] Second.
778 Message-Id: MESSAGE-ID-STRING
779 X-Mailer: X-MAILER-STRING
785 test_expect_success $PREREQ '--suppress-cc=cc' '
791 GIT_SEND_EMAIL_NOTTY=1 \
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
800 test_expect_success $PREREQ '--confirm=always' '
801 test_confirm --confirm=always --suppress-cc=all
804 test_expect_success $PREREQ '--confirm=auto' '
805 test_confirm --confirm=auto
808 test_expect_success $PREREQ '--confirm=cc' '
809 test_confirm --confirm=cc
812 test_expect_success $PREREQ '--confirm=compose' '
813 test_confirm --confirm=compose --compose
816 test_expect_success $PREREQ 'confirm by default (due to cc)' '
817 CONFIRM=$(git config --get sendemail.confirm) &&
818 git config --unset sendemail.confirm &&
821 git config sendemail.confirm ${CONFIRM:-never}
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
830 git config sendemail.confirm ${CONFIRM:-never}
834 test_expect_success $PREREQ 'confirm detects EOF (inform assumes y)' '
835 CONFIRM=$(git config --get sendemail.confirm) &&
836 git config --unset sendemail.confirm &&
838 git format-patch -2 -o outdir &&
839 GIT_SEND_EMAIL_NOTTY=1 \
841 --from="Example <nobody@example.com>" \
842 --to=nobody@example.com \
843 --smtp-server="$(pwd)/fake.sendmail" \
844 outdir/*.patch < /dev/null
846 git config sendemail.confirm ${CONFIRM:-never}
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" \
861 git config sendemail.confirm ${CONFIRM:-never}
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" \
876 git config sendemail.confirm ${CONFIRM:-never}
880 test_expect_success $PREREQ 'utf8 Cc is rfc2047 encoded' '
881 clean_fake_sendmail &&
883 git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
885 --from="Example <nobody@example.com>" \
886 --to=nobody@example.com \
887 --smtp-server="$(pwd)/fake.sendmail" \
890 grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
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\"" \
901 --compose --subject foo \
902 --from="Example <nobody@example.com>" \
903 --to=nobody@example.com \
904 --smtp-server="$(pwd)/fake.sendmail" \
906 grep "^utf8 body" msgtxt1 &&
907 grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
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"
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\"" \
923 --compose --subject foo \
924 --from="Example <nobody@example.com>" \
925 --to=nobody@example.com \
926 --smtp-server="$(pwd)/fake.sendmail" \
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
933 test_expect_success $PREREQ '--compose adds MIME for utf8 subject' '
934 clean_fake_sendmail &&
935 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
937 --compose --subject utf8-sübjëct \
938 --from="Example <nobody@example.com>" \
939 --to=nobody@example.com \
940 --smtp-server="$(pwd)/fake.sendmail" \
942 grep "^fake edit" msgtxt1 &&
943 grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
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" \
956 grep "^From: Füñný Nâmé <odd_?=mail@example.com>" msgtxt1
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" \
969 grep "^From: " msgtxt1 >msgfrom &&
970 test_line_count = 1 msgfrom
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\"" \
982 --compose --subject foo \
983 --from="Example <nobody@example.com>" \
984 --to=nobody@example.com \
985 --smtp-server="$(pwd)/fake.sendmail" \
987 grep "^utf8 body" msgtxt1 &&
988 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
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\"" \
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" \
1005 grep "^utf8 body" msgtxt1 &&
1006 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
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\"" \
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" \
1024 grep "^utf8 body" msgtxt1 &&
1025 grep "^Content-Type: text/plain; charset=iso-8859-2" msgtxt1
1028 test_expect_success $PREREQ '--compose-encoding adds correct MIME for subject' '
1029 clean_fake_sendmail &&
1030 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
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" \
1038 grep "^fake edit" msgtxt1 &&
1039 grep "^Subject: =?iso-8859-2?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
1042 test_expect_success $PREREQ 'detects ambiguous reference/file conflict' '
1043 echo master > master &&
1045 git commit -m"add master" &&
1046 test_must_fail git send-email --dry-run master 2>errors &&
1047 grep disambiguate errors
1050 test_expect_success $PREREQ 'feed two files' '
1052 git format-patch -2 -o outdir &&
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"
1063 test_expect_success $PREREQ 'in-reply-to but no threading' '
1066 --from="Example <nobody@example.com>" \
1067 --to=nobody@example.com \
1068 --in-reply-to="<in-reply-id@example.com>" \
1071 grep "In-Reply-To: <in-reply-id@example.com>"
1074 test_expect_success $PREREQ 'no in-reply-to and no threading' '
1077 --from="Example <nobody@example.com>" \
1078 --to=nobody@example.com \
1080 $patches $patches >stdout &&
1081 ! grep "In-Reply-To: " stdout
1084 test_expect_success $PREREQ 'threading but no chain-reply-to' '
1087 --from="Example <nobody@example.com>" \
1088 --to=nobody@example.com \
1090 --nochain-reply-to \
1091 $patches $patches >stdout &&
1092 grep "In-Reply-To: " stdout
1095 test_expect_success $PREREQ 'sendemail.to works' '
1096 git config --replace-all sendemail.to "Somebody <somebody@ex.com>" &&
1099 --from="Example <nobody@example.com>" \
1100 $patches $patches >stdout &&
1101 grep "To: Somebody <somebody@ex.com>" stdout
1104 test_expect_success $PREREQ '--no-to overrides sendemail.to' '
1107 --from="Example <nobody@example.com>" \
1109 --to=nobody@example.com \
1110 $patches $patches >stdout &&
1111 grep "To: nobody@example.com" stdout &&
1112 ! grep "To: Somebody <somebody@ex.com>" stdout
1115 test_expect_success $PREREQ 'sendemail.cc works' '
1116 git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" &&
1119 --from="Example <nobody@example.com>" \
1120 --to=nobody@example.com \
1121 $patches $patches >stdout &&
1122 grep "Cc: Somebody <somebody@ex.com>" stdout
1125 test_expect_success $PREREQ '--no-cc overrides sendemail.cc' '
1128 --from="Example <nobody@example.com>" \
1130 --cc=bodies@example.com \
1131 --to=nobody@example.com \
1132 $patches $patches >stdout &&
1133 grep "Cc: bodies@example.com" stdout &&
1134 ! grep "Cc: Somebody <somebody@ex.com>" stdout
1137 test_expect_success $PREREQ 'sendemail.bcc works' '
1138 git config --replace-all sendemail.bcc "Other <other@ex.com>" &&
1141 --from="Example <nobody@example.com>" \
1142 --to=nobody@example.com \
1143 --smtp-server relay.example.com \
1144 $patches $patches >stdout &&
1145 grep "RCPT TO:<other@ex.com>" stdout
1148 test_expect_success $PREREQ '--no-bcc overrides sendemail.bcc' '
1151 --from="Example <nobody@example.com>" \
1153 --bcc=bodies@example.com \
1154 --to=nobody@example.com \
1155 --smtp-server relay.example.com \
1156 $patches $patches >stdout &&
1157 grep "RCPT TO:<bodies@example.com>" stdout &&
1158 ! grep "RCPT TO:<other@ex.com>" stdout
1161 test_expect_success $PREREQ 'patches To headers are used by default' '
1162 patch=`git format-patch -1 --to="bodies@example.com"` &&
1163 test_when_finished "rm $patch" &&
1166 --from="Example <nobody@example.com>" \
1167 --smtp-server relay.example.com \
1169 grep "RCPT TO:<bodies@example.com>" stdout
1172 test_expect_success $PREREQ 'patches To headers are appended to' '
1173 patch=`git format-patch -1 --to="bodies@example.com"` &&
1174 test_when_finished "rm $patch" &&
1177 --from="Example <nobody@example.com>" \
1178 --to=nobody@example.com \
1179 --smtp-server relay.example.com \
1181 grep "RCPT TO:<bodies@example.com>" stdout &&
1182 grep "RCPT TO:<nobody@example.com>" stdout
1185 test_expect_success $PREREQ 'To headers from files reset each patch' '
1186 patch1=`git format-patch -1 --to="bodies@example.com"` &&
1187 patch2=`git format-patch -1 --to="other@example.com" HEAD~` &&
1188 test_when_finished "rm $patch1 && rm $patch2" &&
1191 --from="Example <nobody@example.com>" \
1192 --to="nobody@example.com" \
1193 --smtp-server relay.example.com \
1194 $patch1 $patch2 >stdout &&
1195 test $(grep -c "RCPT TO:<bodies@example.com>" stdout) = 1 &&
1196 test $(grep -c "RCPT TO:<nobody@example.com>" stdout) = 2 &&
1197 test $(grep -c "RCPT TO:<other@example.com>" stdout) = 1
1200 test_expect_success $PREREQ 'setup expect' '
1201 cat >email-using-8bit <<EOF
1202 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1203 Message-Id: <bogus-message-id@example.com>
1204 From: author@example.com
1205 Date: Sat, 12 Jun 2010 15:53:58 +0200
1206 Subject: subject goes here
1208 Dieser deutsche Text enthält einen Umlaut!
1212 test_expect_success $PREREQ 'setup expect' '
1214 Subject: subject goes here
1218 test_expect_success $PREREQ 'ASCII subject is not RFC2047 quoted' '
1219 clean_fake_sendmail &&
1221 git send-email --from=author@example.com --to=nobody@example.com \
1222 --smtp-server="$(pwd)/fake.sendmail" \
1223 --8bit-encoding=UTF-8 \
1224 email-using-8bit >stdout &&
1225 grep "Subject" msgtxt1 >actual &&
1226 test_cmp expected actual
1229 test_expect_success $PREREQ 'setup expect' '
1230 cat >content-type-decl <<EOF
1232 Content-Type: text/plain; charset=UTF-8
1233 Content-Transfer-Encoding: 8bit
1237 test_expect_success $PREREQ 'asks about and fixes 8bit encodings' '
1238 clean_fake_sendmail &&
1240 git send-email --from=author@example.com --to=nobody@example.com \
1241 --smtp-server="$(pwd)/fake.sendmail" \
1242 email-using-8bit >stdout &&
1243 grep "do not declare a Content-Transfer-Encoding" stdout &&
1244 grep email-using-8bit stdout &&
1245 grep "Which 8bit encoding" stdout &&
1246 egrep "Content|MIME" msgtxt1 >actual &&
1247 test_cmp actual content-type-decl
1250 test_expect_success $PREREQ 'sendemail.8bitEncoding works' '
1251 clean_fake_sendmail &&
1252 git config sendemail.assume8bitEncoding UTF-8 &&
1254 git send-email --from=author@example.com --to=nobody@example.com \
1255 --smtp-server="$(pwd)/fake.sendmail" \
1256 email-using-8bit >stdout &&
1257 egrep "Content|MIME" msgtxt1 >actual &&
1258 test_cmp actual content-type-decl
1261 test_expect_success $PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
1262 clean_fake_sendmail &&
1263 git config sendemail.assume8bitEncoding "bogus too" &&
1265 git send-email --from=author@example.com --to=nobody@example.com \
1266 --smtp-server="$(pwd)/fake.sendmail" \
1267 --8bit-encoding=UTF-8 \
1268 email-using-8bit >stdout &&
1269 egrep "Content|MIME" msgtxt1 >actual &&
1270 test_cmp actual content-type-decl
1273 test_expect_success $PREREQ 'setup expect' '
1274 cat >email-using-8bit <<EOF
1275 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1276 Message-Id: <bogus-message-id@example.com>
1277 From: author@example.com
1278 Date: Sat, 12 Jun 2010 15:53:58 +0200
1279 Subject: Dieser Betreff enthält auch einen Umlaut!
1281 Nothing to see here.
1285 test_expect_success $PREREQ 'setup expect' '
1287 Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
1291 test_expect_success $PREREQ '--8bit-encoding also treats subject' '
1292 clean_fake_sendmail &&
1294 git send-email --from=author@example.com --to=nobody@example.com \
1295 --smtp-server="$(pwd)/fake.sendmail" \
1296 --8bit-encoding=UTF-8 \
1297 email-using-8bit >stdout &&
1298 grep "Subject" msgtxt1 >actual &&
1299 test_cmp expected actual
1302 # Note that the patches in this test are deliberately out of order; we
1303 # want to make sure it works even if the cover-letter is not in the
1305 test_expect_success $PREREQ 'refusing to send cover letter template' '
1306 clean_fake_sendmail &&
1308 git format-patch --cover-letter -2 -o outdir &&
1309 test_must_fail git send-email \
1310 --from="Example <nobody@example.com>" \
1311 --to=nobody@example.com \
1312 --smtp-server="$(pwd)/fake.sendmail" \
1313 outdir/0002-*.patch \
1314 outdir/0000-*.patch \
1315 outdir/0001-*.patch \
1317 grep "SUBJECT HERE" errors &&
1318 test -z "$(ls msgtxt*)"
1321 test_expect_success $PREREQ '--force sends cover letter template anyway' '
1322 clean_fake_sendmail &&
1324 git format-patch --cover-letter -2 -o outdir &&
1327 --from="Example <nobody@example.com>" \
1328 --to=nobody@example.com \
1329 --smtp-server="$(pwd)/fake.sendmail" \
1330 outdir/0002-*.patch \
1331 outdir/0000-*.patch \
1332 outdir/0001-*.patch \
1334 ! grep "SUBJECT HERE" errors &&
1335 test -n "$(ls msgtxt*)"
1338 test_expect_success $PREREQ 'sendemail.aliasfiletype=mailrc' '
1339 clean_fake_sendmail &&
1340 echo "alias sbd somebody@example.org" >.mailrc &&
1341 git config --replace-all sendemail.aliasesfile "$(pwd)/.mailrc" &&
1342 git config sendemail.aliasfiletype mailrc &&
1344 --from="Example <nobody@example.com>" \
1346 --smtp-server="$(pwd)/fake.sendmail" \
1347 outdir/0001-*.patch \
1349 grep "^!somebody@example\.org!$" commandline1
1352 test_expect_success $PREREQ 'sendemail.aliasfile=~/.mailrc' '
1353 clean_fake_sendmail &&
1354 echo "alias sbd someone@example.org" >~/.mailrc &&
1355 git config --replace-all sendemail.aliasesfile "~/.mailrc" &&
1356 git config sendemail.aliasfiletype mailrc &&
1358 --from="Example <nobody@example.com>" \
1360 --smtp-server="$(pwd)/fake.sendmail" \
1361 outdir/0001-*.patch \
1363 grep "^!someone@example\.org!$" commandline1