3 test_description='git send-email'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
9 # May be altered later in the test
12 replace_variable_fields () {
13 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
14 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
15 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/"
18 test_expect_success $PREREQ 'prepare reference tree' '
19 echo "1A quick brown fox jumps over the" >file &&
20 echo "lazy dog" >>file &&
22 GIT_AUTHOR_NAME="A" git commit -a -m "Initial."
25 test_expect_success $PREREQ 'Setup helper tool' '
26 write_script fake.sendmail <<-\EOF &&
29 while test -f commandline$output
36 done >commandline$output
39 git add fake.sendmail &&
40 GIT_AUTHOR_NAME="A" git commit -a -m "Second."
43 clean_fake_sendmail () {
44 rm -f commandline* msgtxt*
47 test_expect_success $PREREQ 'Extract patches' '
48 patches=$(git format-patch -s --cc="One <one@example.com>" --cc=two@example.com -n HEAD^1) &&
49 threaded_patches=$(git format-patch -o threaded -s --in-reply-to="format" HEAD^1)
52 # Test no confirm early to ensure remaining tests will not hang
56 GIT_SEND_EMAIL_NOTTY=1 \
58 --from="Example <from@example.com>" \
59 --to=nobody@example.com \
60 --smtp-server="$(pwd)/fake.sendmail" \
63 ! grep "Send this email" stdout &&
67 # Exit immediately to prevent hang if a no-confirm test fails
69 if ! test -f no_confirm_okay
71 say 'confirm test failed; skipping remaining tests to prevent hanging'
72 PREREQ="$PREREQ,CHECK_NO_CONFIRM"
77 test_expect_success $PREREQ 'No confirm with --suppress-cc' '
78 test_no_confirm --suppress-cc=sob &&
83 test_expect_success $PREREQ 'No confirm with --confirm=never' '
84 test_no_confirm --confirm=never &&
88 # leave sendemail.confirm set to never after this so that none of the
89 # remaining tests prompt unintentionally.
90 test_expect_success $PREREQ 'No confirm with sendemail.confirm=never' '
91 git config sendemail.confirm never &&
92 test_no_confirm --compose --subject=foo &&
96 test_expect_success $PREREQ 'Send patches' '
97 git send-email --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
100 test_expect_success $PREREQ 'setup expect' '
101 cat >expected <<-\EOF
109 test_expect_success $PREREQ 'Verify commandline' '
110 test_cmp expected commandline1
113 test_expect_success $PREREQ 'Send patches with --envelope-sender' '
114 clean_fake_sendmail &&
115 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
118 test_expect_success $PREREQ 'setup expect' '
119 cat >expected <<-\EOF
129 test_expect_success $PREREQ 'Verify commandline' '
130 test_cmp expected commandline1
133 test_expect_success $PREREQ 'Send patches with --envelope-sender=auto' '
134 clean_fake_sendmail &&
135 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
138 test_expect_success $PREREQ 'setup expect' '
139 cat >expected <<-\EOF
149 test_expect_success $PREREQ 'Verify commandline' '
150 test_cmp expected commandline1
153 test_expect_success $PREREQ 'setup expect for cc trailer' "
154 cat >expected-cc <<\EOF
155 !recipient@example.com!
166 test_expect_success $PREREQ 'cc trailer with various syntax' '
167 test_commit cc-trailer &&
168 test_when_finished "git reset --hard HEAD^" &&
169 git commit --amend -F - <<-EOF &&
173 Cc: <two@example.com> # trailing comments are ignored
174 Cc: <three@example.com>, <not.four@example.com> one address per line
175 Cc: "Some # Body" <four@example.com> [ <also.a.comment> ]
176 Cc: five@example.com # not.six@example.com
177 Cc: six@example.com, not.seven@example.com
179 clean_fake_sendmail &&
180 git send-email -1 --to=recipient@example.com \
181 --smtp-server="$(pwd)/fake.sendmail" &&
182 test_cmp expected-cc commandline1
185 test_expect_success $PREREQ 'setup fake get_maintainer.pl script for cc trailer' "
186 write_script expected-cc-script.sh <<-EOF
187 echo 'One Person <one@example.com> (supporter:THIS (FOO/bar))'
188 echo 'Two Person <two@example.com> (maintainer:THIS THING)'
189 echo 'Third List <three@example.com> (moderated list:THIS THING (FOO/bar))'
190 echo '<four@example.com> (moderated list:FOR THING)'
191 echo 'five@example.com (open list:FOR THING (FOO/bar))'
192 echo 'six@example.com (open list)'
196 test_expect_success $PREREQ 'cc trailer with get_maintainer.pl output' '
197 clean_fake_sendmail &&
198 git send-email -1 --to=recipient@example.com \
199 --cc-cmd=./expected-cc-script.sh \
200 --smtp-server="$(pwd)/fake.sendmail" &&
201 test_cmp expected-cc commandline1
204 test_expect_success $PREREQ 'setup expect' "
205 cat >expected-show-all-headers <<\EOF
207 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
208 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
209 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
211 Server: relay.example.com
212 MAIL FROM:<from@example.com>
213 RCPT TO:<to@example.com>
214 RCPT TO:<cc@example.com>
215 RCPT TO:<author@example.com>
216 RCPT TO:<one@example.com>
217 RCPT TO:<two@example.com>
218 RCPT TO:<bcc@example.com>
219 From: Example <from@example.com>
222 A <author@example.com>,
223 One <one@example.com>,
225 Subject: [PATCH 1/1] Second.
227 Message-Id: MESSAGE-ID-STRING
228 X-Mailer: X-MAILER-STRING
229 In-Reply-To: <unique-message-id@example.com>
230 References: <unique-message-id@example.com>
231 Reply-To: Reply <reply@example.com>
233 Content-Transfer-Encoding: 8bit
239 test_suppress_self () {
241 test_when_finished "git reset --hard HEAD^" &&
243 write_script cccmd-sed <<-EOF &&
244 sed -n -e s/^cccmd--//p "\$1"
247 git commit --amend --author="$1 <$2>" -F - &&
248 clean_fake_sendmail &&
249 git format-patch --stdout -1 >"suppress-self-$3.patch" &&
251 git send-email --from="$1 <$2>" \
252 --to=nobody@example.com \
253 --cc-cmd=./cccmd-sed \
255 --smtp-server="$(pwd)/fake.sendmail" \
256 suppress-self-$3.patch &&
258 mv msgtxt1 msgtxt1-$3 &&
259 sed -e '/^$/q' msgtxt1-$3 >"msghdr1-$3" &&
261 (grep '^Cc:' msghdr1-$3 >"actual-no-cc-$3";
262 test_must_be_empty actual-no-cc-$3)
265 test_suppress_self_unquoted () {
266 test_suppress_self "$1" "$2" "unquoted-$3" <<-EOF
267 test suppress-cc.self unquoted-$3 with name $1 email $2
274 Signed-off-by: $1 <$2>
278 test_suppress_self_quoted () {
279 test_suppress_self "$1" "$2" "quoted-$3" <<-EOF
280 test suppress-cc.self quoted-$3 with name $1 email $2
288 Signed-off-by: $1 <$2>
289 Signed-off-by: "$1" <$2>
293 test_expect_success $PREREQ 'self name is suppressed' "
294 test_suppress_self_unquoted 'A U Thor' 'author@example.com' \
295 'self_name_suppressed'
298 test_expect_success $PREREQ 'self name with dot is suppressed' "
299 test_suppress_self_quoted 'A U. Thor' 'author@example.com' \
300 'self_name_dot_suppressed'
303 test_expect_success $PREREQ 'non-ascii self name is suppressed' "
304 test_suppress_self_quoted 'Füñný Nâmé' 'odd_?=mail@example.com' \
305 'non_ascii_self_suppressed'
308 # This name is long enough to force format-patch to split it into multiple
309 # encoded-words, assuming it uses UTF-8 with the "Q" encoding.
310 test_expect_success $PREREQ 'long non-ascii self name is suppressed' "
311 test_suppress_self_quoted 'Ƒüñníęř €. Nâṁé' 'odd_?=mail@example.com' \
312 'long_non_ascii_self_suppressed'
315 test_expect_success $PREREQ 'sanitized self name is suppressed' "
316 test_suppress_self_unquoted '\"A U. Thor\"' 'author@example.com' \
317 'self_name_sanitized_suppressed'
320 test_expect_success $PREREQ 'Show all headers' '
324 --from="Example <from@example.com>" \
325 --reply-to="Reply <reply@example.com>" \
326 --to=to@example.com \
327 --cc=cc@example.com \
328 --bcc=bcc@example.com \
329 --in-reply-to="<unique-message-id@example.com>" \
330 --smtp-server relay.example.com \
331 $patches | replace_variable_fields \
332 >actual-show-all-headers &&
333 test_cmp expected-show-all-headers actual-show-all-headers
336 test_expect_success $PREREQ 'Prompting works' '
337 clean_fake_sendmail &&
338 (echo "to@example.com" &&
340 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
341 --smtp-server="$(pwd)/fake.sendmail" \
344 grep "^From: A U Thor <author@example.com>\$" msgtxt1 &&
345 grep "^To: to@example.com\$" msgtxt1
348 test_expect_success $PREREQ,AUTOIDENT 'implicit ident is allowed' '
349 clean_fake_sendmail &&
350 (sane_unset GIT_AUTHOR_NAME &&
351 sane_unset GIT_AUTHOR_EMAIL &&
352 sane_unset GIT_COMMITTER_NAME &&
353 sane_unset GIT_COMMITTER_EMAIL &&
354 GIT_SEND_EMAIL_NOTTY=1 git send-email \
355 --smtp-server="$(pwd)/fake.sendmail" \
356 --to=to@example.com \
357 $patches </dev/null 2>errors
361 test_expect_success $PREREQ,!AUTOIDENT 'broken implicit ident aborts send-email' '
362 clean_fake_sendmail &&
363 (sane_unset GIT_AUTHOR_NAME &&
364 sane_unset GIT_AUTHOR_EMAIL &&
365 sane_unset GIT_COMMITTER_NAME &&
366 sane_unset GIT_COMMITTER_EMAIL &&
367 GIT_SEND_EMAIL_NOTTY=1 && export GIT_SEND_EMAIL_NOTTY &&
368 test_must_fail git send-email \
369 --smtp-server="$(pwd)/fake.sendmail" \
370 --to=to@example.com \
371 $patches </dev/null 2>errors &&
372 test_i18ngrep "tell me who you are" errors
376 test_expect_success $PREREQ 'setup tocmd and cccmd scripts' '
377 write_script tocmd-sed <<-\EOF &&
378 sed -n -e "s/^tocmd--//p" "$1"
380 write_script cccmd-sed <<-\EOF
381 sed -n -e "s/^cccmd--//p" "$1"
385 test_expect_success $PREREQ 'tocmd works' '
386 clean_fake_sendmail &&
387 cp $patches tocmd.patch &&
388 echo tocmd--tocmd@example.com >>tocmd.patch &&
390 --from="Example <nobody@example.com>" \
391 --to-cmd=./tocmd-sed \
392 --smtp-server="$(pwd)/fake.sendmail" \
395 grep "^To: tocmd@example.com" msgtxt1
398 test_expect_success $PREREQ 'cccmd works' '
399 clean_fake_sendmail &&
400 cp $patches cccmd.patch &&
401 echo "cccmd-- cccmd@example.com" >>cccmd.patch &&
403 --from="Example <nobody@example.com>" \
404 --to=nobody@example.com \
405 --cc-cmd=./cccmd-sed \
406 --smtp-server="$(pwd)/fake.sendmail" \
409 grep "^ cccmd@example.com" msgtxt1
412 test_expect_success $PREREQ 'reject long lines' '
414 z64=$z8$z8$z8$z8$z8$z8$z8$z8 &&
415 z512=$z64$z64$z64$z64$z64$z64$z64$z64 &&
416 clean_fake_sendmail &&
417 cp $patches longline.patch &&
418 echo $z512$z512 >>longline.patch &&
419 test_must_fail git send-email \
420 --from="Example <nobody@example.com>" \
421 --to=nobody@example.com \
422 --smtp-server="$(pwd)/fake.sendmail" \
423 --transfer-encoding=8bit \
424 $patches longline.patch \
426 grep longline.patch errors
429 test_expect_success $PREREQ 'no patch was sent' '
430 ! test -e commandline1
433 test_expect_success $PREREQ 'Author From: in message body' '
434 clean_fake_sendmail &&
436 --from="Example <nobody@example.com>" \
437 --to=nobody@example.com \
438 --smtp-server="$(pwd)/fake.sendmail" \
440 sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
441 grep "From: A <author@example.com>" msgbody1
444 test_expect_success $PREREQ 'Author From: not in message body' '
445 clean_fake_sendmail &&
447 --from="A <author@example.com>" \
448 --to=nobody@example.com \
449 --smtp-server="$(pwd)/fake.sendmail" \
451 sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
452 ! grep "From: A <author@example.com>" msgbody1
455 test_expect_success $PREREQ 'allow long lines with --no-validate' '
457 --from="Example <nobody@example.com>" \
458 --to=nobody@example.com \
459 --smtp-server="$(pwd)/fake.sendmail" \
461 $patches longline.patch \
465 test_expect_success $PREREQ 'short lines with auto encoding are 8bit' '
466 clean_fake_sendmail &&
468 --from="A <author@example.com>" \
469 --to=nobody@example.com \
470 --smtp-server="$(pwd)/fake.sendmail" \
471 --transfer-encoding=auto \
473 grep "Content-Transfer-Encoding: 8bit" msgtxt1
476 test_expect_success $PREREQ 'long lines with auto encoding are quoted-printable' '
477 clean_fake_sendmail &&
479 --from="Example <nobody@example.com>" \
480 --to=nobody@example.com \
481 --smtp-server="$(pwd)/fake.sendmail" \
482 --transfer-encoding=auto \
485 grep "Content-Transfer-Encoding: quoted-printable" msgtxt1
488 test_expect_success $PREREQ 'carriage returns with auto encoding are quoted-printable' '
489 clean_fake_sendmail &&
490 cp $patches cr.patch &&
491 printf "this is a line\r\n" >>cr.patch &&
493 --from="Example <nobody@example.com>" \
494 --to=nobody@example.com \
495 --smtp-server="$(pwd)/fake.sendmail" \
496 --transfer-encoding=auto \
499 grep "Content-Transfer-Encoding: quoted-printable" msgtxt1
502 for enc in auto quoted-printable base64
504 test_expect_success $PREREQ "--validate passes with encoding $enc" '
506 --from="Example <nobody@example.com>" \
507 --to=nobody@example.com \
508 --smtp-server="$(pwd)/fake.sendmail" \
509 --transfer-encoding=$enc \
511 $patches longline.patch
516 for enc in 7bit 8bit quoted-printable base64
518 test_expect_success $PREREQ "--transfer-encoding=$enc produces correct header" '
519 clean_fake_sendmail &&
521 --from="Example <nobody@example.com>" \
522 --to=nobody@example.com \
523 --smtp-server="$(pwd)/fake.sendmail" \
524 --transfer-encoding=$enc \
526 grep "Content-Transfer-Encoding: $enc" msgtxt1
530 test_expect_success $PREREQ 'Invalid In-Reply-To' '
531 clean_fake_sendmail &&
533 --from="Example <nobody@example.com>" \
534 --to=nobody@example.com \
536 --smtp-server="$(pwd)/fake.sendmail" \
539 ! grep "^In-Reply-To: < *>" msgtxt1
542 test_expect_success $PREREQ 'Valid In-Reply-To when prompting' '
543 clean_fake_sendmail &&
544 (echo "From Example <from@example.com>" &&
545 echo "To Example <to@example.com>" &&
547 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
548 --smtp-server="$(pwd)/fake.sendmail" \
550 ! grep "^In-Reply-To: < *>" msgtxt1
553 test_expect_success $PREREQ 'In-Reply-To without --chain-reply-to' '
554 clean_fake_sendmail &&
555 echo "<unique-message-id@example.com>" >expect &&
557 --from="Example <nobody@example.com>" \
558 --to=nobody@example.com \
559 --no-chain-reply-to \
560 --in-reply-to="$(cat expect)" \
561 --smtp-server="$(pwd)/fake.sendmail" \
562 $patches $patches $patches \
564 # The first message is a reply to --in-reply-to
565 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
566 test_cmp expect actual &&
567 # Second and subsequent messages are replies to the first one
568 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
569 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
570 test_cmp expect actual &&
571 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
572 test_cmp expect actual
575 test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' '
576 clean_fake_sendmail &&
577 echo "<unique-message-id@example.com>" >expect &&
579 --from="Example <nobody@example.com>" \
580 --to=nobody@example.com \
582 --in-reply-to="$(cat expect)" \
583 --smtp-server="$(pwd)/fake.sendmail" \
584 $patches $patches $patches \
586 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
587 test_cmp expect actual &&
588 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
589 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
590 test_cmp expect actual &&
591 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt2 >expect &&
592 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
593 test_cmp expect actual
596 test_expect_success $PREREQ 'setup fake editor' '
597 write_script fake-editor <<-\EOF
598 echo fake edit >>"$1"
602 test_set_editor "$(pwd)/fake-editor"
604 test_expect_success $PREREQ '--compose works' '
605 clean_fake_sendmail &&
607 --compose --subject foo \
608 --from="Example <nobody@example.com>" \
609 --to=nobody@example.com \
610 --smtp-server="$(pwd)/fake.sendmail" \
615 test_expect_success $PREREQ 'first message is compose text' '
616 grep "^fake edit" msgtxt1
619 test_expect_success $PREREQ 'second message is patch' '
620 grep "Subject:.*Second" msgtxt2
623 test_expect_success $PREREQ 'setup expect' "
624 cat >expected-suppress-sob <<\EOF
626 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
627 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
628 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
630 Server: relay.example.com
631 MAIL FROM:<from@example.com>
632 RCPT TO:<to@example.com>
633 RCPT TO:<cc@example.com>
634 RCPT TO:<author@example.com>
635 RCPT TO:<one@example.com>
636 RCPT TO:<two@example.com>
637 From: Example <from@example.com>
640 A <author@example.com>,
641 One <one@example.com>,
643 Subject: [PATCH 1/1] Second.
645 Message-Id: MESSAGE-ID-STRING
646 X-Mailer: X-MAILER-STRING
648 Content-Transfer-Encoding: 8bit
654 test_suppression () {
657 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
658 --from="Example <from@example.com>" \
659 --to=to@example.com \
660 --smtp-server relay.example.com \
661 $patches | replace_variable_fields \
662 >actual-suppress-$1${2+"-$2"} &&
663 test_cmp expected-suppress-$1${2+"-$2"} actual-suppress-$1${2+"-$2"}
666 test_expect_success $PREREQ 'sendemail.cc set' '
667 git config sendemail.cc cc@example.com &&
671 test_expect_success $PREREQ 'setup expect' "
672 cat >expected-suppress-sob <<\EOF
674 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
675 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
676 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
678 Server: relay.example.com
679 MAIL FROM:<from@example.com>
680 RCPT TO:<to@example.com>
681 RCPT TO:<author@example.com>
682 RCPT TO:<one@example.com>
683 RCPT TO:<two@example.com>
684 From: Example <from@example.com>
686 Cc: A <author@example.com>,
687 One <one@example.com>,
689 Subject: [PATCH 1/1] Second.
691 Message-Id: MESSAGE-ID-STRING
692 X-Mailer: X-MAILER-STRING
694 Content-Transfer-Encoding: 8bit
700 test_expect_success $PREREQ 'sendemail.cc unset' '
701 git config --unset sendemail.cc &&
705 test_expect_success $PREREQ 'setup expect' "
706 cat >expected-suppress-cccmd <<\EOF
708 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
709 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
710 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
711 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
713 Server: relay.example.com
714 MAIL FROM:<from@example.com>
715 RCPT TO:<to@example.com>
716 RCPT TO:<author@example.com>
717 RCPT TO:<one@example.com>
718 RCPT TO:<two@example.com>
719 RCPT TO:<committer@example.com>
720 From: Example <from@example.com>
722 Cc: A <author@example.com>,
723 One <one@example.com>,
725 C O Mitter <committer@example.com>
726 Subject: [PATCH 1/1] Second.
728 Message-Id: MESSAGE-ID-STRING
729 X-Mailer: X-MAILER-STRING
731 Content-Transfer-Encoding: 8bit
737 test_expect_success $PREREQ 'sendemail.cccmd' '
738 write_script cccmd <<-\EOF &&
739 echo cc-cmd@example.com
741 git config sendemail.cccmd ./cccmd &&
742 test_suppression cccmd
745 test_expect_success $PREREQ 'setup expect' '
746 cat >expected-suppress-all <<\EOF
749 Server: relay.example.com
750 MAIL FROM:<from@example.com>
751 RCPT TO:<to@example.com>
752 From: Example <from@example.com>
754 Subject: [PATCH 1/1] Second.
756 Message-Id: MESSAGE-ID-STRING
757 X-Mailer: X-MAILER-STRING
759 Content-Transfer-Encoding: 8bit
765 test_expect_success $PREREQ '--suppress-cc=all' '
769 test_expect_success $PREREQ 'setup expect' "
770 cat >expected-suppress-body <<\EOF
772 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
773 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
774 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
775 (cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
777 Server: relay.example.com
778 MAIL FROM:<from@example.com>
779 RCPT TO:<to@example.com>
780 RCPT TO:<author@example.com>
781 RCPT TO:<one@example.com>
782 RCPT TO:<two@example.com>
783 RCPT TO:<cc-cmd@example.com>
784 From: Example <from@example.com>
786 Cc: A <author@example.com>,
787 One <one@example.com>,
790 Subject: [PATCH 1/1] Second.
792 Message-Id: MESSAGE-ID-STRING
793 X-Mailer: X-MAILER-STRING
795 Content-Transfer-Encoding: 8bit
801 test_expect_success $PREREQ '--suppress-cc=body' '
802 test_suppression body
805 test_expect_success $PREREQ 'setup expect' "
806 cat >expected-suppress-body-cccmd <<\EOF
808 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
809 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
810 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
812 Server: relay.example.com
813 MAIL FROM:<from@example.com>
814 RCPT TO:<to@example.com>
815 RCPT TO:<author@example.com>
816 RCPT TO:<one@example.com>
817 RCPT TO:<two@example.com>
818 From: Example <from@example.com>
820 Cc: A <author@example.com>,
821 One <one@example.com>,
823 Subject: [PATCH 1/1] Second.
825 Message-Id: MESSAGE-ID-STRING
826 X-Mailer: X-MAILER-STRING
828 Content-Transfer-Encoding: 8bit
834 test_expect_success $PREREQ '--suppress-cc=body --suppress-cc=cccmd' '
835 test_suppression body cccmd
838 test_expect_success $PREREQ 'setup expect' "
839 cat >expected-suppress-sob <<\EOF
841 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
842 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
843 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
845 Server: relay.example.com
846 MAIL FROM:<from@example.com>
847 RCPT TO:<to@example.com>
848 RCPT TO:<author@example.com>
849 RCPT TO:<one@example.com>
850 RCPT TO:<two@example.com>
851 From: Example <from@example.com>
853 Cc: A <author@example.com>,
854 One <one@example.com>,
856 Subject: [PATCH 1/1] Second.
858 Message-Id: MESSAGE-ID-STRING
859 X-Mailer: X-MAILER-STRING
861 Content-Transfer-Encoding: 8bit
867 test_expect_success $PREREQ '--suppress-cc=sob' '
868 test_might_fail git config --unset sendemail.cccmd &&
872 test_expect_success $PREREQ 'setup expect' "
873 cat >expected-suppress-bodycc <<\EOF
875 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
876 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
877 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
878 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
880 Server: relay.example.com
881 MAIL FROM:<from@example.com>
882 RCPT TO:<to@example.com>
883 RCPT TO:<author@example.com>
884 RCPT TO:<one@example.com>
885 RCPT TO:<two@example.com>
886 RCPT TO:<committer@example.com>
887 From: Example <from@example.com>
889 Cc: A <author@example.com>,
890 One <one@example.com>,
892 C O Mitter <committer@example.com>
893 Subject: [PATCH 1/1] Second.
895 Message-Id: MESSAGE-ID-STRING
896 X-Mailer: X-MAILER-STRING
898 Content-Transfer-Encoding: 8bit
904 test_expect_success $PREREQ '--suppress-cc=bodycc' '
905 test_suppression bodycc
908 test_expect_success $PREREQ 'setup expect' "
909 cat >expected-suppress-cc <<\EOF
911 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
912 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
914 Server: relay.example.com
915 MAIL FROM:<from@example.com>
916 RCPT TO:<to@example.com>
917 RCPT TO:<author@example.com>
918 RCPT TO:<committer@example.com>
919 From: Example <from@example.com>
921 Cc: A <author@example.com>,
922 C O Mitter <committer@example.com>
923 Subject: [PATCH 1/1] Second.
925 Message-Id: MESSAGE-ID-STRING
926 X-Mailer: X-MAILER-STRING
928 Content-Transfer-Encoding: 8bit
934 test_expect_success $PREREQ '--suppress-cc=cc' '
940 GIT_SEND_EMAIL_NOTTY=1 \
942 --from="Example <nobody@example.com>" \
943 --to=nobody@example.com \
944 --smtp-server="$(pwd)/fake.sendmail" \
945 $@ $patches >stdout &&
946 grep "Send this email" stdout
949 test_expect_success $PREREQ '--confirm=always' '
950 test_confirm --confirm=always --suppress-cc=all
953 test_expect_success $PREREQ '--confirm=auto' '
954 test_confirm --confirm=auto
957 test_expect_success $PREREQ '--confirm=cc' '
958 test_confirm --confirm=cc
961 test_expect_success $PREREQ '--confirm=compose' '
962 test_confirm --confirm=compose --compose
965 test_expect_success $PREREQ 'confirm by default (due to cc)' '
966 test_when_finished git config sendemail.confirm never &&
967 git config --unset sendemail.confirm &&
971 test_expect_success $PREREQ 'confirm by default (due to --compose)' '
972 test_when_finished git config sendemail.confirm never &&
973 git config --unset sendemail.confirm &&
974 test_confirm --suppress-cc=all --compose
977 test_expect_success $PREREQ 'confirm detects EOF (inform assumes y)' '
978 test_when_finished git config sendemail.confirm never &&
979 git config --unset sendemail.confirm &&
981 git format-patch -2 -o outdir &&
982 GIT_SEND_EMAIL_NOTTY=1 \
984 --from="Example <nobody@example.com>" \
985 --to=nobody@example.com \
986 --smtp-server="$(pwd)/fake.sendmail" \
987 outdir/*.patch </dev/null
990 test_expect_success $PREREQ 'confirm detects EOF (auto causes failure)' '
991 test_when_finished git config sendemail.confirm never &&
992 git config sendemail.confirm auto &&
993 GIT_SEND_EMAIL_NOTTY=1 &&
994 export GIT_SEND_EMAIL_NOTTY &&
995 test_must_fail git send-email \
996 --from="Example <nobody@example.com>" \
997 --to=nobody@example.com \
998 --smtp-server="$(pwd)/fake.sendmail" \
1002 test_expect_success $PREREQ 'confirm does not loop forever' '
1003 test_when_finished git config sendemail.confirm never &&
1004 git config sendemail.confirm auto &&
1005 GIT_SEND_EMAIL_NOTTY=1 &&
1006 export GIT_SEND_EMAIL_NOTTY &&
1007 yes "bogus" | test_must_fail git send-email \
1008 --from="Example <nobody@example.com>" \
1009 --to=nobody@example.com \
1010 --smtp-server="$(pwd)/fake.sendmail" \
1014 test_expect_success $PREREQ 'utf8 Cc is rfc2047 encoded' '
1015 clean_fake_sendmail &&
1017 git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
1019 --from="Example <nobody@example.com>" \
1020 --to=nobody@example.com \
1021 --smtp-server="$(pwd)/fake.sendmail" \
1024 grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
1027 test_expect_success $PREREQ '--compose adds MIME for utf8 body' '
1028 clean_fake_sendmail &&
1029 write_script fake-editor-utf8 <<-\EOF &&
1030 echo "utf8 body: àéìöú" >>"$1"
1032 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1034 --compose --subject foo \
1035 --from="Example <nobody@example.com>" \
1036 --to=nobody@example.com \
1037 --smtp-server="$(pwd)/fake.sendmail" \
1039 grep "^utf8 body" msgtxt1 &&
1040 grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
1043 test_expect_success $PREREQ '--compose respects user mime type' '
1044 clean_fake_sendmail &&
1045 write_script fake-editor-utf8-mime <<-\EOF &&
1048 Content-Type: text/plain; charset=iso-8859-1
1049 Content-Transfer-Encoding: 8bit
1055 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
1057 --compose --subject foo \
1058 --from="Example <nobody@example.com>" \
1059 --to=nobody@example.com \
1060 --smtp-server="$(pwd)/fake.sendmail" \
1062 grep "^utf8 body" msgtxt1 &&
1063 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
1064 ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
1067 test_expect_success $PREREQ '--compose adds MIME for utf8 subject' '
1068 clean_fake_sendmail &&
1069 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
1071 --compose --subject utf8-sübjëct \
1072 --from="Example <nobody@example.com>" \
1073 --to=nobody@example.com \
1074 --smtp-server="$(pwd)/fake.sendmail" \
1076 grep "^fake edit" msgtxt1 &&
1077 grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
1080 test_expect_success $PREREQ 'utf8 author is correctly passed on' '
1081 clean_fake_sendmail &&
1082 test_commit weird_author &&
1083 test_when_finished "git reset --hard HEAD^" &&
1084 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
1085 git format-patch --stdout -1 >funny_name.patch &&
1086 git send-email --from="Example <nobody@example.com>" \
1087 --to=nobody@example.com \
1088 --smtp-server="$(pwd)/fake.sendmail" \
1090 grep "^From: Füñný Nâmé <odd_?=mail@example.com>" msgtxt1
1093 test_expect_success $PREREQ 'utf8 sender is not duplicated' '
1094 clean_fake_sendmail &&
1095 test_commit weird_sender &&
1096 test_when_finished "git reset --hard HEAD^" &&
1097 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
1098 git format-patch --stdout -1 >funny_name.patch &&
1099 git send-email --from="Füñný Nâmé <odd_?=mail@example.com>" \
1100 --to=nobody@example.com \
1101 --smtp-server="$(pwd)/fake.sendmail" \
1103 grep "^From: " msgtxt1 >msgfrom &&
1104 test_line_count = 1 msgfrom
1107 test_expect_success $PREREQ 'sendemail.composeencoding works' '
1108 clean_fake_sendmail &&
1109 git config sendemail.composeencoding iso-8859-1 &&
1110 write_script fake-editor-utf8 <<-\EOF &&
1111 echo "utf8 body: àéìöú" >>"$1"
1113 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1115 --compose --subject foo \
1116 --from="Example <nobody@example.com>" \
1117 --to=nobody@example.com \
1118 --smtp-server="$(pwd)/fake.sendmail" \
1120 grep "^utf8 body" msgtxt1 &&
1121 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1124 test_expect_success $PREREQ '--compose-encoding works' '
1125 clean_fake_sendmail &&
1126 write_script fake-editor-utf8 <<-\EOF &&
1127 echo "utf8 body: àéìöú" >>"$1"
1129 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1131 --compose-encoding iso-8859-1 \
1132 --compose --subject foo \
1133 --from="Example <nobody@example.com>" \
1134 --to=nobody@example.com \
1135 --smtp-server="$(pwd)/fake.sendmail" \
1137 grep "^utf8 body" msgtxt1 &&
1138 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1141 test_expect_success $PREREQ '--compose-encoding overrides sendemail.composeencoding' '
1142 clean_fake_sendmail &&
1143 git config sendemail.composeencoding iso-8859-1 &&
1144 write_script fake-editor-utf8 <<-\EOF &&
1145 echo "utf8 body: àéìöú" >>"$1"
1147 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1149 --compose-encoding iso-8859-2 \
1150 --compose --subject foo \
1151 --from="Example <nobody@example.com>" \
1152 --to=nobody@example.com \
1153 --smtp-server="$(pwd)/fake.sendmail" \
1155 grep "^utf8 body" msgtxt1 &&
1156 grep "^Content-Type: text/plain; charset=iso-8859-2" msgtxt1
1159 test_expect_success $PREREQ '--compose-encoding adds correct MIME for subject' '
1160 clean_fake_sendmail &&
1161 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
1163 --compose-encoding iso-8859-2 \
1164 --compose --subject utf8-sübjëct \
1165 --from="Example <nobody@example.com>" \
1166 --to=nobody@example.com \
1167 --smtp-server="$(pwd)/fake.sendmail" \
1169 grep "^fake edit" msgtxt1 &&
1170 grep "^Subject: =?iso-8859-2?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
1173 test_expect_success $PREREQ 'detects ambiguous reference/file conflict' '
1176 git commit -m"add main" &&
1177 test_must_fail git send-email --dry-run main 2>errors &&
1178 grep disambiguate errors
1181 test_expect_success $PREREQ 'feed two files' '
1183 git format-patch -2 -o outdir &&
1186 --from="Example <nobody@example.com>" \
1187 --to=nobody@example.com \
1188 outdir/000?-*.patch 2>errors >out &&
1189 grep "^Subject: " out >subjects &&
1190 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
1191 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add main"
1194 test_expect_success $PREREQ 'in-reply-to but no threading' '
1197 --from="Example <nobody@example.com>" \
1198 --to=nobody@example.com \
1199 --in-reply-to="<in-reply-id@example.com>" \
1202 grep "In-Reply-To: <in-reply-id@example.com>" out
1205 test_expect_success $PREREQ 'no in-reply-to and no threading' '
1208 --from="Example <nobody@example.com>" \
1209 --to=nobody@example.com \
1212 ! grep "In-Reply-To: " stdout
1215 test_expect_success $PREREQ 'threading but no chain-reply-to' '
1218 --from="Example <nobody@example.com>" \
1219 --to=nobody@example.com \
1221 --no-chain-reply-to \
1222 $patches $patches >stdout &&
1223 grep "In-Reply-To: " stdout
1226 test_expect_success $PREREQ 'override in-reply-to if no threading' '
1229 --from="Example <nobody@example.com>" \
1230 --to=nobody@example.com \
1232 --in-reply-to="override" \
1233 $threaded_patches >stdout &&
1234 grep "In-Reply-To: <override>" stdout
1237 test_expect_success $PREREQ 'sendemail.to works' '
1238 git config --replace-all sendemail.to "Somebody <somebody@ex.com>" &&
1241 --from="Example <nobody@example.com>" \
1243 grep "To: Somebody <somebody@ex.com>" stdout
1246 test_expect_success $PREREQ 'setup sendemail.identity' '
1247 git config --replace-all sendemail.to "default@example.com" &&
1248 git config --replace-all sendemail.isp.to "isp@example.com" &&
1249 git config --replace-all sendemail.cloud.to "cloud@example.com"
1252 test_expect_success $PREREQ 'sendemail.identity: reads the correct identity config' '
1253 git -c sendemail.identity=cloud send-email \
1255 --from="nobody@example.com" \
1257 grep "To: cloud@example.com" stdout
1260 test_expect_success $PREREQ 'sendemail.identity: identity overrides sendemail.identity' '
1261 git -c sendemail.identity=cloud send-email \
1264 --from="nobody@example.com" \
1266 grep "To: isp@example.com" stdout
1269 test_expect_success $PREREQ 'sendemail.identity: --no-identity clears previous identity' '
1270 git -c sendemail.identity=cloud send-email \
1273 --from="nobody@example.com" \
1275 grep "To: default@example.com" stdout
1278 test_expect_success $PREREQ 'sendemail.identity: bool identity variable existence overrides' '
1279 git -c sendemail.identity=cloud \
1280 -c sendemail.xmailer=true \
1281 -c sendemail.cloud.xmailer=false \
1284 --from="nobody@example.com" \
1286 grep "To: cloud@example.com" stdout &&
1287 ! grep "X-Mailer" stdout
1290 test_expect_success $PREREQ 'sendemail.identity: bool variable fallback' '
1291 git -c sendemail.identity=cloud \
1292 -c sendemail.xmailer=false \
1295 --from="nobody@example.com" \
1297 grep "To: cloud@example.com" stdout &&
1298 ! grep "X-Mailer" stdout
1301 test_expect_success $PREREQ '--no-to overrides sendemail.to' '
1304 --from="Example <nobody@example.com>" \
1306 --to=nobody@example.com \
1308 grep "To: nobody@example.com" stdout &&
1309 ! grep "To: Somebody <somebody@ex.com>" stdout
1312 test_expect_success $PREREQ 'sendemail.cc works' '
1313 git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" &&
1316 --from="Example <nobody@example.com>" \
1317 --to=nobody@example.com \
1319 grep "Cc: Somebody <somebody@ex.com>" stdout
1322 test_expect_success $PREREQ '--no-cc overrides sendemail.cc' '
1325 --from="Example <nobody@example.com>" \
1327 --cc=bodies@example.com \
1328 --to=nobody@example.com \
1330 grep "Cc: bodies@example.com" stdout &&
1331 ! grep "Cc: Somebody <somebody@ex.com>" stdout
1334 test_expect_success $PREREQ 'sendemail.bcc works' '
1335 git config --replace-all sendemail.bcc "Other <other@ex.com>" &&
1338 --from="Example <nobody@example.com>" \
1339 --to=nobody@example.com \
1340 --smtp-server relay.example.com \
1342 grep "RCPT TO:<other@ex.com>" stdout
1345 test_expect_success $PREREQ '--no-bcc overrides sendemail.bcc' '
1348 --from="Example <nobody@example.com>" \
1350 --bcc=bodies@example.com \
1351 --to=nobody@example.com \
1352 --smtp-server relay.example.com \
1354 grep "RCPT TO:<bodies@example.com>" stdout &&
1355 ! grep "RCPT TO:<other@ex.com>" stdout
1358 test_expect_success $PREREQ 'patches To headers are used by default' '
1359 patch=$(git format-patch -1 --to="bodies@example.com") &&
1360 test_when_finished "rm $patch" &&
1363 --from="Example <nobody@example.com>" \
1364 --smtp-server relay.example.com \
1366 grep "RCPT TO:<bodies@example.com>" stdout
1369 test_expect_success $PREREQ 'patches To headers are appended to' '
1370 patch=$(git format-patch -1 --to="bodies@example.com") &&
1371 test_when_finished "rm $patch" &&
1374 --from="Example <nobody@example.com>" \
1375 --to=nobody@example.com \
1376 --smtp-server relay.example.com \
1378 grep "RCPT TO:<bodies@example.com>" stdout &&
1379 grep "RCPT TO:<nobody@example.com>" stdout
1382 test_expect_success $PREREQ 'To headers from files reset each patch' '
1383 patch1=$(git format-patch -1 --to="bodies@example.com") &&
1384 patch2=$(git format-patch -1 --to="other@example.com" HEAD~) &&
1385 test_when_finished "rm $patch1 && rm $patch2" &&
1388 --from="Example <nobody@example.com>" \
1389 --to="nobody@example.com" \
1390 --smtp-server relay.example.com \
1391 $patch1 $patch2 >stdout &&
1392 test $(grep -c "RCPT TO:<bodies@example.com>" stdout) = 1 &&
1393 test $(grep -c "RCPT TO:<nobody@example.com>" stdout) = 2 &&
1394 test $(grep -c "RCPT TO:<other@example.com>" stdout) = 1
1397 test_expect_success $PREREQ 'setup expect' '
1398 cat >email-using-8bit <<\EOF
1399 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1400 Message-Id: <bogus-message-id@example.com>
1401 From: author@example.com
1402 Date: Sat, 12 Jun 2010 15:53:58 +0200
1403 Subject: subject goes here
1405 Dieser deutsche Text enthält einen Umlaut!
1409 test_expect_success $PREREQ 'setup expect' '
1410 echo "Subject: subject goes here" >expected
1413 test_expect_success $PREREQ 'ASCII subject is not RFC2047 quoted' '
1414 clean_fake_sendmail &&
1416 git send-email --from=author@example.com --to=nobody@example.com \
1417 --smtp-server="$(pwd)/fake.sendmail" \
1418 --8bit-encoding=UTF-8 \
1419 email-using-8bit >stdout &&
1420 grep "Subject" msgtxt1 >actual &&
1421 test_cmp expected actual
1424 test_expect_success $PREREQ 'setup expect' '
1425 cat >content-type-decl <<-\EOF
1427 Content-Type: text/plain; charset=UTF-8
1428 Content-Transfer-Encoding: 8bit
1432 test_expect_success $PREREQ 'asks about and fixes 8bit encodings' '
1433 clean_fake_sendmail &&
1435 git send-email --from=author@example.com --to=nobody@example.com \
1436 --smtp-server="$(pwd)/fake.sendmail" \
1437 email-using-8bit >stdout &&
1438 grep "do not declare a Content-Transfer-Encoding" stdout &&
1439 grep email-using-8bit stdout &&
1440 grep "Which 8bit encoding" stdout &&
1441 egrep "Content|MIME" msgtxt1 >actual &&
1442 test_cmp content-type-decl actual
1445 test_expect_success $PREREQ 'sendemail.8bitEncoding works' '
1446 clean_fake_sendmail &&
1447 git config sendemail.assume8bitEncoding UTF-8 &&
1449 git send-email --from=author@example.com --to=nobody@example.com \
1450 --smtp-server="$(pwd)/fake.sendmail" \
1451 email-using-8bit >stdout &&
1452 egrep "Content|MIME" msgtxt1 >actual &&
1453 test_cmp content-type-decl actual
1456 test_expect_success $PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
1457 clean_fake_sendmail &&
1458 git config sendemail.assume8bitEncoding "bogus too" &&
1460 git send-email --from=author@example.com --to=nobody@example.com \
1461 --smtp-server="$(pwd)/fake.sendmail" \
1462 --8bit-encoding=UTF-8 \
1463 email-using-8bit >stdout &&
1464 egrep "Content|MIME" msgtxt1 >actual &&
1465 test_cmp content-type-decl actual
1468 test_expect_success $PREREQ 'setup expect' '
1469 cat >email-using-8bit <<-\EOF
1470 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1471 Message-Id: <bogus-message-id@example.com>
1472 From: author@example.com
1473 Date: Sat, 12 Jun 2010 15:53:58 +0200
1474 Subject: Dieser Betreff enthält auch einen Umlaut!
1476 Nothing to see here.
1480 test_expect_success $PREREQ 'setup expect' '
1481 cat >expected <<-\EOF
1482 Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
1486 test_expect_success $PREREQ '--8bit-encoding also treats subject' '
1487 clean_fake_sendmail &&
1489 git send-email --from=author@example.com --to=nobody@example.com \
1490 --smtp-server="$(pwd)/fake.sendmail" \
1491 --8bit-encoding=UTF-8 \
1492 email-using-8bit >stdout &&
1493 grep "Subject" msgtxt1 >actual &&
1494 test_cmp expected actual
1497 test_expect_success $PREREQ 'setup expect' '
1498 cat >email-using-8bit <<-\EOF
1499 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1500 Message-Id: <bogus-message-id@example.com>
1501 From: A U Thor <author@example.com>
1502 Date: Sat, 12 Jun 2010 15:53:58 +0200
1503 Content-Type: text/plain; charset=UTF-8
1504 Subject: Nothing to see here.
1506 Dieser Betreff enthält auch einen Umlaut!
1510 test_expect_success $PREREQ '--transfer-encoding overrides sendemail.transferEncoding' '
1511 clean_fake_sendmail &&
1512 test_must_fail git -c sendemail.transferEncoding=8bit \
1514 --transfer-encoding=7bit \
1515 --smtp-server="$(pwd)/fake.sendmail" \
1518 grep "cannot send message as 7bit" errors &&
1519 test -z "$(ls msgtxt*)"
1522 test_expect_success $PREREQ 'sendemail.transferEncoding via config' '
1523 clean_fake_sendmail &&
1524 test_must_fail git -c sendemail.transferEncoding=7bit \
1526 --smtp-server="$(pwd)/fake.sendmail" \
1529 grep "cannot send message as 7bit" errors &&
1530 test -z "$(ls msgtxt*)"
1533 test_expect_success $PREREQ 'sendemail.transferEncoding via cli' '
1534 clean_fake_sendmail &&
1535 test_must_fail git send-email \
1536 --transfer-encoding=7bit \
1537 --smtp-server="$(pwd)/fake.sendmail" \
1540 grep "cannot send message as 7bit" errors &&
1541 test -z "$(ls msgtxt*)"
1544 test_expect_success $PREREQ 'setup expect' '
1545 cat >expected <<-\EOF
1546 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1550 test_expect_success $PREREQ '8-bit and sendemail.transferencoding=quoted-printable' '
1551 clean_fake_sendmail &&
1553 --transfer-encoding=quoted-printable \
1554 --smtp-server="$(pwd)/fake.sendmail" \
1557 sed "1,/^$/d" msgtxt1 >actual &&
1558 test_cmp expected actual
1561 test_expect_success $PREREQ 'setup expect' '
1562 cat >expected <<-\EOF
1563 RGllc2VyIEJldHJlZmYgZW50aMOkbHQgYXVjaCBlaW5lbiBVbWxhdXQhCg==
1567 test_expect_success $PREREQ '8-bit and sendemail.transferencoding=base64' '
1568 clean_fake_sendmail &&
1570 --transfer-encoding=base64 \
1571 --smtp-server="$(pwd)/fake.sendmail" \
1574 sed "1,/^$/d" msgtxt1 >actual &&
1575 test_cmp expected actual
1578 test_expect_success $PREREQ 'setup expect' '
1579 cat >email-using-qp <<-\EOF
1580 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1581 Message-Id: <bogus-message-id@example.com>
1582 From: A U Thor <author@example.com>
1583 Date: Sat, 12 Jun 2010 15:53:58 +0200
1585 Content-Transfer-Encoding: quoted-printable
1586 Content-Type: text/plain; charset=UTF-8
1587 Subject: Nothing to see here.
1589 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1593 test_expect_success $PREREQ 'convert from quoted-printable to base64' '
1594 clean_fake_sendmail &&
1596 --transfer-encoding=base64 \
1597 --smtp-server="$(pwd)/fake.sendmail" \
1600 sed "1,/^$/d" msgtxt1 >actual &&
1601 test_cmp expected actual
1604 test_expect_success $PREREQ 'setup expect' "
1605 tr -d '\\015' | tr '%' '\\015' >email-using-crlf <<EOF
1606 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1607 Message-Id: <bogus-message-id@example.com>
1608 From: A U Thor <author@example.com>
1609 Date: Sat, 12 Jun 2010 15:53:58 +0200
1610 Content-Type: text/plain; charset=UTF-8
1611 Subject: Nothing to see here.
1613 Look, I have a CRLF and an = sign!%
1617 test_expect_success $PREREQ 'setup expect' '
1618 cat >expected <<-\EOF
1619 Look, I have a CRLF and an =3D sign!=0D
1623 test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=quoted-printable' '
1624 clean_fake_sendmail &&
1626 --transfer-encoding=quoted-printable \
1627 --smtp-server="$(pwd)/fake.sendmail" \
1630 sed "1,/^$/d" msgtxt1 >actual &&
1631 test_cmp expected actual
1634 test_expect_success $PREREQ 'setup expect' '
1635 cat >expected <<-\EOF
1636 TG9vaywgSSBoYXZlIGEgQ1JMRiBhbmQgYW4gPSBzaWduIQ0K
1640 test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=base64' '
1641 clean_fake_sendmail &&
1643 --transfer-encoding=base64 \
1644 --smtp-server="$(pwd)/fake.sendmail" \
1647 sed "1,/^$/d" msgtxt1 >actual &&
1648 test_cmp expected actual
1652 # Note that the patches in this test are deliberately out of order; we
1653 # want to make sure it works even if the cover-letter is not in the
1655 test_expect_success $PREREQ 'refusing to send cover letter template' '
1656 clean_fake_sendmail &&
1658 git format-patch --cover-letter -2 -o outdir &&
1659 test_must_fail git send-email \
1660 --from="Example <nobody@example.com>" \
1661 --to=nobody@example.com \
1662 --smtp-server="$(pwd)/fake.sendmail" \
1663 outdir/0002-*.patch \
1664 outdir/0000-*.patch \
1665 outdir/0001-*.patch \
1667 grep "SUBJECT HERE" errors &&
1668 test -z "$(ls msgtxt*)"
1671 test_expect_success $PREREQ '--force sends cover letter template anyway' '
1672 clean_fake_sendmail &&
1674 git format-patch --cover-letter -2 -o outdir &&
1677 --from="Example <nobody@example.com>" \
1678 --to=nobody@example.com \
1679 --smtp-server="$(pwd)/fake.sendmail" \
1680 outdir/0002-*.patch \
1681 outdir/0000-*.patch \
1682 outdir/0001-*.patch \
1684 ! grep "SUBJECT HERE" errors &&
1685 test -n "$(ls msgtxt*)"
1688 test_cover_addresses () {
1691 clean_fake_sendmail &&
1693 git format-patch --cover-letter -2 -o outdir &&
1694 cover=$(echo outdir/0000-*.patch) &&
1695 mv $cover cover-to-edit.patch &&
1696 perl -pe "s/^From:/$header: extra\@address.com\nFrom:/" cover-to-edit.patch >"$cover" &&
1699 --from="Example <nobody@example.com>" \
1702 --smtp-server="$(pwd)/fake.sendmail" \
1703 outdir/0000-*.patch \
1704 outdir/0001-*.patch \
1705 outdir/0002-*.patch \
1707 grep "^$header: extra@address.com" msgtxt1 >to1 &&
1708 grep "^$header: extra@address.com" msgtxt2 >to2 &&
1709 grep "^$header: extra@address.com" msgtxt3 >to3 &&
1710 test_line_count = 1 to1 &&
1711 test_line_count = 1 to2 &&
1712 test_line_count = 1 to3
1715 test_expect_success $PREREQ 'to-cover adds To to all mail' '
1716 test_cover_addresses "To" --to-cover
1719 test_expect_success $PREREQ 'cc-cover adds Cc to all mail' '
1720 test_cover_addresses "Cc" --cc-cover
1723 test_expect_success $PREREQ 'tocover adds To to all mail' '
1724 test_config sendemail.tocover true &&
1725 test_cover_addresses "To"
1728 test_expect_success $PREREQ 'cccover adds Cc to all mail' '
1729 test_config sendemail.cccover true &&
1730 test_cover_addresses "Cc"
1733 test_expect_success $PREREQ 'escaped quotes in sendemail.aliasfiletype=mutt' '
1734 clean_fake_sendmail &&
1735 echo "alias sbd \\\"Dot U. Sir\\\" <somebody@example.org>" >.mutt &&
1736 git config --replace-all sendemail.aliasesfile "$(pwd)/.mutt" &&
1737 git config sendemail.aliasfiletype mutt &&
1739 --from="Example <nobody@example.com>" \
1741 --smtp-server="$(pwd)/fake.sendmail" \
1742 outdir/0001-*.patch \
1744 grep "^!somebody@example\.org!$" commandline1 &&
1745 grep -F "To: \"Dot U. Sir\" <somebody@example.org>" out
1748 test_expect_success $PREREQ 'sendemail.aliasfiletype=mailrc' '
1749 clean_fake_sendmail &&
1750 echo "alias sbd somebody@example.org" >.mailrc &&
1751 git config --replace-all sendemail.aliasesfile "$(pwd)/.mailrc" &&
1752 git config sendemail.aliasfiletype mailrc &&
1754 --from="Example <nobody@example.com>" \
1756 --smtp-server="$(pwd)/fake.sendmail" \
1757 outdir/0001-*.patch \
1759 grep "^!somebody@example\.org!$" commandline1
1762 test_expect_success $PREREQ 'sendemail.aliasfile=~/.mailrc' '
1763 clean_fake_sendmail &&
1764 echo "alias sbd someone@example.org" >"$HOME/.mailrc" &&
1765 git config --replace-all sendemail.aliasesfile "~/.mailrc" &&
1766 git config sendemail.aliasfiletype mailrc &&
1768 --from="Example <nobody@example.com>" \
1770 --smtp-server="$(pwd)/fake.sendmail" \
1771 outdir/0001-*.patch \
1773 grep "^!someone@example\.org!$" commandline1
1776 test_dump_aliases () {
1777 msg="$1" && shift &&
1778 filetype="$1" && shift &&
1779 printf '%s\n' "$@" >expect &&
1780 cat >.tmp-email-aliases &&
1782 test_expect_success $PREREQ "$msg" '
1783 clean_fake_sendmail && rm -fr outdir &&
1784 git config --replace-all sendemail.aliasesfile \
1785 "$(pwd)/.tmp-email-aliases" &&
1786 git config sendemail.aliasfiletype "$filetype" &&
1787 git send-email --dump-aliases 2>errors >actual &&
1788 test_cmp expect actual
1792 test_dump_aliases '--dump-aliases sendmail format' \
1799 alice: Alice W Land <awol@example.com>
1800 bob: Robert Bobbyton <bob@example.com>
1801 chloe: chloe@example.com
1803 bcgrp: bob, chloe, Other <o@example.com>
1806 test_dump_aliases '--dump-aliases mutt format' \
1812 alias alice Alice W Land <awol@example.com>
1813 alias donald Donald C Carlton <donc@example.com>
1814 alias bob Robert Bobbyton <bob@example.com>
1815 alias chloe chloe@example.com
1818 test_dump_aliases '--dump-aliases mailrc format' \
1824 alias alice Alice W Land <awol@example.com>
1825 alias eve Eve <eve@example.com>
1826 alias bob Robert Bobbyton <bob@example.com>
1827 alias chloe chloe@example.com
1830 test_dump_aliases '--dump-aliases pine format' \
1836 alice Alice W Land <awol@example.com>
1837 eve Eve <eve@example.com>
1838 bob Robert Bobbyton <bob@example.com>
1839 chloe chloe@example.com
1842 test_dump_aliases '--dump-aliases gnus format' \
1848 (define-mail-alias "alice" "awol@example.com")
1849 (define-mail-alias "eve" "eve@example.com")
1850 (define-mail-alias "bob" "bob@example.com")
1851 (define-mail-alias "chloe" "chloe@example.com")
1854 test_expect_success '--dump-aliases must be used alone' '
1855 test_must_fail git send-email --dump-aliases --to=janice@example.com -1 refs/heads/accounting
1858 test_expect_success $PREREQ 'aliases and sendemail.identity' '
1859 test_must_fail git \
1860 -c sendemail.identity=cloud \
1861 -c sendemail.aliasesfile=default-aliases \
1862 -c sendemail.cloud.aliasesfile=cloud-aliases \
1863 send-email -1 2>stderr &&
1864 test_i18ngrep "cloud-aliases" stderr
1867 test_sendmail_aliases () {
1868 msg="$1" && shift &&
1870 cat >.tmp-email-aliases &&
1872 test_expect_success $PREREQ "$msg" '
1873 clean_fake_sendmail && rm -fr outdir &&
1874 git format-patch -1 -o outdir &&
1875 git config --replace-all sendemail.aliasesfile \
1876 "$(pwd)/.tmp-email-aliases" &&
1877 git config sendemail.aliasfiletype sendmail &&
1879 --from="Example <nobody@example.com>" \
1880 --to=alice --to=bcgrp \
1881 --smtp-server="$(pwd)/fake.sendmail" \
1882 outdir/0001-*.patch \
1886 grep "^!$i!$" commandline1 || return 1
1891 test_sendmail_aliases 'sendemail.aliasfiletype=sendmail' \
1892 'awol@example\.com' \
1893 'bob@example\.com' \
1894 'chloe@example\.com' \
1895 'o@example\.com' <<-\EOF
1896 alice: Alice W Land <awol@example.com>
1897 bob: Robert Bobbyton <bob@example.com>
1899 # this is also a comment
1900 chloe: chloe@example.com
1902 bcgrp: bob, chloe, Other <o@example.com>
1905 test_sendmail_aliases 'sendmail aliases line folding' \
1909 darla1 darla2 darla3 \
1910 elton1 elton2 elton3 \
1927 bcgrp: bob, chuck, darla, elton, fred, greg
1930 test_sendmail_aliases 'sendmail aliases tolerate bogus line folding' \
1936 test_sendmail_aliases 'sendmail aliases empty' alice bcgrp <<-\EOF
1939 test_expect_success $PREREQ 'alias support in To header' '
1940 clean_fake_sendmail &&
1941 echo "alias sbd someone@example.org" >.mailrc &&
1942 test_config sendemail.aliasesfile ".mailrc" &&
1943 test_config sendemail.aliasfiletype mailrc &&
1944 git format-patch --stdout -1 --to=sbd >aliased.patch &&
1946 --from="Example <nobody@example.com>" \
1947 --smtp-server="$(pwd)/fake.sendmail" \
1950 grep "^!someone@example\.org!$" commandline1
1953 test_expect_success $PREREQ 'alias support in Cc header' '
1954 clean_fake_sendmail &&
1955 echo "alias sbd someone@example.org" >.mailrc &&
1956 test_config sendemail.aliasesfile ".mailrc" &&
1957 test_config sendemail.aliasfiletype mailrc &&
1958 git format-patch --stdout -1 --cc=sbd >aliased.patch &&
1960 --from="Example <nobody@example.com>" \
1961 --smtp-server="$(pwd)/fake.sendmail" \
1964 grep "^!someone@example\.org!$" commandline1
1967 test_expect_success $PREREQ 'tocmd works with aliases' '
1968 clean_fake_sendmail &&
1969 echo "alias sbd someone@example.org" >.mailrc &&
1970 test_config sendemail.aliasesfile ".mailrc" &&
1971 test_config sendemail.aliasfiletype mailrc &&
1972 git format-patch --stdout -1 >tocmd.patch &&
1973 echo tocmd--sbd >>tocmd.patch &&
1975 --from="Example <nobody@example.com>" \
1976 --to-cmd=./tocmd-sed \
1977 --smtp-server="$(pwd)/fake.sendmail" \
1980 grep "^!someone@example\.org!$" commandline1
1983 test_expect_success $PREREQ 'cccmd works with aliases' '
1984 clean_fake_sendmail &&
1985 echo "alias sbd someone@example.org" >.mailrc &&
1986 test_config sendemail.aliasesfile ".mailrc" &&
1987 test_config sendemail.aliasfiletype mailrc &&
1988 git format-patch --stdout -1 >cccmd.patch &&
1989 echo cccmd--sbd >>cccmd.patch &&
1991 --from="Example <nobody@example.com>" \
1992 --cc-cmd=./cccmd-sed \
1993 --smtp-server="$(pwd)/fake.sendmail" \
1996 grep "^!someone@example\.org!$" commandline1
1999 do_xmailer_test () {
2000 expected=$1 params=$2 &&
2001 git format-patch -1 &&
2003 --from="Example <nobody@example.com>" \
2004 --to=someone@example.com \
2005 --smtp-server="$(pwd)/fake.sendmail" \
2009 { grep '^X-Mailer:' out || :; } >mailer &&
2010 test_line_count = $expected mailer
2013 test_expect_success $PREREQ '--[no-]xmailer without any configuration' '
2014 do_xmailer_test 1 "--xmailer" &&
2015 do_xmailer_test 0 "--no-xmailer"
2018 test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=true' '
2019 test_config sendemail.xmailer true &&
2020 do_xmailer_test 1 "" &&
2021 do_xmailer_test 0 "--no-xmailer" &&
2022 do_xmailer_test 1 "--xmailer"
2025 test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=false' '
2026 test_config sendemail.xmailer false &&
2027 do_xmailer_test 0 "" &&
2028 do_xmailer_test 0 "--no-xmailer" &&
2029 do_xmailer_test 1 "--xmailer"
2032 test_expect_success $PREREQ 'setup expected-list' '
2035 --from="Example <from@example.com>" \
2036 --to="To 1 <to1@example.com>" \
2037 --to="to2@example.com" \
2038 --to="to3@example.com" \
2039 --cc="Cc 1 <cc1@example.com>" \
2040 --cc="Cc2 <cc2@example.com>" \
2041 --bcc="bcc1@example.com" \
2042 --bcc="bcc2@example.com" \
2043 0001-add-main.patch | replace_variable_fields \
2047 test_expect_success $PREREQ 'use email list in --cc --to and --bcc' '
2050 --from="Example <from@example.com>" \
2051 --to="To 1 <to1@example.com>, to2@example.com" \
2052 --to="to3@example.com" \
2053 --cc="Cc 1 <cc1@example.com>, Cc2 <cc2@example.com>" \
2054 --bcc="bcc1@example.com, bcc2@example.com" \
2055 0001-add-main.patch | replace_variable_fields \
2057 test_cmp expected-list actual-list
2060 test_expect_success $PREREQ 'aliases work with email list' '
2061 echo "alias to2 to2@example.com" >.mutt &&
2062 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt &&
2063 test_config sendemail.aliasesfile ".mutt" &&
2064 test_config sendemail.aliasfiletype mutt &&
2067 --from="Example <from@example.com>" \
2068 --to="To 1 <to1@example.com>, to2, to3@example.com" \
2069 --cc="cc1, Cc2 <cc2@example.com>" \
2070 --bcc="bcc1@example.com, bcc2@example.com" \
2071 0001-add-main.patch | replace_variable_fields \
2073 test_cmp expected-list actual-list
2076 test_expect_success $PREREQ 'leading and trailing whitespaces are removed' '
2077 echo "alias to2 to2@example.com" >.mutt &&
2078 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt &&
2079 test_config sendemail.aliasesfile ".mutt" &&
2080 test_config sendemail.aliasfiletype mutt &&
2081 TO1=$(echo "QTo 1 <to1@example.com>" | q_to_tab) &&
2082 TO2=$(echo "QZto2" | qz_to_tab_space) &&
2083 CC1=$(echo "cc1" | append_cr) &&
2084 BCC1=$(echo " bcc1@example.com Q" | q_to_nul) &&
2087 --from=" Example <from@example.com>" \
2090 --to=" to3@example.com " \
2092 --cc="Cc2 <cc2@example.com>" \
2094 --bcc="bcc2@example.com" \
2095 0001-add-main.patch | replace_variable_fields \
2097 test_cmp expected-list actual-list
2100 test_expect_success $PREREQ 'invoke hook' '
2101 mkdir -p .git/hooks &&
2103 write_script .git/hooks/sendemail-validate <<-\EOF &&
2104 # test that we have the correct environment variable, pwd, and
2114 test -f 0001-add-main.patch &&
2115 grep "add main" "$1"
2120 # Test that it works even if we are not at the root of the
2124 --from="Example <nobody@example.com>" \
2125 --to=nobody@example.com \
2126 --smtp-server="$(pwd)/../fake.sendmail" \
2127 ../0001-add-main.patch &&
2129 # Verify error message when a patch is rejected by the hook
2130 sed -e "s/add main/x/" ../0001-add-main.patch >../another.patch &&
2131 test_must_fail git send-email \
2132 --from="Example <nobody@example.com>" \
2133 --to=nobody@example.com \
2134 --smtp-server="$(pwd)/../fake.sendmail" \
2135 ../another.patch 2>err &&
2136 test_i18ngrep "rejected by sendemail-validate hook" err
2140 test_expect_success $PREREQ 'test that send-email works outside a repo' '
2141 nongit git send-email \
2142 --from="Example <nobody@example.com>" \
2143 --to=nobody@example.com \
2144 --smtp-server="$(pwd)/fake.sendmail" \
2145 "$(pwd)/0001-add-main.patch"
2148 test_expect_success $PREREQ 'test that sendmail config is rejected' '
2149 test_config sendmail.program sendmail &&
2150 test_must_fail git send-email \
2151 --from="Example <nobody@example.com>" \
2152 --to=nobody@example.com \
2153 --smtp-server="$(pwd)/fake.sendmail" \
2155 test_i18ngrep "found configuration options for '"'"sendmail"'"'" err
2158 test_expect_success $PREREQ 'test that sendmail config rejection is specific' '
2159 test_config resendmail.program sendmail &&
2161 --from="Example <nobody@example.com>" \
2162 --to=nobody@example.com \
2163 --smtp-server="$(pwd)/fake.sendmail" \
2167 test_expect_success $PREREQ 'test forbidSendmailVariables behavior override' '
2168 test_config sendmail.program sendmail &&
2169 test_config sendemail.forbidSendmailVariables false &&
2171 --from="Example <nobody@example.com>" \
2172 --to=nobody@example.com \
2173 --smtp-server="$(pwd)/fake.sendmail" \