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" &&
340 echo "my-message-id@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 &&
347 grep "^In-Reply-To: <my-message-id@example.com>" msgtxt1
350 test_expect_success
$PREREQ,AUTOIDENT
'implicit ident is allowed' '
351 clean_fake_sendmail &&
352 (sane_unset GIT_AUTHOR_NAME &&
353 sane_unset GIT_AUTHOR_EMAIL &&
354 sane_unset GIT_COMMITTER_NAME &&
355 sane_unset GIT_COMMITTER_EMAIL &&
356 GIT_SEND_EMAIL_NOTTY=1 git send-email \
357 --smtp-server="$(pwd)/fake.sendmail" \
358 --to=to@example.com \
359 $patches </dev/null 2>errors
363 test_expect_success
$PREREQ,!AUTOIDENT
'broken implicit ident aborts send-email' '
364 clean_fake_sendmail &&
365 (sane_unset GIT_AUTHOR_NAME &&
366 sane_unset GIT_AUTHOR_EMAIL &&
367 sane_unset GIT_COMMITTER_NAME &&
368 sane_unset GIT_COMMITTER_EMAIL &&
369 GIT_SEND_EMAIL_NOTTY=1 && export GIT_SEND_EMAIL_NOTTY &&
370 test_must_fail git send-email \
371 --smtp-server="$(pwd)/fake.sendmail" \
372 --to=to@example.com \
373 $patches </dev/null 2>errors &&
374 test_grep "tell me who you are" errors
378 test_expect_success
$PREREQ 'setup cmd scripts' '
379 write_script tocmd-sed <<-\EOF &&
380 sed -n -e "s/^tocmd--//p" "$1"
382 write_script cccmd-sed <<-\EOF &&
383 sed -n -e "s/^cccmd--//p" "$1"
385 write_script headercmd-sed <<-\EOF
386 sed -n -e "s/^headercmd--//p" "$1"
390 test_expect_success
$PREREQ 'tocmd works' '
391 clean_fake_sendmail &&
392 cp $patches tocmd.patch &&
393 echo tocmd--tocmd@example.com >>tocmd.patch &&
395 --from="Example <nobody@example.com>" \
396 --to-cmd=./tocmd-sed \
397 --smtp-server="$(pwd)/fake.sendmail" \
400 grep "^To: tocmd@example.com" msgtxt1
403 test_expect_success
$PREREQ 'cccmd works' '
404 clean_fake_sendmail &&
405 cp $patches cccmd.patch &&
406 echo "cccmd-- cccmd@example.com" >>cccmd.patch &&
408 --from="Example <nobody@example.com>" \
409 --to=nobody@example.com \
410 --cc-cmd=./cccmd-sed \
411 --smtp-server="$(pwd)/fake.sendmail" \
414 grep "^ cccmd@example.com" msgtxt1
417 test_expect_success
$PREREQ 'headercmd works' '
418 clean_fake_sendmail &&
419 cp $patches headercmd.patch &&
420 echo "headercmd--X-Debbugs-CC: dummy@example.com" >>headercmd.patch &&
422 --from="Example <nobody@example.com>" \
423 --to=nobody@example.com \
424 --header-cmd=./headercmd-sed \
425 --smtp-server="$(pwd)/fake.sendmail" \
428 grep "^X-Debbugs-CC: dummy@example.com" msgtxt1
431 test_expect_success
$PREREQ '--no-header-cmd works' '
432 clean_fake_sendmail &&
433 cp $patches headercmd.patch &&
434 echo "headercmd--X-Debbugs-CC: dummy@example.com" >>headercmd.patch &&
436 --from="Example <nobody@example.com>" \
437 --to=nobody@example.com \
438 --header-cmd=./headercmd-sed \
440 --smtp-server="$(pwd)/fake.sendmail" \
443 ! grep "^X-Debbugs-CC: dummy@example.com" msgtxt1
446 test_expect_success
$PREREQ 'multiline fields are correctly unfolded' '
447 clean_fake_sendmail &&
448 cp $patches headercmd.patch &&
449 write_script headercmd-multiline <<-\EOF &&
450 echo "X-Debbugs-CC: someone@example.com
451 FoldedField: This is a tale
456 --from="Example <nobody@example.com>" \
457 --to=nobody@example.com \
458 --header-cmd=./headercmd-multiline \
459 --smtp-server="$(pwd)/fake.sendmail" \
461 grep "^FoldedField: This is a tale best told using multiple lines.$" msgtxt1
464 # Blank lines in the middle of the output of a command are invalid.
465 test_expect_success
$PREREQ 'malform output reported on blank lines in command output' '
466 clean_fake_sendmail &&
467 cp $patches headercmd.patch &&
468 write_script headercmd-malformed-output <<-\EOF &&
469 echo "X-Debbugs-CC: someone@example.com
471 SomeOtherField: someone-else@example.com"
474 --from="Example <nobody@example.com>" \
475 --to=nobody@example.com \
476 --header-cmd=./headercmd-malformed-output \
477 --smtp-server="$(pwd)/fake.sendmail" \
481 test_expect_success
$PREREQ 'reject long lines' '
483 z64=$z8$z8$z8$z8$z8$z8$z8$z8 &&
484 z512=$z64$z64$z64$z64$z64$z64$z64$z64 &&
485 clean_fake_sendmail &&
486 cp $patches longline.patch &&
487 cat >>longline.patch <<-EOF &&
492 test_must_fail git send-email \
493 --from="Example <nobody@example.com>" \
494 --to=nobody@example.com \
495 --smtp-server="$(pwd)/fake.sendmail" \
496 --transfer-encoding=8bit \
497 $patches longline.patch \
499 cat >expect <<-\EOF &&
500 fatal: longline.patch:35 is longer than 998 characters
501 warning: no patches were sent
503 test_cmp expect actual
506 test_expect_success
$PREREQ 'no patch was sent' '
507 ! test -e commandline1
510 test_expect_success
$PREREQ 'Author From: in message body' '
511 clean_fake_sendmail &&
513 --from="Example <nobody@example.com>" \
514 --to=nobody@example.com \
515 --smtp-server="$(pwd)/fake.sendmail" \
517 sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
518 grep "From: A <author@example.com>" msgbody1
521 test_expect_success
$PREREQ 'Author From: not in message body' '
522 clean_fake_sendmail &&
524 --from="A <author@example.com>" \
525 --to=nobody@example.com \
526 --smtp-server="$(pwd)/fake.sendmail" \
528 sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
529 ! grep "From: A <author@example.com>" msgbody1
532 test_expect_success
$PREREQ 'allow long lines with --no-validate' '
534 --from="Example <nobody@example.com>" \
535 --to=nobody@example.com \
536 --smtp-server="$(pwd)/fake.sendmail" \
538 $patches longline.patch \
542 test_expect_success
$PREREQ 'short lines with auto encoding are 8bit' '
543 clean_fake_sendmail &&
545 --from="A <author@example.com>" \
546 --to=nobody@example.com \
547 --smtp-server="$(pwd)/fake.sendmail" \
548 --transfer-encoding=auto \
550 grep "Content-Transfer-Encoding: 8bit" msgtxt1
553 test_expect_success
$PREREQ 'long lines with auto encoding are quoted-printable' '
554 clean_fake_sendmail &&
556 --from="Example <nobody@example.com>" \
557 --to=nobody@example.com \
558 --smtp-server="$(pwd)/fake.sendmail" \
559 --transfer-encoding=auto \
562 grep "Content-Transfer-Encoding: quoted-printable" msgtxt1
565 test_expect_success
$PREREQ 'carriage returns with auto encoding are quoted-printable' '
566 clean_fake_sendmail &&
567 cp $patches cr.patch &&
568 printf "this is a line\r\n" >>cr.patch &&
570 --from="Example <nobody@example.com>" \
571 --to=nobody@example.com \
572 --smtp-server="$(pwd)/fake.sendmail" \
573 --transfer-encoding=auto \
576 grep "Content-Transfer-Encoding: quoted-printable" msgtxt1
579 for enc
in auto quoted-printable base64
581 test_expect_success
$PREREQ "--validate passes with encoding $enc" '
583 --from="Example <nobody@example.com>" \
584 --to=nobody@example.com \
585 --smtp-server="$(pwd)/fake.sendmail" \
586 --transfer-encoding=$enc \
588 $patches longline.patch
593 test_expect_success
$PREREQ "--validate respects relative core.hooksPath path" '
594 clean_fake_sendmail &&
596 test_when_finished "rm my-hooks.ran" &&
597 write_script my-hooks/sendemail-validate <<-\EOF &&
601 test_config core.hooksPath "my-hooks" &&
602 test_must_fail git send-email \
603 --from="Example <nobody@example.com>" \
604 --to=nobody@example.com \
605 --smtp-server="$(pwd)/fake.sendmail" \
607 longline.patch 2>actual &&
608 test_path_is_file my-hooks.ran &&
609 cat >expect <<-EOF &&
610 fatal: longline.patch: rejected by sendemail-validate hook
611 fatal: command '"'"'git hook run --ignore-missing sendemail-validate -- <patch> <header>'"'"' died with exit code 1
612 warning: no patches were sent
614 test_cmp expect actual
617 test_expect_success
$PREREQ "--validate respects absolute core.hooksPath path" '
618 hooks_path="$(pwd)/my-hooks" &&
619 test_config core.hooksPath "$hooks_path" &&
620 test_when_finished "rm my-hooks.ran" &&
621 test_must_fail git send-email \
622 --from="Example <nobody@example.com>" \
623 --to=nobody@example.com \
624 --smtp-server="$(pwd)/fake.sendmail" \
626 longline.patch 2>actual &&
627 test_path_is_file my-hooks.ran &&
628 cat >expect <<-EOF &&
629 fatal: longline.patch: rejected by sendemail-validate hook
630 fatal: command '"'"'git hook run --ignore-missing sendemail-validate -- <patch> <header>'"'"' died with exit code 1
631 warning: no patches were sent
633 test_cmp expect actual
636 test_expect_success
$PREREQ "--validate hook supports multiple addresses in arguments" '
637 hooks_path="$(pwd)/my-hooks" &&
638 test_config core.hooksPath "$hooks_path" &&
639 test_when_finished "rm my-hooks.ran" &&
640 test_must_fail git send-email \
641 --from="Example <nobody@example.com>" \
642 --to=nobody@example.com,abc@example.com \
643 --smtp-server="$(pwd)/fake.sendmail" \
645 longline.patch 2>actual &&
646 test_path_is_file my-hooks.ran &&
647 cat >expect <<-EOF &&
648 fatal: longline.patch: rejected by sendemail-validate hook
649 fatal: command '"'"'git hook run --ignore-missing sendemail-validate -- <patch> <header>'"'"' died with exit code 1
650 warning: no patches were sent
652 test_cmp expect actual
655 test_expect_success
$PREREQ "--validate hook supports header argument" '
656 write_script my-hooks/sendemail-validate <<-\EOF &&
659 grep "X-test-header: v1.0" "$2"
661 echo "No header arg passed"
665 test_config core.hooksPath "my-hooks" &&
668 --add-header="X-test-header: v1.0" \
669 -n HEAD^1 -o outdir &&
672 --to=nobody@example.com \
673 --smtp-server="$(pwd)/fake.sendmail" \
678 test_expect_success
$PREREQ 'clear message-id before parsing a new message' '
679 clean_fake_sendmail &&
680 echo true | write_script my-hooks/sendemail-validate &&
681 test_config core.hooksPath my-hooks &&
682 git send-email --validate --to=recipient@example.com \
683 --smtp-server="$(pwd)/fake.sendmail" \
684 $patches $threaded_patches &&
685 id0=$(grep "^Message-ID: " $threaded_patches) &&
686 id1=$(grep "^Message-ID: " msgtxt1) &&
687 id2=$(grep "^Message-ID: " msgtxt2) &&
688 test "z$id0" = "z$id2" &&
689 test "z$id1" != "z$id2"
692 for enc
in 7bit
8bit quoted-printable base64
694 test_expect_success
$PREREQ "--transfer-encoding=$enc produces correct header" '
695 clean_fake_sendmail &&
697 --from="Example <nobody@example.com>" \
698 --to=nobody@example.com \
699 --smtp-server="$(pwd)/fake.sendmail" \
700 --transfer-encoding=$enc \
702 grep "Content-Transfer-Encoding: $enc" msgtxt1
706 test_expect_success
$PREREQ 'Invalid In-Reply-To' '
707 clean_fake_sendmail &&
709 --from="Example <nobody@example.com>" \
710 --to=nobody@example.com \
712 --smtp-server="$(pwd)/fake.sendmail" \
715 ! grep "^In-Reply-To: < *>" msgtxt1
718 test_expect_success
$PREREQ 'Valid In-Reply-To when prompting' '
719 clean_fake_sendmail &&
720 (echo "From Example <from@example.com>" &&
721 echo "To Example <to@example.com>" &&
723 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
724 --smtp-server="$(pwd)/fake.sendmail" \
726 ! grep "^In-Reply-To: < *>" msgtxt1
729 test_expect_success
$PREREQ 'In-Reply-To without --chain-reply-to' '
730 clean_fake_sendmail &&
731 echo "<unique-message-id@example.com>" >expect &&
733 --from="Example <nobody@example.com>" \
734 --to=nobody@example.com \
735 --no-chain-reply-to \
736 --in-reply-to="$(cat expect)" \
737 --smtp-server="$(pwd)/fake.sendmail" \
738 $patches $patches $patches \
740 # The first message is a reply to --in-reply-to
741 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
742 test_cmp expect actual &&
743 # Second and subsequent messages are replies to the first one
744 sed -n -e "s/^Message-ID: *\(.*\)/\1/p" msgtxt1 >expect &&
745 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
746 test_cmp expect actual &&
747 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
748 test_cmp expect actual
751 test_expect_success
$PREREQ 'In-Reply-To with --chain-reply-to' '
752 clean_fake_sendmail &&
753 echo "<unique-message-id@example.com>" >expect &&
755 --from="Example <nobody@example.com>" \
756 --to=nobody@example.com \
758 --in-reply-to="$(cat expect)" \
759 --smtp-server="$(pwd)/fake.sendmail" \
760 $patches $patches $patches \
762 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
763 test_cmp expect actual &&
764 sed -n -e "s/^Message-ID: *\(.*\)/\1/p" msgtxt1 >expect &&
765 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
766 test_cmp expect actual &&
767 sed -n -e "s/^Message-ID: *\(.*\)/\1/p" msgtxt2 >expect &&
768 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
769 test_cmp expect actual
772 test_set_editor
"$(pwd)/fake-editor"
774 test_expect_success
$PREREQ 'setup erroring fake editor' '
775 write_script fake-editor <<-\EOF
776 echo >&2 "I am about to error"
781 test_expect_success
$PREREQ 'fake editor dies with error' '
782 clean_fake_sendmail &&
783 test_must_fail git send-email \
784 --compose --subject foo \
785 --from="Example <nobody@example.com>" \
786 --to=nobody@example.com \
787 --smtp-server="$(pwd)/fake.sendmail" \
789 grep "I am about to error" err &&
790 grep "the editor exited uncleanly, aborting everything" err
793 test_expect_success
$PREREQ 'setup fake editor' '
794 write_script fake-editor <<-\EOF
795 echo fake edit >>"$1"
799 test_expect_success
$PREREQ '--compose works' '
800 clean_fake_sendmail &&
802 --compose --subject foo \
803 --from="Example <nobody@example.com>" \
804 --to=nobody@example.com \
805 --smtp-server="$(pwd)/fake.sendmail" \
810 test_expect_success
$PREREQ 'first message is compose text' '
811 grep "^fake edit" msgtxt1
814 test_expect_success
$PREREQ 'second message is patch' '
815 grep "Subject:.*Second" msgtxt2
818 test_expect_success
$PREREQ 'setup expect' "
819 cat >expected-suppress-sob <<\EOF
821 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
822 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
823 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
825 Server: relay.example.com
826 MAIL FROM:<from@example.com>
827 RCPT TO:<to@example.com>
828 RCPT TO:<cc@example.com>
829 RCPT TO:<author@example.com>
830 RCPT TO:<one@example.com>
831 RCPT TO:<two@example.com>
832 From: Example <from@example.com>
835 A <author@example.com>,
836 One <one@example.com>,
838 Subject: [PATCH 1/1] Second.
840 Message-ID: MESSAGE-ID-STRING
841 X-Mailer: X-MAILER-STRING
843 Content-Transfer-Encoding: 8bit
849 test_suppression
() {
852 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
853 --from="Example <from@example.com>" \
854 --to=to@example.com \
855 --smtp-server relay.example.com \
856 $patches | replace_variable_fields \
857 >actual-suppress-
$1${2+"-$2"} &&
858 test_cmp expected-suppress-
$1${2+"-$2"} actual-suppress-
$1${2+"-$2"}
861 test_expect_success
$PREREQ 'sendemail.cc set' '
862 git config sendemail.cc cc@example.com &&
866 test_expect_success
$PREREQ 'setup expect' "
867 cat >expected-suppress-sob <<\EOF
869 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
870 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
871 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
873 Server: relay.example.com
874 MAIL FROM:<from@example.com>
875 RCPT TO:<to@example.com>
876 RCPT TO:<author@example.com>
877 RCPT TO:<one@example.com>
878 RCPT TO:<two@example.com>
879 From: Example <from@example.com>
881 Cc: A <author@example.com>,
882 One <one@example.com>,
884 Subject: [PATCH 1/1] Second.
886 Message-ID: MESSAGE-ID-STRING
887 X-Mailer: X-MAILER-STRING
889 Content-Transfer-Encoding: 8bit
895 test_expect_success
$PREREQ 'sendemail.cc unset' '
896 git config --unset sendemail.cc &&
900 test_expect_success
$PREREQ 'setup expect' "
901 cat >expected-suppress-cccmd <<\EOF
903 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
904 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
905 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
906 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
908 Server: relay.example.com
909 MAIL FROM:<from@example.com>
910 RCPT TO:<to@example.com>
911 RCPT TO:<author@example.com>
912 RCPT TO:<one@example.com>
913 RCPT TO:<two@example.com>
914 RCPT TO:<committer@example.com>
915 From: Example <from@example.com>
917 Cc: A <author@example.com>,
918 One <one@example.com>,
920 C O Mitter <committer@example.com>
921 Subject: [PATCH 1/1] Second.
923 Message-ID: MESSAGE-ID-STRING
924 X-Mailer: X-MAILER-STRING
926 Content-Transfer-Encoding: 8bit
932 test_expect_success
$PREREQ 'sendemail.cccmd' '
933 write_script cccmd <<-\EOF &&
934 echo cc-cmd@example.com
936 git config sendemail.cccmd ./cccmd &&
937 test_suppression cccmd
940 test_expect_success
$PREREQ 'setup expect' '
941 cat >expected-suppress-all <<\EOF
944 Server: relay.example.com
945 MAIL FROM:<from@example.com>
946 RCPT TO:<to@example.com>
947 From: Example <from@example.com>
949 Subject: [PATCH 1/1] Second.
951 Message-ID: MESSAGE-ID-STRING
952 X-Mailer: X-MAILER-STRING
954 Content-Transfer-Encoding: 8bit
960 test_expect_success
$PREREQ '--suppress-cc=all' '
964 test_expect_success
$PREREQ 'setup expect' "
965 cat >expected-suppress-body <<\EOF
967 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
968 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
969 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
970 (cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
972 Server: relay.example.com
973 MAIL FROM:<from@example.com>
974 RCPT TO:<to@example.com>
975 RCPT TO:<author@example.com>
976 RCPT TO:<one@example.com>
977 RCPT TO:<two@example.com>
978 RCPT TO:<cc-cmd@example.com>
979 From: Example <from@example.com>
981 Cc: A <author@example.com>,
982 One <one@example.com>,
985 Subject: [PATCH 1/1] Second.
987 Message-ID: MESSAGE-ID-STRING
988 X-Mailer: X-MAILER-STRING
990 Content-Transfer-Encoding: 8bit
996 test_expect_success
$PREREQ '--suppress-cc=body' '
997 test_suppression body
1000 test_expect_success
$PREREQ 'setup expect' "
1001 cat >expected-suppress-body-cccmd <<\EOF
1003 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
1004 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
1005 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
1007 Server: relay.example.com
1008 MAIL FROM:<from@example.com>
1009 RCPT TO:<to@example.com>
1010 RCPT TO:<author@example.com>
1011 RCPT TO:<one@example.com>
1012 RCPT TO:<two@example.com>
1013 From: Example <from@example.com>
1015 Cc: A <author@example.com>,
1016 One <one@example.com>,
1018 Subject: [PATCH 1/1] Second.
1020 Message-ID: MESSAGE-ID-STRING
1021 X-Mailer: X-MAILER-STRING
1023 Content-Transfer-Encoding: 8bit
1029 test_expect_success
$PREREQ '--suppress-cc=body --suppress-cc=cccmd' '
1030 test_suppression body cccmd
1033 test_expect_success
$PREREQ 'setup expect' "
1034 cat >expected-suppress-sob <<\EOF
1036 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
1037 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
1038 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
1040 Server: relay.example.com
1041 MAIL FROM:<from@example.com>
1042 RCPT TO:<to@example.com>
1043 RCPT TO:<author@example.com>
1044 RCPT TO:<one@example.com>
1045 RCPT TO:<two@example.com>
1046 From: Example <from@example.com>
1048 Cc: A <author@example.com>,
1049 One <one@example.com>,
1051 Subject: [PATCH 1/1] Second.
1053 Message-ID: MESSAGE-ID-STRING
1054 X-Mailer: X-MAILER-STRING
1056 Content-Transfer-Encoding: 8bit
1062 test_expect_success
$PREREQ '--suppress-cc=sob' '
1063 test_might_fail git config --unset sendemail.cccmd &&
1064 test_suppression sob
1067 test_expect_success
$PREREQ 'setup expect' "
1068 cat >expected-suppress-bodycc <<\EOF
1070 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
1071 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
1072 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
1073 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
1075 Server: relay.example.com
1076 MAIL FROM:<from@example.com>
1077 RCPT TO:<to@example.com>
1078 RCPT TO:<author@example.com>
1079 RCPT TO:<one@example.com>
1080 RCPT TO:<two@example.com>
1081 RCPT TO:<committer@example.com>
1082 From: Example <from@example.com>
1084 Cc: A <author@example.com>,
1085 One <one@example.com>,
1087 C O Mitter <committer@example.com>
1088 Subject: [PATCH 1/1] Second.
1090 Message-ID: MESSAGE-ID-STRING
1091 X-Mailer: X-MAILER-STRING
1093 Content-Transfer-Encoding: 8bit
1099 test_expect_success
$PREREQ '--suppress-cc=bodycc' '
1100 test_suppression bodycc
1103 test_expect_success
$PREREQ 'setup expect' "
1104 cat >expected-suppress-cc <<\EOF
1106 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
1107 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
1109 Server: relay.example.com
1110 MAIL FROM:<from@example.com>
1111 RCPT TO:<to@example.com>
1112 RCPT TO:<author@example.com>
1113 RCPT TO:<committer@example.com>
1114 From: Example <from@example.com>
1116 Cc: A <author@example.com>,
1117 C O Mitter <committer@example.com>
1118 Subject: [PATCH 1/1] Second.
1120 Message-ID: MESSAGE-ID-STRING
1121 X-Mailer: X-MAILER-STRING
1123 Content-Transfer-Encoding: 8bit
1129 test_expect_success
$PREREQ '--suppress-cc=cc' '
1135 GIT_SEND_EMAIL_NOTTY
=1 \
1137 --from="Example <nobody@example.com>" \
1138 --to=nobody@example.com \
1139 --smtp-server="$(pwd)/fake.sendmail" \
1140 $@
$patches >stdout
&&
1141 grep "Send this email" stdout
1144 test_expect_success
$PREREQ '--confirm=always' '
1145 test_confirm --confirm=always --suppress-cc=all
1148 test_expect_success
$PREREQ '--confirm=auto' '
1149 test_confirm --confirm=auto
1152 test_expect_success
$PREREQ '--confirm=cc' '
1153 test_confirm --confirm=cc
1156 test_expect_success
$PREREQ '--confirm=compose' '
1157 test_confirm --confirm=compose --compose
1160 test_expect_success
$PREREQ 'confirm by default (due to cc)' '
1161 test_when_finished git config sendemail.confirm never &&
1162 git config --unset sendemail.confirm &&
1166 test_expect_success
$PREREQ 'confirm by default (due to --compose)' '
1167 test_when_finished git config sendemail.confirm never &&
1168 git config --unset sendemail.confirm &&
1169 test_confirm --suppress-cc=all --compose
1172 test_expect_success
$PREREQ 'confirm detects EOF (inform assumes y)' '
1173 test_when_finished git config sendemail.confirm never &&
1174 git config --unset sendemail.confirm &&
1176 git format-patch -2 -o outdir &&
1177 GIT_SEND_EMAIL_NOTTY=1 \
1179 --from="Example <nobody@example.com>" \
1180 --to=nobody@example.com \
1181 --smtp-server="$(pwd)/fake.sendmail" \
1182 outdir/*.patch </dev/null
1185 test_expect_success
$PREREQ 'confirm detects EOF (auto causes failure)' '
1186 test_when_finished git config sendemail.confirm never &&
1187 git config sendemail.confirm auto &&
1188 GIT_SEND_EMAIL_NOTTY=1 &&
1189 export GIT_SEND_EMAIL_NOTTY &&
1190 test_must_fail git send-email \
1191 --from="Example <nobody@example.com>" \
1192 --to=nobody@example.com \
1193 --smtp-server="$(pwd)/fake.sendmail" \
1197 test_expect_success
$PREREQ 'confirm does not loop forever' '
1198 test_when_finished git config sendemail.confirm never &&
1199 git config sendemail.confirm auto &&
1200 GIT_SEND_EMAIL_NOTTY=1 &&
1201 export GIT_SEND_EMAIL_NOTTY &&
1202 yes "bogus" | test_must_fail git send-email \
1203 --from="Example <nobody@example.com>" \
1204 --to=nobody@example.com \
1205 --smtp-server="$(pwd)/fake.sendmail" \
1209 test_expect_success
$PREREQ 'utf8 Cc is rfc2047 encoded' '
1210 clean_fake_sendmail &&
1212 git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
1214 --from="Example <nobody@example.com>" \
1215 --to=nobody@example.com \
1216 --smtp-server="$(pwd)/fake.sendmail" \
1219 grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
1222 test_expect_success
$PREREQ '--compose adds MIME for utf8 body' '
1223 clean_fake_sendmail &&
1224 write_script fake-editor-utf8 <<-\EOF &&
1225 echo "utf8 body: àéìöú" >>"$1"
1227 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1229 --compose --subject foo \
1230 --from="Example <nobody@example.com>" \
1231 --to=nobody@example.com \
1232 --smtp-server="$(pwd)/fake.sendmail" \
1234 grep "^utf8 body" msgtxt1 &&
1235 grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
1238 test_expect_success
$PREREQ '--compose respects user mime type' '
1239 clean_fake_sendmail &&
1240 write_script fake-editor-utf8-mime <<-\EOF &&
1243 Content-Type: text/plain; charset=iso-8859-1
1244 Content-Transfer-Encoding: 8bit
1250 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
1252 --compose --subject foo \
1253 --from="Example <nobody@example.com>" \
1254 --to=nobody@example.com \
1255 --smtp-server="$(pwd)/fake.sendmail" \
1257 grep "^utf8 body" msgtxt1 &&
1258 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
1259 ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
1262 test_expect_success
$PREREQ '--compose adds MIME for utf8 subject' '
1263 clean_fake_sendmail &&
1264 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
1266 --compose --subject utf8-sübjëct \
1267 --from="Example <nobody@example.com>" \
1268 --to=nobody@example.com \
1269 --smtp-server="$(pwd)/fake.sendmail" \
1271 grep "^fake edit" msgtxt1 &&
1272 grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
1275 test_expect_success
$PREREQ 'utf8 author is correctly passed on' '
1276 clean_fake_sendmail &&
1277 test_commit weird_author &&
1278 test_when_finished "git reset --hard HEAD^" &&
1279 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
1280 git format-patch --stdout -1 >funny_name.patch &&
1281 git send-email --from="Example <nobody@example.com>" \
1282 --to=nobody@example.com \
1283 --smtp-server="$(pwd)/fake.sendmail" \
1285 grep "^From: Füñný Nâmé <odd_?=mail@example.com>" msgtxt1
1288 test_expect_success
$PREREQ 'utf8 sender is not duplicated' '
1289 clean_fake_sendmail &&
1290 test_commit weird_sender &&
1291 test_when_finished "git reset --hard HEAD^" &&
1292 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
1293 git format-patch --stdout -1 >funny_name.patch &&
1294 git send-email --from="Füñný Nâmé <odd_?=mail@example.com>" \
1295 --to=nobody@example.com \
1296 --smtp-server="$(pwd)/fake.sendmail" \
1298 grep "^From: " msgtxt1 >msgfrom &&
1299 test_line_count = 1 msgfrom
1302 test_expect_success
$PREREQ 'setup expect for cc list' "
1303 cat >expected-cc <<\EOF
1304 !recipient@example.com!
1305 !author@example.com!
1308 !odd_?=mail@example.com!
1311 !thor.au@example.com!
1315 test_expect_success
$PREREQ 'cc list is sanitized' '
1316 clean_fake_sendmail &&
1317 test_commit weird_cc_body &&
1318 test_when_finished "git reset --hard HEAD^" &&
1319 git commit --amend -F - <<-EOF &&
1320 Test Cc: sanitization.
1322 Cc: Person, One <one@example.com>
1323 Cc: Ronnie O${SQ}Sullivan <os@example.com>
1324 Reviewed-by: Füñný Nâmé <odd_?=mail@example.com>
1325 Reported-by: bugger on Jira
1326 Reported-by: Douglas Reporter <doug@example.com> [from Jira profile]
1328 Co-developed-by: "C. O. Developer" <codev@example.com>
1329 Signed-off-by: A. U. Thor <thor.au@example.com>
1331 git send-email -1 --to=recipient@example.com \
1332 --smtp-server="$(pwd)/fake.sendmail" >actual-show-all-headers &&
1333 test_cmp expected-cc commandline1 &&
1334 test_grep "^(body) Adding cc: \"Person, One\" <one@example.com>" actual-show-all-headers &&
1335 test_grep "^(body) Adding cc: Ronnie O${SQ}Sullivan <os@example.com>" actual-show-all-headers &&
1336 test_grep "^(body) Adding cc: =?UTF-8?q?F=C3=BC=C3=B1n=C3=BD=20N=C3=A2m=C3=A9?="\
1337 " <odd_?=mail@example.com>" actual-show-all-headers &&
1338 test_grep "^(body) Ignoring Reported-by .* bugger on Jira" actual-show-all-headers &&
1339 test_grep "^(body) Adding cc: Douglas Reporter <doug@example.com>" actual-show-all-headers &&
1340 test_grep ! "12345" actual-show-all-headers &&
1341 test_grep "^(body) Adding cc: \"C. O. Developer\" <codev@example.com>" actual-show-all-headers &&
1342 test_grep "^(body) Adding cc: \"A. U. Thor\" <thor.au@example.com>" actual-show-all-headers
1345 test_expect_success
$PREREQ 'sendemail.composeencoding works' '
1346 clean_fake_sendmail &&
1347 git config sendemail.composeencoding iso-8859-1 &&
1348 write_script fake-editor-utf8 <<-\EOF &&
1349 echo "utf8 body: àéìöú" >>"$1"
1351 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1353 --compose --subject foo \
1354 --from="Example <nobody@example.com>" \
1355 --to=nobody@example.com \
1356 --smtp-server="$(pwd)/fake.sendmail" \
1358 grep "^utf8 body" msgtxt1 &&
1359 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1362 test_expect_success
$PREREQ '--compose-encoding works' '
1363 clean_fake_sendmail &&
1364 write_script fake-editor-utf8 <<-\EOF &&
1365 echo "utf8 body: àéìöú" >>"$1"
1367 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1369 --compose-encoding iso-8859-1 \
1370 --compose --subject foo \
1371 --from="Example <nobody@example.com>" \
1372 --to=nobody@example.com \
1373 --smtp-server="$(pwd)/fake.sendmail" \
1375 grep "^utf8 body" msgtxt1 &&
1376 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1379 test_expect_success
$PREREQ '--compose-encoding overrides sendemail.composeencoding' '
1380 clean_fake_sendmail &&
1381 git config sendemail.composeencoding iso-8859-1 &&
1382 write_script fake-editor-utf8 <<-\EOF &&
1383 echo "utf8 body: àéìöú" >>"$1"
1385 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1387 --compose-encoding iso-8859-2 \
1388 --compose --subject foo \
1389 --from="Example <nobody@example.com>" \
1390 --to=nobody@example.com \
1391 --smtp-server="$(pwd)/fake.sendmail" \
1393 grep "^utf8 body" msgtxt1 &&
1394 grep "^Content-Type: text/plain; charset=iso-8859-2" msgtxt1
1397 test_expect_success
$PREREQ '--compose-encoding adds correct MIME for subject' '
1398 clean_fake_sendmail &&
1399 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
1401 --compose-encoding iso-8859-2 \
1402 --compose --subject utf8-sübjëct \
1403 --from="Example <nobody@example.com>" \
1404 --to=nobody@example.com \
1405 --smtp-server="$(pwd)/fake.sendmail" \
1407 grep "^fake edit" msgtxt1 &&
1408 grep "^Subject: =?iso-8859-2?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
1411 test_expect_success
$PREREQ 'detects ambiguous reference/file conflict' '
1414 git commit -m"add main" &&
1415 test_must_fail git send-email --dry-run main 2>errors &&
1416 grep disambiguate errors
1419 test_expect_success
$PREREQ 'feed two files' '
1421 git format-patch -2 -o outdir &&
1424 --from="Example <nobody@example.com>" \
1425 --to=nobody@example.com \
1426 outdir/000?-*.patch 2>errors >out &&
1427 grep "^Subject: " out >subjects &&
1428 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
1429 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add main"
1432 test_expect_success
$PREREQ 'in-reply-to but no threading' '
1435 --from="Example <nobody@example.com>" \
1436 --to=nobody@example.com \
1437 --in-reply-to="<in-reply-id@example.com>" \
1440 grep "In-Reply-To: <in-reply-id@example.com>" out
1443 test_expect_success
$PREREQ 'no in-reply-to and no threading' '
1446 --from="Example <nobody@example.com>" \
1447 --to=nobody@example.com \
1450 ! grep "In-Reply-To: " stdout
1453 test_expect_success
$PREREQ 'threading but no chain-reply-to' '
1456 --from="Example <nobody@example.com>" \
1457 --to=nobody@example.com \
1459 --no-chain-reply-to \
1460 $patches $patches >stdout &&
1461 grep "In-Reply-To: " stdout
1464 test_expect_success
$PREREQ 'override in-reply-to if no threading' '
1467 --from="Example <nobody@example.com>" \
1468 --to=nobody@example.com \
1470 --in-reply-to="override" \
1471 $threaded_patches >stdout &&
1472 grep "In-Reply-To: <override>" stdout
1475 test_expect_success
$PREREQ 'sendemail.to works' '
1476 git config --replace-all sendemail.to "Somebody <somebody@ex.com>" &&
1479 --from="Example <nobody@example.com>" \
1481 grep "To: Somebody <somebody@ex.com>" stdout
1484 test_expect_success
$PREREQ 'setup sendemail.identity' '
1485 git config --replace-all sendemail.to "default@example.com" &&
1486 git config --replace-all sendemail.isp.to "isp@example.com" &&
1487 git config --replace-all sendemail.cloud.to "cloud@example.com"
1490 test_expect_success
$PREREQ 'sendemail.identity: reads the correct identity config' '
1491 git -c sendemail.identity=cloud send-email \
1493 --from="nobody@example.com" \
1495 grep "To: cloud@example.com" stdout
1498 test_expect_success
$PREREQ 'sendemail.identity: identity overrides sendemail.identity' '
1499 git -c sendemail.identity=cloud send-email \
1502 --from="nobody@example.com" \
1504 grep "To: isp@example.com" stdout
1507 test_expect_success
$PREREQ 'sendemail.identity: --no-identity clears previous identity' '
1508 git -c sendemail.identity=cloud send-email \
1511 --from="nobody@example.com" \
1513 grep "To: default@example.com" stdout
1516 test_expect_success
$PREREQ 'sendemail.identity: bool identity variable existence overrides' '
1517 git -c sendemail.identity=cloud \
1518 -c sendemail.xmailer=true \
1519 -c sendemail.cloud.xmailer=false \
1522 --from="nobody@example.com" \
1524 grep "To: cloud@example.com" stdout &&
1525 ! grep "X-Mailer" stdout
1528 test_expect_success
$PREREQ 'sendemail.identity: bool variable fallback' '
1529 git -c sendemail.identity=cloud \
1530 -c sendemail.xmailer=false \
1533 --from="nobody@example.com" \
1535 grep "To: cloud@example.com" stdout &&
1536 ! grep "X-Mailer" stdout
1539 test_expect_success
$PREREQ 'sendemail.identity: bool variable without a value' '
1540 git -c sendemail.xmailer \
1543 --from="nobody@example.com" \
1545 grep "To: default@example.com" stdout &&
1546 grep "X-Mailer" stdout
1549 test_expect_success
$PREREQ '--no-to overrides sendemail.to' '
1552 --from="Example <nobody@example.com>" \
1554 --to=nobody@example.com \
1556 grep "To: nobody@example.com" stdout &&
1557 ! grep "To: Somebody <somebody@ex.com>" stdout
1560 test_expect_success
$PREREQ 'sendemail.cc works' '
1561 git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" &&
1564 --from="Example <nobody@example.com>" \
1565 --to=nobody@example.com \
1567 grep "Cc: Somebody <somebody@ex.com>" stdout
1570 test_expect_success
$PREREQ '--no-cc overrides sendemail.cc' '
1573 --from="Example <nobody@example.com>" \
1575 --cc=bodies@example.com \
1576 --to=nobody@example.com \
1578 grep "Cc: bodies@example.com" stdout &&
1579 ! grep "Cc: Somebody <somebody@ex.com>" stdout
1582 test_expect_success
$PREREQ 'sendemail.bcc works' '
1583 git config --replace-all sendemail.bcc "Other <other@ex.com>" &&
1586 --from="Example <nobody@example.com>" \
1587 --to=nobody@example.com \
1588 --smtp-server relay.example.com \
1590 grep "RCPT TO:<other@ex.com>" stdout
1593 test_expect_success
$PREREQ '--no-bcc overrides sendemail.bcc' '
1596 --from="Example <nobody@example.com>" \
1598 --bcc=bodies@example.com \
1599 --to=nobody@example.com \
1600 --smtp-server relay.example.com \
1602 grep "RCPT TO:<bodies@example.com>" stdout &&
1603 ! grep "RCPT TO:<other@ex.com>" stdout
1606 test_expect_success
$PREREQ 'patches To headers are used by default' '
1607 patch=$(git format-patch -1 --to="bodies@example.com") &&
1608 test_when_finished "rm $patch" &&
1611 --from="Example <nobody@example.com>" \
1612 --smtp-server relay.example.com \
1614 grep "RCPT TO:<bodies@example.com>" stdout
1617 test_expect_success
$PREREQ 'patches To headers are appended to' '
1618 patch=$(git format-patch -1 --to="bodies@example.com") &&
1619 test_when_finished "rm $patch" &&
1622 --from="Example <nobody@example.com>" \
1623 --to=nobody@example.com \
1624 --smtp-server relay.example.com \
1626 grep "RCPT TO:<bodies@example.com>" stdout &&
1627 grep "RCPT TO:<nobody@example.com>" stdout
1630 test_expect_success
$PREREQ 'To headers from files reset each patch' '
1631 patch1=$(git format-patch -1 --to="bodies@example.com") &&
1632 patch2=$(git format-patch -1 --to="other@example.com" HEAD~) &&
1633 test_when_finished "rm $patch1 && rm $patch2" &&
1636 --from="Example <nobody@example.com>" \
1637 --to="nobody@example.com" \
1638 --smtp-server relay.example.com \
1639 $patch1 $patch2 >stdout &&
1640 test $(grep -c "RCPT TO:<bodies@example.com>" stdout) = 1 &&
1641 test $(grep -c "RCPT TO:<nobody@example.com>" stdout) = 2 &&
1642 test $(grep -c "RCPT TO:<other@example.com>" stdout) = 1
1645 test_expect_success
$PREREQ 'setup expect' '
1646 cat >email-using-8bit <<\EOF
1647 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1648 Message-ID: <bogus-message-id@example.com>
1649 From: author@example.com
1650 Date: Sat, 12 Jun 2010 15:53:58 +0200
1651 Subject: subject goes here
1653 Dieser deutsche Text enthält einen Umlaut!
1657 test_expect_success
$PREREQ 'setup expect' '
1658 echo "Subject: subject goes here" >expected
1661 test_expect_success
$PREREQ 'ASCII subject is not RFC2047 quoted' '
1662 clean_fake_sendmail &&
1664 git send-email --from=author@example.com --to=nobody@example.com \
1665 --smtp-server="$(pwd)/fake.sendmail" \
1666 --8bit-encoding=UTF-8 \
1667 email-using-8bit >stdout &&
1668 grep "Subject" msgtxt1 >actual &&
1669 test_cmp expected actual
1672 test_expect_success
$PREREQ 'setup expect' '
1673 cat >content-type-decl <<-\EOF
1675 Content-Type: text/plain; charset=UTF-8
1676 Content-Transfer-Encoding: 8bit
1680 test_expect_success
$PREREQ 'asks about and fixes 8bit encodings' '
1681 clean_fake_sendmail &&
1683 git send-email --from=author@example.com --to=nobody@example.com \
1684 --smtp-server="$(pwd)/fake.sendmail" \
1685 email-using-8bit >stdout &&
1686 grep "do not declare a Content-Transfer-Encoding" stdout &&
1687 grep email-using-8bit stdout &&
1688 grep "Which 8bit encoding" stdout &&
1689 grep -E "Content|MIME" msgtxt1 >actual &&
1690 test_cmp content-type-decl actual
1693 test_expect_success
$PREREQ 'sendemail.8bitEncoding works' '
1694 clean_fake_sendmail &&
1695 git config sendemail.assume8bitEncoding UTF-8 &&
1697 git send-email --from=author@example.com --to=nobody@example.com \
1698 --smtp-server="$(pwd)/fake.sendmail" \
1699 email-using-8bit >stdout &&
1700 grep -E "Content|MIME" msgtxt1 >actual &&
1701 test_cmp content-type-decl actual
1704 test_expect_success
$PREREQ 'sendemail.8bitEncoding in .git/config overrides --global .gitconfig' '
1705 clean_fake_sendmail &&
1706 git config sendemail.assume8bitEncoding UTF-8 &&
1707 test_when_finished "rm -rf home" &&
1709 git config -f home/.gitconfig sendemail.assume8bitEncoding "bogus too" &&
1711 env HOME="$(pwd)/home" DEBUG=1 \
1712 git send-email --from=author@example.com --to=nobody@example.com \
1713 --smtp-server="$(pwd)/fake.sendmail" \
1714 email-using-8bit >stdout &&
1715 grep -E "Content|MIME" msgtxt1 >actual &&
1716 test_cmp content-type-decl actual
1719 test_expect_success
$PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
1720 clean_fake_sendmail &&
1721 git config sendemail.assume8bitEncoding "bogus too" &&
1723 git send-email --from=author@example.com --to=nobody@example.com \
1724 --smtp-server="$(pwd)/fake.sendmail" \
1725 --8bit-encoding=UTF-8 \
1726 email-using-8bit >stdout &&
1727 grep -E "Content|MIME" msgtxt1 >actual &&
1728 test_cmp content-type-decl actual
1731 test_expect_success
$PREREQ 'setup expect' '
1732 cat >email-using-8bit <<-\EOF
1733 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1734 Message-ID: <bogus-message-id@example.com>
1735 From: author@example.com
1736 Date: Sat, 12 Jun 2010 15:53:58 +0200
1737 Subject: Dieser Betreff enthält auch einen Umlaut!
1739 Nothing to see here.
1743 test_expect_success
$PREREQ 'setup expect' '
1744 cat >expected <<-\EOF
1745 Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
1749 test_expect_success
$PREREQ '--8bit-encoding also treats subject' '
1750 clean_fake_sendmail &&
1752 git send-email --from=author@example.com --to=nobody@example.com \
1753 --smtp-server="$(pwd)/fake.sendmail" \
1754 --8bit-encoding=UTF-8 \
1755 email-using-8bit >stdout &&
1756 grep "Subject" msgtxt1 >actual &&
1757 test_cmp expected actual
1760 test_expect_success
$PREREQ 'setup expect' '
1761 cat >email-using-8bit <<-\EOF
1762 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1763 Message-ID: <bogus-message-id@example.com>
1764 From: A U Thor <author@example.com>
1765 Date: Sat, 12 Jun 2010 15:53:58 +0200
1766 Content-Type: text/plain; charset=UTF-8
1767 Subject: Nothing to see here.
1769 Dieser Betreff enthält auch einen Umlaut!
1773 test_expect_success
$PREREQ '--transfer-encoding overrides sendemail.transferEncoding' '
1774 clean_fake_sendmail &&
1775 test_must_fail git -c sendemail.transferEncoding=8bit \
1777 --transfer-encoding=7bit \
1778 --smtp-server="$(pwd)/fake.sendmail" \
1781 grep "cannot send message as 7bit" errors &&
1782 test -z "$(ls msgtxt*)"
1785 test_expect_success
$PREREQ 'sendemail.transferEncoding via config' '
1786 clean_fake_sendmail &&
1787 test_must_fail git -c sendemail.transferEncoding=7bit \
1789 --smtp-server="$(pwd)/fake.sendmail" \
1792 grep "cannot send message as 7bit" errors &&
1793 test -z "$(ls msgtxt*)"
1796 test_expect_success
$PREREQ 'sendemail.transferEncoding via cli' '
1797 clean_fake_sendmail &&
1798 test_must_fail git send-email \
1799 --transfer-encoding=7bit \
1800 --smtp-server="$(pwd)/fake.sendmail" \
1803 grep "cannot send message as 7bit" errors &&
1804 test -z "$(ls msgtxt*)"
1807 test_expect_success
$PREREQ 'setup expect' '
1808 cat >expected <<-\EOF
1809 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1813 test_expect_success
$PREREQ '8-bit and sendemail.transferencoding=quoted-printable' '
1814 clean_fake_sendmail &&
1816 --transfer-encoding=quoted-printable \
1817 --smtp-server="$(pwd)/fake.sendmail" \
1820 sed "1,/^$/d" msgtxt1 >actual &&
1821 test_cmp expected actual
1824 test_expect_success
$PREREQ 'setup expect' '
1825 cat >expected <<-\EOF
1826 RGllc2VyIEJldHJlZmYgZW50aMOkbHQgYXVjaCBlaW5lbiBVbWxhdXQhCg==
1830 test_expect_success
$PREREQ '8-bit and sendemail.transferencoding=base64' '
1831 clean_fake_sendmail &&
1833 --transfer-encoding=base64 \
1834 --smtp-server="$(pwd)/fake.sendmail" \
1837 sed "1,/^$/d" msgtxt1 >actual &&
1838 test_cmp expected actual
1841 test_expect_success
$PREREQ 'setup expect' '
1842 cat >email-using-qp <<-\EOF
1843 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1844 Message-ID: <bogus-message-id@example.com>
1845 From: A U Thor <author@example.com>
1846 Date: Sat, 12 Jun 2010 15:53:58 +0200
1848 Content-Transfer-Encoding: quoted-printable
1849 Content-Type: text/plain; charset=UTF-8
1850 Subject: Nothing to see here.
1852 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1856 test_expect_success
$PREREQ 'convert from quoted-printable to base64' '
1857 clean_fake_sendmail &&
1859 --transfer-encoding=base64 \
1860 --smtp-server="$(pwd)/fake.sendmail" \
1863 sed "1,/^$/d" msgtxt1 >actual &&
1864 test_cmp expected actual
1867 test_expect_success
$PREREQ 'setup expect' "
1868 tr -d '\\015' | tr '%' '\\015' >email-using-crlf <<EOF
1869 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1870 Message-ID: <bogus-message-id@example.com>
1871 From: A U Thor <author@example.com>
1872 Date: Sat, 12 Jun 2010 15:53:58 +0200
1873 Content-Type: text/plain; charset=UTF-8
1874 Subject: Nothing to see here.
1876 Look, I have a CRLF and an = sign!%
1880 test_expect_success
$PREREQ 'setup expect' '
1881 cat >expected <<-\EOF
1882 Look, I have a CRLF and an =3D sign!=0D
1886 test_expect_success
$PREREQ 'CRLF and sendemail.transferencoding=quoted-printable' '
1887 clean_fake_sendmail &&
1889 --transfer-encoding=quoted-printable \
1890 --smtp-server="$(pwd)/fake.sendmail" \
1893 sed "1,/^$/d" msgtxt1 >actual &&
1894 test_cmp expected actual
1897 test_expect_success
$PREREQ 'setup expect' '
1898 cat >expected <<-\EOF
1899 TG9vaywgSSBoYXZlIGEgQ1JMRiBhbmQgYW4gPSBzaWduIQ0K
1903 test_expect_success
$PREREQ 'CRLF and sendemail.transferencoding=base64' '
1904 clean_fake_sendmail &&
1906 --transfer-encoding=base64 \
1907 --smtp-server="$(pwd)/fake.sendmail" \
1910 sed "1,/^$/d" msgtxt1 >actual &&
1911 test_cmp expected actual
1915 # Note that the patches in this test are deliberately out of order; we
1916 # want to make sure it works even if the cover-letter is not in the
1918 test_expect_success
$PREREQ 'refusing to send cover letter template' '
1919 clean_fake_sendmail &&
1921 git format-patch --cover-letter -2 -o outdir &&
1922 test_must_fail git send-email \
1923 --from="Example <nobody@example.com>" \
1924 --to=nobody@example.com \
1925 --smtp-server="$(pwd)/fake.sendmail" \
1926 outdir/0002-*.patch \
1927 outdir/0000-*.patch \
1928 outdir/0001-*.patch \
1930 grep "SUBJECT HERE" errors &&
1931 test -z "$(ls msgtxt*)"
1934 test_expect_success
$PREREQ '--force sends cover letter template anyway' '
1935 clean_fake_sendmail &&
1937 git format-patch --cover-letter -2 -o outdir &&
1940 --from="Example <nobody@example.com>" \
1941 --to=nobody@example.com \
1942 --smtp-server="$(pwd)/fake.sendmail" \
1943 outdir/0002-*.patch \
1944 outdir/0000-*.patch \
1945 outdir/0001-*.patch \
1947 ! grep "SUBJECT HERE" errors &&
1948 test -n "$(ls msgtxt*)"
1951 test_cover_addresses
() {
1954 clean_fake_sendmail
&&
1956 git format-patch
--cover-letter -2 -o outdir
&&
1957 cover
=$
(echo outdir
/0000-*.
patch) &&
1958 mv $cover cover-to-edit.
patch &&
1959 perl
-pe "s/^From:/$header: extra\@address.com\nFrom:/" cover-to-edit.
patch >"$cover" &&
1962 --from="Example <nobody@example.com>" \
1965 --smtp-server="$(pwd)/fake.sendmail" \
1966 outdir
/0000-*.
patch \
1967 outdir
/0001-*.
patch \
1968 outdir
/0002-*.
patch \
1970 grep "^$header: extra@address.com" msgtxt1
>to1
&&
1971 grep "^$header: extra@address.com" msgtxt2
>to2
&&
1972 grep "^$header: extra@address.com" msgtxt3
>to3
&&
1973 test_line_count
= 1 to1
&&
1974 test_line_count
= 1 to2
&&
1975 test_line_count
= 1 to3
1978 test_expect_success
$PREREQ 'to-cover adds To to all mail' '
1979 test_cover_addresses "To" --to-cover
1982 test_expect_success
$PREREQ 'cc-cover adds Cc to all mail' '
1983 test_cover_addresses "Cc" --cc-cover
1986 test_expect_success
$PREREQ 'tocover adds To to all mail' '
1987 test_config sendemail.tocover true &&
1988 test_cover_addresses "To"
1991 test_expect_success
$PREREQ 'cccover adds Cc to all mail' '
1992 test_config sendemail.cccover true &&
1993 test_cover_addresses "Cc"
1996 test_expect_success
$PREREQ 'escaped quotes in sendemail.aliasfiletype=mutt' '
1997 clean_fake_sendmail &&
1998 echo "alias sbd \\\"Dot U. Sir\\\" <somebody@example.org>" >.mutt &&
1999 git config --replace-all sendemail.aliasesfile "$(pwd)/.mutt" &&
2000 git config sendemail.aliasfiletype mutt &&
2002 --from="Example <nobody@example.com>" \
2004 --smtp-server="$(pwd)/fake.sendmail" \
2005 outdir/0001-*.patch \
2007 grep "^!somebody@example\.org!$" commandline1 &&
2008 grep -F "To: \"Dot U. Sir\" <somebody@example.org>" out
2011 test_expect_success
$PREREQ 'sendemail.aliasfiletype=mailrc' '
2012 clean_fake_sendmail &&
2013 echo "alias sbd somebody@example.org" >.mailrc &&
2014 git config --replace-all sendemail.aliasesfile "$(pwd)/.mailrc" &&
2015 git config sendemail.aliasfiletype mailrc &&
2017 --from="Example <nobody@example.com>" \
2019 --smtp-server="$(pwd)/fake.sendmail" \
2020 outdir/0001-*.patch \
2022 grep "^!somebody@example\.org!$" commandline1
2025 test_expect_success
$PREREQ 'sendemail.aliasesfile=~/.mailrc' '
2026 clean_fake_sendmail &&
2027 echo "alias sbd someone@example.org" >"$HOME/.mailrc" &&
2028 git config --replace-all sendemail.aliasesfile "~/.mailrc" &&
2029 git config sendemail.aliasfiletype mailrc &&
2031 --from="Example <nobody@example.com>" \
2033 --smtp-server="$(pwd)/fake.sendmail" \
2034 outdir/0001-*.patch \
2036 grep "^!someone@example\.org!$" commandline1
2039 test_dump_aliases
() {
2040 msg
="$1" && shift &&
2041 filetype
="$1" && shift &&
2042 printf '%s\n' "$@" >expect
&&
2043 cat >.tmp-email-aliases
&&
2045 test_expect_success
$PREREQ "$msg" '
2046 clean_fake_sendmail && rm -fr outdir &&
2047 git config --replace-all sendemail.aliasesfile \
2048 "$(pwd)/.tmp-email-aliases" &&
2049 git config sendemail.aliasfiletype "$filetype" &&
2050 git send-email --dump-aliases 2>errors >actual &&
2051 test_cmp expect actual
2055 test_dump_aliases
'--dump-aliases sendmail format' \
2062 alice: Alice W Land <awol@example.com>
2063 bob: Robert Bobbyton <bob@example.com>
2064 chloe: chloe@example.com
2066 bcgrp: bob, chloe, Other <o@example.com>
2069 test_dump_aliases '--dump-aliases mutt format' \
2075 alias alice Alice W Land <awol@example.com>
2076 alias donald Donald C Carlton <donc@example.com>
2077 alias bob Robert Bobbyton <bob@example.com>
2078 alias chloe chloe@example.com
2081 test_dump_aliases '--dump-aliases mailrc format' \
2087 alias alice Alice W Land <awol@example.com>
2088 alias eve Eve <eve@example.com>
2089 alias bob Robert Bobbyton <bob@example.com>
2090 alias chloe chloe@example.com
2093 test_dump_aliases '--dump-aliases pine format' \
2099 alice Alice W Land <awol@example.com>
2100 eve Eve <eve@example.com>
2101 bob Robert Bobbyton <bob@example.com>
2102 chloe chloe@example.com
2105 test_dump_aliases '--dump-aliases gnus format' \
2111 (define-mail-alias "alice" "awol@example.com")
2112 (define-mail-alias "eve" "eve@example.com")
2113 (define-mail-alias "bob" "bob@example.com")
2114 (define-mail-alias "chloe" "chloe@example.com")
2117 test_expect_success '--dump-aliases must be used alone' '
2118 test_must_fail git send-email --dump-aliases --to=janice@example.com -1 refs/heads/accounting
2121 test_expect_success $PREREQ 'aliases and sendemail.identity' '
2122 test_must_fail git \
2123 -c sendemail.identity=cloud \
2124 -c sendemail.aliasesfile=default-aliases \
2125 -c sendemail.cloud.aliasesfile=cloud-aliases \
2126 send-email -1 2>stderr &&
2127 test_grep "cloud-aliases" stderr
2130 test_sendmail_aliases () {
2131 msg="$1" && shift &&
2133 cat >.tmp-email-aliases &&
2135 test_expect_success $PREREQ "$msg" '
2136 clean_fake_sendmail && rm -fr outdir &&
2137 git format-patch -1 -o outdir &&
2138 git config --replace-all sendemail.aliasesfile \
2139 "$(pwd)/.tmp-email-aliases" &&
2140 git config sendemail.aliasfiletype sendmail &&
2142 --from="Example <nobody@example.com>" \
2143 --to=alice --to=bcgrp \
2144 --smtp-server="$(pwd)/fake.sendmail" \
2145 outdir/0001-*.
patch \
2149 grep "^!$i!$" commandline1 ||
return 1
2154 test_sendmail_aliases 'sendemail.aliasfiletype
=sendmail
' \
2155 'awol@example\.com
' \
2156 'bob@example\.com
' \
2157 'chloe@example\.com
' \
2158 'o@example\.com
' <<-\EOF
2159 alice: Alice W Land <awol@example.com>
2160 bob: Robert Bobbyton <bob@example.com>
2162 # this is also a comment
2163 chloe: chloe@example.com
2165 bcgrp: bob, chloe, Other <o@example.com>
2168 test_sendmail_aliases 'sendmail aliases line folding
' \
2172 darla1 darla2 darla3 \
2173 elton1 elton2 elton3 \
2190 bcgrp: bob, chuck, darla, elton, fred, greg
2193 test_sendmail_aliases 'sendmail aliases tolerate bogus line folding
' \
2199 test_sendmail_aliases 'sendmail aliases empty
' alice bcgrp <<-\EOF
2202 test_expect_success $PREREQ 'alias support
in To header
' '
2203 clean_fake_sendmail
&&
2204 echo "alias sbd someone@example.org" >.mailrc
&&
2205 test_config sendemail.aliasesfile
".mailrc" &&
2206 test_config sendemail.aliasfiletype mailrc
&&
2207 git format-patch
--stdout -1 --to=sbd
>aliased.
patch &&
2209 --from="Example <nobody@example.com>" \
2210 --smtp-server="$(pwd)/fake.sendmail" \
2213 grep "^!someone@example\.org!$" commandline1
2216 test_expect_success $PREREQ 'alias support
in Cc header
' '
2217 clean_fake_sendmail
&&
2218 echo "alias sbd someone@example.org" >.mailrc
&&
2219 test_config sendemail.aliasesfile
".mailrc" &&
2220 test_config sendemail.aliasfiletype mailrc
&&
2221 git format-patch
--stdout -1 --cc=sbd
>aliased.
patch &&
2223 --from="Example <nobody@example.com>" \
2224 --smtp-server="$(pwd)/fake.sendmail" \
2227 grep "^!someone@example\.org!$" commandline1
2230 test_expect_success $PREREQ 'tocmd works with aliases
' '
2231 clean_fake_sendmail
&&
2232 echo "alias sbd someone@example.org" >.mailrc
&&
2233 test_config sendemail.aliasesfile
".mailrc" &&
2234 test_config sendemail.aliasfiletype mailrc
&&
2235 git format-patch
--stdout -1 >tocmd.
patch &&
2236 echo tocmd--sbd
>>tocmd.
patch &&
2238 --from="Example <nobody@example.com>" \
2239 --to-cmd=.
/tocmd-sed \
2240 --smtp-server="$(pwd)/fake.sendmail" \
2243 grep "^!someone@example\.org!$" commandline1
2246 test_expect_success $PREREQ 'cccmd works with aliases
' '
2247 clean_fake_sendmail
&&
2248 echo "alias sbd someone@example.org" >.mailrc
&&
2249 test_config sendemail.aliasesfile
".mailrc" &&
2250 test_config sendemail.aliasfiletype mailrc
&&
2251 git format-patch
--stdout -1 >cccmd.
patch &&
2252 echo cccmd--sbd
>>cccmd.
patch &&
2254 --from="Example <nobody@example.com>" \
2255 --cc-cmd=.
/cccmd-sed \
2256 --smtp-server="$(pwd)/fake.sendmail" \
2259 grep "^!someone@example\.org!$" commandline1
2262 do_xmailer_test () {
2263 expected=$1 params=$2 &&
2264 git format-patch -1 &&
2266 --from="Example <nobody@example.com>" \
2267 --to=someone@example.com \
2268 --smtp-server="$(pwd)/fake.sendmail" \
2272 { grep '^X-Mailer
:' out || :; } >mailer &&
2273 test_line_count = $expected mailer
2276 test_expect_success $PREREQ '--[no-
]xmailer without any configuration
' '
2277 do_xmailer_test
1 "--xmailer" &&
2278 do_xmailer_test
0 "--no-xmailer"
2281 test_expect_success $PREREQ '--[no-
]xmailer with sendemail.xmailer
=true
' '
2282 test_config sendemail.xmailer true
&&
2283 do_xmailer_test
1 "" &&
2284 do_xmailer_test
0 "--no-xmailer" &&
2285 do_xmailer_test
1 "--xmailer"
2288 test_expect_success $PREREQ '--[no-
]xmailer with sendemail.xmailer
' '
2289 test_when_finished
"test_unconfig sendemail.xmailer" &&
2290 cat >>.git
/config
<<-\EOF &&
2294 test_config sendemail.xmailer true &&
2295 do_xmailer_test 1 "" &&
2296 do_xmailer_test 0 "--no-xmailer" &&
2297 do_xmailer_test 1 "--xmailer"
2300 test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=false' '
2301 test_config sendemail.xmailer false &&
2302 do_xmailer_test 0 "" &&
2303 do_xmailer_test 0 "--no-xmailer" &&
2304 do_xmailer_test 1 "--xmailer"
2307 test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=' '
2308 test_config sendemail.xmailer "" &&
2309 do_xmailer_test 0 "" &&
2310 do_xmailer_test 0 "--no-xmailer" &&
2311 do_xmailer_test 1 "--xmailer"
2314 test_expect_success $PREREQ 'setup expected-list' '
2317 --from="Example <from@example.com>" \
2318 --to="To 1 <to1@example.com>" \
2319 --to="to2@example.com" \
2320 --to="to3@example.com" \
2321 --cc="Cc 1 <cc1@example.com>" \
2322 --cc="Cc2 <cc2@example.com>" \
2323 --bcc="bcc1@example.com" \
2324 --bcc="bcc2@example.com" \
2325 0001-add-main.patch | replace_variable_fields \
2329 test_expect_success $PREREQ 'use email list in --cc --to and --bcc' '
2332 --from="Example <from@example.com>" \
2333 --to="To 1 <to1@example.com>, to2@example.com" \
2334 --to="to3@example.com" \
2335 --cc="Cc 1 <cc1@example.com>, Cc2 <cc2@example.com>" \
2336 --bcc="bcc1@example.com, bcc2@example.com" \
2337 0001-add-main.patch | replace_variable_fields \
2339 test_cmp expected-list actual-list
2342 test_expect_success $PREREQ 'aliases work with email list' '
2343 echo "alias to2 to2@example.com" >.mutt &&
2344 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt &&
2345 test_config sendemail.aliasesfile ".mutt" &&
2346 test_config sendemail.aliasfiletype mutt &&
2349 --from="Example <from@example.com>" \
2350 --to="To 1 <to1@example.com>, to2, to3@example.com" \
2351 --cc="cc1, Cc2 <cc2@example.com>" \
2352 --bcc="bcc1@example.com, bcc2@example.com" \
2353 0001-add-main.patch | replace_variable_fields \
2355 test_cmp expected-list actual-list
2358 test_expect_success $PREREQ 'leading and trailing whitespaces are removed' '
2359 echo "alias to2 to2@example.com" >.mutt &&
2360 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt &&
2361 test_config sendemail.aliasesfile ".mutt" &&
2362 test_config sendemail.aliasfiletype mutt &&
2363 TO1=$(echo "QTo 1 <to1@example.com>" | q_to_tab) &&
2364 TO2=$(echo "QZto2" | qz_to_tab_space) &&
2365 CC1=$(echo "cc1" | append_cr) &&
2366 BCC1=$(echo " bcc1@example.com Q" | q_to_nul) &&
2369 --from=" Example <from@example.com>" \
2372 --to=" to3@example.com " \
2374 --cc="Cc2 <cc2@example.com>" \
2376 --bcc="bcc2@example.com" \
2377 0001-add-main.patch | replace_variable_fields \
2379 test_cmp expected-list actual-list
2382 test_expect_success $PREREQ 'test using command name with --sendmail-cmd' '
2383 clean_fake_sendmail &&
2386 --from="Example <nobody@example.com>" \
2387 --to=nobody@example.com \
2388 --sendmail-cmd="fake.sendmail" \
2390 test_path_is_file commandline1
2393 test_expect_success $PREREQ 'test using arguments with --sendmail-cmd' '
2394 clean_fake_sendmail &&
2396 --from="Example <nobody@example.com>" \
2397 --to=nobody@example.com \
2398 --sendmail-cmd='\''"$(pwd)/fake.sendmail" -f nobody@example.com'\'' \
2400 test_path_is_file commandline1
2403 test_expect_success $PREREQ 'test shell expression with --sendmail-cmd' '
2404 clean_fake_sendmail &&
2406 --from="Example <nobody@example.com>" \
2407 --to=nobody@example.com \
2408 --sendmail-cmd='\''f() { "$(pwd)/fake.sendmail" "$@"; };f'\'' \
2410 test_path_is_file commandline1
2413 test_expect_success $PREREQ 'set up in-reply-to/references patches' '
2414 cat >has-reply.patch <<-\
EOF &&
2415 From: A U Thor <author@example.com>
2416 Subject: patch with in-reply-to
2417 Message-ID: <patch.with.in.reply.to@example.com>
2418 In-Reply-To: <replied.to@example.com>
2419 References: <replied.to@example.com>
2423 cat >no-reply.patch <<-\EOF
2424 From: A U Thor <author@example.com>
2425 Subject: patch without in-reply-to
2426 Message-ID: <patch.without.in.reply.to@example.com>
2432 test_expect_success $PREREQ 'patch reply headers correct with --no-thread' '
2433 clean_fake_sendmail &&
2436 --to=nobody@example.com \
2437 --smtp-server="$(pwd)/fake.sendmail" \
2438 has-reply.patch no-reply.patch &&
2439 grep "In-Reply-To: <replied.to@example.com>" msgtxt1 &&
2440 grep "References: <replied.to@example.com>" msgtxt1 &&
2441 ! grep replied.to@example.com msgtxt2
2444 test_expect_success $PREREQ 'cmdline in-reply-to used with --no-thread' '
2445 clean_fake_sendmail &&
2448 --in-reply-to="<cmdline.reply@example.com>" \
2449 --to=nobody@example.com \
2450 --smtp-server="$(pwd)/fake.sendmail" \
2451 has-reply.patch no-reply.patch &&
2452 grep "In-Reply-To: <cmdline.reply@example.com>" msgtxt1 &&
2453 grep "References: <cmdline.reply@example.com>" msgtxt1 &&
2454 grep "In-Reply-To: <cmdline.reply@example.com>" msgtxt2 &&
2455 grep "References: <cmdline.reply@example.com>" msgtxt2
2458 test_expect_success $PREREQ 'invoke hook' '
2459 test_hook sendemail-validate <<-\EOF &&
2460 # test that we have the correct environment variable, pwd, and
2470 test -f 0001-add-main.patch &&
2471 grep "add main" "$1"
2476 # Test that it works even if we are not at the root of the
2480 --from="Example <nobody@example.com>" \
2481 --to=nobody@example.com \
2482 --smtp-server="$(pwd)/../fake.sendmail" \
2483 ../0001-add-main.patch &&
2485 # Verify error message when a patch is rejected by the hook
2486 sed -e "s/add main/x/" ../0001-add-main.patch >../another.patch &&
2487 test_must_fail git send-email \
2488 --from="Example <nobody@example.com>" \
2489 --to=nobody@example.com \
2490 --smtp-server="$(pwd)/../fake.sendmail" \
2491 ../another.patch 2>err &&
2492 test_grep "rejected by sendemail-validate hook" err
2496 expected_file_counter_output () {
2499 while test $count -ne $total
2501 count=$((count + 1)) &&
2502 echo "$count/$total" || return
2506 test_expect_success $PREREQ '--validate hook allows counting of messages' '
2507 test_when_finished "rm -rf my-hooks.log" &&
2508 test_config core.hooksPath "my-hooks" &&
2509 mkdir -p my-hooks &&
2511 write_script my-hooks/sendemail-validate <<-\EOF &&
2512 num=$GIT_SENDEMAIL_FILE_COUNTER &&
2513 tot=$GIT_SENDEMAIL_FILE_TOTAL &&
2514 echo "$num/$tot" >>my-hooks.log || exit 1
2518 expected_file_counter_output 4 >expect &&
2520 --from="Example <from@example.com>" \
2521 --to=nobody@example.com \
2522 --smtp-server="$(pwd)/fake.sendmail" \
2523 --validate -3 --cover-letter --force &&
2524 test_cmp expect my-hooks.log
2527 test_expect_success $PREREQ 'test that send-email works outside a repo' '
2528 nongit git send-email \
2529 --from="Example <nobody@example.com>" \
2530 --to=nobody@example.com \
2531 --smtp-server="$(pwd)/fake.sendmail" \
2532 "$(pwd)/0001-add-main.patch"
2535 test_expect_success $PREREQ 'send-email relays -v 3 to format-patch' '
2536 test_when_finished "rm -f out" &&
2537 git send-email --dry-run -v 3 -1 >out &&
2541 test_expect_success $PREREQ 'test that sendmail config is rejected' '
2542 test_config sendmail.program sendmail &&
2543 test_must_fail git send-email \
2544 --from="Example <nobody@example.com>" \
2545 --to=nobody@example.com \
2546 --smtp-server="$(pwd)/fake.sendmail" \
2548 test_grep "found configuration options for '"'"sendmail"'"'" err
2551 test_expect_success $PREREQ 'test that sendmail config rejection is specific' '
2552 test_config resendmail.program sendmail &&
2554 --from="Example <nobody@example.com>" \
2555 --to=nobody@example.com \
2556 --smtp-server="$(pwd)/fake.sendmail" \
2560 test_expect_success $PREREQ 'test forbidSendmailVariables behavior override' '
2561 test_config sendmail.program sendmail &&
2562 test_config sendemail.forbidSendmailVariables false &&
2564 --from="Example <nobody@example.com>" \
2565 --to=nobody@example.com \
2566 --smtp-server="$(pwd)/fake.sendmail" \
2570 test_expect_success $PREREQ '--compose handles lowercase headers' '
2571 write_script fake-editor <<-\EOF &&
2572 sed "s/^[Ff][Rr][Oo][Mm]:.*/from: edited-from@example.com/" "$1" >"$1.tmp" &&
2575 clean_fake_sendmail &&
2578 --from="Example <from@example.com>" \
2579 --to=nobody@example.com \
2580 --smtp-server="$(pwd)/fake.sendmail" \
2582 grep "From: edited-from@example.com" msgtxt1
2585 test_expect_success $PREREQ '--compose handles to headers' '
2586 write_script fake-editor <<-\EOF &&
2587 sed "s/^To: .*/&, edited-to@example.com/" <"$1" >"$1.tmp" &&
2588 echo this is the body >>"$1.tmp" &&
2591 clean_fake_sendmail &&
2592 GIT_SEND_EMAIL_NOTTY=1 \
2595 --from="Example <from@example.com>" \
2596 --to=nobody@example.com \
2597 --smtp-server="$(pwd)/fake.sendmail" \
2599 # Check both that the cover letter used our modified "to" line,
2600 # but also that it was picked up for the patch.
2601 q_to_tab >expect <<-\EOF &&
2602 To: nobody@example.com,
2603 Qedited-to@example.com
2605 grep -A1 "^To:" msgtxt1 >msgtxt1.to &&
2606 test_cmp expect msgtxt1.to &&
2607 grep -A1 "^To:" msgtxt2 >msgtxt2.to &&
2608 test_cmp expect msgtxt2.to