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_i18ngrep "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 header argument" '
637 write_script my-hooks/sendemail-validate <<-\EOF &&
640 grep "X-test-header: v1.0" "$2"
642 echo "No header arg passed"
646 test_config core.hooksPath "my-hooks" &&
649 --add-header="X-test-header: v1.0" \
650 -n HEAD^1 -o outdir &&
653 --to=nobody@example.com \
654 --smtp-server="$(pwd)/fake.sendmail" \
659 test_expect_success
$PREREQ 'clear message-id before parsing a new message' '
660 clean_fake_sendmail &&
661 echo true | write_script my-hooks/sendemail-validate &&
662 test_config core.hooksPath my-hooks &&
663 git send-email --validate --to=recipient@example.com \
664 --smtp-server="$(pwd)/fake.sendmail" \
665 $patches $threaded_patches &&
666 id0=$(grep "^Message-ID: " $threaded_patches) &&
667 id1=$(grep "^Message-ID: " msgtxt1) &&
668 id2=$(grep "^Message-ID: " msgtxt2) &&
669 test "z$id0" = "z$id2" &&
670 test "z$id1" != "z$id2"
673 for enc
in 7bit
8bit quoted-printable base64
675 test_expect_success
$PREREQ "--transfer-encoding=$enc produces correct header" '
676 clean_fake_sendmail &&
678 --from="Example <nobody@example.com>" \
679 --to=nobody@example.com \
680 --smtp-server="$(pwd)/fake.sendmail" \
681 --transfer-encoding=$enc \
683 grep "Content-Transfer-Encoding: $enc" msgtxt1
687 test_expect_success
$PREREQ 'Invalid In-Reply-To' '
688 clean_fake_sendmail &&
690 --from="Example <nobody@example.com>" \
691 --to=nobody@example.com \
693 --smtp-server="$(pwd)/fake.sendmail" \
696 ! grep "^In-Reply-To: < *>" msgtxt1
699 test_expect_success
$PREREQ 'Valid In-Reply-To when prompting' '
700 clean_fake_sendmail &&
701 (echo "From Example <from@example.com>" &&
702 echo "To Example <to@example.com>" &&
704 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
705 --smtp-server="$(pwd)/fake.sendmail" \
707 ! grep "^In-Reply-To: < *>" msgtxt1
710 test_expect_success
$PREREQ 'In-Reply-To without --chain-reply-to' '
711 clean_fake_sendmail &&
712 echo "<unique-message-id@example.com>" >expect &&
714 --from="Example <nobody@example.com>" \
715 --to=nobody@example.com \
716 --no-chain-reply-to \
717 --in-reply-to="$(cat expect)" \
718 --smtp-server="$(pwd)/fake.sendmail" \
719 $patches $patches $patches \
721 # The first message is a reply to --in-reply-to
722 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
723 test_cmp expect actual &&
724 # Second and subsequent messages are replies to the first one
725 sed -n -e "s/^Message-ID: *\(.*\)/\1/p" msgtxt1 >expect &&
726 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
727 test_cmp expect actual &&
728 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
729 test_cmp expect actual
732 test_expect_success
$PREREQ 'In-Reply-To with --chain-reply-to' '
733 clean_fake_sendmail &&
734 echo "<unique-message-id@example.com>" >expect &&
736 --from="Example <nobody@example.com>" \
737 --to=nobody@example.com \
739 --in-reply-to="$(cat expect)" \
740 --smtp-server="$(pwd)/fake.sendmail" \
741 $patches $patches $patches \
743 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
744 test_cmp expect actual &&
745 sed -n -e "s/^Message-ID: *\(.*\)/\1/p" msgtxt1 >expect &&
746 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
747 test_cmp expect actual &&
748 sed -n -e "s/^Message-ID: *\(.*\)/\1/p" msgtxt2 >expect &&
749 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
750 test_cmp expect actual
753 test_set_editor
"$(pwd)/fake-editor"
755 test_expect_success
$PREREQ 'setup erroring fake editor' '
756 write_script fake-editor <<-\EOF
757 echo >&2 "I am about to error"
762 test_expect_success
$PREREQ 'fake editor dies with error' '
763 clean_fake_sendmail &&
764 test_must_fail git send-email \
765 --compose --subject foo \
766 --from="Example <nobody@example.com>" \
767 --to=nobody@example.com \
768 --smtp-server="$(pwd)/fake.sendmail" \
770 grep "I am about to error" err &&
771 grep "the editor exited uncleanly, aborting everything" err
774 test_expect_success
$PREREQ 'setup fake editor' '
775 write_script fake-editor <<-\EOF
776 echo fake edit >>"$1"
780 test_expect_success
$PREREQ '--compose works' '
781 clean_fake_sendmail &&
783 --compose --subject foo \
784 --from="Example <nobody@example.com>" \
785 --to=nobody@example.com \
786 --smtp-server="$(pwd)/fake.sendmail" \
791 test_expect_success
$PREREQ 'first message is compose text' '
792 grep "^fake edit" msgtxt1
795 test_expect_success
$PREREQ 'second message is patch' '
796 grep "Subject:.*Second" msgtxt2
799 test_expect_success
$PREREQ 'setup expect' "
800 cat >expected-suppress-sob <<\EOF
802 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
803 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
804 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
806 Server: relay.example.com
807 MAIL FROM:<from@example.com>
808 RCPT TO:<to@example.com>
809 RCPT TO:<cc@example.com>
810 RCPT TO:<author@example.com>
811 RCPT TO:<one@example.com>
812 RCPT TO:<two@example.com>
813 From: Example <from@example.com>
816 A <author@example.com>,
817 One <one@example.com>,
819 Subject: [PATCH 1/1] Second.
821 Message-ID: MESSAGE-ID-STRING
822 X-Mailer: X-MAILER-STRING
824 Content-Transfer-Encoding: 8bit
830 test_suppression
() {
833 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
834 --from="Example <from@example.com>" \
835 --to=to@example.com \
836 --smtp-server relay.example.com \
837 $patches | replace_variable_fields \
838 >actual-suppress-
$1${2+"-$2"} &&
839 test_cmp expected-suppress-
$1${2+"-$2"} actual-suppress-
$1${2+"-$2"}
842 test_expect_success
$PREREQ 'sendemail.cc set' '
843 git config sendemail.cc cc@example.com &&
847 test_expect_success
$PREREQ 'setup expect' "
848 cat >expected-suppress-sob <<\EOF
850 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
851 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
852 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
854 Server: relay.example.com
855 MAIL FROM:<from@example.com>
856 RCPT TO:<to@example.com>
857 RCPT TO:<author@example.com>
858 RCPT TO:<one@example.com>
859 RCPT TO:<two@example.com>
860 From: Example <from@example.com>
862 Cc: A <author@example.com>,
863 One <one@example.com>,
865 Subject: [PATCH 1/1] Second.
867 Message-ID: MESSAGE-ID-STRING
868 X-Mailer: X-MAILER-STRING
870 Content-Transfer-Encoding: 8bit
876 test_expect_success
$PREREQ 'sendemail.cc unset' '
877 git config --unset sendemail.cc &&
881 test_expect_success
$PREREQ 'setup expect' "
882 cat >expected-suppress-cccmd <<\EOF
884 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
885 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
886 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
887 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
889 Server: relay.example.com
890 MAIL FROM:<from@example.com>
891 RCPT TO:<to@example.com>
892 RCPT TO:<author@example.com>
893 RCPT TO:<one@example.com>
894 RCPT TO:<two@example.com>
895 RCPT TO:<committer@example.com>
896 From: Example <from@example.com>
898 Cc: A <author@example.com>,
899 One <one@example.com>,
901 C O Mitter <committer@example.com>
902 Subject: [PATCH 1/1] Second.
904 Message-ID: MESSAGE-ID-STRING
905 X-Mailer: X-MAILER-STRING
907 Content-Transfer-Encoding: 8bit
913 test_expect_success
$PREREQ 'sendemail.cccmd' '
914 write_script cccmd <<-\EOF &&
915 echo cc-cmd@example.com
917 git config sendemail.cccmd ./cccmd &&
918 test_suppression cccmd
921 test_expect_success
$PREREQ 'setup expect' '
922 cat >expected-suppress-all <<\EOF
925 Server: relay.example.com
926 MAIL FROM:<from@example.com>
927 RCPT TO:<to@example.com>
928 From: Example <from@example.com>
930 Subject: [PATCH 1/1] Second.
932 Message-ID: MESSAGE-ID-STRING
933 X-Mailer: X-MAILER-STRING
935 Content-Transfer-Encoding: 8bit
941 test_expect_success
$PREREQ '--suppress-cc=all' '
945 test_expect_success
$PREREQ 'setup expect' "
946 cat >expected-suppress-body <<\EOF
948 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
949 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
950 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
951 (cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
953 Server: relay.example.com
954 MAIL FROM:<from@example.com>
955 RCPT TO:<to@example.com>
956 RCPT TO:<author@example.com>
957 RCPT TO:<one@example.com>
958 RCPT TO:<two@example.com>
959 RCPT TO:<cc-cmd@example.com>
960 From: Example <from@example.com>
962 Cc: A <author@example.com>,
963 One <one@example.com>,
966 Subject: [PATCH 1/1] Second.
968 Message-ID: MESSAGE-ID-STRING
969 X-Mailer: X-MAILER-STRING
971 Content-Transfer-Encoding: 8bit
977 test_expect_success
$PREREQ '--suppress-cc=body' '
978 test_suppression body
981 test_expect_success
$PREREQ 'setup expect' "
982 cat >expected-suppress-body-cccmd <<\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'
988 Server: relay.example.com
989 MAIL FROM:<from@example.com>
990 RCPT TO:<to@example.com>
991 RCPT TO:<author@example.com>
992 RCPT TO:<one@example.com>
993 RCPT TO:<two@example.com>
994 From: Example <from@example.com>
996 Cc: A <author@example.com>,
997 One <one@example.com>,
999 Subject: [PATCH 1/1] Second.
1001 Message-ID: MESSAGE-ID-STRING
1002 X-Mailer: X-MAILER-STRING
1004 Content-Transfer-Encoding: 8bit
1010 test_expect_success
$PREREQ '--suppress-cc=body --suppress-cc=cccmd' '
1011 test_suppression body cccmd
1014 test_expect_success
$PREREQ 'setup expect' "
1015 cat >expected-suppress-sob <<\EOF
1017 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
1018 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
1019 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
1021 Server: relay.example.com
1022 MAIL FROM:<from@example.com>
1023 RCPT TO:<to@example.com>
1024 RCPT TO:<author@example.com>
1025 RCPT TO:<one@example.com>
1026 RCPT TO:<two@example.com>
1027 From: Example <from@example.com>
1029 Cc: A <author@example.com>,
1030 One <one@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=sob' '
1044 test_might_fail git config --unset sendemail.cccmd &&
1045 test_suppression sob
1048 test_expect_success
$PREREQ 'setup expect' "
1049 cat >expected-suppress-bodycc <<\EOF
1051 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
1052 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
1053 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
1054 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
1056 Server: relay.example.com
1057 MAIL FROM:<from@example.com>
1058 RCPT TO:<to@example.com>
1059 RCPT TO:<author@example.com>
1060 RCPT TO:<one@example.com>
1061 RCPT TO:<two@example.com>
1062 RCPT TO:<committer@example.com>
1063 From: Example <from@example.com>
1065 Cc: A <author@example.com>,
1066 One <one@example.com>,
1068 C O Mitter <committer@example.com>
1069 Subject: [PATCH 1/1] Second.
1071 Message-ID: MESSAGE-ID-STRING
1072 X-Mailer: X-MAILER-STRING
1074 Content-Transfer-Encoding: 8bit
1080 test_expect_success
$PREREQ '--suppress-cc=bodycc' '
1081 test_suppression bodycc
1084 test_expect_success
$PREREQ 'setup expect' "
1085 cat >expected-suppress-cc <<\EOF
1087 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
1088 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
1090 Server: relay.example.com
1091 MAIL FROM:<from@example.com>
1092 RCPT TO:<to@example.com>
1093 RCPT TO:<author@example.com>
1094 RCPT TO:<committer@example.com>
1095 From: Example <from@example.com>
1097 Cc: A <author@example.com>,
1098 C O Mitter <committer@example.com>
1099 Subject: [PATCH 1/1] Second.
1101 Message-ID: MESSAGE-ID-STRING
1102 X-Mailer: X-MAILER-STRING
1104 Content-Transfer-Encoding: 8bit
1110 test_expect_success
$PREREQ '--suppress-cc=cc' '
1116 GIT_SEND_EMAIL_NOTTY
=1 \
1118 --from="Example <nobody@example.com>" \
1119 --to=nobody@example.com \
1120 --smtp-server="$(pwd)/fake.sendmail" \
1121 $@
$patches >stdout
&&
1122 grep "Send this email" stdout
1125 test_expect_success
$PREREQ '--confirm=always' '
1126 test_confirm --confirm=always --suppress-cc=all
1129 test_expect_success
$PREREQ '--confirm=auto' '
1130 test_confirm --confirm=auto
1133 test_expect_success
$PREREQ '--confirm=cc' '
1134 test_confirm --confirm=cc
1137 test_expect_success
$PREREQ '--confirm=compose' '
1138 test_confirm --confirm=compose --compose
1141 test_expect_success
$PREREQ 'confirm by default (due to cc)' '
1142 test_when_finished git config sendemail.confirm never &&
1143 git config --unset sendemail.confirm &&
1147 test_expect_success
$PREREQ 'confirm by default (due to --compose)' '
1148 test_when_finished git config sendemail.confirm never &&
1149 git config --unset sendemail.confirm &&
1150 test_confirm --suppress-cc=all --compose
1153 test_expect_success
$PREREQ 'confirm detects EOF (inform assumes y)' '
1154 test_when_finished git config sendemail.confirm never &&
1155 git config --unset sendemail.confirm &&
1157 git format-patch -2 -o outdir &&
1158 GIT_SEND_EMAIL_NOTTY=1 \
1160 --from="Example <nobody@example.com>" \
1161 --to=nobody@example.com \
1162 --smtp-server="$(pwd)/fake.sendmail" \
1163 outdir/*.patch </dev/null
1166 test_expect_success
$PREREQ 'confirm detects EOF (auto causes failure)' '
1167 test_when_finished git config sendemail.confirm never &&
1168 git config sendemail.confirm auto &&
1169 GIT_SEND_EMAIL_NOTTY=1 &&
1170 export GIT_SEND_EMAIL_NOTTY &&
1171 test_must_fail git send-email \
1172 --from="Example <nobody@example.com>" \
1173 --to=nobody@example.com \
1174 --smtp-server="$(pwd)/fake.sendmail" \
1178 test_expect_success
$PREREQ 'confirm does not loop forever' '
1179 test_when_finished git config sendemail.confirm never &&
1180 git config sendemail.confirm auto &&
1181 GIT_SEND_EMAIL_NOTTY=1 &&
1182 export GIT_SEND_EMAIL_NOTTY &&
1183 yes "bogus" | test_must_fail git send-email \
1184 --from="Example <nobody@example.com>" \
1185 --to=nobody@example.com \
1186 --smtp-server="$(pwd)/fake.sendmail" \
1190 test_expect_success
$PREREQ 'utf8 Cc is rfc2047 encoded' '
1191 clean_fake_sendmail &&
1193 git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
1195 --from="Example <nobody@example.com>" \
1196 --to=nobody@example.com \
1197 --smtp-server="$(pwd)/fake.sendmail" \
1200 grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
1203 test_expect_success
$PREREQ '--compose adds MIME for utf8 body' '
1204 clean_fake_sendmail &&
1205 write_script fake-editor-utf8 <<-\EOF &&
1206 echo "utf8 body: àéìöú" >>"$1"
1208 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1210 --compose --subject foo \
1211 --from="Example <nobody@example.com>" \
1212 --to=nobody@example.com \
1213 --smtp-server="$(pwd)/fake.sendmail" \
1215 grep "^utf8 body" msgtxt1 &&
1216 grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
1219 test_expect_success
$PREREQ '--compose respects user mime type' '
1220 clean_fake_sendmail &&
1221 write_script fake-editor-utf8-mime <<-\EOF &&
1224 Content-Type: text/plain; charset=iso-8859-1
1225 Content-Transfer-Encoding: 8bit
1231 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
1233 --compose --subject foo \
1234 --from="Example <nobody@example.com>" \
1235 --to=nobody@example.com \
1236 --smtp-server="$(pwd)/fake.sendmail" \
1238 grep "^utf8 body" msgtxt1 &&
1239 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
1240 ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
1243 test_expect_success
$PREREQ '--compose adds MIME for utf8 subject' '
1244 clean_fake_sendmail &&
1245 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
1247 --compose --subject utf8-sübjëct \
1248 --from="Example <nobody@example.com>" \
1249 --to=nobody@example.com \
1250 --smtp-server="$(pwd)/fake.sendmail" \
1252 grep "^fake edit" msgtxt1 &&
1253 grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
1256 test_expect_success
$PREREQ 'utf8 author is correctly passed on' '
1257 clean_fake_sendmail &&
1258 test_commit weird_author &&
1259 test_when_finished "git reset --hard HEAD^" &&
1260 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
1261 git format-patch --stdout -1 >funny_name.patch &&
1262 git send-email --from="Example <nobody@example.com>" \
1263 --to=nobody@example.com \
1264 --smtp-server="$(pwd)/fake.sendmail" \
1266 grep "^From: Füñný Nâmé <odd_?=mail@example.com>" msgtxt1
1269 test_expect_success
$PREREQ 'utf8 sender is not duplicated' '
1270 clean_fake_sendmail &&
1271 test_commit weird_sender &&
1272 test_when_finished "git reset --hard HEAD^" &&
1273 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
1274 git format-patch --stdout -1 >funny_name.patch &&
1275 git send-email --from="Füñný Nâmé <odd_?=mail@example.com>" \
1276 --to=nobody@example.com \
1277 --smtp-server="$(pwd)/fake.sendmail" \
1279 grep "^From: " msgtxt1 >msgfrom &&
1280 test_line_count = 1 msgfrom
1283 test_expect_success
$PREREQ 'sendemail.composeencoding works' '
1284 clean_fake_sendmail &&
1285 git config sendemail.composeencoding iso-8859-1 &&
1286 write_script fake-editor-utf8 <<-\EOF &&
1287 echo "utf8 body: àéìöú" >>"$1"
1289 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1291 --compose --subject foo \
1292 --from="Example <nobody@example.com>" \
1293 --to=nobody@example.com \
1294 --smtp-server="$(pwd)/fake.sendmail" \
1296 grep "^utf8 body" msgtxt1 &&
1297 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1300 test_expect_success
$PREREQ '--compose-encoding works' '
1301 clean_fake_sendmail &&
1302 write_script fake-editor-utf8 <<-\EOF &&
1303 echo "utf8 body: àéìöú" >>"$1"
1305 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1307 --compose-encoding iso-8859-1 \
1308 --compose --subject foo \
1309 --from="Example <nobody@example.com>" \
1310 --to=nobody@example.com \
1311 --smtp-server="$(pwd)/fake.sendmail" \
1313 grep "^utf8 body" msgtxt1 &&
1314 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1317 test_expect_success
$PREREQ '--compose-encoding overrides sendemail.composeencoding' '
1318 clean_fake_sendmail &&
1319 git config sendemail.composeencoding iso-8859-1 &&
1320 write_script fake-editor-utf8 <<-\EOF &&
1321 echo "utf8 body: àéìöú" >>"$1"
1323 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1325 --compose-encoding iso-8859-2 \
1326 --compose --subject foo \
1327 --from="Example <nobody@example.com>" \
1328 --to=nobody@example.com \
1329 --smtp-server="$(pwd)/fake.sendmail" \
1331 grep "^utf8 body" msgtxt1 &&
1332 grep "^Content-Type: text/plain; charset=iso-8859-2" msgtxt1
1335 test_expect_success
$PREREQ '--compose-encoding adds correct MIME for subject' '
1336 clean_fake_sendmail &&
1337 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
1339 --compose-encoding iso-8859-2 \
1340 --compose --subject utf8-sübjëct \
1341 --from="Example <nobody@example.com>" \
1342 --to=nobody@example.com \
1343 --smtp-server="$(pwd)/fake.sendmail" \
1345 grep "^fake edit" msgtxt1 &&
1346 grep "^Subject: =?iso-8859-2?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
1349 test_expect_success
$PREREQ 'detects ambiguous reference/file conflict' '
1352 git commit -m"add main" &&
1353 test_must_fail git send-email --dry-run main 2>errors &&
1354 grep disambiguate errors
1357 test_expect_success
$PREREQ 'feed two files' '
1359 git format-patch -2 -o outdir &&
1362 --from="Example <nobody@example.com>" \
1363 --to=nobody@example.com \
1364 outdir/000?-*.patch 2>errors >out &&
1365 grep "^Subject: " out >subjects &&
1366 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
1367 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add main"
1370 test_expect_success
$PREREQ 'in-reply-to but no threading' '
1373 --from="Example <nobody@example.com>" \
1374 --to=nobody@example.com \
1375 --in-reply-to="<in-reply-id@example.com>" \
1378 grep "In-Reply-To: <in-reply-id@example.com>" out
1381 test_expect_success
$PREREQ 'no in-reply-to and no threading' '
1384 --from="Example <nobody@example.com>" \
1385 --to=nobody@example.com \
1388 ! grep "In-Reply-To: " stdout
1391 test_expect_success
$PREREQ 'threading but no chain-reply-to' '
1394 --from="Example <nobody@example.com>" \
1395 --to=nobody@example.com \
1397 --no-chain-reply-to \
1398 $patches $patches >stdout &&
1399 grep "In-Reply-To: " stdout
1402 test_expect_success
$PREREQ 'override in-reply-to if no threading' '
1405 --from="Example <nobody@example.com>" \
1406 --to=nobody@example.com \
1408 --in-reply-to="override" \
1409 $threaded_patches >stdout &&
1410 grep "In-Reply-To: <override>" stdout
1413 test_expect_success
$PREREQ 'sendemail.to works' '
1414 git config --replace-all sendemail.to "Somebody <somebody@ex.com>" &&
1417 --from="Example <nobody@example.com>" \
1419 grep "To: Somebody <somebody@ex.com>" stdout
1422 test_expect_success
$PREREQ 'setup sendemail.identity' '
1423 git config --replace-all sendemail.to "default@example.com" &&
1424 git config --replace-all sendemail.isp.to "isp@example.com" &&
1425 git config --replace-all sendemail.cloud.to "cloud@example.com"
1428 test_expect_success
$PREREQ 'sendemail.identity: reads the correct identity config' '
1429 git -c sendemail.identity=cloud send-email \
1431 --from="nobody@example.com" \
1433 grep "To: cloud@example.com" stdout
1436 test_expect_success
$PREREQ 'sendemail.identity: identity overrides sendemail.identity' '
1437 git -c sendemail.identity=cloud send-email \
1440 --from="nobody@example.com" \
1442 grep "To: isp@example.com" stdout
1445 test_expect_success
$PREREQ 'sendemail.identity: --no-identity clears previous identity' '
1446 git -c sendemail.identity=cloud send-email \
1449 --from="nobody@example.com" \
1451 grep "To: default@example.com" stdout
1454 test_expect_success
$PREREQ 'sendemail.identity: bool identity variable existence overrides' '
1455 git -c sendemail.identity=cloud \
1456 -c sendemail.xmailer=true \
1457 -c sendemail.cloud.xmailer=false \
1460 --from="nobody@example.com" \
1462 grep "To: cloud@example.com" stdout &&
1463 ! grep "X-Mailer" stdout
1466 test_expect_success
$PREREQ 'sendemail.identity: bool variable fallback' '
1467 git -c sendemail.identity=cloud \
1468 -c sendemail.xmailer=false \
1471 --from="nobody@example.com" \
1473 grep "To: cloud@example.com" stdout &&
1474 ! grep "X-Mailer" stdout
1477 test_expect_success
$PREREQ 'sendemail.identity: bool variable without a value' '
1478 git -c sendemail.xmailer \
1481 --from="nobody@example.com" \
1483 grep "To: default@example.com" stdout &&
1484 grep "X-Mailer" stdout
1487 test_expect_success
$PREREQ '--no-to overrides sendemail.to' '
1490 --from="Example <nobody@example.com>" \
1492 --to=nobody@example.com \
1494 grep "To: nobody@example.com" stdout &&
1495 ! grep "To: Somebody <somebody@ex.com>" stdout
1498 test_expect_success
$PREREQ 'sendemail.cc works' '
1499 git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" &&
1502 --from="Example <nobody@example.com>" \
1503 --to=nobody@example.com \
1505 grep "Cc: Somebody <somebody@ex.com>" stdout
1508 test_expect_success
$PREREQ '--no-cc overrides sendemail.cc' '
1511 --from="Example <nobody@example.com>" \
1513 --cc=bodies@example.com \
1514 --to=nobody@example.com \
1516 grep "Cc: bodies@example.com" stdout &&
1517 ! grep "Cc: Somebody <somebody@ex.com>" stdout
1520 test_expect_success
$PREREQ 'sendemail.bcc works' '
1521 git config --replace-all sendemail.bcc "Other <other@ex.com>" &&
1524 --from="Example <nobody@example.com>" \
1525 --to=nobody@example.com \
1526 --smtp-server relay.example.com \
1528 grep "RCPT TO:<other@ex.com>" stdout
1531 test_expect_success
$PREREQ '--no-bcc overrides sendemail.bcc' '
1534 --from="Example <nobody@example.com>" \
1536 --bcc=bodies@example.com \
1537 --to=nobody@example.com \
1538 --smtp-server relay.example.com \
1540 grep "RCPT TO:<bodies@example.com>" stdout &&
1541 ! grep "RCPT TO:<other@ex.com>" stdout
1544 test_expect_success
$PREREQ 'patches To headers are used by default' '
1545 patch=$(git format-patch -1 --to="bodies@example.com") &&
1546 test_when_finished "rm $patch" &&
1549 --from="Example <nobody@example.com>" \
1550 --smtp-server relay.example.com \
1552 grep "RCPT TO:<bodies@example.com>" stdout
1555 test_expect_success
$PREREQ 'patches To headers are appended to' '
1556 patch=$(git format-patch -1 --to="bodies@example.com") &&
1557 test_when_finished "rm $patch" &&
1560 --from="Example <nobody@example.com>" \
1561 --to=nobody@example.com \
1562 --smtp-server relay.example.com \
1564 grep "RCPT TO:<bodies@example.com>" stdout &&
1565 grep "RCPT TO:<nobody@example.com>" stdout
1568 test_expect_success
$PREREQ 'To headers from files reset each patch' '
1569 patch1=$(git format-patch -1 --to="bodies@example.com") &&
1570 patch2=$(git format-patch -1 --to="other@example.com" HEAD~) &&
1571 test_when_finished "rm $patch1 && rm $patch2" &&
1574 --from="Example <nobody@example.com>" \
1575 --to="nobody@example.com" \
1576 --smtp-server relay.example.com \
1577 $patch1 $patch2 >stdout &&
1578 test $(grep -c "RCPT TO:<bodies@example.com>" stdout) = 1 &&
1579 test $(grep -c "RCPT TO:<nobody@example.com>" stdout) = 2 &&
1580 test $(grep -c "RCPT TO:<other@example.com>" stdout) = 1
1583 test_expect_success
$PREREQ 'setup expect' '
1584 cat >email-using-8bit <<\EOF
1585 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1586 Message-ID: <bogus-message-id@example.com>
1587 From: author@example.com
1588 Date: Sat, 12 Jun 2010 15:53:58 +0200
1589 Subject: subject goes here
1591 Dieser deutsche Text enthält einen Umlaut!
1595 test_expect_success
$PREREQ 'setup expect' '
1596 echo "Subject: subject goes here" >expected
1599 test_expect_success
$PREREQ 'ASCII subject is not RFC2047 quoted' '
1600 clean_fake_sendmail &&
1602 git send-email --from=author@example.com --to=nobody@example.com \
1603 --smtp-server="$(pwd)/fake.sendmail" \
1604 --8bit-encoding=UTF-8 \
1605 email-using-8bit >stdout &&
1606 grep "Subject" msgtxt1 >actual &&
1607 test_cmp expected actual
1610 test_expect_success
$PREREQ 'setup expect' '
1611 cat >content-type-decl <<-\EOF
1613 Content-Type: text/plain; charset=UTF-8
1614 Content-Transfer-Encoding: 8bit
1618 test_expect_success
$PREREQ 'asks about and fixes 8bit encodings' '
1619 clean_fake_sendmail &&
1621 git send-email --from=author@example.com --to=nobody@example.com \
1622 --smtp-server="$(pwd)/fake.sendmail" \
1623 email-using-8bit >stdout &&
1624 grep "do not declare a Content-Transfer-Encoding" stdout &&
1625 grep email-using-8bit stdout &&
1626 grep "Which 8bit encoding" stdout &&
1627 grep -E "Content|MIME" msgtxt1 >actual &&
1628 test_cmp content-type-decl actual
1631 test_expect_success
$PREREQ 'sendemail.8bitEncoding works' '
1632 clean_fake_sendmail &&
1633 git config sendemail.assume8bitEncoding UTF-8 &&
1635 git send-email --from=author@example.com --to=nobody@example.com \
1636 --smtp-server="$(pwd)/fake.sendmail" \
1637 email-using-8bit >stdout &&
1638 grep -E "Content|MIME" msgtxt1 >actual &&
1639 test_cmp content-type-decl actual
1642 test_expect_success
$PREREQ 'sendemail.8bitEncoding in .git/config overrides --global .gitconfig' '
1643 clean_fake_sendmail &&
1644 git config sendemail.assume8bitEncoding UTF-8 &&
1645 test_when_finished "rm -rf home" &&
1647 git config -f home/.gitconfig sendemail.assume8bitEncoding "bogus too" &&
1649 env HOME="$(pwd)/home" DEBUG=1 \
1650 git send-email --from=author@example.com --to=nobody@example.com \
1651 --smtp-server="$(pwd)/fake.sendmail" \
1652 email-using-8bit >stdout &&
1653 grep -E "Content|MIME" msgtxt1 >actual &&
1654 test_cmp content-type-decl actual
1657 test_expect_success
$PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
1658 clean_fake_sendmail &&
1659 git config sendemail.assume8bitEncoding "bogus too" &&
1661 git send-email --from=author@example.com --to=nobody@example.com \
1662 --smtp-server="$(pwd)/fake.sendmail" \
1663 --8bit-encoding=UTF-8 \
1664 email-using-8bit >stdout &&
1665 grep -E "Content|MIME" msgtxt1 >actual &&
1666 test_cmp content-type-decl actual
1669 test_expect_success
$PREREQ 'setup expect' '
1670 cat >email-using-8bit <<-\EOF
1671 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1672 Message-ID: <bogus-message-id@example.com>
1673 From: author@example.com
1674 Date: Sat, 12 Jun 2010 15:53:58 +0200
1675 Subject: Dieser Betreff enthält auch einen Umlaut!
1677 Nothing to see here.
1681 test_expect_success
$PREREQ 'setup expect' '
1682 cat >expected <<-\EOF
1683 Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
1687 test_expect_success
$PREREQ '--8bit-encoding also treats subject' '
1688 clean_fake_sendmail &&
1690 git send-email --from=author@example.com --to=nobody@example.com \
1691 --smtp-server="$(pwd)/fake.sendmail" \
1692 --8bit-encoding=UTF-8 \
1693 email-using-8bit >stdout &&
1694 grep "Subject" msgtxt1 >actual &&
1695 test_cmp expected actual
1698 test_expect_success
$PREREQ 'setup expect' '
1699 cat >email-using-8bit <<-\EOF
1700 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1701 Message-ID: <bogus-message-id@example.com>
1702 From: A U Thor <author@example.com>
1703 Date: Sat, 12 Jun 2010 15:53:58 +0200
1704 Content-Type: text/plain; charset=UTF-8
1705 Subject: Nothing to see here.
1707 Dieser Betreff enthält auch einen Umlaut!
1711 test_expect_success
$PREREQ '--transfer-encoding overrides sendemail.transferEncoding' '
1712 clean_fake_sendmail &&
1713 test_must_fail git -c sendemail.transferEncoding=8bit \
1715 --transfer-encoding=7bit \
1716 --smtp-server="$(pwd)/fake.sendmail" \
1719 grep "cannot send message as 7bit" errors &&
1720 test -z "$(ls msgtxt*)"
1723 test_expect_success
$PREREQ 'sendemail.transferEncoding via config' '
1724 clean_fake_sendmail &&
1725 test_must_fail git -c sendemail.transferEncoding=7bit \
1727 --smtp-server="$(pwd)/fake.sendmail" \
1730 grep "cannot send message as 7bit" errors &&
1731 test -z "$(ls msgtxt*)"
1734 test_expect_success
$PREREQ 'sendemail.transferEncoding via cli' '
1735 clean_fake_sendmail &&
1736 test_must_fail git send-email \
1737 --transfer-encoding=7bit \
1738 --smtp-server="$(pwd)/fake.sendmail" \
1741 grep "cannot send message as 7bit" errors &&
1742 test -z "$(ls msgtxt*)"
1745 test_expect_success
$PREREQ 'setup expect' '
1746 cat >expected <<-\EOF
1747 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1751 test_expect_success
$PREREQ '8-bit and sendemail.transferencoding=quoted-printable' '
1752 clean_fake_sendmail &&
1754 --transfer-encoding=quoted-printable \
1755 --smtp-server="$(pwd)/fake.sendmail" \
1758 sed "1,/^$/d" msgtxt1 >actual &&
1759 test_cmp expected actual
1762 test_expect_success
$PREREQ 'setup expect' '
1763 cat >expected <<-\EOF
1764 RGllc2VyIEJldHJlZmYgZW50aMOkbHQgYXVjaCBlaW5lbiBVbWxhdXQhCg==
1768 test_expect_success
$PREREQ '8-bit and sendemail.transferencoding=base64' '
1769 clean_fake_sendmail &&
1771 --transfer-encoding=base64 \
1772 --smtp-server="$(pwd)/fake.sendmail" \
1775 sed "1,/^$/d" msgtxt1 >actual &&
1776 test_cmp expected actual
1779 test_expect_success
$PREREQ 'setup expect' '
1780 cat >email-using-qp <<-\EOF
1781 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1782 Message-ID: <bogus-message-id@example.com>
1783 From: A U Thor <author@example.com>
1784 Date: Sat, 12 Jun 2010 15:53:58 +0200
1786 Content-Transfer-Encoding: quoted-printable
1787 Content-Type: text/plain; charset=UTF-8
1788 Subject: Nothing to see here.
1790 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1794 test_expect_success
$PREREQ 'convert from quoted-printable to base64' '
1795 clean_fake_sendmail &&
1797 --transfer-encoding=base64 \
1798 --smtp-server="$(pwd)/fake.sendmail" \
1801 sed "1,/^$/d" msgtxt1 >actual &&
1802 test_cmp expected actual
1805 test_expect_success
$PREREQ 'setup expect' "
1806 tr -d '\\015' | tr '%' '\\015' >email-using-crlf <<EOF
1807 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1808 Message-ID: <bogus-message-id@example.com>
1809 From: A U Thor <author@example.com>
1810 Date: Sat, 12 Jun 2010 15:53:58 +0200
1811 Content-Type: text/plain; charset=UTF-8
1812 Subject: Nothing to see here.
1814 Look, I have a CRLF and an = sign!%
1818 test_expect_success
$PREREQ 'setup expect' '
1819 cat >expected <<-\EOF
1820 Look, I have a CRLF and an =3D sign!=0D
1824 test_expect_success
$PREREQ 'CRLF and sendemail.transferencoding=quoted-printable' '
1825 clean_fake_sendmail &&
1827 --transfer-encoding=quoted-printable \
1828 --smtp-server="$(pwd)/fake.sendmail" \
1831 sed "1,/^$/d" msgtxt1 >actual &&
1832 test_cmp expected actual
1835 test_expect_success
$PREREQ 'setup expect' '
1836 cat >expected <<-\EOF
1837 TG9vaywgSSBoYXZlIGEgQ1JMRiBhbmQgYW4gPSBzaWduIQ0K
1841 test_expect_success
$PREREQ 'CRLF and sendemail.transferencoding=base64' '
1842 clean_fake_sendmail &&
1844 --transfer-encoding=base64 \
1845 --smtp-server="$(pwd)/fake.sendmail" \
1848 sed "1,/^$/d" msgtxt1 >actual &&
1849 test_cmp expected actual
1853 # Note that the patches in this test are deliberately out of order; we
1854 # want to make sure it works even if the cover-letter is not in the
1856 test_expect_success
$PREREQ 'refusing to send cover letter template' '
1857 clean_fake_sendmail &&
1859 git format-patch --cover-letter -2 -o outdir &&
1860 test_must_fail git send-email \
1861 --from="Example <nobody@example.com>" \
1862 --to=nobody@example.com \
1863 --smtp-server="$(pwd)/fake.sendmail" \
1864 outdir/0002-*.patch \
1865 outdir/0000-*.patch \
1866 outdir/0001-*.patch \
1868 grep "SUBJECT HERE" errors &&
1869 test -z "$(ls msgtxt*)"
1872 test_expect_success
$PREREQ '--force sends cover letter template anyway' '
1873 clean_fake_sendmail &&
1875 git format-patch --cover-letter -2 -o outdir &&
1878 --from="Example <nobody@example.com>" \
1879 --to=nobody@example.com \
1880 --smtp-server="$(pwd)/fake.sendmail" \
1881 outdir/0002-*.patch \
1882 outdir/0000-*.patch \
1883 outdir/0001-*.patch \
1885 ! grep "SUBJECT HERE" errors &&
1886 test -n "$(ls msgtxt*)"
1889 test_cover_addresses
() {
1892 clean_fake_sendmail
&&
1894 git format-patch
--cover-letter -2 -o outdir
&&
1895 cover
=$
(echo outdir
/0000-*.
patch) &&
1896 mv $cover cover-to-edit.
patch &&
1897 perl
-pe "s/^From:/$header: extra\@address.com\nFrom:/" cover-to-edit.
patch >"$cover" &&
1900 --from="Example <nobody@example.com>" \
1903 --smtp-server="$(pwd)/fake.sendmail" \
1904 outdir
/0000-*.
patch \
1905 outdir
/0001-*.
patch \
1906 outdir
/0002-*.
patch \
1908 grep "^$header: extra@address.com" msgtxt1
>to1
&&
1909 grep "^$header: extra@address.com" msgtxt2
>to2
&&
1910 grep "^$header: extra@address.com" msgtxt3
>to3
&&
1911 test_line_count
= 1 to1
&&
1912 test_line_count
= 1 to2
&&
1913 test_line_count
= 1 to3
1916 test_expect_success
$PREREQ 'to-cover adds To to all mail' '
1917 test_cover_addresses "To" --to-cover
1920 test_expect_success
$PREREQ 'cc-cover adds Cc to all mail' '
1921 test_cover_addresses "Cc" --cc-cover
1924 test_expect_success
$PREREQ 'tocover adds To to all mail' '
1925 test_config sendemail.tocover true &&
1926 test_cover_addresses "To"
1929 test_expect_success
$PREREQ 'cccover adds Cc to all mail' '
1930 test_config sendemail.cccover true &&
1931 test_cover_addresses "Cc"
1934 test_expect_success
$PREREQ 'escaped quotes in sendemail.aliasfiletype=mutt' '
1935 clean_fake_sendmail &&
1936 echo "alias sbd \\\"Dot U. Sir\\\" <somebody@example.org>" >.mutt &&
1937 git config --replace-all sendemail.aliasesfile "$(pwd)/.mutt" &&
1938 git config sendemail.aliasfiletype mutt &&
1940 --from="Example <nobody@example.com>" \
1942 --smtp-server="$(pwd)/fake.sendmail" \
1943 outdir/0001-*.patch \
1945 grep "^!somebody@example\.org!$" commandline1 &&
1946 grep -F "To: \"Dot U. Sir\" <somebody@example.org>" out
1949 test_expect_success
$PREREQ 'sendemail.aliasfiletype=mailrc' '
1950 clean_fake_sendmail &&
1951 echo "alias sbd somebody@example.org" >.mailrc &&
1952 git config --replace-all sendemail.aliasesfile "$(pwd)/.mailrc" &&
1953 git config sendemail.aliasfiletype mailrc &&
1955 --from="Example <nobody@example.com>" \
1957 --smtp-server="$(pwd)/fake.sendmail" \
1958 outdir/0001-*.patch \
1960 grep "^!somebody@example\.org!$" commandline1
1963 test_expect_success
$PREREQ 'sendemail.aliasesfile=~/.mailrc' '
1964 clean_fake_sendmail &&
1965 echo "alias sbd someone@example.org" >"$HOME/.mailrc" &&
1966 git config --replace-all sendemail.aliasesfile "~/.mailrc" &&
1967 git config sendemail.aliasfiletype mailrc &&
1969 --from="Example <nobody@example.com>" \
1971 --smtp-server="$(pwd)/fake.sendmail" \
1972 outdir/0001-*.patch \
1974 grep "^!someone@example\.org!$" commandline1
1977 test_dump_aliases
() {
1978 msg
="$1" && shift &&
1979 filetype
="$1" && shift &&
1980 printf '%s\n' "$@" >expect
&&
1981 cat >.tmp-email-aliases
&&
1983 test_expect_success
$PREREQ "$msg" '
1984 clean_fake_sendmail && rm -fr outdir &&
1985 git config --replace-all sendemail.aliasesfile \
1986 "$(pwd)/.tmp-email-aliases" &&
1987 git config sendemail.aliasfiletype "$filetype" &&
1988 git send-email --dump-aliases 2>errors >actual &&
1989 test_cmp expect actual
1993 test_dump_aliases
'--dump-aliases sendmail format' \
2000 alice: Alice W Land <awol@example.com>
2001 bob: Robert Bobbyton <bob@example.com>
2002 chloe: chloe@example.com
2004 bcgrp: bob, chloe, Other <o@example.com>
2007 test_dump_aliases '--dump-aliases mutt format' \
2013 alias alice Alice W Land <awol@example.com>
2014 alias donald Donald C Carlton <donc@example.com>
2015 alias bob Robert Bobbyton <bob@example.com>
2016 alias chloe chloe@example.com
2019 test_dump_aliases '--dump-aliases mailrc format' \
2025 alias alice Alice W Land <awol@example.com>
2026 alias eve Eve <eve@example.com>
2027 alias bob Robert Bobbyton <bob@example.com>
2028 alias chloe chloe@example.com
2031 test_dump_aliases '--dump-aliases pine format' \
2037 alice Alice W Land <awol@example.com>
2038 eve Eve <eve@example.com>
2039 bob Robert Bobbyton <bob@example.com>
2040 chloe chloe@example.com
2043 test_dump_aliases '--dump-aliases gnus format' \
2049 (define-mail-alias "alice" "awol@example.com")
2050 (define-mail-alias "eve" "eve@example.com")
2051 (define-mail-alias "bob" "bob@example.com")
2052 (define-mail-alias "chloe" "chloe@example.com")
2055 test_expect_success '--dump-aliases must be used alone' '
2056 test_must_fail git send-email --dump-aliases --to=janice@example.com -1 refs/heads/accounting
2059 test_expect_success $PREREQ 'aliases and sendemail.identity' '
2060 test_must_fail git \
2061 -c sendemail.identity=cloud \
2062 -c sendemail.aliasesfile=default-aliases \
2063 -c sendemail.cloud.aliasesfile=cloud-aliases \
2064 send-email -1 2>stderr &&
2065 test_i18ngrep "cloud-aliases" stderr
2068 test_sendmail_aliases () {
2069 msg="$1" && shift &&
2071 cat >.tmp-email-aliases &&
2073 test_expect_success $PREREQ "$msg" '
2074 clean_fake_sendmail && rm -fr outdir &&
2075 git format-patch -1 -o outdir &&
2076 git config --replace-all sendemail.aliasesfile \
2077 "$(pwd)/.tmp-email-aliases" &&
2078 git config sendemail.aliasfiletype sendmail &&
2080 --from="Example <nobody@example.com>" \
2081 --to=alice --to=bcgrp \
2082 --smtp-server="$(pwd)/fake.sendmail" \
2083 outdir/0001-*.
patch \
2087 grep "^!$i!$" commandline1 ||
return 1
2092 test_sendmail_aliases 'sendemail.aliasfiletype
=sendmail
' \
2093 'awol@example\.com
' \
2094 'bob@example\.com
' \
2095 'chloe@example\.com
' \
2096 'o@example\.com
' <<-\EOF
2097 alice: Alice W Land <awol@example.com>
2098 bob: Robert Bobbyton <bob@example.com>
2100 # this is also a comment
2101 chloe: chloe@example.com
2103 bcgrp: bob, chloe, Other <o@example.com>
2106 test_sendmail_aliases 'sendmail aliases line folding
' \
2110 darla1 darla2 darla3 \
2111 elton1 elton2 elton3 \
2128 bcgrp: bob, chuck, darla, elton, fred, greg
2131 test_sendmail_aliases 'sendmail aliases tolerate bogus line folding
' \
2137 test_sendmail_aliases 'sendmail aliases empty
' alice bcgrp <<-\EOF
2140 test_expect_success $PREREQ 'alias support
in To header
' '
2141 clean_fake_sendmail
&&
2142 echo "alias sbd someone@example.org" >.mailrc
&&
2143 test_config sendemail.aliasesfile
".mailrc" &&
2144 test_config sendemail.aliasfiletype mailrc
&&
2145 git format-patch
--stdout -1 --to=sbd
>aliased.
patch &&
2147 --from="Example <nobody@example.com>" \
2148 --smtp-server="$(pwd)/fake.sendmail" \
2151 grep "^!someone@example\.org!$" commandline1
2154 test_expect_success $PREREQ 'alias support
in Cc header
' '
2155 clean_fake_sendmail
&&
2156 echo "alias sbd someone@example.org" >.mailrc
&&
2157 test_config sendemail.aliasesfile
".mailrc" &&
2158 test_config sendemail.aliasfiletype mailrc
&&
2159 git format-patch
--stdout -1 --cc=sbd
>aliased.
patch &&
2161 --from="Example <nobody@example.com>" \
2162 --smtp-server="$(pwd)/fake.sendmail" \
2165 grep "^!someone@example\.org!$" commandline1
2168 test_expect_success $PREREQ 'tocmd works with aliases
' '
2169 clean_fake_sendmail
&&
2170 echo "alias sbd someone@example.org" >.mailrc
&&
2171 test_config sendemail.aliasesfile
".mailrc" &&
2172 test_config sendemail.aliasfiletype mailrc
&&
2173 git format-patch
--stdout -1 >tocmd.
patch &&
2174 echo tocmd--sbd
>>tocmd.
patch &&
2176 --from="Example <nobody@example.com>" \
2177 --to-cmd=.
/tocmd-sed \
2178 --smtp-server="$(pwd)/fake.sendmail" \
2181 grep "^!someone@example\.org!$" commandline1
2184 test_expect_success $PREREQ 'cccmd works with aliases
' '
2185 clean_fake_sendmail
&&
2186 echo "alias sbd someone@example.org" >.mailrc
&&
2187 test_config sendemail.aliasesfile
".mailrc" &&
2188 test_config sendemail.aliasfiletype mailrc
&&
2189 git format-patch
--stdout -1 >cccmd.
patch &&
2190 echo cccmd--sbd
>>cccmd.
patch &&
2192 --from="Example <nobody@example.com>" \
2193 --cc-cmd=.
/cccmd-sed \
2194 --smtp-server="$(pwd)/fake.sendmail" \
2197 grep "^!someone@example\.org!$" commandline1
2200 do_xmailer_test () {
2201 expected=$1 params=$2 &&
2202 git format-patch -1 &&
2204 --from="Example <nobody@example.com>" \
2205 --to=someone@example.com \
2206 --smtp-server="$(pwd)/fake.sendmail" \
2210 { grep '^X-Mailer
:' out || :; } >mailer &&
2211 test_line_count = $expected mailer
2214 test_expect_success $PREREQ '--[no-
]xmailer without any configuration
' '
2215 do_xmailer_test
1 "--xmailer" &&
2216 do_xmailer_test
0 "--no-xmailer"
2219 test_expect_success $PREREQ '--[no-
]xmailer with sendemail.xmailer
=true
' '
2220 test_config sendemail.xmailer true
&&
2221 do_xmailer_test
1 "" &&
2222 do_xmailer_test
0 "--no-xmailer" &&
2223 do_xmailer_test
1 "--xmailer"
2226 test_expect_success $PREREQ '--[no-
]xmailer with sendemail.xmailer
' '
2227 test_when_finished
"test_unconfig sendemail.xmailer" &&
2228 cat >>.git
/config
<<-\EOF &&
2232 test_config sendemail.xmailer true &&
2233 do_xmailer_test 1 "" &&
2234 do_xmailer_test 0 "--no-xmailer" &&
2235 do_xmailer_test 1 "--xmailer"
2238 test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=false' '
2239 test_config sendemail.xmailer false &&
2240 do_xmailer_test 0 "" &&
2241 do_xmailer_test 0 "--no-xmailer" &&
2242 do_xmailer_test 1 "--xmailer"
2245 test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=' '
2246 test_config sendemail.xmailer "" &&
2247 do_xmailer_test 0 "" &&
2248 do_xmailer_test 0 "--no-xmailer" &&
2249 do_xmailer_test 1 "--xmailer"
2252 test_expect_success $PREREQ 'setup expected-list' '
2255 --from="Example <from@example.com>" \
2256 --to="To 1 <to1@example.com>" \
2257 --to="to2@example.com" \
2258 --to="to3@example.com" \
2259 --cc="Cc 1 <cc1@example.com>" \
2260 --cc="Cc2 <cc2@example.com>" \
2261 --bcc="bcc1@example.com" \
2262 --bcc="bcc2@example.com" \
2263 0001-add-main.patch | replace_variable_fields \
2267 test_expect_success $PREREQ 'use email list in --cc --to and --bcc' '
2270 --from="Example <from@example.com>" \
2271 --to="To 1 <to1@example.com>, to2@example.com" \
2272 --to="to3@example.com" \
2273 --cc="Cc 1 <cc1@example.com>, Cc2 <cc2@example.com>" \
2274 --bcc="bcc1@example.com, bcc2@example.com" \
2275 0001-add-main.patch | replace_variable_fields \
2277 test_cmp expected-list actual-list
2280 test_expect_success $PREREQ 'aliases work with email list' '
2281 echo "alias to2 to2@example.com" >.mutt &&
2282 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt &&
2283 test_config sendemail.aliasesfile ".mutt" &&
2284 test_config sendemail.aliasfiletype mutt &&
2287 --from="Example <from@example.com>" \
2288 --to="To 1 <to1@example.com>, to2, to3@example.com" \
2289 --cc="cc1, Cc2 <cc2@example.com>" \
2290 --bcc="bcc1@example.com, bcc2@example.com" \
2291 0001-add-main.patch | replace_variable_fields \
2293 test_cmp expected-list actual-list
2296 test_expect_success $PREREQ 'leading and trailing whitespaces are removed' '
2297 echo "alias to2 to2@example.com" >.mutt &&
2298 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt &&
2299 test_config sendemail.aliasesfile ".mutt" &&
2300 test_config sendemail.aliasfiletype mutt &&
2301 TO1=$(echo "QTo 1 <to1@example.com>" | q_to_tab) &&
2302 TO2=$(echo "QZto2" | qz_to_tab_space) &&
2303 CC1=$(echo "cc1" | append_cr) &&
2304 BCC1=$(echo " bcc1@example.com Q" | q_to_nul) &&
2307 --from=" Example <from@example.com>" \
2310 --to=" to3@example.com " \
2312 --cc="Cc2 <cc2@example.com>" \
2314 --bcc="bcc2@example.com" \
2315 0001-add-main.patch | replace_variable_fields \
2317 test_cmp expected-list actual-list
2320 test_expect_success $PREREQ 'test using command name with --sendmail-cmd' '
2321 clean_fake_sendmail &&
2324 --from="Example <nobody@example.com>" \
2325 --to=nobody@example.com \
2326 --sendmail-cmd="fake.sendmail" \
2328 test_path_is_file commandline1
2331 test_expect_success $PREREQ 'test using arguments with --sendmail-cmd' '
2332 clean_fake_sendmail &&
2334 --from="Example <nobody@example.com>" \
2335 --to=nobody@example.com \
2336 --sendmail-cmd='\''"$(pwd)/fake.sendmail" -f nobody@example.com'\'' \
2338 test_path_is_file commandline1
2341 test_expect_success $PREREQ 'test shell expression with --sendmail-cmd' '
2342 clean_fake_sendmail &&
2344 --from="Example <nobody@example.com>" \
2345 --to=nobody@example.com \
2346 --sendmail-cmd='\''f() { "$(pwd)/fake.sendmail" "$@"; };f'\'' \
2348 test_path_is_file commandline1
2351 test_expect_success $PREREQ 'set up in-reply-to/references patches' '
2352 cat >has-reply.patch <<-\
EOF &&
2353 From: A U Thor <author@example.com>
2354 Subject: patch with in-reply-to
2355 Message-ID: <patch.with.in.reply.to@example.com>
2356 In-Reply-To: <replied.to@example.com>
2357 References: <replied.to@example.com>
2361 cat >no-reply.patch <<-\EOF
2362 From: A U Thor <author@example.com>
2363 Subject: patch without in-reply-to
2364 Message-ID: <patch.without.in.reply.to@example.com>
2370 test_expect_success $PREREQ 'patch reply headers correct with --no-thread' '
2371 clean_fake_sendmail &&
2374 --to=nobody@example.com \
2375 --smtp-server="$(pwd)/fake.sendmail" \
2376 has-reply.patch no-reply.patch &&
2377 grep "In-Reply-To: <replied.to@example.com>" msgtxt1 &&
2378 grep "References: <replied.to@example.com>" msgtxt1 &&
2379 ! grep replied.to@example.com msgtxt2
2382 test_expect_success $PREREQ 'cmdline in-reply-to used with --no-thread' '
2383 clean_fake_sendmail &&
2386 --in-reply-to="<cmdline.reply@example.com>" \
2387 --to=nobody@example.com \
2388 --smtp-server="$(pwd)/fake.sendmail" \
2389 has-reply.patch no-reply.patch &&
2390 grep "In-Reply-To: <cmdline.reply@example.com>" msgtxt1 &&
2391 grep "References: <cmdline.reply@example.com>" msgtxt1 &&
2392 grep "In-Reply-To: <cmdline.reply@example.com>" msgtxt2 &&
2393 grep "References: <cmdline.reply@example.com>" msgtxt2
2396 test_expect_success $PREREQ 'invoke hook' '
2397 test_hook sendemail-validate <<-\EOF &&
2398 # test that we have the correct environment variable, pwd, and
2408 test -f 0001-add-main.patch &&
2409 grep "add main" "$1"
2414 # Test that it works even if we are not at the root of the
2418 --from="Example <nobody@example.com>" \
2419 --to=nobody@example.com \
2420 --smtp-server="$(pwd)/../fake.sendmail" \
2421 ../0001-add-main.patch &&
2423 # Verify error message when a patch is rejected by the hook
2424 sed -e "s/add main/x/" ../0001-add-main.patch >../another.patch &&
2425 test_must_fail git send-email \
2426 --from="Example <nobody@example.com>" \
2427 --to=nobody@example.com \
2428 --smtp-server="$(pwd)/../fake.sendmail" \
2429 ../another.patch 2>err &&
2430 test_i18ngrep "rejected by sendemail-validate hook" err
2434 expected_file_counter_output () {
2437 while test $count -ne $total
2439 count=$((count + 1)) &&
2440 echo "$count/$total" || return
2444 test_expect_success $PREREQ '--validate hook allows counting of messages' '
2445 test_when_finished "rm -rf my-hooks.log" &&
2446 test_config core.hooksPath "my-hooks" &&
2447 mkdir -p my-hooks &&
2449 write_script my-hooks/sendemail-validate <<-\EOF &&
2450 num=$GIT_SENDEMAIL_FILE_COUNTER &&
2451 tot=$GIT_SENDEMAIL_FILE_TOTAL &&
2452 echo "$num/$tot" >>my-hooks.log || exit 1
2456 expected_file_counter_output 4 >expect &&
2458 --from="Example <from@example.com>" \
2459 --to=nobody@example.com \
2460 --smtp-server="$(pwd)/fake.sendmail" \
2461 --validate -3 --cover-letter --force &&
2462 test_cmp expect my-hooks.log
2465 test_expect_success $PREREQ 'test that send-email works outside a repo' '
2466 nongit git send-email \
2467 --from="Example <nobody@example.com>" \
2468 --to=nobody@example.com \
2469 --smtp-server="$(pwd)/fake.sendmail" \
2470 "$(pwd)/0001-add-main.patch"
2473 test_expect_success $PREREQ 'send-email relays -v 3 to format-patch' '
2474 test_when_finished "rm -f out" &&
2475 git send-email --dry-run -v 3 -1 >out &&
2479 test_expect_success $PREREQ 'test that sendmail config is rejected' '
2480 test_config sendmail.program sendmail &&
2481 test_must_fail git send-email \
2482 --from="Example <nobody@example.com>" \
2483 --to=nobody@example.com \
2484 --smtp-server="$(pwd)/fake.sendmail" \
2486 test_i18ngrep "found configuration options for '"'"sendmail"'"'" err
2489 test_expect_success $PREREQ 'test that sendmail config rejection is specific' '
2490 test_config resendmail.program sendmail &&
2492 --from="Example <nobody@example.com>" \
2493 --to=nobody@example.com \
2494 --smtp-server="$(pwd)/fake.sendmail" \
2498 test_expect_success $PREREQ 'test forbidSendmailVariables behavior override' '
2499 test_config sendmail.program sendmail &&
2500 test_config sendemail.forbidSendmailVariables false &&
2502 --from="Example <nobody@example.com>" \
2503 --to=nobody@example.com \
2504 --smtp-server="$(pwd)/fake.sendmail" \