3 test_description='git send-email'
6 # May be altered later in the test
9 replace_variable_fields () {
10 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
11 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
12 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/"
15 test_expect_success $PREREQ 'prepare reference tree' '
16 echo "1A quick brown fox jumps over the" >file &&
17 echo "lazy dog" >>file &&
19 GIT_AUTHOR_NAME="A" git commit -a -m "Initial."
22 test_expect_success $PREREQ 'Setup helper tool' '
23 write_script fake.sendmail <<-\EOF &&
26 while test -f commandline$output
33 done >commandline$output
36 git add fake.sendmail &&
37 GIT_AUTHOR_NAME="A" git commit -a -m "Second."
40 clean_fake_sendmail () {
41 rm -f commandline* msgtxt*
44 test_expect_success $PREREQ 'Extract patches' '
45 patches=$(git format-patch -s --cc="One <one@example.com>" --cc=two@example.com -n HEAD^1)
48 # Test no confirm early to ensure remaining tests will not hang
52 GIT_SEND_EMAIL_NOTTY=1 \
54 --from="Example <from@example.com>" \
55 --to=nobody@example.com \
56 --smtp-server="$(pwd)/fake.sendmail" \
59 ! grep "Send this email" stdout &&
63 # Exit immediately to prevent hang if a no-confirm test fails
65 if ! test -f no_confirm_okay
67 say 'confirm test failed; skipping remaining tests to prevent hanging'
68 PREREQ="$PREREQ,CHECK_NO_CONFIRM"
73 test_expect_success $PREREQ 'No confirm with --suppress-cc' '
74 test_no_confirm --suppress-cc=sob &&
79 test_expect_success $PREREQ 'No confirm with --confirm=never' '
80 test_no_confirm --confirm=never &&
84 # leave sendemail.confirm set to never after this so that none of the
85 # remaining tests prompt unintentionally.
86 test_expect_success $PREREQ 'No confirm with sendemail.confirm=never' '
87 git config sendemail.confirm never &&
88 test_no_confirm --compose --subject=foo &&
92 test_expect_success $PREREQ 'Send patches' '
93 git send-email --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
96 test_expect_success $PREREQ 'setup expect' '
105 test_expect_success $PREREQ 'Verify commandline' '
106 test_cmp expected commandline1
109 test_expect_success $PREREQ 'Send patches with --envelope-sender' '
110 clean_fake_sendmail &&
111 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
114 test_expect_success $PREREQ 'setup expect' '
115 cat >expected <<-\EOF
125 test_expect_success $PREREQ 'Verify commandline' '
126 test_cmp expected commandline1
129 test_expect_success $PREREQ 'Send patches with --envelope-sender=auto' '
130 clean_fake_sendmail &&
131 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
134 test_expect_success $PREREQ 'setup expect' '
135 cat >expected <<-\EOF
145 test_expect_success $PREREQ 'Verify commandline' '
146 test_cmp expected commandline1
149 test_expect_success $PREREQ 'setup expect for cc trailer' "
150 cat >expected-cc <<\EOF
151 !recipient@example.com!
162 test_expect_success $PREREQ 'cc trailer with various syntax' '
163 test_commit cc-trailer &&
164 test_when_finished "git reset --hard HEAD^" &&
165 git commit --amend -F - <<-EOF &&
169 Cc: <two@example.com> # trailing comments are ignored
170 Cc: <three@example.com>, <not.four@example.com> one address per line
171 Cc: "Some # Body" <four@example.com> [ <also.a.comment> ]
172 Cc: five@example.com # not.six@example.com
173 Cc: six@example.com, not.seven@example.com
175 clean_fake_sendmail &&
176 git send-email -1 --to=recipient@example.com \
177 --smtp-server="$(pwd)/fake.sendmail" &&
178 test_cmp expected-cc commandline1
181 test_expect_success $PREREQ 'setup fake get_maintainer.pl script for cc trailer' "
182 write_script expected-cc-script.sh <<-EOF
183 echo 'One Person <one@example.com> (supporter:THIS (FOO/bar))'
184 echo 'Two Person <two@example.com> (maintainer:THIS THING)'
185 echo 'Third List <three@example.com> (moderated list:THIS THING (FOO/bar))'
186 echo '<four@example.com> (moderated list:FOR THING)'
187 echo 'five@example.com (open list:FOR THING (FOO/bar))'
188 echo 'six@example.com (open list)'
192 test_expect_success $PREREQ 'cc trailer with get_maintainer.pl output' '
193 clean_fake_sendmail &&
194 git send-email -1 --to=recipient@example.com \
195 --cc-cmd=./expected-cc-script.sh \
196 --smtp-server="$(pwd)/fake.sendmail" &&
197 test_cmp expected-cc commandline1
200 test_expect_success $PREREQ 'setup expect' "
201 cat >expected-show-all-headers <<\EOF
203 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
204 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
205 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
207 Server: relay.example.com
208 MAIL FROM:<from@example.com>
209 RCPT TO:<to@example.com>
210 RCPT TO:<cc@example.com>
211 RCPT TO:<author@example.com>
212 RCPT TO:<one@example.com>
213 RCPT TO:<two@example.com>
214 RCPT TO:<bcc@example.com>
215 From: Example <from@example.com>
218 A <author@example.com>,
219 One <one@example.com>,
221 Subject: [PATCH 1/1] Second.
223 Message-Id: MESSAGE-ID-STRING
224 X-Mailer: X-MAILER-STRING
225 In-Reply-To: <unique-message-id@example.com>
226 References: <unique-message-id@example.com>
227 Reply-To: Reply <reply@example.com>
229 Content-Transfer-Encoding: 8bit
235 test_suppress_self () {
237 test_when_finished "git reset --hard HEAD^" &&
239 write_script cccmd-sed <<-EOF &&
240 sed -n -e s/^cccmd--//p "\$1"
243 git commit --amend --author="$1 <$2>" -F - &&
244 clean_fake_sendmail &&
245 git format-patch --stdout -1 >"suppress-self-$3.patch" &&
247 git send-email --from="$1 <$2>" \
248 --to=nobody@example.com \
249 --cc-cmd=./cccmd-sed \
251 --smtp-server="$(pwd)/fake.sendmail" \
252 suppress-self-$3.patch &&
254 mv msgtxt1 msgtxt1-$3 &&
255 sed -e '/^$/q' msgtxt1-$3 >"msghdr1-$3" &&
257 (grep '^Cc:' msghdr1-$3 >"actual-no-cc-$3";
258 test_must_be_empty actual-no-cc-$3)
261 test_suppress_self_unquoted () {
262 test_suppress_self "$1" "$2" "unquoted-$3" <<-EOF
263 test suppress-cc.self unquoted-$3 with name $1 email $2
270 Signed-off-by: $1 <$2>
274 test_suppress_self_quoted () {
275 test_suppress_self "$1" "$2" "quoted-$3" <<-EOF
276 test suppress-cc.self quoted-$3 with name $1 email $2
284 Signed-off-by: $1 <$2>
285 Signed-off-by: "$1" <$2>
289 test_expect_success $PREREQ 'self name is suppressed' "
290 test_suppress_self_unquoted 'A U Thor' 'author@example.com' \
291 'self_name_suppressed'
294 test_expect_success $PREREQ 'self name with dot is suppressed' "
295 test_suppress_self_quoted 'A U. Thor' 'author@example.com' \
296 'self_name_dot_suppressed'
299 test_expect_success $PREREQ 'non-ascii self name is suppressed' "
300 test_suppress_self_quoted 'Füñný Nâmé' 'odd_?=mail@example.com' \
301 'non_ascii_self_suppressed'
304 # This name is long enough to force format-patch to split it into multiple
305 # encoded-words, assuming it uses UTF-8 with the "Q" encoding.
306 test_expect_success $PREREQ 'long non-ascii self name is suppressed' "
307 test_suppress_self_quoted 'Ƒüñníęř €. Nâṁé' 'odd_?=mail@example.com' \
308 'long_non_ascii_self_suppressed'
311 test_expect_success $PREREQ 'sanitized self name is suppressed' "
312 test_suppress_self_unquoted '\"A U. Thor\"' 'author@example.com' \
313 'self_name_sanitized_suppressed'
316 test_expect_success $PREREQ 'Show all headers' '
320 --from="Example <from@example.com>" \
321 --reply-to="Reply <reply@example.com>" \
322 --to=to@example.com \
323 --cc=cc@example.com \
324 --bcc=bcc@example.com \
325 --in-reply-to="<unique-message-id@example.com>" \
326 --smtp-server relay.example.com \
327 $patches | replace_variable_fields \
328 >actual-show-all-headers &&
329 test_cmp expected-show-all-headers actual-show-all-headers
332 test_expect_success $PREREQ 'Prompting works' '
333 clean_fake_sendmail &&
334 (echo "to@example.com" &&
336 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
337 --smtp-server="$(pwd)/fake.sendmail" \
340 grep "^From: A U Thor <author@example.com>\$" msgtxt1 &&
341 grep "^To: to@example.com\$" msgtxt1
344 test_expect_success $PREREQ,AUTOIDENT 'implicit ident is allowed' '
345 clean_fake_sendmail &&
346 (sane_unset GIT_AUTHOR_NAME &&
347 sane_unset GIT_AUTHOR_EMAIL &&
348 sane_unset GIT_COMMITTER_NAME &&
349 sane_unset GIT_COMMITTER_EMAIL &&
350 GIT_SEND_EMAIL_NOTTY=1 git send-email \
351 --smtp-server="$(pwd)/fake.sendmail" \
352 --to=to@example.com \
353 $patches </dev/null 2>errors
357 test_expect_success $PREREQ,!AUTOIDENT 'broken implicit ident aborts send-email' '
358 clean_fake_sendmail &&
359 (sane_unset GIT_AUTHOR_NAME &&
360 sane_unset GIT_AUTHOR_EMAIL &&
361 sane_unset GIT_COMMITTER_NAME &&
362 sane_unset GIT_COMMITTER_EMAIL &&
363 GIT_SEND_EMAIL_NOTTY=1 && export GIT_SEND_EMAIL_NOTTY &&
364 test_must_fail git send-email \
365 --smtp-server="$(pwd)/fake.sendmail" \
366 --to=to@example.com \
367 $patches </dev/null 2>errors &&
368 test_i18ngrep "tell me who you are" errors
372 test_expect_success $PREREQ 'setup tocmd and cccmd scripts' '
373 write_script tocmd-sed <<-\EOF &&
374 sed -n -e "s/^tocmd--//p" "$1"
376 write_script cccmd-sed <<-\EOF
377 sed -n -e "s/^cccmd--//p" "$1"
381 test_expect_success $PREREQ 'tocmd works' '
382 clean_fake_sendmail &&
383 cp $patches tocmd.patch &&
384 echo tocmd--tocmd@example.com >>tocmd.patch &&
386 --from="Example <nobody@example.com>" \
387 --to-cmd=./tocmd-sed \
388 --smtp-server="$(pwd)/fake.sendmail" \
391 grep "^To: tocmd@example.com" msgtxt1
394 test_expect_success $PREREQ 'cccmd works' '
395 clean_fake_sendmail &&
396 cp $patches cccmd.patch &&
397 echo "cccmd-- cccmd@example.com" >>cccmd.patch &&
399 --from="Example <nobody@example.com>" \
400 --to=nobody@example.com \
401 --cc-cmd=./cccmd-sed \
402 --smtp-server="$(pwd)/fake.sendmail" \
405 grep "^ cccmd@example.com" msgtxt1
408 test_expect_success $PREREQ 'reject long lines' '
410 z64=$z8$z8$z8$z8$z8$z8$z8$z8 &&
411 z512=$z64$z64$z64$z64$z64$z64$z64$z64 &&
412 clean_fake_sendmail &&
413 cp $patches longline.patch &&
414 echo $z512$z512 >>longline.patch &&
415 test_must_fail git send-email \
416 --from="Example <nobody@example.com>" \
417 --to=nobody@example.com \
418 --smtp-server="$(pwd)/fake.sendmail" \
419 --transfer-encoding=8bit \
420 $patches longline.patch \
422 grep longline.patch errors
425 test_expect_success $PREREQ 'no patch was sent' '
426 ! test -e commandline1
429 test_expect_success $PREREQ 'Author From: in message body' '
430 clean_fake_sendmail &&
432 --from="Example <nobody@example.com>" \
433 --to=nobody@example.com \
434 --smtp-server="$(pwd)/fake.sendmail" \
436 sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
437 grep "From: A <author@example.com>" msgbody1
440 test_expect_success $PREREQ 'Author From: not in message body' '
441 clean_fake_sendmail &&
443 --from="A <author@example.com>" \
444 --to=nobody@example.com \
445 --smtp-server="$(pwd)/fake.sendmail" \
447 sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
448 ! grep "From: A <author@example.com>" msgbody1
451 test_expect_success $PREREQ 'allow long lines with --no-validate' '
453 --from="Example <nobody@example.com>" \
454 --to=nobody@example.com \
455 --smtp-server="$(pwd)/fake.sendmail" \
457 $patches longline.patch \
461 test_expect_success $PREREQ 'short lines with auto encoding are 8bit' '
462 clean_fake_sendmail &&
464 --from="A <author@example.com>" \
465 --to=nobody@example.com \
466 --smtp-server="$(pwd)/fake.sendmail" \
467 --transfer-encoding=auto \
469 grep "Content-Transfer-Encoding: 8bit" msgtxt1
472 test_expect_success $PREREQ 'long lines with auto encoding are quoted-printable' '
473 clean_fake_sendmail &&
475 --from="Example <nobody@example.com>" \
476 --to=nobody@example.com \
477 --smtp-server="$(pwd)/fake.sendmail" \
478 --transfer-encoding=auto \
481 grep "Content-Transfer-Encoding: quoted-printable" msgtxt1
484 for enc in auto quoted-printable base64
486 test_expect_success $PREREQ "--validate passes with encoding $enc" '
488 --from="Example <nobody@example.com>" \
489 --to=nobody@example.com \
490 --smtp-server="$(pwd)/fake.sendmail" \
491 --transfer-encoding=$enc \
493 $patches longline.patch
498 for enc in 7bit 8bit quoted-printable base64
500 test_expect_success $PREREQ "--transfer-encoding=$enc produces correct header" '
501 clean_fake_sendmail &&
503 --from="Example <nobody@example.com>" \
504 --to=nobody@example.com \
505 --smtp-server="$(pwd)/fake.sendmail" \
506 --transfer-encoding=$enc \
508 grep "Content-Transfer-Encoding: $enc" msgtxt1
512 test_expect_success $PREREQ 'Invalid In-Reply-To' '
513 clean_fake_sendmail &&
515 --from="Example <nobody@example.com>" \
516 --to=nobody@example.com \
518 --smtp-server="$(pwd)/fake.sendmail" \
521 ! grep "^In-Reply-To: < *>" msgtxt1
524 test_expect_success $PREREQ 'Valid In-Reply-To when prompting' '
525 clean_fake_sendmail &&
526 (echo "From Example <from@example.com>" &&
527 echo "To Example <to@example.com>" &&
529 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
530 --smtp-server="$(pwd)/fake.sendmail" \
532 ! grep "^In-Reply-To: < *>" msgtxt1
535 test_expect_success $PREREQ 'In-Reply-To without --chain-reply-to' '
536 clean_fake_sendmail &&
537 echo "<unique-message-id@example.com>" >expect &&
539 --from="Example <nobody@example.com>" \
540 --to=nobody@example.com \
541 --no-chain-reply-to \
542 --in-reply-to="$(cat expect)" \
543 --smtp-server="$(pwd)/fake.sendmail" \
544 $patches $patches $patches \
546 # The first message is a reply to --in-reply-to
547 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
548 test_cmp expect actual &&
549 # Second and subsequent messages are replies to the first one
550 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
551 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
552 test_cmp expect actual &&
553 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
554 test_cmp expect actual
557 test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' '
558 clean_fake_sendmail &&
559 echo "<unique-message-id@example.com>" >expect &&
561 --from="Example <nobody@example.com>" \
562 --to=nobody@example.com \
564 --in-reply-to="$(cat expect)" \
565 --smtp-server="$(pwd)/fake.sendmail" \
566 $patches $patches $patches \
568 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
569 test_cmp expect actual &&
570 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
571 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
572 test_cmp expect actual &&
573 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt2 >expect &&
574 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
575 test_cmp expect actual
578 test_expect_success $PREREQ 'setup fake editor' '
579 write_script fake-editor <<-\EOF
580 echo fake edit >>"$1"
584 test_set_editor "$(pwd)/fake-editor"
586 test_expect_success $PREREQ '--compose works' '
587 clean_fake_sendmail &&
589 --compose --subject foo \
590 --from="Example <nobody@example.com>" \
591 --to=nobody@example.com \
592 --smtp-server="$(pwd)/fake.sendmail" \
597 test_expect_success $PREREQ 'first message is compose text' '
598 grep "^fake edit" msgtxt1
601 test_expect_success $PREREQ 'second message is patch' '
602 grep "Subject:.*Second" msgtxt2
605 test_expect_success $PREREQ 'setup expect' "
606 cat >expected-suppress-sob <<\EOF
608 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
609 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
610 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
612 Server: relay.example.com
613 MAIL FROM:<from@example.com>
614 RCPT TO:<to@example.com>
615 RCPT TO:<cc@example.com>
616 RCPT TO:<author@example.com>
617 RCPT TO:<one@example.com>
618 RCPT TO:<two@example.com>
619 From: Example <from@example.com>
622 A <author@example.com>,
623 One <one@example.com>,
625 Subject: [PATCH 1/1] Second.
627 Message-Id: MESSAGE-ID-STRING
628 X-Mailer: X-MAILER-STRING
630 Content-Transfer-Encoding: 8bit
636 test_suppression () {
639 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
640 --from="Example <from@example.com>" \
641 --to=to@example.com \
642 --smtp-server relay.example.com \
643 $patches | replace_variable_fields \
644 >actual-suppress-$1${2+"-$2"} &&
645 test_cmp expected-suppress-$1${2+"-$2"} actual-suppress-$1${2+"-$2"}
648 test_expect_success $PREREQ 'sendemail.cc set' '
649 git config sendemail.cc cc@example.com &&
653 test_expect_success $PREREQ 'setup expect' "
654 cat >expected-suppress-sob <<\EOF
656 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
657 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
658 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
660 Server: relay.example.com
661 MAIL FROM:<from@example.com>
662 RCPT TO:<to@example.com>
663 RCPT TO:<author@example.com>
664 RCPT TO:<one@example.com>
665 RCPT TO:<two@example.com>
666 From: Example <from@example.com>
668 Cc: A <author@example.com>,
669 One <one@example.com>,
671 Subject: [PATCH 1/1] Second.
673 Message-Id: MESSAGE-ID-STRING
674 X-Mailer: X-MAILER-STRING
676 Content-Transfer-Encoding: 8bit
682 test_expect_success $PREREQ 'sendemail.cc unset' '
683 git config --unset sendemail.cc &&
687 test_expect_success $PREREQ 'setup expect' "
688 cat >expected-suppress-cccmd <<\EOF
690 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
691 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
692 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
693 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
695 Server: relay.example.com
696 MAIL FROM:<from@example.com>
697 RCPT TO:<to@example.com>
698 RCPT TO:<author@example.com>
699 RCPT TO:<one@example.com>
700 RCPT TO:<two@example.com>
701 RCPT TO:<committer@example.com>
702 From: Example <from@example.com>
704 Cc: A <author@example.com>,
705 One <one@example.com>,
707 C O Mitter <committer@example.com>
708 Subject: [PATCH 1/1] Second.
710 Message-Id: MESSAGE-ID-STRING
711 X-Mailer: X-MAILER-STRING
713 Content-Transfer-Encoding: 8bit
719 test_expect_success $PREREQ 'sendemail.cccmd' '
720 write_script cccmd <<-\EOF &&
721 echo cc-cmd@example.com
723 git config sendemail.cccmd ./cccmd &&
724 test_suppression cccmd
727 test_expect_success $PREREQ 'setup expect' '
728 cat >expected-suppress-all <<\EOF
731 Server: relay.example.com
732 MAIL FROM:<from@example.com>
733 RCPT TO:<to@example.com>
734 From: Example <from@example.com>
736 Subject: [PATCH 1/1] Second.
738 Message-Id: MESSAGE-ID-STRING
739 X-Mailer: X-MAILER-STRING
741 Content-Transfer-Encoding: 8bit
747 test_expect_success $PREREQ '--suppress-cc=all' '
751 test_expect_success $PREREQ 'setup expect' "
752 cat >expected-suppress-body <<\EOF
754 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
755 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
756 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
757 (cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
759 Server: relay.example.com
760 MAIL FROM:<from@example.com>
761 RCPT TO:<to@example.com>
762 RCPT TO:<author@example.com>
763 RCPT TO:<one@example.com>
764 RCPT TO:<two@example.com>
765 RCPT TO:<cc-cmd@example.com>
766 From: Example <from@example.com>
768 Cc: A <author@example.com>,
769 One <one@example.com>,
772 Subject: [PATCH 1/1] Second.
774 Message-Id: MESSAGE-ID-STRING
775 X-Mailer: X-MAILER-STRING
777 Content-Transfer-Encoding: 8bit
783 test_expect_success $PREREQ '--suppress-cc=body' '
784 test_suppression body
787 test_expect_success $PREREQ 'setup expect' "
788 cat >expected-suppress-body-cccmd <<\EOF
790 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
791 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
792 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
794 Server: relay.example.com
795 MAIL FROM:<from@example.com>
796 RCPT TO:<to@example.com>
797 RCPT TO:<author@example.com>
798 RCPT TO:<one@example.com>
799 RCPT TO:<two@example.com>
800 From: Example <from@example.com>
802 Cc: A <author@example.com>,
803 One <one@example.com>,
805 Subject: [PATCH 1/1] Second.
807 Message-Id: MESSAGE-ID-STRING
808 X-Mailer: X-MAILER-STRING
810 Content-Transfer-Encoding: 8bit
816 test_expect_success $PREREQ '--suppress-cc=body --suppress-cc=cccmd' '
817 test_suppression body cccmd
820 test_expect_success $PREREQ 'setup expect' "
821 cat >expected-suppress-sob <<\EOF
823 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
824 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
825 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
827 Server: relay.example.com
828 MAIL FROM:<from@example.com>
829 RCPT TO:<to@example.com>
830 RCPT TO:<author@example.com>
831 RCPT TO:<one@example.com>
832 RCPT TO:<two@example.com>
833 From: Example <from@example.com>
835 Cc: A <author@example.com>,
836 One <one@example.com>,
838 Subject: [PATCH 1/1] Second.
840 Message-Id: MESSAGE-ID-STRING
841 X-Mailer: X-MAILER-STRING
843 Content-Transfer-Encoding: 8bit
849 test_expect_success $PREREQ '--suppress-cc=sob' '
850 test_might_fail git config --unset sendemail.cccmd &&
854 test_expect_success $PREREQ 'setup expect' "
855 cat >expected-suppress-bodycc <<\EOF
857 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
858 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
859 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
860 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
862 Server: relay.example.com
863 MAIL FROM:<from@example.com>
864 RCPT TO:<to@example.com>
865 RCPT TO:<author@example.com>
866 RCPT TO:<one@example.com>
867 RCPT TO:<two@example.com>
868 RCPT TO:<committer@example.com>
869 From: Example <from@example.com>
871 Cc: A <author@example.com>,
872 One <one@example.com>,
874 C O Mitter <committer@example.com>
875 Subject: [PATCH 1/1] Second.
877 Message-Id: MESSAGE-ID-STRING
878 X-Mailer: X-MAILER-STRING
880 Content-Transfer-Encoding: 8bit
886 test_expect_success $PREREQ '--suppress-cc=bodycc' '
887 test_suppression bodycc
890 test_expect_success $PREREQ 'setup expect' "
891 cat >expected-suppress-cc <<\EOF
893 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
894 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
896 Server: relay.example.com
897 MAIL FROM:<from@example.com>
898 RCPT TO:<to@example.com>
899 RCPT TO:<author@example.com>
900 RCPT TO:<committer@example.com>
901 From: Example <from@example.com>
903 Cc: A <author@example.com>,
904 C O Mitter <committer@example.com>
905 Subject: [PATCH 1/1] Second.
907 Message-Id: MESSAGE-ID-STRING
908 X-Mailer: X-MAILER-STRING
910 Content-Transfer-Encoding: 8bit
916 test_expect_success $PREREQ '--suppress-cc=cc' '
922 GIT_SEND_EMAIL_NOTTY=1 \
924 --from="Example <nobody@example.com>" \
925 --to=nobody@example.com \
926 --smtp-server="$(pwd)/fake.sendmail" \
927 $@ $patches >stdout &&
928 grep "Send this email" stdout
931 test_expect_success $PREREQ '--confirm=always' '
932 test_confirm --confirm=always --suppress-cc=all
935 test_expect_success $PREREQ '--confirm=auto' '
936 test_confirm --confirm=auto
939 test_expect_success $PREREQ '--confirm=cc' '
940 test_confirm --confirm=cc
943 test_expect_success $PREREQ '--confirm=compose' '
944 test_confirm --confirm=compose --compose
947 test_expect_success $PREREQ 'confirm by default (due to cc)' '
948 test_when_finished git config sendemail.confirm never &&
949 git config --unset sendemail.confirm &&
953 test_expect_success $PREREQ 'confirm by default (due to --compose)' '
954 test_when_finished git config sendemail.confirm never &&
955 git config --unset sendemail.confirm &&
956 test_confirm --suppress-cc=all --compose
959 test_expect_success $PREREQ 'confirm detects EOF (inform assumes y)' '
960 test_when_finished git config sendemail.confirm never &&
961 git config --unset sendemail.confirm &&
963 git format-patch -2 -o outdir &&
964 GIT_SEND_EMAIL_NOTTY=1 \
966 --from="Example <nobody@example.com>" \
967 --to=nobody@example.com \
968 --smtp-server="$(pwd)/fake.sendmail" \
969 outdir/*.patch </dev/null
972 test_expect_success $PREREQ 'confirm detects EOF (auto causes failure)' '
973 test_when_finished git config sendemail.confirm never &&
974 git config sendemail.confirm auto &&
975 GIT_SEND_EMAIL_NOTTY=1 &&
976 export GIT_SEND_EMAIL_NOTTY &&
977 test_must_fail git send-email \
978 --from="Example <nobody@example.com>" \
979 --to=nobody@example.com \
980 --smtp-server="$(pwd)/fake.sendmail" \
984 test_expect_success $PREREQ 'confirm does not loop forever' '
985 test_when_finished git config sendemail.confirm never &&
986 git config sendemail.confirm auto &&
987 GIT_SEND_EMAIL_NOTTY=1 &&
988 export GIT_SEND_EMAIL_NOTTY &&
989 yes "bogus" | test_must_fail git send-email \
990 --from="Example <nobody@example.com>" \
991 --to=nobody@example.com \
992 --smtp-server="$(pwd)/fake.sendmail" \
996 test_expect_success $PREREQ 'utf8 Cc is rfc2047 encoded' '
997 clean_fake_sendmail &&
999 git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
1001 --from="Example <nobody@example.com>" \
1002 --to=nobody@example.com \
1003 --smtp-server="$(pwd)/fake.sendmail" \
1006 grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
1009 test_expect_success $PREREQ '--compose adds MIME for utf8 body' '
1010 clean_fake_sendmail &&
1011 write_script fake-editor-utf8 <<-\EOF &&
1012 echo "utf8 body: àéìöú" >>"$1"
1014 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1016 --compose --subject foo \
1017 --from="Example <nobody@example.com>" \
1018 --to=nobody@example.com \
1019 --smtp-server="$(pwd)/fake.sendmail" \
1021 grep "^utf8 body" msgtxt1 &&
1022 grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
1025 test_expect_success $PREREQ '--compose respects user mime type' '
1026 clean_fake_sendmail &&
1027 write_script fake-editor-utf8-mime <<-\EOF &&
1030 Content-Type: text/plain; charset=iso-8859-1
1031 Content-Transfer-Encoding: 8bit
1037 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
1039 --compose --subject foo \
1040 --from="Example <nobody@example.com>" \
1041 --to=nobody@example.com \
1042 --smtp-server="$(pwd)/fake.sendmail" \
1044 grep "^utf8 body" msgtxt1 &&
1045 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
1046 ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
1049 test_expect_success $PREREQ '--compose adds MIME for utf8 subject' '
1050 clean_fake_sendmail &&
1051 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
1053 --compose --subject utf8-sübjëct \
1054 --from="Example <nobody@example.com>" \
1055 --to=nobody@example.com \
1056 --smtp-server="$(pwd)/fake.sendmail" \
1058 grep "^fake edit" msgtxt1 &&
1059 grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
1062 test_expect_success $PREREQ 'utf8 author is correctly passed on' '
1063 clean_fake_sendmail &&
1064 test_commit weird_author &&
1065 test_when_finished "git reset --hard HEAD^" &&
1066 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
1067 git format-patch --stdout -1 >funny_name.patch &&
1068 git send-email --from="Example <nobody@example.com>" \
1069 --to=nobody@example.com \
1070 --smtp-server="$(pwd)/fake.sendmail" \
1072 grep "^From: Füñný Nâmé <odd_?=mail@example.com>" msgtxt1
1075 test_expect_success $PREREQ 'utf8 sender is not duplicated' '
1076 clean_fake_sendmail &&
1077 test_commit weird_sender &&
1078 test_when_finished "git reset --hard HEAD^" &&
1079 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
1080 git format-patch --stdout -1 >funny_name.patch &&
1081 git send-email --from="Füñný Nâmé <odd_?=mail@example.com>" \
1082 --to=nobody@example.com \
1083 --smtp-server="$(pwd)/fake.sendmail" \
1085 grep "^From: " msgtxt1 >msgfrom &&
1086 test_line_count = 1 msgfrom
1089 test_expect_success $PREREQ 'sendemail.composeencoding works' '
1090 clean_fake_sendmail &&
1091 git config sendemail.composeencoding iso-8859-1 &&
1092 write_script fake-editor-utf8 <<-\EOF &&
1093 echo "utf8 body: àéìöú" >>"$1"
1095 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1097 --compose --subject foo \
1098 --from="Example <nobody@example.com>" \
1099 --to=nobody@example.com \
1100 --smtp-server="$(pwd)/fake.sendmail" \
1102 grep "^utf8 body" msgtxt1 &&
1103 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1106 test_expect_success $PREREQ '--compose-encoding works' '
1107 clean_fake_sendmail &&
1108 write_script fake-editor-utf8 <<-\EOF &&
1109 echo "utf8 body: àéìöú" >>"$1"
1111 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1113 --compose-encoding iso-8859-1 \
1114 --compose --subject foo \
1115 --from="Example <nobody@example.com>" \
1116 --to=nobody@example.com \
1117 --smtp-server="$(pwd)/fake.sendmail" \
1119 grep "^utf8 body" msgtxt1 &&
1120 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1123 test_expect_success $PREREQ '--compose-encoding overrides sendemail.composeencoding' '
1124 clean_fake_sendmail &&
1125 git config sendemail.composeencoding iso-8859-1 &&
1126 write_script fake-editor-utf8 <<-\EOF &&
1127 echo "utf8 body: àéìöú" >>"$1"
1129 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1131 --compose-encoding iso-8859-2 \
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-2" msgtxt1
1141 test_expect_success $PREREQ '--compose-encoding adds correct MIME for subject' '
1142 clean_fake_sendmail &&
1143 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
1145 --compose-encoding iso-8859-2 \
1146 --compose --subject utf8-sübjëct \
1147 --from="Example <nobody@example.com>" \
1148 --to=nobody@example.com \
1149 --smtp-server="$(pwd)/fake.sendmail" \
1151 grep "^fake edit" msgtxt1 &&
1152 grep "^Subject: =?iso-8859-2?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
1155 test_expect_success $PREREQ 'detects ambiguous reference/file conflict' '
1156 echo master >master &&
1158 git commit -m"add master" &&
1159 test_must_fail git send-email --dry-run master 2>errors &&
1160 grep disambiguate errors
1163 test_expect_success $PREREQ 'feed two files' '
1165 git format-patch -2 -o outdir &&
1168 --from="Example <nobody@example.com>" \
1169 --to=nobody@example.com \
1170 outdir/000?-*.patch 2>errors >out &&
1171 grep "^Subject: " out >subjects &&
1172 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
1173 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"
1176 test_expect_success $PREREQ 'in-reply-to but no threading' '
1179 --from="Example <nobody@example.com>" \
1180 --to=nobody@example.com \
1181 --in-reply-to="<in-reply-id@example.com>" \
1184 grep "In-Reply-To: <in-reply-id@example.com>"
1187 test_expect_success $PREREQ 'no in-reply-to and no threading' '
1190 --from="Example <nobody@example.com>" \
1191 --to=nobody@example.com \
1193 $patches $patches >stdout &&
1194 ! grep "In-Reply-To: " stdout
1197 test_expect_success $PREREQ 'threading but no chain-reply-to' '
1200 --from="Example <nobody@example.com>" \
1201 --to=nobody@example.com \
1203 --no-chain-reply-to \
1204 $patches $patches >stdout &&
1205 grep "In-Reply-To: " stdout
1208 test_expect_success $PREREQ 'sendemail.to works' '
1209 git config --replace-all sendemail.to "Somebody <somebody@ex.com>" &&
1212 --from="Example <nobody@example.com>" \
1213 $patches $patches >stdout &&
1214 grep "To: Somebody <somebody@ex.com>" stdout
1217 test_expect_success $PREREQ '--no-to overrides sendemail.to' '
1220 --from="Example <nobody@example.com>" \
1222 --to=nobody@example.com \
1223 $patches $patches >stdout &&
1224 grep "To: nobody@example.com" stdout &&
1225 ! grep "To: Somebody <somebody@ex.com>" stdout
1228 test_expect_success $PREREQ 'sendemail.cc works' '
1229 git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" &&
1232 --from="Example <nobody@example.com>" \
1233 --to=nobody@example.com \
1234 $patches $patches >stdout &&
1235 grep "Cc: Somebody <somebody@ex.com>" stdout
1238 test_expect_success $PREREQ '--no-cc overrides sendemail.cc' '
1241 --from="Example <nobody@example.com>" \
1243 --cc=bodies@example.com \
1244 --to=nobody@example.com \
1245 $patches $patches >stdout &&
1246 grep "Cc: bodies@example.com" stdout &&
1247 ! grep "Cc: Somebody <somebody@ex.com>" stdout
1250 test_expect_success $PREREQ 'sendemail.bcc works' '
1251 git config --replace-all sendemail.bcc "Other <other@ex.com>" &&
1254 --from="Example <nobody@example.com>" \
1255 --to=nobody@example.com \
1256 --smtp-server relay.example.com \
1257 $patches $patches >stdout &&
1258 grep "RCPT TO:<other@ex.com>" stdout
1261 test_expect_success $PREREQ '--no-bcc overrides sendemail.bcc' '
1264 --from="Example <nobody@example.com>" \
1266 --bcc=bodies@example.com \
1267 --to=nobody@example.com \
1268 --smtp-server relay.example.com \
1269 $patches $patches >stdout &&
1270 grep "RCPT TO:<bodies@example.com>" stdout &&
1271 ! grep "RCPT TO:<other@ex.com>" stdout
1274 test_expect_success $PREREQ 'patches To headers are used by default' '
1275 patch=$(git format-patch -1 --to="bodies@example.com") &&
1276 test_when_finished "rm $patch" &&
1279 --from="Example <nobody@example.com>" \
1280 --smtp-server relay.example.com \
1282 grep "RCPT TO:<bodies@example.com>" stdout
1285 test_expect_success $PREREQ 'patches To headers are appended to' '
1286 patch=$(git format-patch -1 --to="bodies@example.com") &&
1287 test_when_finished "rm $patch" &&
1290 --from="Example <nobody@example.com>" \
1291 --to=nobody@example.com \
1292 --smtp-server relay.example.com \
1294 grep "RCPT TO:<bodies@example.com>" stdout &&
1295 grep "RCPT TO:<nobody@example.com>" stdout
1298 test_expect_success $PREREQ 'To headers from files reset each patch' '
1299 patch1=$(git format-patch -1 --to="bodies@example.com") &&
1300 patch2=$(git format-patch -1 --to="other@example.com" HEAD~) &&
1301 test_when_finished "rm $patch1 && rm $patch2" &&
1304 --from="Example <nobody@example.com>" \
1305 --to="nobody@example.com" \
1306 --smtp-server relay.example.com \
1307 $patch1 $patch2 >stdout &&
1308 test $(grep -c "RCPT TO:<bodies@example.com>" stdout) = 1 &&
1309 test $(grep -c "RCPT TO:<nobody@example.com>" stdout) = 2 &&
1310 test $(grep -c "RCPT TO:<other@example.com>" stdout) = 1
1313 test_expect_success $PREREQ 'setup expect' '
1314 cat >email-using-8bit <<\EOF
1315 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1316 Message-Id: <bogus-message-id@example.com>
1317 From: author@example.com
1318 Date: Sat, 12 Jun 2010 15:53:58 +0200
1319 Subject: subject goes here
1321 Dieser deutsche Text enthält einen Umlaut!
1325 test_expect_success $PREREQ 'setup expect' '
1326 echo "Subject: subject goes here" >expected
1329 test_expect_success $PREREQ 'ASCII subject is not RFC2047 quoted' '
1330 clean_fake_sendmail &&
1332 git send-email --from=author@example.com --to=nobody@example.com \
1333 --smtp-server="$(pwd)/fake.sendmail" \
1334 --8bit-encoding=UTF-8 \
1335 email-using-8bit >stdout &&
1336 grep "Subject" msgtxt1 >actual &&
1337 test_cmp expected actual
1340 test_expect_success $PREREQ 'setup expect' '
1341 cat >content-type-decl <<-\EOF
1343 Content-Type: text/plain; charset=UTF-8
1344 Content-Transfer-Encoding: 8bit
1348 test_expect_success $PREREQ 'asks about and fixes 8bit encodings' '
1349 clean_fake_sendmail &&
1351 git send-email --from=author@example.com --to=nobody@example.com \
1352 --smtp-server="$(pwd)/fake.sendmail" \
1353 email-using-8bit >stdout &&
1354 grep "do not declare a Content-Transfer-Encoding" stdout &&
1355 grep email-using-8bit stdout &&
1356 grep "Which 8bit encoding" stdout &&
1357 egrep "Content|MIME" msgtxt1 >actual &&
1358 test_cmp content-type-decl actual
1361 test_expect_success $PREREQ 'sendemail.8bitEncoding works' '
1362 clean_fake_sendmail &&
1363 git config sendemail.assume8bitEncoding UTF-8 &&
1365 git send-email --from=author@example.com --to=nobody@example.com \
1366 --smtp-server="$(pwd)/fake.sendmail" \
1367 email-using-8bit >stdout &&
1368 egrep "Content|MIME" msgtxt1 >actual &&
1369 test_cmp content-type-decl actual
1372 test_expect_success $PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
1373 clean_fake_sendmail &&
1374 git config sendemail.assume8bitEncoding "bogus too" &&
1376 git send-email --from=author@example.com --to=nobody@example.com \
1377 --smtp-server="$(pwd)/fake.sendmail" \
1378 --8bit-encoding=UTF-8 \
1379 email-using-8bit >stdout &&
1380 egrep "Content|MIME" msgtxt1 >actual &&
1381 test_cmp content-type-decl actual
1384 test_expect_success $PREREQ 'setup expect' '
1385 cat >email-using-8bit <<-\EOF
1386 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1387 Message-Id: <bogus-message-id@example.com>
1388 From: author@example.com
1389 Date: Sat, 12 Jun 2010 15:53:58 +0200
1390 Subject: Dieser Betreff enthält auch einen Umlaut!
1392 Nothing to see here.
1396 test_expect_success $PREREQ 'setup expect' '
1397 cat >expected <<-\EOF
1398 Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
1402 test_expect_success $PREREQ '--8bit-encoding also treats subject' '
1403 clean_fake_sendmail &&
1405 git send-email --from=author@example.com --to=nobody@example.com \
1406 --smtp-server="$(pwd)/fake.sendmail" \
1407 --8bit-encoding=UTF-8 \
1408 email-using-8bit >stdout &&
1409 grep "Subject" msgtxt1 >actual &&
1410 test_cmp expected actual
1413 test_expect_success $PREREQ 'setup expect' '
1414 cat >email-using-8bit <<-\EOF
1415 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1416 Message-Id: <bogus-message-id@example.com>
1417 From: A U Thor <author@example.com>
1418 Date: Sat, 12 Jun 2010 15:53:58 +0200
1419 Content-Type: text/plain; charset=UTF-8
1420 Subject: Nothing to see here.
1422 Dieser Betreff enthält auch einen Umlaut!
1426 test_expect_success $PREREQ 'sendemail.transferencoding=7bit fails on 8bit data' '
1427 clean_fake_sendmail &&
1428 git config sendemail.transferEncoding 7bit &&
1429 test_must_fail git send-email \
1430 --transfer-encoding=7bit \
1431 --smtp-server="$(pwd)/fake.sendmail" \
1434 grep "cannot send message as 7bit" errors &&
1435 test -z "$(ls msgtxt*)"
1438 test_expect_success $PREREQ '--transfer-encoding overrides sendemail.transferEncoding' '
1439 clean_fake_sendmail &&
1440 git config sendemail.transferEncoding 8bit &&
1441 test_must_fail git send-email \
1442 --transfer-encoding=7bit \
1443 --smtp-server="$(pwd)/fake.sendmail" \
1446 grep "cannot send message as 7bit" errors &&
1447 test -z "$(ls msgtxt*)"
1450 test_expect_success $PREREQ 'sendemail.transferencoding=8bit' '
1451 clean_fake_sendmail &&
1453 --transfer-encoding=8bit \
1454 --smtp-server="$(pwd)/fake.sendmail" \
1457 sed '1,/^$/d' msgtxt1 >actual &&
1458 sed '1,/^$/d' email-using-8bit >expected &&
1459 test_cmp expected actual
1462 test_expect_success $PREREQ 'setup expect' '
1463 cat >expected <<-\EOF
1464 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1468 test_expect_success $PREREQ '8-bit and sendemail.transferencoding=quoted-printable' '
1469 clean_fake_sendmail &&
1471 --transfer-encoding=quoted-printable \
1472 --smtp-server="$(pwd)/fake.sendmail" \
1475 sed '1,/^$/d' msgtxt1 >actual &&
1476 test_cmp expected actual
1479 test_expect_success $PREREQ 'setup expect' '
1480 cat >expected <<-\EOF
1481 RGllc2VyIEJldHJlZmYgZW50aMOkbHQgYXVjaCBlaW5lbiBVbWxhdXQhCg==
1485 test_expect_success $PREREQ '8-bit and sendemail.transferencoding=base64' '
1486 clean_fake_sendmail &&
1488 --transfer-encoding=base64 \
1489 --smtp-server="$(pwd)/fake.sendmail" \
1492 sed '1,/^$/d' msgtxt1 >actual &&
1493 test_cmp expected actual
1496 test_expect_success $PREREQ 'setup expect' '
1497 cat >email-using-qp <<-\EOF
1498 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1499 Message-Id: <bogus-message-id@example.com>
1500 From: A U Thor <author@example.com>
1501 Date: Sat, 12 Jun 2010 15:53:58 +0200
1503 Content-Transfer-Encoding: quoted-printable
1504 Content-Type: text/plain; charset=UTF-8
1505 Subject: Nothing to see here.
1507 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1511 test_expect_success $PREREQ 'convert from quoted-printable to base64' '
1512 clean_fake_sendmail &&
1514 --transfer-encoding=base64 \
1515 --smtp-server="$(pwd)/fake.sendmail" \
1518 sed '1,/^$/d' msgtxt1 >actual &&
1519 test_cmp expected actual
1522 test_expect_success $PREREQ 'setup expect' "
1523 tr -d '\\015' | tr '%' '\\015' >email-using-crlf <<EOF
1524 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1525 Message-Id: <bogus-message-id@example.com>
1526 From: A U Thor <author@example.com>
1527 Date: Sat, 12 Jun 2010 15:53:58 +0200
1528 Content-Type: text/plain; charset=UTF-8
1529 Subject: Nothing to see here.
1531 Look, I have a CRLF and an = sign!%
1535 test_expect_success $PREREQ 'setup expect' '
1536 cat >expected <<-\EOF
1537 Look, I have a CRLF and an =3D sign!=0D
1541 test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=quoted-printable' '
1542 clean_fake_sendmail &&
1544 --transfer-encoding=quoted-printable \
1545 --smtp-server="$(pwd)/fake.sendmail" \
1548 sed '1,/^$/d' msgtxt1 >actual &&
1549 test_cmp expected actual
1552 test_expect_success $PREREQ 'setup expect' '
1553 cat >expected <<-\EOF
1554 TG9vaywgSSBoYXZlIGEgQ1JMRiBhbmQgYW4gPSBzaWduIQ0K
1558 test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=base64' '
1559 clean_fake_sendmail &&
1561 --transfer-encoding=base64 \
1562 --smtp-server="$(pwd)/fake.sendmail" \
1565 sed '1,/^$/d' msgtxt1 >actual &&
1566 test_cmp expected actual
1570 # Note that the patches in this test are deliberately out of order; we
1571 # want to make sure it works even if the cover-letter is not in the
1573 test_expect_success $PREREQ 'refusing to send cover letter template' '
1574 clean_fake_sendmail &&
1576 git format-patch --cover-letter -2 -o outdir &&
1577 test_must_fail git send-email \
1578 --from="Example <nobody@example.com>" \
1579 --to=nobody@example.com \
1580 --smtp-server="$(pwd)/fake.sendmail" \
1581 outdir/0002-*.patch \
1582 outdir/0000-*.patch \
1583 outdir/0001-*.patch \
1585 grep "SUBJECT HERE" errors &&
1586 test -z "$(ls msgtxt*)"
1589 test_expect_success $PREREQ '--force sends cover letter template anyway' '
1590 clean_fake_sendmail &&
1592 git format-patch --cover-letter -2 -o outdir &&
1595 --from="Example <nobody@example.com>" \
1596 --to=nobody@example.com \
1597 --smtp-server="$(pwd)/fake.sendmail" \
1598 outdir/0002-*.patch \
1599 outdir/0000-*.patch \
1600 outdir/0001-*.patch \
1602 ! grep "SUBJECT HERE" errors &&
1603 test -n "$(ls msgtxt*)"
1606 test_cover_addresses () {
1609 clean_fake_sendmail &&
1611 git format-patch --cover-letter -2 -o outdir &&
1612 cover=$(echo outdir/0000-*.patch) &&
1613 mv $cover cover-to-edit.patch &&
1614 perl -pe "s/^From:/$header: extra\@address.com\nFrom:/" cover-to-edit.patch >"$cover" &&
1617 --from="Example <nobody@example.com>" \
1620 --smtp-server="$(pwd)/fake.sendmail" \
1621 outdir/0000-*.patch \
1622 outdir/0001-*.patch \
1623 outdir/0002-*.patch \
1625 grep "^$header: extra@address.com" msgtxt1 >to1 &&
1626 grep "^$header: extra@address.com" msgtxt2 >to2 &&
1627 grep "^$header: extra@address.com" msgtxt3 >to3 &&
1628 test_line_count = 1 to1 &&
1629 test_line_count = 1 to2 &&
1630 test_line_count = 1 to3
1633 test_expect_success $PREREQ 'to-cover adds To to all mail' '
1634 test_cover_addresses "To" --to-cover
1637 test_expect_success $PREREQ 'cc-cover adds Cc to all mail' '
1638 test_cover_addresses "Cc" --cc-cover
1641 test_expect_success $PREREQ 'tocover adds To to all mail' '
1642 test_config sendemail.tocover true &&
1643 test_cover_addresses "To"
1646 test_expect_success $PREREQ 'cccover adds Cc to all mail' '
1647 test_config sendemail.cccover true &&
1648 test_cover_addresses "Cc"
1651 test_expect_success $PREREQ 'escaped quotes in sendemail.aliasfiletype=mutt' '
1652 clean_fake_sendmail &&
1653 echo "alias sbd \\\"Dot U. Sir\\\" <somebody@example.org>" >.mutt &&
1654 git config --replace-all sendemail.aliasesfile "$(pwd)/.mutt" &&
1655 git config sendemail.aliasfiletype mutt &&
1657 --from="Example <nobody@example.com>" \
1659 --smtp-server="$(pwd)/fake.sendmail" \
1660 outdir/0001-*.patch \
1662 grep "^!somebody@example\.org!$" commandline1 &&
1663 grep -F "To: \"Dot U. Sir\" <somebody@example.org>" out
1666 test_expect_success $PREREQ 'sendemail.aliasfiletype=mailrc' '
1667 clean_fake_sendmail &&
1668 echo "alias sbd somebody@example.org" >.mailrc &&
1669 git config --replace-all sendemail.aliasesfile "$(pwd)/.mailrc" &&
1670 git config sendemail.aliasfiletype mailrc &&
1672 --from="Example <nobody@example.com>" \
1674 --smtp-server="$(pwd)/fake.sendmail" \
1675 outdir/0001-*.patch \
1677 grep "^!somebody@example\.org!$" commandline1
1680 test_expect_success $PREREQ 'sendemail.aliasfile=~/.mailrc' '
1681 clean_fake_sendmail &&
1682 echo "alias sbd someone@example.org" >"$HOME/.mailrc" &&
1683 git config --replace-all sendemail.aliasesfile "~/.mailrc" &&
1684 git config sendemail.aliasfiletype mailrc &&
1686 --from="Example <nobody@example.com>" \
1688 --smtp-server="$(pwd)/fake.sendmail" \
1689 outdir/0001-*.patch \
1691 grep "^!someone@example\.org!$" commandline1
1694 test_dump_aliases () {
1695 msg="$1" && shift &&
1696 filetype="$1" && shift &&
1697 printf '%s\n' "$@" >expect &&
1698 cat >.tmp-email-aliases &&
1700 test_expect_success $PREREQ "$msg" '
1701 clean_fake_sendmail && rm -fr outdir &&
1702 git config --replace-all sendemail.aliasesfile \
1703 "$(pwd)/.tmp-email-aliases" &&
1704 git config sendemail.aliasfiletype "$filetype" &&
1705 git send-email --dump-aliases 2>errors >actual &&
1706 test_cmp expect actual
1710 test_dump_aliases '--dump-aliases sendmail format' \
1717 alice: Alice W Land <awol@example.com>
1718 bob: Robert Bobbyton <bob@example.com>
1719 chloe: chloe@example.com
1721 bcgrp: bob, chloe, Other <o@example.com>
1724 test_dump_aliases '--dump-aliases mutt format' \
1730 alias alice Alice W Land <awol@example.com>
1731 alias donald Donald C Carlton <donc@example.com>
1732 alias bob Robert Bobbyton <bob@example.com>
1733 alias chloe chloe@example.com
1736 test_dump_aliases '--dump-aliases mailrc format' \
1742 alias alice Alice W Land <awol@example.com>
1743 alias eve Eve <eve@example.com>
1744 alias bob Robert Bobbyton <bob@example.com>
1745 alias chloe chloe@example.com
1748 test_dump_aliases '--dump-aliases pine format' \
1754 alice Alice W Land <awol@example.com>
1755 eve Eve <eve@example.com>
1756 bob Robert Bobbyton <bob@example.com>
1757 chloe chloe@example.com
1760 test_dump_aliases '--dump-aliases gnus format' \
1766 (define-mail-alias "alice" "awol@example.com")
1767 (define-mail-alias "eve" "eve@example.com")
1768 (define-mail-alias "bob" "bob@example.com")
1769 (define-mail-alias "chloe" "chloe@example.com")
1772 test_expect_success '--dump-aliases must be used alone' '
1773 test_must_fail git send-email --dump-aliases --to=janice@example.com -1 refs/heads/accounting
1776 test_sendmail_aliases () {
1777 msg="$1" && shift &&
1779 cat >.tmp-email-aliases &&
1781 test_expect_success $PREREQ "$msg" '
1782 clean_fake_sendmail && rm -fr outdir &&
1783 git format-patch -1 -o outdir &&
1784 git config --replace-all sendemail.aliasesfile \
1785 "$(pwd)/.tmp-email-aliases" &&
1786 git config sendemail.aliasfiletype sendmail &&
1788 --from="Example <nobody@example.com>" \
1789 --to=alice --to=bcgrp \
1790 --smtp-server="$(pwd)/fake.sendmail" \
1791 outdir/0001-*.patch \
1795 grep "^!$i!$" commandline1 || return 1
1800 test_sendmail_aliases 'sendemail.aliasfiletype=sendmail' \
1801 'awol@example\.com' \
1802 'bob@example\.com' \
1803 'chloe@example\.com' \
1804 'o@example\.com' <<-\EOF
1805 alice: Alice W Land <awol@example.com>
1806 bob: Robert Bobbyton <bob@example.com>
1808 # this is also a comment
1809 chloe: chloe@example.com
1811 bcgrp: bob, chloe, Other <o@example.com>
1814 test_sendmail_aliases 'sendmail aliases line folding' \
1818 darla1 darla2 darla3 \
1819 elton1 elton2 elton3 \
1836 bcgrp: bob, chuck, darla, elton, fred, greg
1839 test_sendmail_aliases 'sendmail aliases tolerate bogus line folding' \
1845 test_sendmail_aliases 'sendmail aliases empty' alice bcgrp <<-\EOF
1848 test_expect_success $PREREQ 'alias support in To header' '
1849 clean_fake_sendmail &&
1850 echo "alias sbd someone@example.org" >.mailrc &&
1851 test_config sendemail.aliasesfile ".mailrc" &&
1852 test_config sendemail.aliasfiletype mailrc &&
1853 git format-patch --stdout -1 --to=sbd >aliased.patch &&
1855 --from="Example <nobody@example.com>" \
1856 --smtp-server="$(pwd)/fake.sendmail" \
1859 grep "^!someone@example\.org!$" commandline1
1862 test_expect_success $PREREQ 'alias support in Cc header' '
1863 clean_fake_sendmail &&
1864 echo "alias sbd someone@example.org" >.mailrc &&
1865 test_config sendemail.aliasesfile ".mailrc" &&
1866 test_config sendemail.aliasfiletype mailrc &&
1867 git format-patch --stdout -1 --cc=sbd >aliased.patch &&
1869 --from="Example <nobody@example.com>" \
1870 --smtp-server="$(pwd)/fake.sendmail" \
1873 grep "^!someone@example\.org!$" commandline1
1876 test_expect_success $PREREQ 'tocmd works with aliases' '
1877 clean_fake_sendmail &&
1878 echo "alias sbd someone@example.org" >.mailrc &&
1879 test_config sendemail.aliasesfile ".mailrc" &&
1880 test_config sendemail.aliasfiletype mailrc &&
1881 git format-patch --stdout -1 >tocmd.patch &&
1882 echo tocmd--sbd >>tocmd.patch &&
1884 --from="Example <nobody@example.com>" \
1885 --to-cmd=./tocmd-sed \
1886 --smtp-server="$(pwd)/fake.sendmail" \
1889 grep "^!someone@example\.org!$" commandline1
1892 test_expect_success $PREREQ 'cccmd works with aliases' '
1893 clean_fake_sendmail &&
1894 echo "alias sbd someone@example.org" >.mailrc &&
1895 test_config sendemail.aliasesfile ".mailrc" &&
1896 test_config sendemail.aliasfiletype mailrc &&
1897 git format-patch --stdout -1 >cccmd.patch &&
1898 echo cccmd--sbd >>cccmd.patch &&
1900 --from="Example <nobody@example.com>" \
1901 --cc-cmd=./cccmd-sed \
1902 --smtp-server="$(pwd)/fake.sendmail" \
1905 grep "^!someone@example\.org!$" commandline1
1908 do_xmailer_test () {
1909 expected=$1 params=$2 &&
1910 git format-patch -1 &&
1912 --from="Example <nobody@example.com>" \
1913 --to=someone@example.com \
1914 --smtp-server="$(pwd)/fake.sendmail" \
1918 { grep '^X-Mailer:' out || :; } >mailer &&
1919 test_line_count = $expected mailer
1922 test_expect_success $PREREQ '--[no-]xmailer without any configuration' '
1923 do_xmailer_test 1 "--xmailer" &&
1924 do_xmailer_test 0 "--no-xmailer"
1927 test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=true' '
1928 test_config sendemail.xmailer true &&
1929 do_xmailer_test 1 "" &&
1930 do_xmailer_test 0 "--no-xmailer" &&
1931 do_xmailer_test 1 "--xmailer"
1934 test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=false' '
1935 test_config sendemail.xmailer false &&
1936 do_xmailer_test 0 "" &&
1937 do_xmailer_test 0 "--no-xmailer" &&
1938 do_xmailer_test 1 "--xmailer"
1941 test_expect_success $PREREQ 'setup expected-list' '
1944 --from="Example <from@example.com>" \
1945 --to="To 1 <to1@example.com>" \
1946 --to="to2@example.com" \
1947 --to="to3@example.com" \
1948 --cc="Cc 1 <cc1@example.com>" \
1949 --cc="Cc2 <cc2@example.com>" \
1950 --bcc="bcc1@example.com" \
1951 --bcc="bcc2@example.com" \
1952 0001-add-master.patch | replace_variable_fields \
1956 test_expect_success $PREREQ 'use email list in --cc --to and --bcc' '
1959 --from="Example <from@example.com>" \
1960 --to="To 1 <to1@example.com>, to2@example.com" \
1961 --to="to3@example.com" \
1962 --cc="Cc 1 <cc1@example.com>, Cc2 <cc2@example.com>" \
1963 --bcc="bcc1@example.com, bcc2@example.com" \
1964 0001-add-master.patch | replace_variable_fields \
1966 test_cmp expected-list actual-list
1969 test_expect_success $PREREQ 'aliases work with email list' '
1970 echo "alias to2 to2@example.com" >.mutt &&
1971 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt &&
1972 test_config sendemail.aliasesfile ".mutt" &&
1973 test_config sendemail.aliasfiletype mutt &&
1976 --from="Example <from@example.com>" \
1977 --to="To 1 <to1@example.com>, to2, to3@example.com" \
1978 --cc="cc1, Cc2 <cc2@example.com>" \
1979 --bcc="bcc1@example.com, bcc2@example.com" \
1980 0001-add-master.patch | replace_variable_fields \
1982 test_cmp expected-list actual-list
1985 test_expect_success $PREREQ 'leading and trailing whitespaces are removed' '
1986 echo "alias to2 to2@example.com" >.mutt &&
1987 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt &&
1988 test_config sendemail.aliasesfile ".mutt" &&
1989 test_config sendemail.aliasfiletype mutt &&
1990 TO1=$(echo "QTo 1 <to1@example.com>" | q_to_tab) &&
1991 TO2=$(echo "QZto2" | qz_to_tab_space) &&
1992 CC1=$(echo "cc1" | append_cr) &&
1993 BCC1=$(echo "Q bcc1@example.com Q" | q_to_nul) &&
1996 --from=" Example <from@example.com>" \
1999 --to=" to3@example.com " \
2001 --cc="Cc2 <cc2@example.com>" \
2003 --bcc="bcc2@example.com" \
2004 0001-add-master.patch | replace_variable_fields \
2006 test_cmp expected-list actual-list
2009 test_expect_success $PREREQ 'invoke hook' '
2010 mkdir -p .git/hooks &&
2012 write_script .git/hooks/sendemail-validate <<-\EOF &&
2013 # test that we have the correct environment variable, pwd, and
2023 test -f 0001-add-master.patch &&
2024 grep "add master" "$1"
2029 # Test that it works even if we are not at the root of the
2033 --from="Example <nobody@example.com>" \
2034 --to=nobody@example.com \
2035 --smtp-server="$(pwd)/../fake.sendmail" \
2036 ../0001-add-master.patch &&
2038 # Verify error message when a patch is rejected by the hook
2039 sed -e "s/add master/x/" ../0001-add-master.patch >../another.patch &&
2040 test_must_fail git send-email \
2041 --from="Example <nobody@example.com>" \
2042 --to=nobody@example.com \
2043 --smtp-server="$(pwd)/../fake.sendmail" \
2044 ../another.patch 2>err &&
2045 test_i18ngrep "rejected by sendemail-validate hook" err
2049 test_expect_success $PREREQ 'test that send-email works outside a repo' '
2050 nongit git send-email \
2051 --from="Example <nobody@example.com>" \
2052 --to=nobody@example.com \
2053 --smtp-server="$(pwd)/fake.sendmail" \
2054 "$(pwd)/0001-add-master.patch"