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 -s --in-reply-to="format" HEAD^1)
53 # Test no confirm early to ensure remaining tests will not hang
57 GIT_SEND_EMAIL_NOTTY
=1 \
59 --from="Example <from@example.com>" \
60 --to=nobody@example.com \
61 --smtp-server="$(pwd)/fake.sendmail" \
64 ! grep "Send this email" stdout
&&
68 # Exit immediately to prevent hang if a no-confirm test fails
70 if ! test -f no_confirm_okay
72 say
'confirm test failed; skipping remaining tests to prevent hanging'
73 PREREQ
="$PREREQ,CHECK_NO_CONFIRM"
78 test_expect_success
$PREREQ 'No confirm with --suppress-cc' '
79 test_no_confirm --suppress-cc=sob &&
84 test_expect_success
$PREREQ 'No confirm with --confirm=never' '
85 test_no_confirm --confirm=never &&
89 # leave sendemail.confirm set to never after this so that none of the
90 # remaining tests prompt unintentionally.
91 test_expect_success
$PREREQ 'No confirm with sendemail.confirm=never' '
92 git config sendemail.confirm never &&
93 test_no_confirm --compose --subject=foo &&
97 test_expect_success
$PREREQ 'Send patches' '
98 git send-email --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
101 test_expect_success
$PREREQ 'setup expect' '
102 cat >expected <<-\EOF
110 test_expect_success
$PREREQ 'Verify commandline' '
111 test_cmp expected commandline1
114 test_expect_success
$PREREQ 'Send patches with --envelope-sender' '
115 clean_fake_sendmail &&
116 git send-email --envelope-sender="Patch Contributor <patch@example.com>" --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
119 test_expect_success
$PREREQ 'setup expect' '
120 cat >expected <<-\EOF
130 test_expect_success
$PREREQ 'Verify commandline' '
131 test_cmp expected commandline1
134 test_expect_success
$PREREQ 'Send patches with --envelope-sender=auto' '
135 clean_fake_sendmail &&
136 git send-email --envelope-sender=auto --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
139 test_expect_success
$PREREQ 'setup expect' '
140 cat >expected <<-\EOF
150 test_expect_success
$PREREQ 'Verify commandline' '
151 test_cmp expected commandline1
154 test_expect_success
$PREREQ 'setup expect for cc trailer' "
155 cat >expected-cc <<\EOF
156 !recipient@example.com!
167 test_expect_success
$PREREQ 'cc trailer with various syntax' '
168 test_commit cc-trailer &&
169 test_when_finished "git reset --hard HEAD^" &&
170 git commit --amend -F - <<-EOF &&
174 Cc: <two@example.com> # trailing comments are ignored
175 Cc: <three@example.com>, <not.four@example.com> one address per line
176 Cc: "Some # Body" <four@example.com> [ <also.a.comment> ]
177 Cc: five@example.com # not.six@example.com
178 Cc: six@example.com, not.seven@example.com
180 clean_fake_sendmail &&
181 git send-email -1 --to=recipient@example.com \
182 --smtp-server="$(pwd)/fake.sendmail" &&
183 test_cmp expected-cc commandline1
186 test_expect_success
$PREREQ 'setup fake get_maintainer.pl script for cc trailer' "
187 write_script expected-cc-script.sh <<-EOF
188 echo 'One Person <one@example.com> (supporter:THIS (FOO/bar))'
189 echo 'Two Person <two@example.com> (maintainer:THIS THING)'
190 echo 'Third List <three@example.com> (moderated list:THIS THING (FOO/bar))'
191 echo '<four@example.com> (moderated list:FOR THING)'
192 echo 'five@example.com (open list:FOR THING (FOO/bar))'
193 echo 'six@example.com (open list)'
197 test_expect_success
$PREREQ 'cc trailer with get_maintainer.pl output' '
198 clean_fake_sendmail &&
199 git send-email -1 --to=recipient@example.com \
200 --cc-cmd=./expected-cc-script.sh \
201 --smtp-server="$(pwd)/fake.sendmail" &&
202 test_cmp expected-cc commandline1
205 test_expect_success
$PREREQ 'setup expect' "
206 cat >expected-show-all-headers <<\EOF
208 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
209 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
210 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
212 Server: relay.example.com
213 MAIL FROM:<from@example.com>
214 RCPT TO:<to@example.com>
215 RCPT TO:<cc@example.com>
216 RCPT TO:<author@example.com>
217 RCPT TO:<one@example.com>
218 RCPT TO:<two@example.com>
219 RCPT TO:<bcc@example.com>
220 From: Example <from@example.com>
223 A <author@example.com>,
224 One <one@example.com>,
226 Subject: [PATCH 1/1] Second.
228 Message-Id: MESSAGE-ID-STRING
229 X-Mailer: X-MAILER-STRING
230 In-Reply-To: <unique-message-id@example.com>
231 References: <unique-message-id@example.com>
232 Reply-To: Reply <reply@example.com>
234 Content-Transfer-Encoding: 8bit
240 test_suppress_self
() {
242 test_when_finished
"git reset --hard HEAD^" &&
244 write_script cccmd-sed
<<-EOF &&
245 sed -n -e s/^cccmd--//p "\$1"
248 git commit
--amend --author="$1 <$2>" -F - &&
249 clean_fake_sendmail
&&
250 git format-patch
--stdout -1 >"suppress-self-$3.patch" &&
252 git send-email
--from="$1 <$2>" \
253 --to=nobody@example.com \
254 --cc-cmd=.
/cccmd-sed \
256 --smtp-server="$(pwd)/fake.sendmail" \
257 suppress-self-
$3.
patch &&
259 mv msgtxt1 msgtxt1-
$3 &&
260 sed -e '/^$/q' msgtxt1-
$3 >"msghdr1-$3" &&
262 (grep '^Cc:' msghdr1-
$3 >"actual-no-cc-$3";
263 test_must_be_empty actual-no-cc-
$3)
266 test_suppress_self_unquoted
() {
267 test_suppress_self
"$1" "$2" "unquoted-$3" <<-EOF
268 test suppress-cc.self unquoted-$3 with name $1 email $2
275 Signed-off-by: $1 <$2>
279 test_suppress_self_quoted
() {
280 test_suppress_self
"$1" "$2" "quoted-$3" <<-EOF
281 test suppress-cc.self quoted-$3 with name $1 email $2
289 Signed-off-by: $1 <$2>
290 Signed-off-by: "$1" <$2>
294 test_expect_success
$PREREQ 'self name is suppressed' "
295 test_suppress_self_unquoted 'A U Thor' 'author@example.com' \
296 'self_name_suppressed'
299 test_expect_success
$PREREQ 'self name with dot is suppressed' "
300 test_suppress_self_quoted 'A U. Thor' 'author@example.com' \
301 'self_name_dot_suppressed'
304 test_expect_success
$PREREQ 'non-ascii self name is suppressed' "
305 test_suppress_self_quoted 'Füñný Nâmé' 'odd_?=mail@example.com' \
306 'non_ascii_self_suppressed'
309 # This name is long enough to force format-patch to split it into multiple
310 # encoded-words, assuming it uses UTF-8 with the "Q" encoding.
311 test_expect_success
$PREREQ 'long non-ascii self name is suppressed' "
312 test_suppress_self_quoted 'Ƒüñníęř €. Nâṁé' 'odd_?=mail@example.com' \
313 'long_non_ascii_self_suppressed'
316 test_expect_success
$PREREQ 'sanitized self name is suppressed' "
317 test_suppress_self_unquoted '\"A U. Thor\"' 'author@example.com' \
318 'self_name_sanitized_suppressed'
321 test_expect_success
$PREREQ 'Show all headers' '
325 --from="Example <from@example.com>" \
326 --reply-to="Reply <reply@example.com>" \
327 --to=to@example.com \
328 --cc=cc@example.com \
329 --bcc=bcc@example.com \
330 --in-reply-to="<unique-message-id@example.com>" \
331 --smtp-server relay.example.com \
332 $patches | replace_variable_fields \
333 >actual-show-all-headers &&
334 test_cmp expected-show-all-headers actual-show-all-headers
337 test_expect_success
$PREREQ 'Prompting works' '
338 clean_fake_sendmail &&
339 (echo "to@example.com" &&
341 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
342 --smtp-server="$(pwd)/fake.sendmail" \
345 grep "^From: A U Thor <author@example.com>\$" msgtxt1 &&
346 grep "^To: to@example.com\$" msgtxt1
349 test_expect_success
$PREREQ,AUTOIDENT
'implicit ident is allowed' '
350 clean_fake_sendmail &&
351 (sane_unset GIT_AUTHOR_NAME &&
352 sane_unset GIT_AUTHOR_EMAIL &&
353 sane_unset GIT_COMMITTER_NAME &&
354 sane_unset GIT_COMMITTER_EMAIL &&
355 GIT_SEND_EMAIL_NOTTY=1 git send-email \
356 --smtp-server="$(pwd)/fake.sendmail" \
357 --to=to@example.com \
358 $patches </dev/null 2>errors
362 test_expect_success
$PREREQ,!AUTOIDENT
'broken implicit ident aborts send-email' '
363 clean_fake_sendmail &&
364 (sane_unset GIT_AUTHOR_NAME &&
365 sane_unset GIT_AUTHOR_EMAIL &&
366 sane_unset GIT_COMMITTER_NAME &&
367 sane_unset GIT_COMMITTER_EMAIL &&
368 GIT_SEND_EMAIL_NOTTY=1 && export GIT_SEND_EMAIL_NOTTY &&
369 test_must_fail git send-email \
370 --smtp-server="$(pwd)/fake.sendmail" \
371 --to=to@example.com \
372 $patches </dev/null 2>errors &&
373 test_i18ngrep "tell me who you are" errors
377 test_expect_success
$PREREQ 'setup tocmd and cccmd scripts' '
378 write_script tocmd-sed <<-\EOF &&
379 sed -n -e "s/^tocmd--//p" "$1"
381 write_script cccmd-sed <<-\EOF
382 sed -n -e "s/^cccmd--//p" "$1"
386 test_expect_success
$PREREQ 'tocmd works' '
387 clean_fake_sendmail &&
388 cp $patches tocmd.patch &&
389 echo tocmd--tocmd@example.com >>tocmd.patch &&
391 --from="Example <nobody@example.com>" \
392 --to-cmd=./tocmd-sed \
393 --smtp-server="$(pwd)/fake.sendmail" \
396 grep "^To: tocmd@example.com" msgtxt1
399 test_expect_success
$PREREQ 'cccmd works' '
400 clean_fake_sendmail &&
401 cp $patches cccmd.patch &&
402 echo "cccmd-- cccmd@example.com" >>cccmd.patch &&
404 --from="Example <nobody@example.com>" \
405 --to=nobody@example.com \
406 --cc-cmd=./cccmd-sed \
407 --smtp-server="$(pwd)/fake.sendmail" \
410 grep "^ cccmd@example.com" msgtxt1
413 test_expect_success
$PREREQ 'reject long lines' '
415 z64=$z8$z8$z8$z8$z8$z8$z8$z8 &&
416 z512=$z64$z64$z64$z64$z64$z64$z64$z64 &&
417 clean_fake_sendmail &&
418 cp $patches longline.patch &&
419 cat >>longline.patch <<-EOF &&
424 test_must_fail git send-email \
425 --from="Example <nobody@example.com>" \
426 --to=nobody@example.com \
427 --smtp-server="$(pwd)/fake.sendmail" \
428 --transfer-encoding=8bit \
429 $patches longline.patch \
431 cat >expect <<-\EOF &&
432 fatal: longline.patch:35 is longer than 998 characters
433 warning: no patches were sent
435 test_cmp expect actual
438 test_expect_success
$PREREQ 'no patch was sent' '
439 ! test -e commandline1
442 test_expect_success
$PREREQ 'Author From: in message body' '
443 clean_fake_sendmail &&
445 --from="Example <nobody@example.com>" \
446 --to=nobody@example.com \
447 --smtp-server="$(pwd)/fake.sendmail" \
449 sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
450 grep "From: A <author@example.com>" msgbody1
453 test_expect_success
$PREREQ 'Author From: not in message body' '
454 clean_fake_sendmail &&
456 --from="A <author@example.com>" \
457 --to=nobody@example.com \
458 --smtp-server="$(pwd)/fake.sendmail" \
460 sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
461 ! grep "From: A <author@example.com>" msgbody1
464 test_expect_success
$PREREQ 'allow long lines with --no-validate' '
466 --from="Example <nobody@example.com>" \
467 --to=nobody@example.com \
468 --smtp-server="$(pwd)/fake.sendmail" \
470 $patches longline.patch \
474 test_expect_success
$PREREQ 'short lines with auto encoding are 8bit' '
475 clean_fake_sendmail &&
477 --from="A <author@example.com>" \
478 --to=nobody@example.com \
479 --smtp-server="$(pwd)/fake.sendmail" \
480 --transfer-encoding=auto \
482 grep "Content-Transfer-Encoding: 8bit" msgtxt1
485 test_expect_success
$PREREQ 'long lines with auto encoding are quoted-printable' '
486 clean_fake_sendmail &&
488 --from="Example <nobody@example.com>" \
489 --to=nobody@example.com \
490 --smtp-server="$(pwd)/fake.sendmail" \
491 --transfer-encoding=auto \
494 grep "Content-Transfer-Encoding: quoted-printable" msgtxt1
497 test_expect_success
$PREREQ 'carriage returns with auto encoding are quoted-printable' '
498 clean_fake_sendmail &&
499 cp $patches cr.patch &&
500 printf "this is a line\r\n" >>cr.patch &&
502 --from="Example <nobody@example.com>" \
503 --to=nobody@example.com \
504 --smtp-server="$(pwd)/fake.sendmail" \
505 --transfer-encoding=auto \
508 grep "Content-Transfer-Encoding: quoted-printable" msgtxt1
511 for enc
in auto quoted-printable base64
513 test_expect_success
$PREREQ "--validate passes with encoding $enc" '
515 --from="Example <nobody@example.com>" \
516 --to=nobody@example.com \
517 --smtp-server="$(pwd)/fake.sendmail" \
518 --transfer-encoding=$enc \
520 $patches longline.patch
525 test_expect_success
$PREREQ "--validate respects relative core.hooksPath path" '
526 clean_fake_sendmail &&
528 test_when_finished "rm my-hooks.ran" &&
529 write_script my-hooks/sendemail-validate <<-\EOF &&
533 test_config core.hooksPath "my-hooks" &&
534 test_must_fail git send-email \
535 --from="Example <nobody@example.com>" \
536 --to=nobody@example.com \
537 --smtp-server="$(pwd)/fake.sendmail" \
539 longline.patch 2>actual &&
540 test_path_is_file my-hooks.ran &&
541 cat >expect <<-EOF &&
542 fatal: longline.patch: rejected by sendemail-validate hook
543 fatal: command '"'"'git hook run --ignore-missing sendemail-validate -- <patch>'"'"' died with exit code 1
544 warning: no patches were sent
546 test_cmp expect actual
549 test_expect_success
$PREREQ "--validate respects absolute core.hooksPath path" '
550 hooks_path="$(pwd)/my-hooks" &&
551 test_config core.hooksPath "$hooks_path" &&
552 test_when_finished "rm my-hooks.ran" &&
553 test_must_fail git send-email \
554 --from="Example <nobody@example.com>" \
555 --to=nobody@example.com \
556 --smtp-server="$(pwd)/fake.sendmail" \
558 longline.patch 2>actual &&
559 test_path_is_file my-hooks.ran &&
560 cat >expect <<-EOF &&
561 fatal: longline.patch: rejected by sendemail-validate hook
562 fatal: command '"'"'git hook run --ignore-missing sendemail-validate -- <patch>'"'"' died with exit code 1
563 warning: no patches were sent
565 test_cmp expect actual
568 for enc
in 7bit
8bit quoted-printable base64
570 test_expect_success
$PREREQ "--transfer-encoding=$enc produces correct header" '
571 clean_fake_sendmail &&
573 --from="Example <nobody@example.com>" \
574 --to=nobody@example.com \
575 --smtp-server="$(pwd)/fake.sendmail" \
576 --transfer-encoding=$enc \
578 grep "Content-Transfer-Encoding: $enc" msgtxt1
582 test_expect_success
$PREREQ 'Invalid In-Reply-To' '
583 clean_fake_sendmail &&
585 --from="Example <nobody@example.com>" \
586 --to=nobody@example.com \
588 --smtp-server="$(pwd)/fake.sendmail" \
591 ! grep "^In-Reply-To: < *>" msgtxt1
594 test_expect_success
$PREREQ 'Valid In-Reply-To when prompting' '
595 clean_fake_sendmail &&
596 (echo "From Example <from@example.com>" &&
597 echo "To Example <to@example.com>" &&
599 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
600 --smtp-server="$(pwd)/fake.sendmail" \
602 ! grep "^In-Reply-To: < *>" msgtxt1
605 test_expect_success
$PREREQ 'In-Reply-To without --chain-reply-to' '
606 clean_fake_sendmail &&
607 echo "<unique-message-id@example.com>" >expect &&
609 --from="Example <nobody@example.com>" \
610 --to=nobody@example.com \
611 --no-chain-reply-to \
612 --in-reply-to="$(cat expect)" \
613 --smtp-server="$(pwd)/fake.sendmail" \
614 $patches $patches $patches \
616 # The first message is a reply to --in-reply-to
617 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
618 test_cmp expect actual &&
619 # Second and subsequent messages are replies to the first one
620 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
621 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
622 test_cmp expect actual &&
623 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
624 test_cmp expect actual
627 test_expect_success
$PREREQ 'In-Reply-To with --chain-reply-to' '
628 clean_fake_sendmail &&
629 echo "<unique-message-id@example.com>" >expect &&
631 --from="Example <nobody@example.com>" \
632 --to=nobody@example.com \
634 --in-reply-to="$(cat expect)" \
635 --smtp-server="$(pwd)/fake.sendmail" \
636 $patches $patches $patches \
638 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
639 test_cmp expect actual &&
640 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
641 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
642 test_cmp expect actual &&
643 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt2 >expect &&
644 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
645 test_cmp expect actual
648 test_set_editor
"$(pwd)/fake-editor"
650 test_expect_success
$PREREQ 'setup erroring fake editor' '
651 write_script fake-editor <<-\EOF
652 echo >&2 "I am about to error"
657 test_expect_success
$PREREQ 'fake editor dies with error' '
658 clean_fake_sendmail &&
659 test_must_fail git send-email \
660 --compose --subject foo \
661 --from="Example <nobody@example.com>" \
662 --to=nobody@example.com \
663 --smtp-server="$(pwd)/fake.sendmail" \
665 grep "I am about to error" err &&
666 grep "the editor exited uncleanly, aborting everything" err
669 test_expect_success
$PREREQ 'setup fake editor' '
670 write_script fake-editor <<-\EOF
671 echo fake edit >>"$1"
675 test_expect_success
$PREREQ '--compose works' '
676 clean_fake_sendmail &&
678 --compose --subject foo \
679 --from="Example <nobody@example.com>" \
680 --to=nobody@example.com \
681 --smtp-server="$(pwd)/fake.sendmail" \
686 test_expect_success
$PREREQ 'first message is compose text' '
687 grep "^fake edit" msgtxt1
690 test_expect_success
$PREREQ 'second message is patch' '
691 grep "Subject:.*Second" msgtxt2
694 test_expect_success
$PREREQ 'setup expect' "
695 cat >expected-suppress-sob <<\EOF
697 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
698 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
699 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
701 Server: relay.example.com
702 MAIL FROM:<from@example.com>
703 RCPT TO:<to@example.com>
704 RCPT TO:<cc@example.com>
705 RCPT TO:<author@example.com>
706 RCPT TO:<one@example.com>
707 RCPT TO:<two@example.com>
708 From: Example <from@example.com>
711 A <author@example.com>,
712 One <one@example.com>,
714 Subject: [PATCH 1/1] Second.
716 Message-Id: MESSAGE-ID-STRING
717 X-Mailer: X-MAILER-STRING
719 Content-Transfer-Encoding: 8bit
725 test_suppression
() {
728 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
729 --from="Example <from@example.com>" \
730 --to=to@example.com \
731 --smtp-server relay.example.com \
732 $patches | replace_variable_fields \
733 >actual-suppress-
$1${2+"-$2"} &&
734 test_cmp expected-suppress-
$1${2+"-$2"} actual-suppress-
$1${2+"-$2"}
737 test_expect_success
$PREREQ 'sendemail.cc set' '
738 git config sendemail.cc cc@example.com &&
742 test_expect_success
$PREREQ 'setup expect' "
743 cat >expected-suppress-sob <<\EOF
745 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
746 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
747 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
749 Server: relay.example.com
750 MAIL FROM:<from@example.com>
751 RCPT TO:<to@example.com>
752 RCPT TO:<author@example.com>
753 RCPT TO:<one@example.com>
754 RCPT TO:<two@example.com>
755 From: Example <from@example.com>
757 Cc: A <author@example.com>,
758 One <one@example.com>,
760 Subject: [PATCH 1/1] Second.
762 Message-Id: MESSAGE-ID-STRING
763 X-Mailer: X-MAILER-STRING
765 Content-Transfer-Encoding: 8bit
771 test_expect_success
$PREREQ 'sendemail.cc unset' '
772 git config --unset sendemail.cc &&
776 test_expect_success
$PREREQ 'setup expect' "
777 cat >expected-suppress-cccmd <<\EOF
779 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
780 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
781 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
782 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
784 Server: relay.example.com
785 MAIL FROM:<from@example.com>
786 RCPT TO:<to@example.com>
787 RCPT TO:<author@example.com>
788 RCPT TO:<one@example.com>
789 RCPT TO:<two@example.com>
790 RCPT TO:<committer@example.com>
791 From: Example <from@example.com>
793 Cc: A <author@example.com>,
794 One <one@example.com>,
796 C O Mitter <committer@example.com>
797 Subject: [PATCH 1/1] Second.
799 Message-Id: MESSAGE-ID-STRING
800 X-Mailer: X-MAILER-STRING
802 Content-Transfer-Encoding: 8bit
808 test_expect_success
$PREREQ 'sendemail.cccmd' '
809 write_script cccmd <<-\EOF &&
810 echo cc-cmd@example.com
812 git config sendemail.cccmd ./cccmd &&
813 test_suppression cccmd
816 test_expect_success
$PREREQ 'setup expect' '
817 cat >expected-suppress-all <<\EOF
820 Server: relay.example.com
821 MAIL FROM:<from@example.com>
822 RCPT TO:<to@example.com>
823 From: Example <from@example.com>
825 Subject: [PATCH 1/1] Second.
827 Message-Id: MESSAGE-ID-STRING
828 X-Mailer: X-MAILER-STRING
830 Content-Transfer-Encoding: 8bit
836 test_expect_success
$PREREQ '--suppress-cc=all' '
840 test_expect_success
$PREREQ 'setup expect' "
841 cat >expected-suppress-body <<\EOF
843 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
844 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
845 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
846 (cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
848 Server: relay.example.com
849 MAIL FROM:<from@example.com>
850 RCPT TO:<to@example.com>
851 RCPT TO:<author@example.com>
852 RCPT TO:<one@example.com>
853 RCPT TO:<two@example.com>
854 RCPT TO:<cc-cmd@example.com>
855 From: Example <from@example.com>
857 Cc: A <author@example.com>,
858 One <one@example.com>,
861 Subject: [PATCH 1/1] Second.
863 Message-Id: MESSAGE-ID-STRING
864 X-Mailer: X-MAILER-STRING
866 Content-Transfer-Encoding: 8bit
872 test_expect_success
$PREREQ '--suppress-cc=body' '
873 test_suppression body
876 test_expect_success
$PREREQ 'setup expect' "
877 cat >expected-suppress-body-cccmd <<\EOF
879 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
880 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
881 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
883 Server: relay.example.com
884 MAIL FROM:<from@example.com>
885 RCPT TO:<to@example.com>
886 RCPT TO:<author@example.com>
887 RCPT TO:<one@example.com>
888 RCPT TO:<two@example.com>
889 From: Example <from@example.com>
891 Cc: A <author@example.com>,
892 One <one@example.com>,
894 Subject: [PATCH 1/1] Second.
896 Message-Id: MESSAGE-ID-STRING
897 X-Mailer: X-MAILER-STRING
899 Content-Transfer-Encoding: 8bit
905 test_expect_success
$PREREQ '--suppress-cc=body --suppress-cc=cccmd' '
906 test_suppression body cccmd
909 test_expect_success
$PREREQ 'setup expect' "
910 cat >expected-suppress-sob <<\EOF
912 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
913 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
914 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
916 Server: relay.example.com
917 MAIL FROM:<from@example.com>
918 RCPT TO:<to@example.com>
919 RCPT TO:<author@example.com>
920 RCPT TO:<one@example.com>
921 RCPT TO:<two@example.com>
922 From: Example <from@example.com>
924 Cc: A <author@example.com>,
925 One <one@example.com>,
927 Subject: [PATCH 1/1] Second.
929 Message-Id: MESSAGE-ID-STRING
930 X-Mailer: X-MAILER-STRING
932 Content-Transfer-Encoding: 8bit
938 test_expect_success
$PREREQ '--suppress-cc=sob' '
939 test_might_fail git config --unset sendemail.cccmd &&
943 test_expect_success
$PREREQ 'setup expect' "
944 cat >expected-suppress-bodycc <<\EOF
946 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
947 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
948 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
949 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
951 Server: relay.example.com
952 MAIL FROM:<from@example.com>
953 RCPT TO:<to@example.com>
954 RCPT TO:<author@example.com>
955 RCPT TO:<one@example.com>
956 RCPT TO:<two@example.com>
957 RCPT TO:<committer@example.com>
958 From: Example <from@example.com>
960 Cc: A <author@example.com>,
961 One <one@example.com>,
963 C O Mitter <committer@example.com>
964 Subject: [PATCH 1/1] Second.
966 Message-Id: MESSAGE-ID-STRING
967 X-Mailer: X-MAILER-STRING
969 Content-Transfer-Encoding: 8bit
975 test_expect_success
$PREREQ '--suppress-cc=bodycc' '
976 test_suppression bodycc
979 test_expect_success
$PREREQ 'setup expect' "
980 cat >expected-suppress-cc <<\EOF
982 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
983 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
985 Server: relay.example.com
986 MAIL FROM:<from@example.com>
987 RCPT TO:<to@example.com>
988 RCPT TO:<author@example.com>
989 RCPT TO:<committer@example.com>
990 From: Example <from@example.com>
992 Cc: A <author@example.com>,
993 C O Mitter <committer@example.com>
994 Subject: [PATCH 1/1] Second.
996 Message-Id: MESSAGE-ID-STRING
997 X-Mailer: X-MAILER-STRING
999 Content-Transfer-Encoding: 8bit
1005 test_expect_success
$PREREQ '--suppress-cc=cc' '
1011 GIT_SEND_EMAIL_NOTTY
=1 \
1013 --from="Example <nobody@example.com>" \
1014 --to=nobody@example.com \
1015 --smtp-server="$(pwd)/fake.sendmail" \
1016 $@
$patches >stdout
&&
1017 grep "Send this email" stdout
1020 test_expect_success
$PREREQ '--confirm=always' '
1021 test_confirm --confirm=always --suppress-cc=all
1024 test_expect_success
$PREREQ '--confirm=auto' '
1025 test_confirm --confirm=auto
1028 test_expect_success
$PREREQ '--confirm=cc' '
1029 test_confirm --confirm=cc
1032 test_expect_success
$PREREQ '--confirm=compose' '
1033 test_confirm --confirm=compose --compose
1036 test_expect_success
$PREREQ 'confirm by default (due to cc)' '
1037 test_when_finished git config sendemail.confirm never &&
1038 git config --unset sendemail.confirm &&
1042 test_expect_success
$PREREQ 'confirm by default (due to --compose)' '
1043 test_when_finished git config sendemail.confirm never &&
1044 git config --unset sendemail.confirm &&
1045 test_confirm --suppress-cc=all --compose
1048 test_expect_success
$PREREQ 'confirm detects EOF (inform assumes y)' '
1049 test_when_finished git config sendemail.confirm never &&
1050 git config --unset sendemail.confirm &&
1052 git format-patch -2 -o outdir &&
1053 GIT_SEND_EMAIL_NOTTY=1 \
1055 --from="Example <nobody@example.com>" \
1056 --to=nobody@example.com \
1057 --smtp-server="$(pwd)/fake.sendmail" \
1058 outdir/*.patch </dev/null
1061 test_expect_success
$PREREQ 'confirm detects EOF (auto causes failure)' '
1062 test_when_finished git config sendemail.confirm never &&
1063 git config sendemail.confirm auto &&
1064 GIT_SEND_EMAIL_NOTTY=1 &&
1065 export GIT_SEND_EMAIL_NOTTY &&
1066 test_must_fail git send-email \
1067 --from="Example <nobody@example.com>" \
1068 --to=nobody@example.com \
1069 --smtp-server="$(pwd)/fake.sendmail" \
1073 test_expect_success
$PREREQ 'confirm does not loop forever' '
1074 test_when_finished git config sendemail.confirm never &&
1075 git config sendemail.confirm auto &&
1076 GIT_SEND_EMAIL_NOTTY=1 &&
1077 export GIT_SEND_EMAIL_NOTTY &&
1078 yes "bogus" | test_must_fail git send-email \
1079 --from="Example <nobody@example.com>" \
1080 --to=nobody@example.com \
1081 --smtp-server="$(pwd)/fake.sendmail" \
1085 test_expect_success
$PREREQ 'utf8 Cc is rfc2047 encoded' '
1086 clean_fake_sendmail &&
1088 git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
1090 --from="Example <nobody@example.com>" \
1091 --to=nobody@example.com \
1092 --smtp-server="$(pwd)/fake.sendmail" \
1095 grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
1098 test_expect_success
$PREREQ '--compose adds MIME for utf8 body' '
1099 clean_fake_sendmail &&
1100 write_script fake-editor-utf8 <<-\EOF &&
1101 echo "utf8 body: àéìöú" >>"$1"
1103 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1105 --compose --subject foo \
1106 --from="Example <nobody@example.com>" \
1107 --to=nobody@example.com \
1108 --smtp-server="$(pwd)/fake.sendmail" \
1110 grep "^utf8 body" msgtxt1 &&
1111 grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
1114 test_expect_success
$PREREQ '--compose respects user mime type' '
1115 clean_fake_sendmail &&
1116 write_script fake-editor-utf8-mime <<-\EOF &&
1119 Content-Type: text/plain; charset=iso-8859-1
1120 Content-Transfer-Encoding: 8bit
1126 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
1128 --compose --subject foo \
1129 --from="Example <nobody@example.com>" \
1130 --to=nobody@example.com \
1131 --smtp-server="$(pwd)/fake.sendmail" \
1133 grep "^utf8 body" msgtxt1 &&
1134 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
1135 ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
1138 test_expect_success
$PREREQ '--compose adds MIME for utf8 subject' '
1139 clean_fake_sendmail &&
1140 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
1142 --compose --subject utf8-sübjëct \
1143 --from="Example <nobody@example.com>" \
1144 --to=nobody@example.com \
1145 --smtp-server="$(pwd)/fake.sendmail" \
1147 grep "^fake edit" msgtxt1 &&
1148 grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
1151 test_expect_success
$PREREQ 'utf8 author is correctly passed on' '
1152 clean_fake_sendmail &&
1153 test_commit weird_author &&
1154 test_when_finished "git reset --hard HEAD^" &&
1155 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
1156 git format-patch --stdout -1 >funny_name.patch &&
1157 git send-email --from="Example <nobody@example.com>" \
1158 --to=nobody@example.com \
1159 --smtp-server="$(pwd)/fake.sendmail" \
1161 grep "^From: Füñný Nâmé <odd_?=mail@example.com>" msgtxt1
1164 test_expect_success
$PREREQ 'utf8 sender is not duplicated' '
1165 clean_fake_sendmail &&
1166 test_commit weird_sender &&
1167 test_when_finished "git reset --hard HEAD^" &&
1168 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
1169 git format-patch --stdout -1 >funny_name.patch &&
1170 git send-email --from="Füñný Nâmé <odd_?=mail@example.com>" \
1171 --to=nobody@example.com \
1172 --smtp-server="$(pwd)/fake.sendmail" \
1174 grep "^From: " msgtxt1 >msgfrom &&
1175 test_line_count = 1 msgfrom
1178 test_expect_success
$PREREQ 'sendemail.composeencoding works' '
1179 clean_fake_sendmail &&
1180 git config sendemail.composeencoding iso-8859-1 &&
1181 write_script fake-editor-utf8 <<-\EOF &&
1182 echo "utf8 body: àéìöú" >>"$1"
1184 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1186 --compose --subject foo \
1187 --from="Example <nobody@example.com>" \
1188 --to=nobody@example.com \
1189 --smtp-server="$(pwd)/fake.sendmail" \
1191 grep "^utf8 body" msgtxt1 &&
1192 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1195 test_expect_success
$PREREQ '--compose-encoding works' '
1196 clean_fake_sendmail &&
1197 write_script fake-editor-utf8 <<-\EOF &&
1198 echo "utf8 body: àéìöú" >>"$1"
1200 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1202 --compose-encoding iso-8859-1 \
1203 --compose --subject foo \
1204 --from="Example <nobody@example.com>" \
1205 --to=nobody@example.com \
1206 --smtp-server="$(pwd)/fake.sendmail" \
1208 grep "^utf8 body" msgtxt1 &&
1209 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1212 test_expect_success
$PREREQ '--compose-encoding overrides sendemail.composeencoding' '
1213 clean_fake_sendmail &&
1214 git config sendemail.composeencoding iso-8859-1 &&
1215 write_script fake-editor-utf8 <<-\EOF &&
1216 echo "utf8 body: àéìöú" >>"$1"
1218 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1220 --compose-encoding iso-8859-2 \
1221 --compose --subject foo \
1222 --from="Example <nobody@example.com>" \
1223 --to=nobody@example.com \
1224 --smtp-server="$(pwd)/fake.sendmail" \
1226 grep "^utf8 body" msgtxt1 &&
1227 grep "^Content-Type: text/plain; charset=iso-8859-2" msgtxt1
1230 test_expect_success
$PREREQ '--compose-encoding adds correct MIME for subject' '
1231 clean_fake_sendmail &&
1232 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
1234 --compose-encoding iso-8859-2 \
1235 --compose --subject utf8-sübjëct \
1236 --from="Example <nobody@example.com>" \
1237 --to=nobody@example.com \
1238 --smtp-server="$(pwd)/fake.sendmail" \
1240 grep "^fake edit" msgtxt1 &&
1241 grep "^Subject: =?iso-8859-2?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
1244 test_expect_success
$PREREQ 'detects ambiguous reference/file conflict' '
1247 git commit -m"add main" &&
1248 test_must_fail git send-email --dry-run main 2>errors &&
1249 grep disambiguate errors
1252 test_expect_success
$PREREQ 'feed two files' '
1254 git format-patch -2 -o outdir &&
1257 --from="Example <nobody@example.com>" \
1258 --to=nobody@example.com \
1259 outdir/000?-*.patch 2>errors >out &&
1260 grep "^Subject: " out >subjects &&
1261 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
1262 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add main"
1265 test_expect_success
$PREREQ 'in-reply-to but no threading' '
1268 --from="Example <nobody@example.com>" \
1269 --to=nobody@example.com \
1270 --in-reply-to="<in-reply-id@example.com>" \
1273 grep "In-Reply-To: <in-reply-id@example.com>" out
1276 test_expect_success
$PREREQ 'no in-reply-to and no threading' '
1279 --from="Example <nobody@example.com>" \
1280 --to=nobody@example.com \
1283 ! grep "In-Reply-To: " stdout
1286 test_expect_success
$PREREQ 'threading but no chain-reply-to' '
1289 --from="Example <nobody@example.com>" \
1290 --to=nobody@example.com \
1292 --no-chain-reply-to \
1293 $patches $patches >stdout &&
1294 grep "In-Reply-To: " stdout
1297 test_expect_success
$PREREQ 'override in-reply-to if no threading' '
1300 --from="Example <nobody@example.com>" \
1301 --to=nobody@example.com \
1303 --in-reply-to="override" \
1304 $threaded_patches >stdout &&
1305 grep "In-Reply-To: <override>" stdout
1308 test_expect_success
$PREREQ 'sendemail.to works' '
1309 git config --replace-all sendemail.to "Somebody <somebody@ex.com>" &&
1312 --from="Example <nobody@example.com>" \
1314 grep "To: Somebody <somebody@ex.com>" stdout
1317 test_expect_success
$PREREQ 'setup sendemail.identity' '
1318 git config --replace-all sendemail.to "default@example.com" &&
1319 git config --replace-all sendemail.isp.to "isp@example.com" &&
1320 git config --replace-all sendemail.cloud.to "cloud@example.com"
1323 test_expect_success
$PREREQ 'sendemail.identity: reads the correct identity config' '
1324 git -c sendemail.identity=cloud send-email \
1326 --from="nobody@example.com" \
1328 grep "To: cloud@example.com" stdout
1331 test_expect_success
$PREREQ 'sendemail.identity: identity overrides sendemail.identity' '
1332 git -c sendemail.identity=cloud send-email \
1335 --from="nobody@example.com" \
1337 grep "To: isp@example.com" stdout
1340 test_expect_success
$PREREQ 'sendemail.identity: --no-identity clears previous identity' '
1341 git -c sendemail.identity=cloud send-email \
1344 --from="nobody@example.com" \
1346 grep "To: default@example.com" stdout
1349 test_expect_success
$PREREQ 'sendemail.identity: bool identity variable existence overrides' '
1350 git -c sendemail.identity=cloud \
1351 -c sendemail.xmailer=true \
1352 -c sendemail.cloud.xmailer=false \
1355 --from="nobody@example.com" \
1357 grep "To: cloud@example.com" stdout &&
1358 ! grep "X-Mailer" stdout
1361 test_expect_success
$PREREQ 'sendemail.identity: bool variable fallback' '
1362 git -c sendemail.identity=cloud \
1363 -c sendemail.xmailer=false \
1366 --from="nobody@example.com" \
1368 grep "To: cloud@example.com" stdout &&
1369 ! grep "X-Mailer" stdout
1372 test_expect_success
$PREREQ 'sendemail.identity: bool variable without a value' '
1373 git -c sendemail.xmailer \
1376 --from="nobody@example.com" \
1378 grep "To: default@example.com" stdout &&
1379 grep "X-Mailer" stdout
1382 test_expect_success
$PREREQ '--no-to overrides sendemail.to' '
1385 --from="Example <nobody@example.com>" \
1387 --to=nobody@example.com \
1389 grep "To: nobody@example.com" stdout &&
1390 ! grep "To: Somebody <somebody@ex.com>" stdout
1393 test_expect_success
$PREREQ 'sendemail.cc works' '
1394 git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" &&
1397 --from="Example <nobody@example.com>" \
1398 --to=nobody@example.com \
1400 grep "Cc: Somebody <somebody@ex.com>" stdout
1403 test_expect_success
$PREREQ '--no-cc overrides sendemail.cc' '
1406 --from="Example <nobody@example.com>" \
1408 --cc=bodies@example.com \
1409 --to=nobody@example.com \
1411 grep "Cc: bodies@example.com" stdout &&
1412 ! grep "Cc: Somebody <somebody@ex.com>" stdout
1415 test_expect_success
$PREREQ 'sendemail.bcc works' '
1416 git config --replace-all sendemail.bcc "Other <other@ex.com>" &&
1419 --from="Example <nobody@example.com>" \
1420 --to=nobody@example.com \
1421 --smtp-server relay.example.com \
1423 grep "RCPT TO:<other@ex.com>" stdout
1426 test_expect_success
$PREREQ '--no-bcc overrides sendemail.bcc' '
1429 --from="Example <nobody@example.com>" \
1431 --bcc=bodies@example.com \
1432 --to=nobody@example.com \
1433 --smtp-server relay.example.com \
1435 grep "RCPT TO:<bodies@example.com>" stdout &&
1436 ! grep "RCPT TO:<other@ex.com>" stdout
1439 test_expect_success
$PREREQ 'patches To headers are used by default' '
1440 patch=$(git format-patch -1 --to="bodies@example.com") &&
1441 test_when_finished "rm $patch" &&
1444 --from="Example <nobody@example.com>" \
1445 --smtp-server relay.example.com \
1447 grep "RCPT TO:<bodies@example.com>" stdout
1450 test_expect_success
$PREREQ 'patches To headers are appended to' '
1451 patch=$(git format-patch -1 --to="bodies@example.com") &&
1452 test_when_finished "rm $patch" &&
1455 --from="Example <nobody@example.com>" \
1456 --to=nobody@example.com \
1457 --smtp-server relay.example.com \
1459 grep "RCPT TO:<bodies@example.com>" stdout &&
1460 grep "RCPT TO:<nobody@example.com>" stdout
1463 test_expect_success
$PREREQ 'To headers from files reset each patch' '
1464 patch1=$(git format-patch -1 --to="bodies@example.com") &&
1465 patch2=$(git format-patch -1 --to="other@example.com" HEAD~) &&
1466 test_when_finished "rm $patch1 && rm $patch2" &&
1469 --from="Example <nobody@example.com>" \
1470 --to="nobody@example.com" \
1471 --smtp-server relay.example.com \
1472 $patch1 $patch2 >stdout &&
1473 test $(grep -c "RCPT TO:<bodies@example.com>" stdout) = 1 &&
1474 test $(grep -c "RCPT TO:<nobody@example.com>" stdout) = 2 &&
1475 test $(grep -c "RCPT TO:<other@example.com>" stdout) = 1
1478 test_expect_success
$PREREQ 'setup expect' '
1479 cat >email-using-8bit <<\EOF
1480 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1481 Message-Id: <bogus-message-id@example.com>
1482 From: author@example.com
1483 Date: Sat, 12 Jun 2010 15:53:58 +0200
1484 Subject: subject goes here
1486 Dieser deutsche Text enthält einen Umlaut!
1490 test_expect_success
$PREREQ 'setup expect' '
1491 echo "Subject: subject goes here" >expected
1494 test_expect_success
$PREREQ 'ASCII subject is not RFC2047 quoted' '
1495 clean_fake_sendmail &&
1497 git send-email --from=author@example.com --to=nobody@example.com \
1498 --smtp-server="$(pwd)/fake.sendmail" \
1499 --8bit-encoding=UTF-8 \
1500 email-using-8bit >stdout &&
1501 grep "Subject" msgtxt1 >actual &&
1502 test_cmp expected actual
1505 test_expect_success
$PREREQ 'setup expect' '
1506 cat >content-type-decl <<-\EOF
1508 Content-Type: text/plain; charset=UTF-8
1509 Content-Transfer-Encoding: 8bit
1513 test_expect_success
$PREREQ 'asks about and fixes 8bit encodings' '
1514 clean_fake_sendmail &&
1516 git send-email --from=author@example.com --to=nobody@example.com \
1517 --smtp-server="$(pwd)/fake.sendmail" \
1518 email-using-8bit >stdout &&
1519 grep "do not declare a Content-Transfer-Encoding" stdout &&
1520 grep email-using-8bit stdout &&
1521 grep "Which 8bit encoding" stdout &&
1522 egrep "Content|MIME" msgtxt1 >actual &&
1523 test_cmp content-type-decl actual
1526 test_expect_success
$PREREQ 'sendemail.8bitEncoding works' '
1527 clean_fake_sendmail &&
1528 git config sendemail.assume8bitEncoding UTF-8 &&
1530 git send-email --from=author@example.com --to=nobody@example.com \
1531 --smtp-server="$(pwd)/fake.sendmail" \
1532 email-using-8bit >stdout &&
1533 egrep "Content|MIME" msgtxt1 >actual &&
1534 test_cmp content-type-decl actual
1537 test_expect_success
$PREREQ 'sendemail.8bitEncoding in .git/config overrides --global .gitconfig' '
1538 clean_fake_sendmail &&
1539 git config sendemail.assume8bitEncoding UTF-8 &&
1540 test_when_finished "rm -rf home" &&
1542 git config -f home/.gitconfig sendemail.assume8bitEncoding "bogus too" &&
1544 env HOME="$(pwd)/home" DEBUG=1 \
1545 git send-email --from=author@example.com --to=nobody@example.com \
1546 --smtp-server="$(pwd)/fake.sendmail" \
1547 email-using-8bit >stdout &&
1548 egrep "Content|MIME" msgtxt1 >actual &&
1549 test_cmp content-type-decl actual
1552 test_expect_success
$PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
1553 clean_fake_sendmail &&
1554 git config sendemail.assume8bitEncoding "bogus too" &&
1556 git send-email --from=author@example.com --to=nobody@example.com \
1557 --smtp-server="$(pwd)/fake.sendmail" \
1558 --8bit-encoding=UTF-8 \
1559 email-using-8bit >stdout &&
1560 egrep "Content|MIME" msgtxt1 >actual &&
1561 test_cmp content-type-decl actual
1564 test_expect_success
$PREREQ 'setup expect' '
1565 cat >email-using-8bit <<-\EOF
1566 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1567 Message-Id: <bogus-message-id@example.com>
1568 From: author@example.com
1569 Date: Sat, 12 Jun 2010 15:53:58 +0200
1570 Subject: Dieser Betreff enthält auch einen Umlaut!
1572 Nothing to see here.
1576 test_expect_success
$PREREQ 'setup expect' '
1577 cat >expected <<-\EOF
1578 Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
1582 test_expect_success
$PREREQ '--8bit-encoding also treats subject' '
1583 clean_fake_sendmail &&
1585 git send-email --from=author@example.com --to=nobody@example.com \
1586 --smtp-server="$(pwd)/fake.sendmail" \
1587 --8bit-encoding=UTF-8 \
1588 email-using-8bit >stdout &&
1589 grep "Subject" msgtxt1 >actual &&
1590 test_cmp expected actual
1593 test_expect_success
$PREREQ 'setup expect' '
1594 cat >email-using-8bit <<-\EOF
1595 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1596 Message-Id: <bogus-message-id@example.com>
1597 From: A U Thor <author@example.com>
1598 Date: Sat, 12 Jun 2010 15:53:58 +0200
1599 Content-Type: text/plain; charset=UTF-8
1600 Subject: Nothing to see here.
1602 Dieser Betreff enthält auch einen Umlaut!
1606 test_expect_success
$PREREQ '--transfer-encoding overrides sendemail.transferEncoding' '
1607 clean_fake_sendmail &&
1608 test_must_fail git -c sendemail.transferEncoding=8bit \
1610 --transfer-encoding=7bit \
1611 --smtp-server="$(pwd)/fake.sendmail" \
1614 grep "cannot send message as 7bit" errors &&
1615 test -z "$(ls msgtxt*)"
1618 test_expect_success
$PREREQ 'sendemail.transferEncoding via config' '
1619 clean_fake_sendmail &&
1620 test_must_fail git -c sendemail.transferEncoding=7bit \
1622 --smtp-server="$(pwd)/fake.sendmail" \
1625 grep "cannot send message as 7bit" errors &&
1626 test -z "$(ls msgtxt*)"
1629 test_expect_success
$PREREQ 'sendemail.transferEncoding via cli' '
1630 clean_fake_sendmail &&
1631 test_must_fail git send-email \
1632 --transfer-encoding=7bit \
1633 --smtp-server="$(pwd)/fake.sendmail" \
1636 grep "cannot send message as 7bit" errors &&
1637 test -z "$(ls msgtxt*)"
1640 test_expect_success
$PREREQ 'setup expect' '
1641 cat >expected <<-\EOF
1642 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1646 test_expect_success
$PREREQ '8-bit and sendemail.transferencoding=quoted-printable' '
1647 clean_fake_sendmail &&
1649 --transfer-encoding=quoted-printable \
1650 --smtp-server="$(pwd)/fake.sendmail" \
1653 sed "1,/^$/d" msgtxt1 >actual &&
1654 test_cmp expected actual
1657 test_expect_success
$PREREQ 'setup expect' '
1658 cat >expected <<-\EOF
1659 RGllc2VyIEJldHJlZmYgZW50aMOkbHQgYXVjaCBlaW5lbiBVbWxhdXQhCg==
1663 test_expect_success
$PREREQ '8-bit and sendemail.transferencoding=base64' '
1664 clean_fake_sendmail &&
1666 --transfer-encoding=base64 \
1667 --smtp-server="$(pwd)/fake.sendmail" \
1670 sed "1,/^$/d" msgtxt1 >actual &&
1671 test_cmp expected actual
1674 test_expect_success
$PREREQ 'setup expect' '
1675 cat >email-using-qp <<-\EOF
1676 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1677 Message-Id: <bogus-message-id@example.com>
1678 From: A U Thor <author@example.com>
1679 Date: Sat, 12 Jun 2010 15:53:58 +0200
1681 Content-Transfer-Encoding: quoted-printable
1682 Content-Type: text/plain; charset=UTF-8
1683 Subject: Nothing to see here.
1685 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1689 test_expect_success
$PREREQ 'convert from quoted-printable to base64' '
1690 clean_fake_sendmail &&
1692 --transfer-encoding=base64 \
1693 --smtp-server="$(pwd)/fake.sendmail" \
1696 sed "1,/^$/d" msgtxt1 >actual &&
1697 test_cmp expected actual
1700 test_expect_success
$PREREQ 'setup expect' "
1701 tr -d '\\015' | tr '%' '\\015' >email-using-crlf <<EOF
1702 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1703 Message-Id: <bogus-message-id@example.com>
1704 From: A U Thor <author@example.com>
1705 Date: Sat, 12 Jun 2010 15:53:58 +0200
1706 Content-Type: text/plain; charset=UTF-8
1707 Subject: Nothing to see here.
1709 Look, I have a CRLF and an = sign!%
1713 test_expect_success
$PREREQ 'setup expect' '
1714 cat >expected <<-\EOF
1715 Look, I have a CRLF and an =3D sign!=0D
1719 test_expect_success
$PREREQ 'CRLF and sendemail.transferencoding=quoted-printable' '
1720 clean_fake_sendmail &&
1722 --transfer-encoding=quoted-printable \
1723 --smtp-server="$(pwd)/fake.sendmail" \
1726 sed "1,/^$/d" msgtxt1 >actual &&
1727 test_cmp expected actual
1730 test_expect_success
$PREREQ 'setup expect' '
1731 cat >expected <<-\EOF
1732 TG9vaywgSSBoYXZlIGEgQ1JMRiBhbmQgYW4gPSBzaWduIQ0K
1736 test_expect_success
$PREREQ 'CRLF and sendemail.transferencoding=base64' '
1737 clean_fake_sendmail &&
1739 --transfer-encoding=base64 \
1740 --smtp-server="$(pwd)/fake.sendmail" \
1743 sed "1,/^$/d" msgtxt1 >actual &&
1744 test_cmp expected actual
1748 # Note that the patches in this test are deliberately out of order; we
1749 # want to make sure it works even if the cover-letter is not in the
1751 test_expect_success
$PREREQ 'refusing to send cover letter template' '
1752 clean_fake_sendmail &&
1754 git format-patch --cover-letter -2 -o outdir &&
1755 test_must_fail git send-email \
1756 --from="Example <nobody@example.com>" \
1757 --to=nobody@example.com \
1758 --smtp-server="$(pwd)/fake.sendmail" \
1759 outdir/0002-*.patch \
1760 outdir/0000-*.patch \
1761 outdir/0001-*.patch \
1763 grep "SUBJECT HERE" errors &&
1764 test -z "$(ls msgtxt*)"
1767 test_expect_success
$PREREQ '--force sends cover letter template anyway' '
1768 clean_fake_sendmail &&
1770 git format-patch --cover-letter -2 -o outdir &&
1773 --from="Example <nobody@example.com>" \
1774 --to=nobody@example.com \
1775 --smtp-server="$(pwd)/fake.sendmail" \
1776 outdir/0002-*.patch \
1777 outdir/0000-*.patch \
1778 outdir/0001-*.patch \
1780 ! grep "SUBJECT HERE" errors &&
1781 test -n "$(ls msgtxt*)"
1784 test_cover_addresses
() {
1787 clean_fake_sendmail
&&
1789 git format-patch
--cover-letter -2 -o outdir
&&
1790 cover
=$
(echo outdir
/0000-*.
patch) &&
1791 mv $cover cover-to-edit.
patch &&
1792 perl
-pe "s/^From:/$header: extra\@address.com\nFrom:/" cover-to-edit.
patch >"$cover" &&
1795 --from="Example <nobody@example.com>" \
1798 --smtp-server="$(pwd)/fake.sendmail" \
1799 outdir
/0000-*.
patch \
1800 outdir
/0001-*.
patch \
1801 outdir
/0002-*.
patch \
1803 grep "^$header: extra@address.com" msgtxt1
>to1
&&
1804 grep "^$header: extra@address.com" msgtxt2
>to2
&&
1805 grep "^$header: extra@address.com" msgtxt3
>to3
&&
1806 test_line_count
= 1 to1
&&
1807 test_line_count
= 1 to2
&&
1808 test_line_count
= 1 to3
1811 test_expect_success
$PREREQ 'to-cover adds To to all mail' '
1812 test_cover_addresses "To" --to-cover
1815 test_expect_success
$PREREQ 'cc-cover adds Cc to all mail' '
1816 test_cover_addresses "Cc" --cc-cover
1819 test_expect_success
$PREREQ 'tocover adds To to all mail' '
1820 test_config sendemail.tocover true &&
1821 test_cover_addresses "To"
1824 test_expect_success
$PREREQ 'cccover adds Cc to all mail' '
1825 test_config sendemail.cccover true &&
1826 test_cover_addresses "Cc"
1829 test_expect_success
$PREREQ 'escaped quotes in sendemail.aliasfiletype=mutt' '
1830 clean_fake_sendmail &&
1831 echo "alias sbd \\\"Dot U. Sir\\\" <somebody@example.org>" >.mutt &&
1832 git config --replace-all sendemail.aliasesfile "$(pwd)/.mutt" &&
1833 git config sendemail.aliasfiletype mutt &&
1835 --from="Example <nobody@example.com>" \
1837 --smtp-server="$(pwd)/fake.sendmail" \
1838 outdir/0001-*.patch \
1840 grep "^!somebody@example\.org!$" commandline1 &&
1841 grep -F "To: \"Dot U. Sir\" <somebody@example.org>" out
1844 test_expect_success
$PREREQ 'sendemail.aliasfiletype=mailrc' '
1845 clean_fake_sendmail &&
1846 echo "alias sbd somebody@example.org" >.mailrc &&
1847 git config --replace-all sendemail.aliasesfile "$(pwd)/.mailrc" &&
1848 git config sendemail.aliasfiletype mailrc &&
1850 --from="Example <nobody@example.com>" \
1852 --smtp-server="$(pwd)/fake.sendmail" \
1853 outdir/0001-*.patch \
1855 grep "^!somebody@example\.org!$" commandline1
1858 test_expect_success
$PREREQ 'sendemail.aliasesfile=~/.mailrc' '
1859 clean_fake_sendmail &&
1860 echo "alias sbd someone@example.org" >"$HOME/.mailrc" &&
1861 git config --replace-all sendemail.aliasesfile "~/.mailrc" &&
1862 git config sendemail.aliasfiletype mailrc &&
1864 --from="Example <nobody@example.com>" \
1866 --smtp-server="$(pwd)/fake.sendmail" \
1867 outdir/0001-*.patch \
1869 grep "^!someone@example\.org!$" commandline1
1872 test_dump_aliases
() {
1873 msg
="$1" && shift &&
1874 filetype
="$1" && shift &&
1875 printf '%s\n' "$@" >expect
&&
1876 cat >.tmp-email-aliases
&&
1878 test_expect_success
$PREREQ "$msg" '
1879 clean_fake_sendmail && rm -fr outdir &&
1880 git config --replace-all sendemail.aliasesfile \
1881 "$(pwd)/.tmp-email-aliases" &&
1882 git config sendemail.aliasfiletype "$filetype" &&
1883 git send-email --dump-aliases 2>errors >actual &&
1884 test_cmp expect actual
1888 test_dump_aliases
'--dump-aliases sendmail format' \
1895 alice: Alice W Land <awol@example.com>
1896 bob: Robert Bobbyton <bob@example.com>
1897 chloe: chloe@example.com
1899 bcgrp: bob, chloe, Other <o@example.com>
1902 test_dump_aliases '--dump-aliases mutt format' \
1908 alias alice Alice W Land <awol@example.com>
1909 alias donald Donald C Carlton <donc@example.com>
1910 alias bob Robert Bobbyton <bob@example.com>
1911 alias chloe chloe@example.com
1914 test_dump_aliases '--dump-aliases mailrc format' \
1920 alias alice Alice W Land <awol@example.com>
1921 alias eve Eve <eve@example.com>
1922 alias bob Robert Bobbyton <bob@example.com>
1923 alias chloe chloe@example.com
1926 test_dump_aliases '--dump-aliases pine format' \
1932 alice Alice W Land <awol@example.com>
1933 eve Eve <eve@example.com>
1934 bob Robert Bobbyton <bob@example.com>
1935 chloe chloe@example.com
1938 test_dump_aliases '--dump-aliases gnus format' \
1944 (define-mail-alias "alice" "awol@example.com")
1945 (define-mail-alias "eve" "eve@example.com")
1946 (define-mail-alias "bob" "bob@example.com")
1947 (define-mail-alias "chloe" "chloe@example.com")
1950 test_expect_success '--dump-aliases must be used alone' '
1951 test_must_fail git send-email --dump-aliases --to=janice@example.com -1 refs/heads/accounting
1954 test_expect_success $PREREQ 'aliases and sendemail.identity' '
1955 test_must_fail git \
1956 -c sendemail.identity=cloud \
1957 -c sendemail.aliasesfile=default-aliases \
1958 -c sendemail.cloud.aliasesfile=cloud-aliases \
1959 send-email -1 2>stderr &&
1960 test_i18ngrep "cloud-aliases" stderr
1963 test_sendmail_aliases () {
1964 msg="$1" && shift &&
1966 cat >.tmp-email-aliases &&
1968 test_expect_success $PREREQ "$msg" '
1969 clean_fake_sendmail && rm -fr outdir &&
1970 git format-patch -1 -o outdir &&
1971 git config --replace-all sendemail.aliasesfile \
1972 "$(pwd)/.tmp-email-aliases" &&
1973 git config sendemail.aliasfiletype sendmail &&
1975 --from="Example <nobody@example.com>" \
1976 --to=alice --to=bcgrp \
1977 --smtp-server="$(pwd)/fake.sendmail" \
1978 outdir/0001-*.
patch \
1982 grep "^!$i!$" commandline1 ||
return 1
1987 test_sendmail_aliases 'sendemail.aliasfiletype
=sendmail
' \
1988 'awol@example\.com
' \
1989 'bob@example\.com
' \
1990 'chloe@example\.com
' \
1991 'o@example\.com
' <<-\EOF
1992 alice: Alice W Land <awol@example.com>
1993 bob: Robert Bobbyton <bob@example.com>
1995 # this is also a comment
1996 chloe: chloe@example.com
1998 bcgrp: bob, chloe, Other <o@example.com>
2001 test_sendmail_aliases 'sendmail aliases line folding
' \
2005 darla1 darla2 darla3 \
2006 elton1 elton2 elton3 \
2023 bcgrp: bob, chuck, darla, elton, fred, greg
2026 test_sendmail_aliases 'sendmail aliases tolerate bogus line folding
' \
2032 test_sendmail_aliases 'sendmail aliases empty
' alice bcgrp <<-\EOF
2035 test_expect_success $PREREQ 'alias support
in To header
' '
2036 clean_fake_sendmail
&&
2037 echo "alias sbd someone@example.org" >.mailrc
&&
2038 test_config sendemail.aliasesfile
".mailrc" &&
2039 test_config sendemail.aliasfiletype mailrc
&&
2040 git format-patch
--stdout -1 --to=sbd
>aliased.
patch &&
2042 --from="Example <nobody@example.com>" \
2043 --smtp-server="$(pwd)/fake.sendmail" \
2046 grep "^!someone@example\.org!$" commandline1
2049 test_expect_success $PREREQ 'alias support
in Cc header
' '
2050 clean_fake_sendmail
&&
2051 echo "alias sbd someone@example.org" >.mailrc
&&
2052 test_config sendemail.aliasesfile
".mailrc" &&
2053 test_config sendemail.aliasfiletype mailrc
&&
2054 git format-patch
--stdout -1 --cc=sbd
>aliased.
patch &&
2056 --from="Example <nobody@example.com>" \
2057 --smtp-server="$(pwd)/fake.sendmail" \
2060 grep "^!someone@example\.org!$" commandline1
2063 test_expect_success $PREREQ 'tocmd works with aliases
' '
2064 clean_fake_sendmail
&&
2065 echo "alias sbd someone@example.org" >.mailrc
&&
2066 test_config sendemail.aliasesfile
".mailrc" &&
2067 test_config sendemail.aliasfiletype mailrc
&&
2068 git format-patch
--stdout -1 >tocmd.
patch &&
2069 echo tocmd--sbd
>>tocmd.
patch &&
2071 --from="Example <nobody@example.com>" \
2072 --to-cmd=.
/tocmd-sed \
2073 --smtp-server="$(pwd)/fake.sendmail" \
2076 grep "^!someone@example\.org!$" commandline1
2079 test_expect_success $PREREQ 'cccmd works with aliases
' '
2080 clean_fake_sendmail
&&
2081 echo "alias sbd someone@example.org" >.mailrc
&&
2082 test_config sendemail.aliasesfile
".mailrc" &&
2083 test_config sendemail.aliasfiletype mailrc
&&
2084 git format-patch
--stdout -1 >cccmd.
patch &&
2085 echo cccmd--sbd
>>cccmd.
patch &&
2087 --from="Example <nobody@example.com>" \
2088 --cc-cmd=.
/cccmd-sed \
2089 --smtp-server="$(pwd)/fake.sendmail" \
2092 grep "^!someone@example\.org!$" commandline1
2095 do_xmailer_test () {
2096 expected=$1 params=$2 &&
2097 git format-patch -1 &&
2099 --from="Example <nobody@example.com>" \
2100 --to=someone@example.com \
2101 --smtp-server="$(pwd)/fake.sendmail" \
2105 { grep '^X-Mailer
:' out || :; } >mailer &&
2106 test_line_count = $expected mailer
2109 test_expect_success $PREREQ '--[no-
]xmailer without any configuration
' '
2110 do_xmailer_test
1 "--xmailer" &&
2111 do_xmailer_test
0 "--no-xmailer"
2114 test_expect_success $PREREQ '--[no-
]xmailer with sendemail.xmailer
=true
' '
2115 test_config sendemail.xmailer true
&&
2116 do_xmailer_test
1 "" &&
2117 do_xmailer_test
0 "--no-xmailer" &&
2118 do_xmailer_test
1 "--xmailer"
2121 test_expect_success $PREREQ '--[no-
]xmailer with sendemail.xmailer
' '
2122 test_when_finished
"test_unconfig sendemail.xmailer" &&
2123 cat >>.git
/config
<<-\EOF &&
2127 test_config sendemail.xmailer true &&
2128 do_xmailer_test 1 "" &&
2129 do_xmailer_test 0 "--no-xmailer" &&
2130 do_xmailer_test 1 "--xmailer"
2133 test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=false' '
2134 test_config sendemail.xmailer false &&
2135 do_xmailer_test 0 "" &&
2136 do_xmailer_test 0 "--no-xmailer" &&
2137 do_xmailer_test 1 "--xmailer"
2140 test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=' '
2141 test_config sendemail.xmailer "" &&
2142 do_xmailer_test 0 "" &&
2143 do_xmailer_test 0 "--no-xmailer" &&
2144 do_xmailer_test 1 "--xmailer"
2147 test_expect_success $PREREQ 'setup expected-list' '
2150 --from="Example <from@example.com>" \
2151 --to="To 1 <to1@example.com>" \
2152 --to="to2@example.com" \
2153 --to="to3@example.com" \
2154 --cc="Cc 1 <cc1@example.com>" \
2155 --cc="Cc2 <cc2@example.com>" \
2156 --bcc="bcc1@example.com" \
2157 --bcc="bcc2@example.com" \
2158 0001-add-main.patch | replace_variable_fields \
2162 test_expect_success $PREREQ 'use email list in --cc --to and --bcc' '
2165 --from="Example <from@example.com>" \
2166 --to="To 1 <to1@example.com>, to2@example.com" \
2167 --to="to3@example.com" \
2168 --cc="Cc 1 <cc1@example.com>, Cc2 <cc2@example.com>" \
2169 --bcc="bcc1@example.com, bcc2@example.com" \
2170 0001-add-main.patch | replace_variable_fields \
2172 test_cmp expected-list actual-list
2175 test_expect_success $PREREQ 'aliases work with email list' '
2176 echo "alias to2 to2@example.com" >.mutt &&
2177 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt &&
2178 test_config sendemail.aliasesfile ".mutt" &&
2179 test_config sendemail.aliasfiletype mutt &&
2182 --from="Example <from@example.com>" \
2183 --to="To 1 <to1@example.com>, to2, to3@example.com" \
2184 --cc="cc1, Cc2 <cc2@example.com>" \
2185 --bcc="bcc1@example.com, bcc2@example.com" \
2186 0001-add-main.patch | replace_variable_fields \
2188 test_cmp expected-list actual-list
2191 test_expect_success $PREREQ 'leading and trailing whitespaces are removed' '
2192 echo "alias to2 to2@example.com" >.mutt &&
2193 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt &&
2194 test_config sendemail.aliasesfile ".mutt" &&
2195 test_config sendemail.aliasfiletype mutt &&
2196 TO1=$(echo "QTo 1 <to1@example.com>" | q_to_tab) &&
2197 TO2=$(echo "QZto2" | qz_to_tab_space) &&
2198 CC1=$(echo "cc1" | append_cr) &&
2199 BCC1=$(echo " bcc1@example.com Q" | q_to_nul) &&
2202 --from=" Example <from@example.com>" \
2205 --to=" to3@example.com " \
2207 --cc="Cc2 <cc2@example.com>" \
2209 --bcc="bcc2@example.com" \
2210 0001-add-main.patch | replace_variable_fields \
2212 test_cmp expected-list actual-list
2215 test_expect_success $PREREQ 'test using command name with --sendmail-cmd' '
2216 clean_fake_sendmail &&
2219 --from="Example <nobody@example.com>" \
2220 --to=nobody@example.com \
2221 --sendmail-cmd="fake.sendmail" \
2223 test_path_is_file commandline1
2226 test_expect_success $PREREQ 'test using arguments with --sendmail-cmd' '
2227 clean_fake_sendmail &&
2229 --from="Example <nobody@example.com>" \
2230 --to=nobody@example.com \
2231 --sendmail-cmd='\''"$(pwd)/fake.sendmail" -f nobody@example.com'\'' \
2233 test_path_is_file commandline1
2236 test_expect_success $PREREQ 'test shell expression with --sendmail-cmd' '
2237 clean_fake_sendmail &&
2239 --from="Example <nobody@example.com>" \
2240 --to=nobody@example.com \
2241 --sendmail-cmd='\''f() { "$(pwd)/fake.sendmail" "$@"; };f'\'' \
2243 test_path_is_file commandline1
2246 test_expect_success $PREREQ 'set up in-reply-to/references patches' '
2247 cat >has-reply.patch <<-\
EOF &&
2248 From: A U Thor <author@example.com>
2249 Subject: patch with in-reply-to
2250 Message-ID: <patch.with.in.reply.to@example.com>
2251 In-Reply-To: <replied.to@example.com>
2252 References: <replied.to@example.com>
2256 cat >no-reply.patch <<-\EOF
2257 From: A U Thor <author@example.com>
2258 Subject: patch without in-reply-to
2259 Message-ID: <patch.without.in.reply.to@example.com>
2265 test_expect_success $PREREQ 'patch reply headers correct with --no-thread' '
2266 clean_fake_sendmail &&
2269 --to=nobody@example.com \
2270 --smtp-server="$(pwd)/fake.sendmail" \
2271 has-reply.patch no-reply.patch &&
2272 grep "In-Reply-To: <replied.to@example.com>" msgtxt1 &&
2273 grep "References: <replied.to@example.com>" msgtxt1 &&
2274 ! grep replied.to@example.com msgtxt2
2277 test_expect_success $PREREQ 'cmdline in-reply-to used with --no-thread' '
2278 clean_fake_sendmail &&
2281 --in-reply-to="<cmdline.reply@example.com>" \
2282 --to=nobody@example.com \
2283 --smtp-server="$(pwd)/fake.sendmail" \
2284 has-reply.patch no-reply.patch &&
2285 grep "In-Reply-To: <cmdline.reply@example.com>" msgtxt1 &&
2286 grep "References: <cmdline.reply@example.com>" msgtxt1 &&
2287 grep "In-Reply-To: <cmdline.reply@example.com>" msgtxt2 &&
2288 grep "References: <cmdline.reply@example.com>" msgtxt2
2291 test_expect_success $PREREQ 'invoke hook' '
2292 test_hook sendemail-validate <<-\EOF &&
2293 # test that we have the correct environment variable, pwd, and
2303 test -f 0001-add-main.patch &&
2304 grep "add main" "$1"
2309 # Test that it works even if we are not at the root of the
2313 --from="Example <nobody@example.com>" \
2314 --to=nobody@example.com \
2315 --smtp-server="$(pwd)/../fake.sendmail" \
2316 ../0001-add-main.patch &&
2318 # Verify error message when a patch is rejected by the hook
2319 sed -e "s/add main/x/" ../0001-add-main.patch >../another.patch &&
2320 test_must_fail git send-email \
2321 --from="Example <nobody@example.com>" \
2322 --to=nobody@example.com \
2323 --smtp-server="$(pwd)/../fake.sendmail" \
2324 ../another.patch 2>err &&
2325 test_i18ngrep "rejected by sendemail-validate hook" err
2329 test_expect_success $PREREQ 'test that send-email works outside a repo' '
2330 nongit git send-email \
2331 --from="Example <nobody@example.com>" \
2332 --to=nobody@example.com \
2333 --smtp-server="$(pwd)/fake.sendmail" \
2334 "$(pwd)/0001-add-main.patch"
2337 test_expect_success $PREREQ 'test that sendmail config is rejected' '
2338 test_config sendmail.program sendmail &&
2339 test_must_fail git send-email \
2340 --from="Example <nobody@example.com>" \
2341 --to=nobody@example.com \
2342 --smtp-server="$(pwd)/fake.sendmail" \
2344 test_i18ngrep "found configuration options for '"'"sendmail"'"'" err
2347 test_expect_success $PREREQ 'test that sendmail config rejection is specific' '
2348 test_config resendmail.program sendmail &&
2350 --from="Example <nobody@example.com>" \
2351 --to=nobody@example.com \
2352 --smtp-server="$(pwd)/fake.sendmail" \
2356 test_expect_success $PREREQ 'test forbidSendmailVariables behavior override' '
2357 test_config sendmail.program sendmail &&
2358 test_config sendemail.forbidSendmailVariables false &&
2360 --from="Example <nobody@example.com>" \
2361 --to=nobody@example.com \
2362 --smtp-server="$(pwd)/fake.sendmail" \