3 test_description
='git send-email'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7 TEST_PASSES_SANITIZE_LEAK
=true
10 # May be altered later in the test
13 replace_variable_fields
() {
14 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
15 -e "s/^\(Message-ID:\).*/\1 MESSAGE-ID-STRING/" \
16 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/"
19 test_expect_success
$PREREQ 'prepare reference tree' '
20 echo "1A quick brown fox jumps over the" >file &&
21 echo "lazy dog" >>file &&
23 GIT_AUTHOR_NAME="A" git commit -a -m "Initial."
26 test_expect_success
$PREREQ 'Setup helper tool' '
27 write_script fake.sendmail <<-\EOF &&
30 while test -f commandline$output
37 done >commandline$output
40 git add fake.sendmail &&
41 GIT_AUTHOR_NAME="A" git commit -a -m "Second."
44 clean_fake_sendmail
() {
45 rm -f commandline
* msgtxt
*
48 test_expect_success
$PREREQ 'Extract patches' '
49 patches=$(git format-patch -s --cc="One <one@example.com>" --cc=two@example.com -n HEAD^1) &&
50 threaded_patches=$(git format-patch -o threaded --thread=shallow -s --in-reply-to="format" HEAD^1)
53 # Test no confirm early to ensure remaining tests will not hang
57 GIT_SEND_EMAIL_NOTTY
=1 \
59 --from="Example <from@example.com>" \
60 --to=nobody@example.com \
61 --smtp-server="$(pwd)/fake.sendmail" \
64 ! grep "Send this email" stdout
&&
68 # Exit immediately to prevent hang if a no-confirm test fails
70 if ! test -f no_confirm_okay
72 say
'confirm test failed; skipping remaining tests to prevent hanging'
73 PREREQ
="$PREREQ,CHECK_NO_CONFIRM"
78 test_expect_success
$PREREQ 'No confirm with --suppress-cc' '
79 test_no_confirm --suppress-cc=sob &&
84 test_expect_success
$PREREQ 'No confirm with --confirm=never' '
85 test_no_confirm --confirm=never &&
89 # leave sendemail.confirm set to never after this so that none of the
90 # remaining tests prompt unintentionally.
91 test_expect_success
$PREREQ 'No confirm with sendemail.confirm=never' '
92 git config sendemail.confirm never &&
93 test_no_confirm --compose --subject=foo &&
97 test_expect_success
$PREREQ 'Send patches' '
98 git send-email --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
101 test_expect_success
$PREREQ 'setup expect' '
102 cat >expected <<-\EOF
110 test_expect_success
$PREREQ 'Verify commandline' '
111 test_cmp expected commandline1
114 test_expect_success
$PREREQ 'Send patches with --envelope-sender' '
115 clean_fake_sendmail &&
116 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
119 test_expect_success
$PREREQ 'setup expect' '
120 cat >expected <<-\EOF
130 test_expect_success
$PREREQ 'Verify commandline' '
131 test_cmp expected commandline1
134 test_expect_success
$PREREQ 'Send patches with --envelope-sender=auto' '
135 clean_fake_sendmail &&
136 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
139 test_expect_success
$PREREQ 'setup expect' '
140 cat >expected <<-\EOF
150 test_expect_success
$PREREQ 'Verify commandline' '
151 test_cmp expected commandline1
154 test_expect_success
$PREREQ 'setup expect for cc trailer' "
155 cat >expected-cc <<\EOF
156 !recipient@example.com!
167 test_expect_success
$PREREQ 'cc trailer with various syntax' '
168 test_commit cc-trailer &&
169 test_when_finished "git reset --hard HEAD^" &&
170 git commit --amend -F - <<-EOF &&
174 Cc: <two@example.com> # trailing comments are ignored
175 Cc: <three@example.com>, <not.four@example.com> one address per line
176 Cc: "Some # Body" <four@example.com> [ <also.a.comment> ]
177 Cc: five@example.com # not.six@example.com
178 Cc: six@example.com, not.seven@example.com
180 clean_fake_sendmail &&
181 git send-email -1 --to=recipient@example.com \
182 --smtp-server="$(pwd)/fake.sendmail" &&
183 test_cmp expected-cc commandline1
186 test_expect_success
$PREREQ 'setup fake get_maintainer.pl script for cc trailer' "
187 write_script expected-cc-script.sh <<-EOF
188 echo 'One Person <one@example.com> (supporter:THIS (FOO/bar))'
189 echo 'Two Person <two@example.com> (maintainer:THIS THING)'
190 echo 'Third List <three@example.com> (moderated list:THIS THING (FOO/bar))'
191 echo '<four@example.com> (moderated list:FOR THING)'
192 echo 'five@example.com (open list:FOR THING (FOO/bar))'
193 echo 'six@example.com (open list)'
197 test_expect_success
$PREREQ 'cc trailer with get_maintainer.pl output' '
198 clean_fake_sendmail &&
199 git send-email -1 --to=recipient@example.com \
200 --cc-cmd=./expected-cc-script.sh \
201 --smtp-server="$(pwd)/fake.sendmail" &&
202 test_cmp expected-cc commandline1
205 test_expect_success
$PREREQ 'setup expect' "
206 cat >expected-show-all-headers <<\EOF
208 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
209 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
210 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
212 Server: relay.example.com
213 MAIL FROM:<from@example.com>
214 RCPT TO:<to@example.com>
215 RCPT TO:<cc@example.com>
216 RCPT TO:<author@example.com>
217 RCPT TO:<one@example.com>
218 RCPT TO:<two@example.com>
219 RCPT TO:<bcc@example.com>
220 From: Example <from@example.com>
223 A <author@example.com>,
224 One <one@example.com>,
226 Subject: [PATCH 1/1] Second.
228 Message-ID: MESSAGE-ID-STRING
229 X-Mailer: X-MAILER-STRING
230 In-Reply-To: <unique-message-id@example.com>
231 References: <unique-message-id@example.com>
232 Reply-To: Reply <reply@example.com>
234 Content-Transfer-Encoding: 8bit
240 test_suppress_self
() {
242 test_when_finished
"git reset --hard HEAD^" &&
244 write_script cccmd-sed
<<-EOF &&
245 sed -n -e s/^cccmd--//p "\$1"
248 git commit
--amend --author="$1 <$2>" -F - &&
249 clean_fake_sendmail
&&
250 git format-patch
--stdout -1 >"suppress-self-$3.patch" &&
252 git send-email
--from="$1 <$2>" \
253 --to=nobody@example.com \
254 --cc-cmd=.
/cccmd-sed \
256 --smtp-server="$(pwd)/fake.sendmail" \
257 suppress-self-
$3.
patch &&
259 mv msgtxt1 msgtxt1-
$3 &&
260 sed -e '/^$/q' msgtxt1-
$3 >"msghdr1-$3" &&
262 (grep '^Cc:' msghdr1-
$3 >"actual-no-cc-$3";
263 test_must_be_empty actual-no-cc-
$3)
266 test_suppress_self_unquoted
() {
267 test_suppress_self
"$1" "$2" "unquoted-$3" <<-EOF
268 test suppress-cc.self unquoted-$3 with name $1 email $2
275 Signed-off-by: $1 <$2>
279 test_suppress_self_quoted
() {
280 test_suppress_self
"$1" "$2" "quoted-$3" <<-EOF
281 test suppress-cc.self quoted-$3 with name $1 email $2
289 Signed-off-by: $1 <$2>
290 Signed-off-by: "$1" <$2>
294 test_expect_success
$PREREQ 'self name is suppressed' "
295 test_suppress_self_unquoted 'A U Thor' 'author@example.com' \
296 'self_name_suppressed'
299 test_expect_success
$PREREQ 'self name with dot is suppressed' "
300 test_suppress_self_quoted 'A U. Thor' 'author@example.com' \
301 'self_name_dot_suppressed'
304 test_expect_success
$PREREQ 'non-ascii self name is suppressed' "
305 test_suppress_self_quoted 'Füñný Nâmé' 'odd_?=mail@example.com' \
306 'non_ascii_self_suppressed'
309 # This name is long enough to force format-patch to split it into multiple
310 # encoded-words, assuming it uses UTF-8 with the "Q" encoding.
311 test_expect_success
$PREREQ 'long non-ascii self name is suppressed' "
312 test_suppress_self_quoted 'Ƒüñníęř €. Nâṁé' 'odd_?=mail@example.com' \
313 'long_non_ascii_self_suppressed'
316 test_expect_success
$PREREQ 'sanitized self name is suppressed' "
317 test_suppress_self_unquoted '\"A U. Thor\"' 'author@example.com' \
318 'self_name_sanitized_suppressed'
321 test_expect_success
$PREREQ 'Show all headers' '
325 --from="Example <from@example.com>" \
326 --reply-to="Reply <reply@example.com>" \
327 --to=to@example.com \
328 --cc=cc@example.com \
329 --bcc=bcc@example.com \
330 --in-reply-to="<unique-message-id@example.com>" \
331 --smtp-server relay.example.com \
332 $patches | replace_variable_fields \
333 >actual-show-all-headers &&
334 test_cmp expected-show-all-headers actual-show-all-headers
337 test_expect_success
$PREREQ 'Prompting works' '
338 clean_fake_sendmail &&
339 (echo "to@example.com" &&
341 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
342 --smtp-server="$(pwd)/fake.sendmail" \
345 grep "^From: A U Thor <author@example.com>\$" msgtxt1 &&
346 grep "^To: to@example.com\$" msgtxt1
349 test_expect_success
$PREREQ,AUTOIDENT
'implicit ident is allowed' '
350 clean_fake_sendmail &&
351 (sane_unset GIT_AUTHOR_NAME &&
352 sane_unset GIT_AUTHOR_EMAIL &&
353 sane_unset GIT_COMMITTER_NAME &&
354 sane_unset GIT_COMMITTER_EMAIL &&
355 GIT_SEND_EMAIL_NOTTY=1 git send-email \
356 --smtp-server="$(pwd)/fake.sendmail" \
357 --to=to@example.com \
358 $patches </dev/null 2>errors
362 test_expect_success
$PREREQ,!AUTOIDENT
'broken implicit ident aborts send-email' '
363 clean_fake_sendmail &&
364 (sane_unset GIT_AUTHOR_NAME &&
365 sane_unset GIT_AUTHOR_EMAIL &&
366 sane_unset GIT_COMMITTER_NAME &&
367 sane_unset GIT_COMMITTER_EMAIL &&
368 GIT_SEND_EMAIL_NOTTY=1 && export GIT_SEND_EMAIL_NOTTY &&
369 test_must_fail git send-email \
370 --smtp-server="$(pwd)/fake.sendmail" \
371 --to=to@example.com \
372 $patches </dev/null 2>errors &&
373 test_i18ngrep "tell me who you are" errors
377 test_expect_success
$PREREQ 'setup tocmd and cccmd scripts' '
378 write_script tocmd-sed <<-\EOF &&
379 sed -n -e "s/^tocmd--//p" "$1"
381 write_script cccmd-sed <<-\EOF
382 sed -n -e "s/^cccmd--//p" "$1"
386 test_expect_success
$PREREQ 'tocmd works' '
387 clean_fake_sendmail &&
388 cp $patches tocmd.patch &&
389 echo tocmd--tocmd@example.com >>tocmd.patch &&
391 --from="Example <nobody@example.com>" \
392 --to-cmd=./tocmd-sed \
393 --smtp-server="$(pwd)/fake.sendmail" \
396 grep "^To: tocmd@example.com" msgtxt1
399 test_expect_success
$PREREQ 'cccmd works' '
400 clean_fake_sendmail &&
401 cp $patches cccmd.patch &&
402 echo "cccmd-- cccmd@example.com" >>cccmd.patch &&
404 --from="Example <nobody@example.com>" \
405 --to=nobody@example.com \
406 --cc-cmd=./cccmd-sed \
407 --smtp-server="$(pwd)/fake.sendmail" \
410 grep "^ cccmd@example.com" msgtxt1
413 test_expect_success
$PREREQ 'reject long lines' '
415 z64=$z8$z8$z8$z8$z8$z8$z8$z8 &&
416 z512=$z64$z64$z64$z64$z64$z64$z64$z64 &&
417 clean_fake_sendmail &&
418 cp $patches longline.patch &&
419 cat >>longline.patch <<-EOF &&
424 test_must_fail git send-email \
425 --from="Example <nobody@example.com>" \
426 --to=nobody@example.com \
427 --smtp-server="$(pwd)/fake.sendmail" \
428 --transfer-encoding=8bit \
429 $patches longline.patch \
431 cat >expect <<-\EOF &&
432 fatal: longline.patch:35 is longer than 998 characters
433 warning: no patches were sent
435 test_cmp expect actual
438 test_expect_success
$PREREQ 'no patch was sent' '
439 ! test -e commandline1
442 test_expect_success
$PREREQ 'Author From: in message body' '
443 clean_fake_sendmail &&
445 --from="Example <nobody@example.com>" \
446 --to=nobody@example.com \
447 --smtp-server="$(pwd)/fake.sendmail" \
449 sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
450 grep "From: A <author@example.com>" msgbody1
453 test_expect_success
$PREREQ 'Author From: not in message body' '
454 clean_fake_sendmail &&
456 --from="A <author@example.com>" \
457 --to=nobody@example.com \
458 --smtp-server="$(pwd)/fake.sendmail" \
460 sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
461 ! grep "From: A <author@example.com>" msgbody1
464 test_expect_success
$PREREQ 'allow long lines with --no-validate' '
466 --from="Example <nobody@example.com>" \
467 --to=nobody@example.com \
468 --smtp-server="$(pwd)/fake.sendmail" \
470 $patches longline.patch \
474 test_expect_success
$PREREQ 'short lines with auto encoding are 8bit' '
475 clean_fake_sendmail &&
477 --from="A <author@example.com>" \
478 --to=nobody@example.com \
479 --smtp-server="$(pwd)/fake.sendmail" \
480 --transfer-encoding=auto \
482 grep "Content-Transfer-Encoding: 8bit" msgtxt1
485 test_expect_success
$PREREQ 'long lines with auto encoding are quoted-printable' '
486 clean_fake_sendmail &&
488 --from="Example <nobody@example.com>" \
489 --to=nobody@example.com \
490 --smtp-server="$(pwd)/fake.sendmail" \
491 --transfer-encoding=auto \
494 grep "Content-Transfer-Encoding: quoted-printable" msgtxt1
497 test_expect_success
$PREREQ 'carriage returns with auto encoding are quoted-printable' '
498 clean_fake_sendmail &&
499 cp $patches cr.patch &&
500 printf "this is a line\r\n" >>cr.patch &&
502 --from="Example <nobody@example.com>" \
503 --to=nobody@example.com \
504 --smtp-server="$(pwd)/fake.sendmail" \
505 --transfer-encoding=auto \
508 grep "Content-Transfer-Encoding: quoted-printable" msgtxt1
511 for enc
in auto quoted-printable base64
513 test_expect_success
$PREREQ "--validate passes with encoding $enc" '
515 --from="Example <nobody@example.com>" \
516 --to=nobody@example.com \
517 --smtp-server="$(pwd)/fake.sendmail" \
518 --transfer-encoding=$enc \
520 $patches longline.patch
525 test_expect_success
$PREREQ "--validate respects relative core.hooksPath path" '
526 clean_fake_sendmail &&
528 test_when_finished "rm my-hooks.ran" &&
529 write_script my-hooks/sendemail-validate <<-\EOF &&
533 test_config core.hooksPath "my-hooks" &&
534 test_must_fail git send-email \
535 --from="Example <nobody@example.com>" \
536 --to=nobody@example.com \
537 --smtp-server="$(pwd)/fake.sendmail" \
539 longline.patch 2>actual &&
540 test_path_is_file my-hooks.ran &&
541 cat >expect <<-EOF &&
542 fatal: longline.patch: rejected by sendemail-validate hook
543 fatal: command '"'"'git hook run --ignore-missing sendemail-validate -- <patch> <header>'"'"' died with exit code 1
544 warning: no patches were sent
546 test_cmp expect actual
549 test_expect_success
$PREREQ "--validate respects absolute core.hooksPath path" '
550 hooks_path="$(pwd)/my-hooks" &&
551 test_config core.hooksPath "$hooks_path" &&
552 test_when_finished "rm my-hooks.ran" &&
553 test_must_fail git send-email \
554 --from="Example <nobody@example.com>" \
555 --to=nobody@example.com \
556 --smtp-server="$(pwd)/fake.sendmail" \
558 longline.patch 2>actual &&
559 test_path_is_file my-hooks.ran &&
560 cat >expect <<-EOF &&
561 fatal: longline.patch: rejected by sendemail-validate hook
562 fatal: command '"'"'git hook run --ignore-missing sendemail-validate -- <patch> <header>'"'"' died with exit code 1
563 warning: no patches were sent
565 test_cmp expect actual
568 test_expect_success
$PREREQ "--validate hook supports header argument" '
569 write_script my-hooks/sendemail-validate <<-\EOF &&
572 grep "X-test-header: v1.0" "$2"
574 echo "No header arg passed"
578 test_config core.hooksPath "my-hooks" &&
581 --add-header="X-test-header: v1.0" \
582 -n HEAD^1 -o outdir &&
585 --to=nobody@example.com \
586 --smtp-server="$(pwd)/fake.sendmail" \
591 test_expect_success
$PREREQ 'clear message-id before parsing a new message' '
592 clean_fake_sendmail &&
593 echo true | write_script my-hooks/sendemail-validate &&
594 test_config core.hooksPath my-hooks &&
595 GIT_SEND_EMAIL_NOTTY=1 \
596 git send-email --validate --to=recipient@example.com \
597 --smtp-server="$(pwd)/fake.sendmail" \
598 $patches $threaded_patches &&
599 id0=$(grep "^Message-ID: " $threaded_patches) &&
600 id1=$(grep "^Message-ID: " msgtxt1) &&
601 id2=$(grep "^Message-ID: " msgtxt2) &&
602 test "z$id0" = "z$id2" &&
603 test "z$id1" != "z$id2"
606 for enc
in 7bit
8bit quoted-printable base64
608 test_expect_success
$PREREQ "--transfer-encoding=$enc produces correct header" '
609 clean_fake_sendmail &&
611 --from="Example <nobody@example.com>" \
612 --to=nobody@example.com \
613 --smtp-server="$(pwd)/fake.sendmail" \
614 --transfer-encoding=$enc \
616 grep "Content-Transfer-Encoding: $enc" msgtxt1
620 test_expect_success
$PREREQ 'Invalid In-Reply-To' '
621 clean_fake_sendmail &&
623 --from="Example <nobody@example.com>" \
624 --to=nobody@example.com \
626 --smtp-server="$(pwd)/fake.sendmail" \
629 ! grep "^In-Reply-To: < *>" msgtxt1
632 test_expect_success
$PREREQ 'Valid In-Reply-To when prompting' '
633 clean_fake_sendmail &&
634 (echo "From Example <from@example.com>" &&
635 echo "To Example <to@example.com>" &&
637 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
638 --smtp-server="$(pwd)/fake.sendmail" \
640 ! grep "^In-Reply-To: < *>" msgtxt1
643 test_expect_success
$PREREQ 'In-Reply-To without --chain-reply-to' '
644 clean_fake_sendmail &&
645 echo "<unique-message-id@example.com>" >expect &&
647 --from="Example <nobody@example.com>" \
648 --to=nobody@example.com \
649 --no-chain-reply-to \
650 --in-reply-to="$(cat expect)" \
651 --smtp-server="$(pwd)/fake.sendmail" \
652 $patches $patches $patches \
654 # The first message is a reply to --in-reply-to
655 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
656 test_cmp expect actual &&
657 # Second and subsequent messages are replies to the first one
658 sed -n -e "s/^Message-ID: *\(.*\)/\1/p" msgtxt1 >expect &&
659 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
660 test_cmp expect actual &&
661 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
662 test_cmp expect actual
665 test_expect_success
$PREREQ 'In-Reply-To with --chain-reply-to' '
666 clean_fake_sendmail &&
667 echo "<unique-message-id@example.com>" >expect &&
669 --from="Example <nobody@example.com>" \
670 --to=nobody@example.com \
672 --in-reply-to="$(cat expect)" \
673 --smtp-server="$(pwd)/fake.sendmail" \
674 $patches $patches $patches \
676 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
677 test_cmp expect actual &&
678 sed -n -e "s/^Message-ID: *\(.*\)/\1/p" msgtxt1 >expect &&
679 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
680 test_cmp expect actual &&
681 sed -n -e "s/^Message-ID: *\(.*\)/\1/p" msgtxt2 >expect &&
682 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
683 test_cmp expect actual
686 test_set_editor
"$(pwd)/fake-editor"
688 test_expect_success
$PREREQ 'setup erroring fake editor' '
689 write_script fake-editor <<-\EOF
690 echo >&2 "I am about to error"
695 test_expect_success
$PREREQ 'fake editor dies with error' '
696 clean_fake_sendmail &&
697 test_must_fail git send-email \
698 --compose --subject foo \
699 --from="Example <nobody@example.com>" \
700 --to=nobody@example.com \
701 --smtp-server="$(pwd)/fake.sendmail" \
703 grep "I am about to error" err &&
704 grep "the editor exited uncleanly, aborting everything" err
707 test_expect_success
$PREREQ 'setup fake editor' '
708 write_script fake-editor <<-\EOF
709 echo fake edit >>"$1"
713 test_expect_success
$PREREQ '--compose works' '
714 clean_fake_sendmail &&
716 --compose --subject foo \
717 --from="Example <nobody@example.com>" \
718 --to=nobody@example.com \
719 --smtp-server="$(pwd)/fake.sendmail" \
724 test_expect_success
$PREREQ 'first message is compose text' '
725 grep "^fake edit" msgtxt1
728 test_expect_success
$PREREQ 'second message is patch' '
729 grep "Subject:.*Second" msgtxt2
732 test_expect_success
$PREREQ 'setup expect' "
733 cat >expected-suppress-sob <<\EOF
735 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
736 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
737 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
739 Server: relay.example.com
740 MAIL FROM:<from@example.com>
741 RCPT TO:<to@example.com>
742 RCPT TO:<cc@example.com>
743 RCPT TO:<author@example.com>
744 RCPT TO:<one@example.com>
745 RCPT TO:<two@example.com>
746 From: Example <from@example.com>
749 A <author@example.com>,
750 One <one@example.com>,
752 Subject: [PATCH 1/1] Second.
754 Message-ID: MESSAGE-ID-STRING
755 X-Mailer: X-MAILER-STRING
757 Content-Transfer-Encoding: 8bit
763 test_suppression
() {
766 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
767 --from="Example <from@example.com>" \
768 --to=to@example.com \
769 --smtp-server relay.example.com \
770 $patches | replace_variable_fields \
771 >actual-suppress-
$1${2+"-$2"} &&
772 test_cmp expected-suppress-
$1${2+"-$2"} actual-suppress-
$1${2+"-$2"}
775 test_expect_success
$PREREQ 'sendemail.cc set' '
776 git config sendemail.cc cc@example.com &&
780 test_expect_success
$PREREQ 'setup expect' "
781 cat >expected-suppress-sob <<\EOF
783 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
784 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
785 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
787 Server: relay.example.com
788 MAIL FROM:<from@example.com>
789 RCPT TO:<to@example.com>
790 RCPT TO:<author@example.com>
791 RCPT TO:<one@example.com>
792 RCPT TO:<two@example.com>
793 From: Example <from@example.com>
795 Cc: A <author@example.com>,
796 One <one@example.com>,
798 Subject: [PATCH 1/1] Second.
800 Message-ID: MESSAGE-ID-STRING
801 X-Mailer: X-MAILER-STRING
803 Content-Transfer-Encoding: 8bit
809 test_expect_success
$PREREQ 'sendemail.cc unset' '
810 git config --unset sendemail.cc &&
814 test_expect_success
$PREREQ 'setup expect' "
815 cat >expected-suppress-cccmd <<\EOF
817 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
818 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
819 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
820 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
822 Server: relay.example.com
823 MAIL FROM:<from@example.com>
824 RCPT TO:<to@example.com>
825 RCPT TO:<author@example.com>
826 RCPT TO:<one@example.com>
827 RCPT TO:<two@example.com>
828 RCPT TO:<committer@example.com>
829 From: Example <from@example.com>
831 Cc: A <author@example.com>,
832 One <one@example.com>,
834 C O Mitter <committer@example.com>
835 Subject: [PATCH 1/1] Second.
837 Message-ID: MESSAGE-ID-STRING
838 X-Mailer: X-MAILER-STRING
840 Content-Transfer-Encoding: 8bit
846 test_expect_success
$PREREQ 'sendemail.cccmd' '
847 write_script cccmd <<-\EOF &&
848 echo cc-cmd@example.com
850 git config sendemail.cccmd ./cccmd &&
851 test_suppression cccmd
854 test_expect_success
$PREREQ 'setup expect' '
855 cat >expected-suppress-all <<\EOF
858 Server: relay.example.com
859 MAIL FROM:<from@example.com>
860 RCPT TO:<to@example.com>
861 From: Example <from@example.com>
863 Subject: [PATCH 1/1] Second.
865 Message-ID: MESSAGE-ID-STRING
866 X-Mailer: X-MAILER-STRING
868 Content-Transfer-Encoding: 8bit
874 test_expect_success
$PREREQ '--suppress-cc=all' '
878 test_expect_success
$PREREQ 'setup expect' "
879 cat >expected-suppress-body <<\EOF
881 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
882 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
883 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
884 (cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
886 Server: relay.example.com
887 MAIL FROM:<from@example.com>
888 RCPT TO:<to@example.com>
889 RCPT TO:<author@example.com>
890 RCPT TO:<one@example.com>
891 RCPT TO:<two@example.com>
892 RCPT TO:<cc-cmd@example.com>
893 From: Example <from@example.com>
895 Cc: A <author@example.com>,
896 One <one@example.com>,
899 Subject: [PATCH 1/1] Second.
901 Message-ID: MESSAGE-ID-STRING
902 X-Mailer: X-MAILER-STRING
904 Content-Transfer-Encoding: 8bit
910 test_expect_success
$PREREQ '--suppress-cc=body' '
911 test_suppression body
914 test_expect_success
$PREREQ 'setup expect' "
915 cat >expected-suppress-body-cccmd <<\EOF
917 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
918 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
919 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
921 Server: relay.example.com
922 MAIL FROM:<from@example.com>
923 RCPT TO:<to@example.com>
924 RCPT TO:<author@example.com>
925 RCPT TO:<one@example.com>
926 RCPT TO:<two@example.com>
927 From: Example <from@example.com>
929 Cc: A <author@example.com>,
930 One <one@example.com>,
932 Subject: [PATCH 1/1] Second.
934 Message-ID: MESSAGE-ID-STRING
935 X-Mailer: X-MAILER-STRING
937 Content-Transfer-Encoding: 8bit
943 test_expect_success
$PREREQ '--suppress-cc=body --suppress-cc=cccmd' '
944 test_suppression body cccmd
947 test_expect_success
$PREREQ 'setup expect' "
948 cat >expected-suppress-sob <<\EOF
950 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
951 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
952 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
954 Server: relay.example.com
955 MAIL FROM:<from@example.com>
956 RCPT TO:<to@example.com>
957 RCPT TO:<author@example.com>
958 RCPT TO:<one@example.com>
959 RCPT TO:<two@example.com>
960 From: Example <from@example.com>
962 Cc: A <author@example.com>,
963 One <one@example.com>,
965 Subject: [PATCH 1/1] Second.
967 Message-ID: MESSAGE-ID-STRING
968 X-Mailer: X-MAILER-STRING
970 Content-Transfer-Encoding: 8bit
976 test_expect_success
$PREREQ '--suppress-cc=sob' '
977 test_might_fail git config --unset sendemail.cccmd &&
981 test_expect_success
$PREREQ 'setup expect' "
982 cat >expected-suppress-bodycc <<\EOF
984 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
985 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
986 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
987 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
989 Server: relay.example.com
990 MAIL FROM:<from@example.com>
991 RCPT TO:<to@example.com>
992 RCPT TO:<author@example.com>
993 RCPT TO:<one@example.com>
994 RCPT TO:<two@example.com>
995 RCPT TO:<committer@example.com>
996 From: Example <from@example.com>
998 Cc: A <author@example.com>,
999 One <one@example.com>,
1001 C O Mitter <committer@example.com>
1002 Subject: [PATCH 1/1] Second.
1004 Message-ID: MESSAGE-ID-STRING
1005 X-Mailer: X-MAILER-STRING
1007 Content-Transfer-Encoding: 8bit
1013 test_expect_success
$PREREQ '--suppress-cc=bodycc' '
1014 test_suppression bodycc
1017 test_expect_success
$PREREQ 'setup expect' "
1018 cat >expected-suppress-cc <<\EOF
1020 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
1021 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
1023 Server: relay.example.com
1024 MAIL FROM:<from@example.com>
1025 RCPT TO:<to@example.com>
1026 RCPT TO:<author@example.com>
1027 RCPT TO:<committer@example.com>
1028 From: Example <from@example.com>
1030 Cc: A <author@example.com>,
1031 C O Mitter <committer@example.com>
1032 Subject: [PATCH 1/1] Second.
1034 Message-ID: MESSAGE-ID-STRING
1035 X-Mailer: X-MAILER-STRING
1037 Content-Transfer-Encoding: 8bit
1043 test_expect_success
$PREREQ '--suppress-cc=cc' '
1049 GIT_SEND_EMAIL_NOTTY
=1 \
1051 --from="Example <nobody@example.com>" \
1052 --to=nobody@example.com \
1053 --smtp-server="$(pwd)/fake.sendmail" \
1054 $@
$patches >stdout
&&
1055 grep "Send this email" stdout
1058 test_expect_success
$PREREQ '--confirm=always' '
1059 test_confirm --confirm=always --suppress-cc=all
1062 test_expect_success
$PREREQ '--confirm=auto' '
1063 test_confirm --confirm=auto
1066 test_expect_success
$PREREQ '--confirm=cc' '
1067 test_confirm --confirm=cc
1070 test_expect_success
$PREREQ '--confirm=compose' '
1071 test_confirm --confirm=compose --compose
1074 test_expect_success
$PREREQ 'confirm by default (due to cc)' '
1075 test_when_finished git config sendemail.confirm never &&
1076 git config --unset sendemail.confirm &&
1080 test_expect_success
$PREREQ 'confirm by default (due to --compose)' '
1081 test_when_finished git config sendemail.confirm never &&
1082 git config --unset sendemail.confirm &&
1083 test_confirm --suppress-cc=all --compose
1086 test_expect_success
$PREREQ 'confirm detects EOF (inform assumes y)' '
1087 test_when_finished git config sendemail.confirm never &&
1088 git config --unset sendemail.confirm &&
1090 git format-patch -2 -o outdir &&
1091 GIT_SEND_EMAIL_NOTTY=1 \
1093 --from="Example <nobody@example.com>" \
1094 --to=nobody@example.com \
1095 --smtp-server="$(pwd)/fake.sendmail" \
1096 outdir/*.patch </dev/null
1099 test_expect_success
$PREREQ 'confirm detects EOF (auto causes failure)' '
1100 test_when_finished git config sendemail.confirm never &&
1101 git config sendemail.confirm auto &&
1102 GIT_SEND_EMAIL_NOTTY=1 &&
1103 export GIT_SEND_EMAIL_NOTTY &&
1104 test_must_fail git send-email \
1105 --from="Example <nobody@example.com>" \
1106 --to=nobody@example.com \
1107 --smtp-server="$(pwd)/fake.sendmail" \
1111 test_expect_success
$PREREQ 'confirm does not loop forever' '
1112 test_when_finished git config sendemail.confirm never &&
1113 git config sendemail.confirm auto &&
1114 GIT_SEND_EMAIL_NOTTY=1 &&
1115 export GIT_SEND_EMAIL_NOTTY &&
1116 yes "bogus" | test_must_fail git send-email \
1117 --from="Example <nobody@example.com>" \
1118 --to=nobody@example.com \
1119 --smtp-server="$(pwd)/fake.sendmail" \
1123 test_expect_success
$PREREQ 'utf8 Cc is rfc2047 encoded' '
1124 clean_fake_sendmail &&
1126 git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
1128 --from="Example <nobody@example.com>" \
1129 --to=nobody@example.com \
1130 --smtp-server="$(pwd)/fake.sendmail" \
1133 grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
1136 test_expect_success
$PREREQ '--compose adds MIME for utf8 body' '
1137 clean_fake_sendmail &&
1138 write_script fake-editor-utf8 <<-\EOF &&
1139 echo "utf8 body: àéìöú" >>"$1"
1141 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1143 --compose --subject foo \
1144 --from="Example <nobody@example.com>" \
1145 --to=nobody@example.com \
1146 --smtp-server="$(pwd)/fake.sendmail" \
1148 grep "^utf8 body" msgtxt1 &&
1149 grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
1152 test_expect_success
$PREREQ '--compose respects user mime type' '
1153 clean_fake_sendmail &&
1154 write_script fake-editor-utf8-mime <<-\EOF &&
1157 Content-Type: text/plain; charset=iso-8859-1
1158 Content-Transfer-Encoding: 8bit
1164 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
1166 --compose --subject foo \
1167 --from="Example <nobody@example.com>" \
1168 --to=nobody@example.com \
1169 --smtp-server="$(pwd)/fake.sendmail" \
1171 grep "^utf8 body" msgtxt1 &&
1172 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
1173 ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
1176 test_expect_success
$PREREQ '--compose adds MIME for utf8 subject' '
1177 clean_fake_sendmail &&
1178 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
1180 --compose --subject utf8-sübjëct \
1181 --from="Example <nobody@example.com>" \
1182 --to=nobody@example.com \
1183 --smtp-server="$(pwd)/fake.sendmail" \
1185 grep "^fake edit" msgtxt1 &&
1186 grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
1189 test_expect_success
$PREREQ 'utf8 author is correctly passed on' '
1190 clean_fake_sendmail &&
1191 test_commit weird_author &&
1192 test_when_finished "git reset --hard HEAD^" &&
1193 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
1194 git format-patch --stdout -1 >funny_name.patch &&
1195 git send-email --from="Example <nobody@example.com>" \
1196 --to=nobody@example.com \
1197 --smtp-server="$(pwd)/fake.sendmail" \
1199 grep "^From: Füñný Nâmé <odd_?=mail@example.com>" msgtxt1
1202 test_expect_success
$PREREQ 'utf8 sender is not duplicated' '
1203 clean_fake_sendmail &&
1204 test_commit weird_sender &&
1205 test_when_finished "git reset --hard HEAD^" &&
1206 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
1207 git format-patch --stdout -1 >funny_name.patch &&
1208 git send-email --from="Füñný Nâmé <odd_?=mail@example.com>" \
1209 --to=nobody@example.com \
1210 --smtp-server="$(pwd)/fake.sendmail" \
1212 grep "^From: " msgtxt1 >msgfrom &&
1213 test_line_count = 1 msgfrom
1216 test_expect_success
$PREREQ 'sendemail.composeencoding works' '
1217 clean_fake_sendmail &&
1218 git config sendemail.composeencoding iso-8859-1 &&
1219 write_script fake-editor-utf8 <<-\EOF &&
1220 echo "utf8 body: àéìöú" >>"$1"
1222 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1224 --compose --subject foo \
1225 --from="Example <nobody@example.com>" \
1226 --to=nobody@example.com \
1227 --smtp-server="$(pwd)/fake.sendmail" \
1229 grep "^utf8 body" msgtxt1 &&
1230 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1233 test_expect_success
$PREREQ '--compose-encoding works' '
1234 clean_fake_sendmail &&
1235 write_script fake-editor-utf8 <<-\EOF &&
1236 echo "utf8 body: àéìöú" >>"$1"
1238 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1240 --compose-encoding iso-8859-1 \
1241 --compose --subject foo \
1242 --from="Example <nobody@example.com>" \
1243 --to=nobody@example.com \
1244 --smtp-server="$(pwd)/fake.sendmail" \
1246 grep "^utf8 body" msgtxt1 &&
1247 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1250 test_expect_success
$PREREQ '--compose-encoding overrides sendemail.composeencoding' '
1251 clean_fake_sendmail &&
1252 git config sendemail.composeencoding iso-8859-1 &&
1253 write_script fake-editor-utf8 <<-\EOF &&
1254 echo "utf8 body: àéìöú" >>"$1"
1256 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1258 --compose-encoding iso-8859-2 \
1259 --compose --subject foo \
1260 --from="Example <nobody@example.com>" \
1261 --to=nobody@example.com \
1262 --smtp-server="$(pwd)/fake.sendmail" \
1264 grep "^utf8 body" msgtxt1 &&
1265 grep "^Content-Type: text/plain; charset=iso-8859-2" msgtxt1
1268 test_expect_success
$PREREQ '--compose-encoding adds correct MIME for subject' '
1269 clean_fake_sendmail &&
1270 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
1272 --compose-encoding iso-8859-2 \
1273 --compose --subject utf8-sübjëct \
1274 --from="Example <nobody@example.com>" \
1275 --to=nobody@example.com \
1276 --smtp-server="$(pwd)/fake.sendmail" \
1278 grep "^fake edit" msgtxt1 &&
1279 grep "^Subject: =?iso-8859-2?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
1282 test_expect_success
$PREREQ 'detects ambiguous reference/file conflict' '
1285 git commit -m"add main" &&
1286 test_must_fail git send-email --dry-run main 2>errors &&
1287 grep disambiguate errors
1290 test_expect_success
$PREREQ 'feed two files' '
1292 git format-patch -2 -o outdir &&
1295 --from="Example <nobody@example.com>" \
1296 --to=nobody@example.com \
1297 outdir/000?-*.patch 2>errors >out &&
1298 grep "^Subject: " out >subjects &&
1299 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
1300 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add main"
1303 test_expect_success
$PREREQ 'in-reply-to but no threading' '
1306 --from="Example <nobody@example.com>" \
1307 --to=nobody@example.com \
1308 --in-reply-to="<in-reply-id@example.com>" \
1311 grep "In-Reply-To: <in-reply-id@example.com>" out
1314 test_expect_success
$PREREQ 'no in-reply-to and no threading' '
1317 --from="Example <nobody@example.com>" \
1318 --to=nobody@example.com \
1321 ! grep "In-Reply-To: " stdout
1324 test_expect_success
$PREREQ 'threading but no chain-reply-to' '
1327 --from="Example <nobody@example.com>" \
1328 --to=nobody@example.com \
1330 --no-chain-reply-to \
1331 $patches $patches >stdout &&
1332 grep "In-Reply-To: " stdout
1335 test_expect_success
$PREREQ 'override in-reply-to if no threading' '
1338 --from="Example <nobody@example.com>" \
1339 --to=nobody@example.com \
1341 --in-reply-to="override" \
1342 $threaded_patches >stdout &&
1343 grep "In-Reply-To: <override>" stdout
1346 test_expect_success
$PREREQ 'sendemail.to works' '
1347 git config --replace-all sendemail.to "Somebody <somebody@ex.com>" &&
1350 --from="Example <nobody@example.com>" \
1352 grep "To: Somebody <somebody@ex.com>" stdout
1355 test_expect_success
$PREREQ 'setup sendemail.identity' '
1356 git config --replace-all sendemail.to "default@example.com" &&
1357 git config --replace-all sendemail.isp.to "isp@example.com" &&
1358 git config --replace-all sendemail.cloud.to "cloud@example.com"
1361 test_expect_success
$PREREQ 'sendemail.identity: reads the correct identity config' '
1362 git -c sendemail.identity=cloud send-email \
1364 --from="nobody@example.com" \
1366 grep "To: cloud@example.com" stdout
1369 test_expect_success
$PREREQ 'sendemail.identity: identity overrides sendemail.identity' '
1370 git -c sendemail.identity=cloud send-email \
1373 --from="nobody@example.com" \
1375 grep "To: isp@example.com" stdout
1378 test_expect_success
$PREREQ 'sendemail.identity: --no-identity clears previous identity' '
1379 git -c sendemail.identity=cloud send-email \
1382 --from="nobody@example.com" \
1384 grep "To: default@example.com" stdout
1387 test_expect_success
$PREREQ 'sendemail.identity: bool identity variable existence overrides' '
1388 git -c sendemail.identity=cloud \
1389 -c sendemail.xmailer=true \
1390 -c sendemail.cloud.xmailer=false \
1393 --from="nobody@example.com" \
1395 grep "To: cloud@example.com" stdout &&
1396 ! grep "X-Mailer" stdout
1399 test_expect_success
$PREREQ 'sendemail.identity: bool variable fallback' '
1400 git -c sendemail.identity=cloud \
1401 -c sendemail.xmailer=false \
1404 --from="nobody@example.com" \
1406 grep "To: cloud@example.com" stdout &&
1407 ! grep "X-Mailer" stdout
1410 test_expect_success
$PREREQ 'sendemail.identity: bool variable without a value' '
1411 git -c sendemail.xmailer \
1414 --from="nobody@example.com" \
1416 grep "To: default@example.com" stdout &&
1417 grep "X-Mailer" stdout
1420 test_expect_success
$PREREQ '--no-to overrides sendemail.to' '
1423 --from="Example <nobody@example.com>" \
1425 --to=nobody@example.com \
1427 grep "To: nobody@example.com" stdout &&
1428 ! grep "To: Somebody <somebody@ex.com>" stdout
1431 test_expect_success
$PREREQ 'sendemail.cc works' '
1432 git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" &&
1435 --from="Example <nobody@example.com>" \
1436 --to=nobody@example.com \
1438 grep "Cc: Somebody <somebody@ex.com>" stdout
1441 test_expect_success
$PREREQ '--no-cc overrides sendemail.cc' '
1444 --from="Example <nobody@example.com>" \
1446 --cc=bodies@example.com \
1447 --to=nobody@example.com \
1449 grep "Cc: bodies@example.com" stdout &&
1450 ! grep "Cc: Somebody <somebody@ex.com>" stdout
1453 test_expect_success
$PREREQ 'sendemail.bcc works' '
1454 git config --replace-all sendemail.bcc "Other <other@ex.com>" &&
1457 --from="Example <nobody@example.com>" \
1458 --to=nobody@example.com \
1459 --smtp-server relay.example.com \
1461 grep "RCPT TO:<other@ex.com>" stdout
1464 test_expect_success
$PREREQ '--no-bcc overrides sendemail.bcc' '
1467 --from="Example <nobody@example.com>" \
1469 --bcc=bodies@example.com \
1470 --to=nobody@example.com \
1471 --smtp-server relay.example.com \
1473 grep "RCPT TO:<bodies@example.com>" stdout &&
1474 ! grep "RCPT TO:<other@ex.com>" stdout
1477 test_expect_success
$PREREQ 'patches To headers are used by default' '
1478 patch=$(git format-patch -1 --to="bodies@example.com") &&
1479 test_when_finished "rm $patch" &&
1482 --from="Example <nobody@example.com>" \
1483 --smtp-server relay.example.com \
1485 grep "RCPT TO:<bodies@example.com>" stdout
1488 test_expect_success
$PREREQ 'patches To headers are appended to' '
1489 patch=$(git format-patch -1 --to="bodies@example.com") &&
1490 test_when_finished "rm $patch" &&
1493 --from="Example <nobody@example.com>" \
1494 --to=nobody@example.com \
1495 --smtp-server relay.example.com \
1497 grep "RCPT TO:<bodies@example.com>" stdout &&
1498 grep "RCPT TO:<nobody@example.com>" stdout
1501 test_expect_success
$PREREQ 'To headers from files reset each patch' '
1502 patch1=$(git format-patch -1 --to="bodies@example.com") &&
1503 patch2=$(git format-patch -1 --to="other@example.com" HEAD~) &&
1504 test_when_finished "rm $patch1 && rm $patch2" &&
1507 --from="Example <nobody@example.com>" \
1508 --to="nobody@example.com" \
1509 --smtp-server relay.example.com \
1510 $patch1 $patch2 >stdout &&
1511 test $(grep -c "RCPT TO:<bodies@example.com>" stdout) = 1 &&
1512 test $(grep -c "RCPT TO:<nobody@example.com>" stdout) = 2 &&
1513 test $(grep -c "RCPT TO:<other@example.com>" stdout) = 1
1516 test_expect_success
$PREREQ 'setup expect' '
1517 cat >email-using-8bit <<\EOF
1518 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1519 Message-ID: <bogus-message-id@example.com>
1520 From: author@example.com
1521 Date: Sat, 12 Jun 2010 15:53:58 +0200
1522 Subject: subject goes here
1524 Dieser deutsche Text enthält einen Umlaut!
1528 test_expect_success
$PREREQ 'setup expect' '
1529 echo "Subject: subject goes here" >expected
1532 test_expect_success
$PREREQ 'ASCII subject is not RFC2047 quoted' '
1533 clean_fake_sendmail &&
1535 git send-email --from=author@example.com --to=nobody@example.com \
1536 --smtp-server="$(pwd)/fake.sendmail" \
1537 --8bit-encoding=UTF-8 \
1538 email-using-8bit >stdout &&
1539 grep "Subject" msgtxt1 >actual &&
1540 test_cmp expected actual
1543 test_expect_success
$PREREQ 'setup expect' '
1544 cat >content-type-decl <<-\EOF
1546 Content-Type: text/plain; charset=UTF-8
1547 Content-Transfer-Encoding: 8bit
1551 test_expect_success
$PREREQ 'asks about and fixes 8bit encodings' '
1552 clean_fake_sendmail &&
1554 git send-email --from=author@example.com --to=nobody@example.com \
1555 --smtp-server="$(pwd)/fake.sendmail" \
1556 email-using-8bit >stdout &&
1557 grep "do not declare a Content-Transfer-Encoding" stdout &&
1558 grep email-using-8bit stdout &&
1559 grep "Which 8bit encoding" stdout &&
1560 grep -E "Content|MIME" msgtxt1 >actual &&
1561 test_cmp content-type-decl actual
1564 test_expect_success
$PREREQ 'sendemail.8bitEncoding works' '
1565 clean_fake_sendmail &&
1566 git config sendemail.assume8bitEncoding UTF-8 &&
1568 git send-email --from=author@example.com --to=nobody@example.com \
1569 --smtp-server="$(pwd)/fake.sendmail" \
1570 email-using-8bit >stdout &&
1571 grep -E "Content|MIME" msgtxt1 >actual &&
1572 test_cmp content-type-decl actual
1575 test_expect_success
$PREREQ 'sendemail.8bitEncoding in .git/config overrides --global .gitconfig' '
1576 clean_fake_sendmail &&
1577 git config sendemail.assume8bitEncoding UTF-8 &&
1578 test_when_finished "rm -rf home" &&
1580 git config -f home/.gitconfig sendemail.assume8bitEncoding "bogus too" &&
1582 env HOME="$(pwd)/home" DEBUG=1 \
1583 git send-email --from=author@example.com --to=nobody@example.com \
1584 --smtp-server="$(pwd)/fake.sendmail" \
1585 email-using-8bit >stdout &&
1586 grep -E "Content|MIME" msgtxt1 >actual &&
1587 test_cmp content-type-decl actual
1590 test_expect_success
$PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
1591 clean_fake_sendmail &&
1592 git config sendemail.assume8bitEncoding "bogus too" &&
1594 git send-email --from=author@example.com --to=nobody@example.com \
1595 --smtp-server="$(pwd)/fake.sendmail" \
1596 --8bit-encoding=UTF-8 \
1597 email-using-8bit >stdout &&
1598 grep -E "Content|MIME" msgtxt1 >actual &&
1599 test_cmp content-type-decl actual
1602 test_expect_success
$PREREQ 'setup expect' '
1603 cat >email-using-8bit <<-\EOF
1604 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1605 Message-ID: <bogus-message-id@example.com>
1606 From: author@example.com
1607 Date: Sat, 12 Jun 2010 15:53:58 +0200
1608 Subject: Dieser Betreff enthält auch einen Umlaut!
1610 Nothing to see here.
1614 test_expect_success
$PREREQ 'setup expect' '
1615 cat >expected <<-\EOF
1616 Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
1620 test_expect_success
$PREREQ '--8bit-encoding also treats subject' '
1621 clean_fake_sendmail &&
1623 git send-email --from=author@example.com --to=nobody@example.com \
1624 --smtp-server="$(pwd)/fake.sendmail" \
1625 --8bit-encoding=UTF-8 \
1626 email-using-8bit >stdout &&
1627 grep "Subject" msgtxt1 >actual &&
1628 test_cmp expected actual
1631 test_expect_success
$PREREQ 'setup expect' '
1632 cat >email-using-8bit <<-\EOF
1633 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1634 Message-ID: <bogus-message-id@example.com>
1635 From: A U Thor <author@example.com>
1636 Date: Sat, 12 Jun 2010 15:53:58 +0200
1637 Content-Type: text/plain; charset=UTF-8
1638 Subject: Nothing to see here.
1640 Dieser Betreff enthält auch einen Umlaut!
1644 test_expect_success
$PREREQ '--transfer-encoding overrides sendemail.transferEncoding' '
1645 clean_fake_sendmail &&
1646 test_must_fail git -c sendemail.transferEncoding=8bit \
1648 --transfer-encoding=7bit \
1649 --smtp-server="$(pwd)/fake.sendmail" \
1652 grep "cannot send message as 7bit" errors &&
1653 test -z "$(ls msgtxt*)"
1656 test_expect_success
$PREREQ 'sendemail.transferEncoding via config' '
1657 clean_fake_sendmail &&
1658 test_must_fail git -c sendemail.transferEncoding=7bit \
1660 --smtp-server="$(pwd)/fake.sendmail" \
1663 grep "cannot send message as 7bit" errors &&
1664 test -z "$(ls msgtxt*)"
1667 test_expect_success
$PREREQ 'sendemail.transferEncoding via cli' '
1668 clean_fake_sendmail &&
1669 test_must_fail git send-email \
1670 --transfer-encoding=7bit \
1671 --smtp-server="$(pwd)/fake.sendmail" \
1674 grep "cannot send message as 7bit" errors &&
1675 test -z "$(ls msgtxt*)"
1678 test_expect_success
$PREREQ 'setup expect' '
1679 cat >expected <<-\EOF
1680 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1684 test_expect_success
$PREREQ '8-bit and sendemail.transferencoding=quoted-printable' '
1685 clean_fake_sendmail &&
1687 --transfer-encoding=quoted-printable \
1688 --smtp-server="$(pwd)/fake.sendmail" \
1691 sed "1,/^$/d" msgtxt1 >actual &&
1692 test_cmp expected actual
1695 test_expect_success
$PREREQ 'setup expect' '
1696 cat >expected <<-\EOF
1697 RGllc2VyIEJldHJlZmYgZW50aMOkbHQgYXVjaCBlaW5lbiBVbWxhdXQhCg==
1701 test_expect_success
$PREREQ '8-bit and sendemail.transferencoding=base64' '
1702 clean_fake_sendmail &&
1704 --transfer-encoding=base64 \
1705 --smtp-server="$(pwd)/fake.sendmail" \
1708 sed "1,/^$/d" msgtxt1 >actual &&
1709 test_cmp expected actual
1712 test_expect_success
$PREREQ 'setup expect' '
1713 cat >email-using-qp <<-\EOF
1714 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1715 Message-ID: <bogus-message-id@example.com>
1716 From: A U Thor <author@example.com>
1717 Date: Sat, 12 Jun 2010 15:53:58 +0200
1719 Content-Transfer-Encoding: quoted-printable
1720 Content-Type: text/plain; charset=UTF-8
1721 Subject: Nothing to see here.
1723 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1727 test_expect_success
$PREREQ 'convert from quoted-printable to base64' '
1728 clean_fake_sendmail &&
1730 --transfer-encoding=base64 \
1731 --smtp-server="$(pwd)/fake.sendmail" \
1734 sed "1,/^$/d" msgtxt1 >actual &&
1735 test_cmp expected actual
1738 test_expect_success
$PREREQ 'setup expect' "
1739 tr -d '\\015' | tr '%' '\\015' >email-using-crlf <<EOF
1740 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1741 Message-ID: <bogus-message-id@example.com>
1742 From: A U Thor <author@example.com>
1743 Date: Sat, 12 Jun 2010 15:53:58 +0200
1744 Content-Type: text/plain; charset=UTF-8
1745 Subject: Nothing to see here.
1747 Look, I have a CRLF and an = sign!%
1751 test_expect_success
$PREREQ 'setup expect' '
1752 cat >expected <<-\EOF
1753 Look, I have a CRLF and an =3D sign!=0D
1757 test_expect_success
$PREREQ 'CRLF and sendemail.transferencoding=quoted-printable' '
1758 clean_fake_sendmail &&
1760 --transfer-encoding=quoted-printable \
1761 --smtp-server="$(pwd)/fake.sendmail" \
1764 sed "1,/^$/d" msgtxt1 >actual &&
1765 test_cmp expected actual
1768 test_expect_success
$PREREQ 'setup expect' '
1769 cat >expected <<-\EOF
1770 TG9vaywgSSBoYXZlIGEgQ1JMRiBhbmQgYW4gPSBzaWduIQ0K
1774 test_expect_success
$PREREQ 'CRLF and sendemail.transferencoding=base64' '
1775 clean_fake_sendmail &&
1777 --transfer-encoding=base64 \
1778 --smtp-server="$(pwd)/fake.sendmail" \
1781 sed "1,/^$/d" msgtxt1 >actual &&
1782 test_cmp expected actual
1786 # Note that the patches in this test are deliberately out of order; we
1787 # want to make sure it works even if the cover-letter is not in the
1789 test_expect_success
$PREREQ 'refusing to send cover letter template' '
1790 clean_fake_sendmail &&
1792 git format-patch --cover-letter -2 -o outdir &&
1793 test_must_fail git send-email \
1794 --from="Example <nobody@example.com>" \
1795 --to=nobody@example.com \
1796 --smtp-server="$(pwd)/fake.sendmail" \
1797 outdir/0002-*.patch \
1798 outdir/0000-*.patch \
1799 outdir/0001-*.patch \
1801 grep "SUBJECT HERE" errors &&
1802 test -z "$(ls msgtxt*)"
1805 test_expect_success
$PREREQ '--force sends cover letter template anyway' '
1806 clean_fake_sendmail &&
1808 git format-patch --cover-letter -2 -o outdir &&
1811 --from="Example <nobody@example.com>" \
1812 --to=nobody@example.com \
1813 --smtp-server="$(pwd)/fake.sendmail" \
1814 outdir/0002-*.patch \
1815 outdir/0000-*.patch \
1816 outdir/0001-*.patch \
1818 ! grep "SUBJECT HERE" errors &&
1819 test -n "$(ls msgtxt*)"
1822 test_cover_addresses
() {
1825 clean_fake_sendmail
&&
1827 git format-patch
--cover-letter -2 -o outdir
&&
1828 cover
=$
(echo outdir
/0000-*.
patch) &&
1829 mv $cover cover-to-edit.
patch &&
1830 perl
-pe "s/^From:/$header: extra\@address.com\nFrom:/" cover-to-edit.
patch >"$cover" &&
1833 --from="Example <nobody@example.com>" \
1836 --smtp-server="$(pwd)/fake.sendmail" \
1837 outdir
/0000-*.
patch \
1838 outdir
/0001-*.
patch \
1839 outdir
/0002-*.
patch \
1841 grep "^$header: extra@address.com" msgtxt1
>to1
&&
1842 grep "^$header: extra@address.com" msgtxt2
>to2
&&
1843 grep "^$header: extra@address.com" msgtxt3
>to3
&&
1844 test_line_count
= 1 to1
&&
1845 test_line_count
= 1 to2
&&
1846 test_line_count
= 1 to3
1849 test_expect_success
$PREREQ 'to-cover adds To to all mail' '
1850 test_cover_addresses "To" --to-cover
1853 test_expect_success
$PREREQ 'cc-cover adds Cc to all mail' '
1854 test_cover_addresses "Cc" --cc-cover
1857 test_expect_success
$PREREQ 'tocover adds To to all mail' '
1858 test_config sendemail.tocover true &&
1859 test_cover_addresses "To"
1862 test_expect_success
$PREREQ 'cccover adds Cc to all mail' '
1863 test_config sendemail.cccover true &&
1864 test_cover_addresses "Cc"
1867 test_expect_success
$PREREQ 'escaped quotes in sendemail.aliasfiletype=mutt' '
1868 clean_fake_sendmail &&
1869 echo "alias sbd \\\"Dot U. Sir\\\" <somebody@example.org>" >.mutt &&
1870 git config --replace-all sendemail.aliasesfile "$(pwd)/.mutt" &&
1871 git config sendemail.aliasfiletype mutt &&
1873 --from="Example <nobody@example.com>" \
1875 --smtp-server="$(pwd)/fake.sendmail" \
1876 outdir/0001-*.patch \
1878 grep "^!somebody@example\.org!$" commandline1 &&
1879 grep -F "To: \"Dot U. Sir\" <somebody@example.org>" out
1882 test_expect_success
$PREREQ 'sendemail.aliasfiletype=mailrc' '
1883 clean_fake_sendmail &&
1884 echo "alias sbd somebody@example.org" >.mailrc &&
1885 git config --replace-all sendemail.aliasesfile "$(pwd)/.mailrc" &&
1886 git config sendemail.aliasfiletype mailrc &&
1888 --from="Example <nobody@example.com>" \
1890 --smtp-server="$(pwd)/fake.sendmail" \
1891 outdir/0001-*.patch \
1893 grep "^!somebody@example\.org!$" commandline1
1896 test_expect_success
$PREREQ 'sendemail.aliasesfile=~/.mailrc' '
1897 clean_fake_sendmail &&
1898 echo "alias sbd someone@example.org" >"$HOME/.mailrc" &&
1899 git config --replace-all sendemail.aliasesfile "~/.mailrc" &&
1900 git config sendemail.aliasfiletype mailrc &&
1902 --from="Example <nobody@example.com>" \
1904 --smtp-server="$(pwd)/fake.sendmail" \
1905 outdir/0001-*.patch \
1907 grep "^!someone@example\.org!$" commandline1
1910 test_dump_aliases
() {
1911 msg
="$1" && shift &&
1912 filetype
="$1" && shift &&
1913 printf '%s\n' "$@" >expect
&&
1914 cat >.tmp-email-aliases
&&
1916 test_expect_success
$PREREQ "$msg" '
1917 clean_fake_sendmail && rm -fr outdir &&
1918 git config --replace-all sendemail.aliasesfile \
1919 "$(pwd)/.tmp-email-aliases" &&
1920 git config sendemail.aliasfiletype "$filetype" &&
1921 git send-email --dump-aliases 2>errors >actual &&
1922 test_cmp expect actual
1926 test_dump_aliases
'--dump-aliases sendmail format' \
1933 alice: Alice W Land <awol@example.com>
1934 bob: Robert Bobbyton <bob@example.com>
1935 chloe: chloe@example.com
1937 bcgrp: bob, chloe, Other <o@example.com>
1940 test_dump_aliases '--dump-aliases mutt format' \
1946 alias alice Alice W Land <awol@example.com>
1947 alias donald Donald C Carlton <donc@example.com>
1948 alias bob Robert Bobbyton <bob@example.com>
1949 alias chloe chloe@example.com
1952 test_dump_aliases '--dump-aliases mailrc format' \
1958 alias alice Alice W Land <awol@example.com>
1959 alias eve Eve <eve@example.com>
1960 alias bob Robert Bobbyton <bob@example.com>
1961 alias chloe chloe@example.com
1964 test_dump_aliases '--dump-aliases pine format' \
1970 alice Alice W Land <awol@example.com>
1971 eve Eve <eve@example.com>
1972 bob Robert Bobbyton <bob@example.com>
1973 chloe chloe@example.com
1976 test_dump_aliases '--dump-aliases gnus format' \
1982 (define-mail-alias "alice" "awol@example.com")
1983 (define-mail-alias "eve" "eve@example.com")
1984 (define-mail-alias "bob" "bob@example.com")
1985 (define-mail-alias "chloe" "chloe@example.com")
1988 test_expect_success '--dump-aliases must be used alone' '
1989 test_must_fail git send-email --dump-aliases --to=janice@example.com -1 refs/heads/accounting
1992 test_expect_success $PREREQ 'aliases and sendemail.identity' '
1993 test_must_fail git \
1994 -c sendemail.identity=cloud \
1995 -c sendemail.aliasesfile=default-aliases \
1996 -c sendemail.cloud.aliasesfile=cloud-aliases \
1997 send-email -1 2>stderr &&
1998 test_i18ngrep "cloud-aliases" stderr
2001 test_sendmail_aliases () {
2002 msg="$1" && shift &&
2004 cat >.tmp-email-aliases &&
2006 test_expect_success $PREREQ "$msg" '
2007 clean_fake_sendmail && rm -fr outdir &&
2008 git format-patch -1 -o outdir &&
2009 git config --replace-all sendemail.aliasesfile \
2010 "$(pwd)/.tmp-email-aliases" &&
2011 git config sendemail.aliasfiletype sendmail &&
2013 --from="Example <nobody@example.com>" \
2014 --to=alice --to=bcgrp \
2015 --smtp-server="$(pwd)/fake.sendmail" \
2016 outdir/0001-*.
patch \
2020 grep "^!$i!$" commandline1 ||
return 1
2025 test_sendmail_aliases 'sendemail.aliasfiletype
=sendmail
' \
2026 'awol@example\.com
' \
2027 'bob@example\.com
' \
2028 'chloe@example\.com
' \
2029 'o@example\.com
' <<-\EOF
2030 alice: Alice W Land <awol@example.com>
2031 bob: Robert Bobbyton <bob@example.com>
2033 # this is also a comment
2034 chloe: chloe@example.com
2036 bcgrp: bob, chloe, Other <o@example.com>
2039 test_sendmail_aliases 'sendmail aliases line folding
' \
2043 darla1 darla2 darla3 \
2044 elton1 elton2 elton3 \
2061 bcgrp: bob, chuck, darla, elton, fred, greg
2064 test_sendmail_aliases 'sendmail aliases tolerate bogus line folding
' \
2070 test_sendmail_aliases 'sendmail aliases empty
' alice bcgrp <<-\EOF
2073 test_expect_success $PREREQ 'alias support
in To header
' '
2074 clean_fake_sendmail
&&
2075 echo "alias sbd someone@example.org" >.mailrc
&&
2076 test_config sendemail.aliasesfile
".mailrc" &&
2077 test_config sendemail.aliasfiletype mailrc
&&
2078 git format-patch
--stdout -1 --to=sbd
>aliased.
patch &&
2080 --from="Example <nobody@example.com>" \
2081 --smtp-server="$(pwd)/fake.sendmail" \
2084 grep "^!someone@example\.org!$" commandline1
2087 test_expect_success $PREREQ 'alias support
in Cc header
' '
2088 clean_fake_sendmail
&&
2089 echo "alias sbd someone@example.org" >.mailrc
&&
2090 test_config sendemail.aliasesfile
".mailrc" &&
2091 test_config sendemail.aliasfiletype mailrc
&&
2092 git format-patch
--stdout -1 --cc=sbd
>aliased.
patch &&
2094 --from="Example <nobody@example.com>" \
2095 --smtp-server="$(pwd)/fake.sendmail" \
2098 grep "^!someone@example\.org!$" commandline1
2101 test_expect_success $PREREQ 'tocmd works with aliases
' '
2102 clean_fake_sendmail
&&
2103 echo "alias sbd someone@example.org" >.mailrc
&&
2104 test_config sendemail.aliasesfile
".mailrc" &&
2105 test_config sendemail.aliasfiletype mailrc
&&
2106 git format-patch
--stdout -1 >tocmd.
patch &&
2107 echo tocmd--sbd
>>tocmd.
patch &&
2109 --from="Example <nobody@example.com>" \
2110 --to-cmd=.
/tocmd-sed \
2111 --smtp-server="$(pwd)/fake.sendmail" \
2114 grep "^!someone@example\.org!$" commandline1
2117 test_expect_success $PREREQ 'cccmd works with aliases
' '
2118 clean_fake_sendmail
&&
2119 echo "alias sbd someone@example.org" >.mailrc
&&
2120 test_config sendemail.aliasesfile
".mailrc" &&
2121 test_config sendemail.aliasfiletype mailrc
&&
2122 git format-patch
--stdout -1 >cccmd.
patch &&
2123 echo cccmd--sbd
>>cccmd.
patch &&
2125 --from="Example <nobody@example.com>" \
2126 --cc-cmd=.
/cccmd-sed \
2127 --smtp-server="$(pwd)/fake.sendmail" \
2130 grep "^!someone@example\.org!$" commandline1
2133 do_xmailer_test () {
2134 expected=$1 params=$2 &&
2135 git format-patch -1 &&
2137 --from="Example <nobody@example.com>" \
2138 --to=someone@example.com \
2139 --smtp-server="$(pwd)/fake.sendmail" \
2143 { grep '^X-Mailer
:' out || :; } >mailer &&
2144 test_line_count = $expected mailer
2147 test_expect_success $PREREQ '--[no-
]xmailer without any configuration
' '
2148 do_xmailer_test
1 "--xmailer" &&
2149 do_xmailer_test
0 "--no-xmailer"
2152 test_expect_success $PREREQ '--[no-
]xmailer with sendemail.xmailer
=true
' '
2153 test_config sendemail.xmailer true
&&
2154 do_xmailer_test
1 "" &&
2155 do_xmailer_test
0 "--no-xmailer" &&
2156 do_xmailer_test
1 "--xmailer"
2159 test_expect_success $PREREQ '--[no-
]xmailer with sendemail.xmailer
' '
2160 test_when_finished
"test_unconfig sendemail.xmailer" &&
2161 cat >>.git
/config
<<-\EOF &&
2165 test_config sendemail.xmailer true &&
2166 do_xmailer_test 1 "" &&
2167 do_xmailer_test 0 "--no-xmailer" &&
2168 do_xmailer_test 1 "--xmailer"
2171 test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=false' '
2172 test_config sendemail.xmailer false &&
2173 do_xmailer_test 0 "" &&
2174 do_xmailer_test 0 "--no-xmailer" &&
2175 do_xmailer_test 1 "--xmailer"
2178 test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=' '
2179 test_config sendemail.xmailer "" &&
2180 do_xmailer_test 0 "" &&
2181 do_xmailer_test 0 "--no-xmailer" &&
2182 do_xmailer_test 1 "--xmailer"
2185 test_expect_success $PREREQ 'setup expected-list' '
2188 --from="Example <from@example.com>" \
2189 --to="To 1 <to1@example.com>" \
2190 --to="to2@example.com" \
2191 --to="to3@example.com" \
2192 --cc="Cc 1 <cc1@example.com>" \
2193 --cc="Cc2 <cc2@example.com>" \
2194 --bcc="bcc1@example.com" \
2195 --bcc="bcc2@example.com" \
2196 0001-add-main.patch | replace_variable_fields \
2200 test_expect_success $PREREQ 'use email list in --cc --to and --bcc' '
2203 --from="Example <from@example.com>" \
2204 --to="To 1 <to1@example.com>, to2@example.com" \
2205 --to="to3@example.com" \
2206 --cc="Cc 1 <cc1@example.com>, Cc2 <cc2@example.com>" \
2207 --bcc="bcc1@example.com, bcc2@example.com" \
2208 0001-add-main.patch | replace_variable_fields \
2210 test_cmp expected-list actual-list
2213 test_expect_success $PREREQ 'aliases work with email list' '
2214 echo "alias to2 to2@example.com" >.mutt &&
2215 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt &&
2216 test_config sendemail.aliasesfile ".mutt" &&
2217 test_config sendemail.aliasfiletype mutt &&
2220 --from="Example <from@example.com>" \
2221 --to="To 1 <to1@example.com>, to2, to3@example.com" \
2222 --cc="cc1, Cc2 <cc2@example.com>" \
2223 --bcc="bcc1@example.com, bcc2@example.com" \
2224 0001-add-main.patch | replace_variable_fields \
2226 test_cmp expected-list actual-list
2229 test_expect_success $PREREQ 'leading and trailing whitespaces are removed' '
2230 echo "alias to2 to2@example.com" >.mutt &&
2231 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt &&
2232 test_config sendemail.aliasesfile ".mutt" &&
2233 test_config sendemail.aliasfiletype mutt &&
2234 TO1=$(echo "QTo 1 <to1@example.com>" | q_to_tab) &&
2235 TO2=$(echo "QZto2" | qz_to_tab_space) &&
2236 CC1=$(echo "cc1" | append_cr) &&
2237 BCC1=$(echo " bcc1@example.com Q" | q_to_nul) &&
2240 --from=" Example <from@example.com>" \
2243 --to=" to3@example.com " \
2245 --cc="Cc2 <cc2@example.com>" \
2247 --bcc="bcc2@example.com" \
2248 0001-add-main.patch | replace_variable_fields \
2250 test_cmp expected-list actual-list
2253 test_expect_success $PREREQ 'test using command name with --sendmail-cmd' '
2254 clean_fake_sendmail &&
2257 --from="Example <nobody@example.com>" \
2258 --to=nobody@example.com \
2259 --sendmail-cmd="fake.sendmail" \
2261 test_path_is_file commandline1
2264 test_expect_success $PREREQ 'test using arguments with --sendmail-cmd' '
2265 clean_fake_sendmail &&
2267 --from="Example <nobody@example.com>" \
2268 --to=nobody@example.com \
2269 --sendmail-cmd='\''"$(pwd)/fake.sendmail" -f nobody@example.com'\'' \
2271 test_path_is_file commandline1
2274 test_expect_success $PREREQ 'test shell expression with --sendmail-cmd' '
2275 clean_fake_sendmail &&
2277 --from="Example <nobody@example.com>" \
2278 --to=nobody@example.com \
2279 --sendmail-cmd='\''f() { "$(pwd)/fake.sendmail" "$@"; };f'\'' \
2281 test_path_is_file commandline1
2284 test_expect_success $PREREQ 'set up in-reply-to/references patches' '
2285 cat >has-reply.patch <<-\
EOF &&
2286 From: A U Thor <author@example.com>
2287 Subject: patch with in-reply-to
2288 Message-ID: <patch.with.in.reply.to@example.com>
2289 In-Reply-To: <replied.to@example.com>
2290 References: <replied.to@example.com>
2294 cat >no-reply.patch <<-\EOF
2295 From: A U Thor <author@example.com>
2296 Subject: patch without in-reply-to
2297 Message-ID: <patch.without.in.reply.to@example.com>
2303 test_expect_success $PREREQ 'patch reply headers correct with --no-thread' '
2304 clean_fake_sendmail &&
2307 --to=nobody@example.com \
2308 --smtp-server="$(pwd)/fake.sendmail" \
2309 has-reply.patch no-reply.patch &&
2310 grep "In-Reply-To: <replied.to@example.com>" msgtxt1 &&
2311 grep "References: <replied.to@example.com>" msgtxt1 &&
2312 ! grep replied.to@example.com msgtxt2
2315 test_expect_success $PREREQ 'cmdline in-reply-to used with --no-thread' '
2316 clean_fake_sendmail &&
2319 --in-reply-to="<cmdline.reply@example.com>" \
2320 --to=nobody@example.com \
2321 --smtp-server="$(pwd)/fake.sendmail" \
2322 has-reply.patch no-reply.patch &&
2323 grep "In-Reply-To: <cmdline.reply@example.com>" msgtxt1 &&
2324 grep "References: <cmdline.reply@example.com>" msgtxt1 &&
2325 grep "In-Reply-To: <cmdline.reply@example.com>" msgtxt2 &&
2326 grep "References: <cmdline.reply@example.com>" msgtxt2
2329 test_expect_success $PREREQ 'invoke hook' '
2330 test_hook sendemail-validate <<-\EOF &&
2331 # test that we have the correct environment variable, pwd, and
2341 test -f 0001-add-main.patch &&
2342 grep "add main" "$1"
2347 # Test that it works even if we are not at the root of the
2351 --from="Example <nobody@example.com>" \
2352 --to=nobody@example.com \
2353 --smtp-server="$(pwd)/../fake.sendmail" \
2354 ../0001-add-main.patch &&
2356 # Verify error message when a patch is rejected by the hook
2357 sed -e "s/add main/x/" ../0001-add-main.patch >../another.patch &&
2358 test_must_fail git send-email \
2359 --from="Example <nobody@example.com>" \
2360 --to=nobody@example.com \
2361 --smtp-server="$(pwd)/../fake.sendmail" \
2362 ../another.patch 2>err &&
2363 test_i18ngrep "rejected by sendemail-validate hook" err
2367 test_expect_success $PREREQ 'test that send-email works outside a repo' '
2368 nongit git send-email \
2369 --from="Example <nobody@example.com>" \
2370 --to=nobody@example.com \
2371 --smtp-server="$(pwd)/fake.sendmail" \
2372 "$(pwd)/0001-add-main.patch"
2375 test_expect_success $PREREQ 'send-email relays -v 3 to format-patch' '
2376 test_when_finished "rm -f out" &&
2377 git send-email --dry-run -v 3 -1 >out &&
2381 test_expect_success $PREREQ 'test that sendmail config is rejected' '
2382 test_config sendmail.program sendmail &&
2383 test_must_fail git send-email \
2384 --from="Example <nobody@example.com>" \
2385 --to=nobody@example.com \
2386 --smtp-server="$(pwd)/fake.sendmail" \
2388 test_i18ngrep "found configuration options for '"'"sendmail"'"'" err
2391 test_expect_success $PREREQ 'test that sendmail config rejection is specific' '
2392 test_config resendmail.program sendmail &&
2394 --from="Example <nobody@example.com>" \
2395 --to=nobody@example.com \
2396 --smtp-server="$(pwd)/fake.sendmail" \
2400 test_expect_success $PREREQ 'test forbidSendmailVariables behavior override' '
2401 test_config sendmail.program sendmail &&
2402 test_config sendemail.forbidSendmailVariables false &&
2404 --from="Example <nobody@example.com>" \
2405 --to=nobody@example.com \
2406 --smtp-server="$(pwd)/fake.sendmail" \