3 test_description
='git send-email'
6 # May be altered later in the test
9 test_expect_success
$PREREQ 'prepare reference tree' '
10 echo "1A quick brown fox jumps over the" >file &&
11 echo "lazy dog" >>file &&
13 GIT_AUTHOR_NAME="A" git commit -a -m "Initial."
16 test_expect_success
$PREREQ 'Setup helper tool' '
17 write_script fake.sendmail <<-\EOF &&
20 while test -f commandline$output
27 done >commandline$output
30 git add fake.sendmail &&
31 GIT_AUTHOR_NAME="A" git commit -a -m "Second."
34 clean_fake_sendmail
() {
35 rm -f commandline
* msgtxt
*
38 test_expect_success
$PREREQ 'Extract patches' '
39 patches=$(git format-patch -s --cc="One <one@example.com>" --cc=two@example.com -n HEAD^1)
42 # Test no confirm early to ensure remaining tests will not hang
46 GIT_SEND_EMAIL_NOTTY
=1 \
48 --from="Example <from@example.com>" \
49 --to=nobody@example.com \
50 --smtp-server="$(pwd)/fake.sendmail" \
53 ! grep "Send this email" stdout
&&
57 # Exit immediately to prevent hang if a no-confirm test fails
59 if ! test -f no_confirm_okay
61 say
'confirm test failed; skipping remaining tests to prevent hanging'
62 PREREQ
="$PREREQ,CHECK_NO_CONFIRM"
67 test_expect_success
$PREREQ 'No confirm with --suppress-cc' '
68 test_no_confirm --suppress-cc=sob &&
73 test_expect_success
$PREREQ 'No confirm with --confirm=never' '
74 test_no_confirm --confirm=never &&
78 # leave sendemail.confirm set to never after this so that none of the
79 # remaining tests prompt unintentionally.
80 test_expect_success
$PREREQ 'No confirm with sendemail.confirm=never' '
81 git config sendemail.confirm never &&
82 test_no_confirm --compose --subject=foo &&
86 test_expect_success
$PREREQ 'Send patches' '
87 git send-email --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
90 test_expect_success
$PREREQ 'setup expect' '
99 test_expect_success
$PREREQ 'Verify commandline' '
100 test_cmp expected commandline1
103 test_expect_success
$PREREQ 'Send patches with --envelope-sender' '
104 clean_fake_sendmail &&
105 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
108 test_expect_success
$PREREQ 'setup expect' '
109 cat >expected <<-\EOF
119 test_expect_success
$PREREQ 'Verify commandline' '
120 test_cmp expected commandline1
123 test_expect_success
$PREREQ 'Send patches with --envelope-sender=auto' '
124 clean_fake_sendmail &&
125 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
128 test_expect_success
$PREREQ 'setup expect' '
129 cat >expected <<-\EOF
139 test_expect_success
$PREREQ 'Verify commandline' '
140 test_cmp expected commandline1
143 test_expect_success
$PREREQ 'setup expect for cc trailer' "
144 cat >expected-cc <<\EOF
145 !recipient@example.com!
156 test_expect_success
$PREREQ 'cc trailer with various syntax' '
157 test_commit cc-trailer &&
158 test_when_finished "git reset --hard HEAD^" &&
159 git commit --amend -F - <<-EOF &&
163 Cc: <two@example.com> # trailing comments are ignored
164 Cc: <three@example.com>, <not.four@example.com> one address per line
165 Cc: "Some # Body" <four@example.com> [ <also.a.comment> ]
166 Cc: five@example.com # not.six@example.com
167 Cc: six@example.com, not.seven@example.com
169 clean_fake_sendmail &&
170 git send-email -1 --to=recipient@example.com \
171 --smtp-server="$(pwd)/fake.sendmail" &&
172 test_cmp expected-cc commandline1
175 test_expect_success
$PREREQ 'setup fake get_maintainer.pl script for cc trailer' "
176 write_script expected-cc-script.sh <<-EOF
177 echo 'One Person <one@example.com> (supporter:THIS (FOO/bar))'
178 echo 'Two Person <two@example.com> (maintainer:THIS THING)'
179 echo 'Third List <three@example.com> (moderated list:THIS THING (FOO/bar))'
180 echo '<four@example.com> (moderated list:FOR THING)'
181 echo 'five@example.com (open list:FOR THING (FOO/bar))'
182 echo 'six@example.com (open list)'
186 test_expect_success
$PREREQ 'cc trailer with get_maintainer.pl output' '
187 clean_fake_sendmail &&
188 git send-email -1 --to=recipient@example.com \
189 --cc-cmd=./expected-cc-script.sh \
190 --smtp-server="$(pwd)/fake.sendmail" &&
191 test_cmp expected-cc commandline1
194 test_expect_success
$PREREQ 'setup expect' "
195 cat >expected-show-all-headers <<\EOF
197 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
198 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
199 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
201 Server: relay.example.com
202 MAIL FROM:<from@example.com>
203 RCPT TO:<to@example.com>
204 RCPT TO:<cc@example.com>
205 RCPT TO:<author@example.com>
206 RCPT TO:<one@example.com>
207 RCPT TO:<two@example.com>
208 RCPT TO:<bcc@example.com>
209 From: Example <from@example.com>
212 A <author@example.com>,
213 One <one@example.com>,
215 Subject: [PATCH 1/1] Second.
217 Message-Id: MESSAGE-ID-STRING
218 X-Mailer: X-MAILER-STRING
219 In-Reply-To: <unique-message-id@example.com>
220 References: <unique-message-id@example.com>
226 test_suppress_self
() {
228 test_when_finished
"git reset --hard HEAD^" &&
230 write_script cccmd-sed
<<-EOF &&
231 sed -n -e s/^cccmd--//p "\$1"
234 git commit
--amend --author="$1 <$2>" -F - &&
235 clean_fake_sendmail
&&
236 git format-patch
--stdout -1 >"suppress-self-$3.patch" &&
238 git send-email
--from="$1 <$2>" \
239 --to=nobody@example.com \
240 --cc-cmd=.
/cccmd-sed \
242 --smtp-server="$(pwd)/fake.sendmail" \
243 suppress-self-
$3.
patch &&
245 mv msgtxt1 msgtxt1-
$3 &&
246 sed -e '/^$/q' msgtxt1-
$3 >"msghdr1-$3" &&
247 >"expected-no-cc-$3" &&
249 (grep '^Cc:' msghdr1-
$3 >"actual-no-cc-$3";
250 test_cmp expected-no-cc-
$3 actual-no-cc-
$3)
253 test_suppress_self_unquoted
() {
254 test_suppress_self
"$1" "$2" "unquoted-$3" <<-EOF
255 test suppress-cc.self unquoted-$3 with name $1 email $2
262 Signed-off-by: $1 <$2>
266 test_suppress_self_quoted
() {
267 test_suppress_self
"$1" "$2" "quoted-$3" <<-EOF
268 test suppress-cc.self quoted-$3 with name $1 email $2
276 Signed-off-by: $1 <$2>
277 Signed-off-by: "$1" <$2>
281 test_expect_success
$PREREQ 'self name is suppressed' "
282 test_suppress_self_unquoted 'A U Thor' 'author@example.com' \
283 'self_name_suppressed'
286 test_expect_success
$PREREQ 'self name with dot is suppressed' "
287 test_suppress_self_quoted 'A U. Thor' 'author@example.com' \
288 'self_name_dot_suppressed'
291 test_expect_success
$PREREQ 'non-ascii self name is suppressed' "
292 test_suppress_self_quoted 'Füñný Nâmé' 'odd_?=mail@example.com' \
293 'non_ascii_self_suppressed'
296 # This name is long enough to force format-patch to split it into multiple
297 # encoded-words, assuming it uses UTF-8 with the "Q" encoding.
298 test_expect_success
$PREREQ 'long non-ascii self name is suppressed' "
299 test_suppress_self_quoted 'Ƒüñníęř €. Nâṁé' 'odd_?=mail@example.com' \
300 'long_non_ascii_self_suppressed'
303 test_expect_success
$PREREQ 'sanitized self name is suppressed' "
304 test_suppress_self_unquoted '\"A U. Thor\"' 'author@example.com' \
305 'self_name_sanitized_suppressed'
308 test_expect_success
$PREREQ 'Show all headers' '
312 --from="Example <from@example.com>" \
313 --to=to@example.com \
314 --cc=cc@example.com \
315 --bcc=bcc@example.com \
316 --in-reply-to="<unique-message-id@example.com>" \
317 --smtp-server relay.example.com \
319 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
320 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
321 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
322 >actual-show-all-headers &&
323 test_cmp expected-show-all-headers actual-show-all-headers
326 test_expect_success
$PREREQ 'Prompting works' '
327 clean_fake_sendmail &&
328 (echo "to@example.com"
330 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
331 --smtp-server="$(pwd)/fake.sendmail" \
334 grep "^From: A U Thor <author@example.com>\$" msgtxt1 &&
335 grep "^To: to@example.com\$" msgtxt1
338 test_expect_success
$PREREQ,AUTOIDENT
'implicit ident is allowed' '
339 clean_fake_sendmail &&
340 (sane_unset GIT_AUTHOR_NAME &&
341 sane_unset GIT_AUTHOR_EMAIL &&
342 sane_unset GIT_COMMITTER_NAME &&
343 sane_unset GIT_COMMITTER_EMAIL &&
344 GIT_SEND_EMAIL_NOTTY=1 git send-email \
345 --smtp-server="$(pwd)/fake.sendmail" \
346 --to=to@example.com \
347 $patches </dev/null 2>errors
351 test_expect_success
$PREREQ,!AUTOIDENT
'broken implicit ident aborts send-email' '
352 clean_fake_sendmail &&
353 (sane_unset GIT_AUTHOR_NAME &&
354 sane_unset GIT_AUTHOR_EMAIL &&
355 sane_unset GIT_COMMITTER_NAME &&
356 sane_unset GIT_COMMITTER_EMAIL &&
357 GIT_SEND_EMAIL_NOTTY=1 && export GIT_SEND_EMAIL_NOTTY &&
358 test_must_fail git send-email \
359 --smtp-server="$(pwd)/fake.sendmail" \
360 --to=to@example.com \
361 $patches </dev/null 2>errors &&
362 test_i18ngrep "tell me who you are" errors
366 test_expect_success
$PREREQ 'setup tocmd and cccmd scripts' '
367 write_script tocmd-sed <<-\EOF &&
368 sed -n -e "s/^tocmd--//p" "$1"
370 write_script cccmd-sed <<-\EOF
371 sed -n -e "s/^cccmd--//p" "$1"
375 test_expect_success
$PREREQ 'tocmd works' '
376 clean_fake_sendmail &&
377 cp $patches tocmd.patch &&
378 echo tocmd--tocmd@example.com >>tocmd.patch &&
380 --from="Example <nobody@example.com>" \
381 --to-cmd=./tocmd-sed \
382 --smtp-server="$(pwd)/fake.sendmail" \
385 grep "^To: tocmd@example.com" msgtxt1
388 test_expect_success
$PREREQ 'cccmd works' '
389 clean_fake_sendmail &&
390 cp $patches cccmd.patch &&
391 echo "cccmd-- cccmd@example.com" >>cccmd.patch &&
393 --from="Example <nobody@example.com>" \
394 --to=nobody@example.com \
395 --cc-cmd=./cccmd-sed \
396 --smtp-server="$(pwd)/fake.sendmail" \
399 grep "^ cccmd@example.com" msgtxt1
402 test_expect_success
$PREREQ 'reject long lines' '
404 z64=$z8$z8$z8$z8$z8$z8$z8$z8 &&
405 z512=$z64$z64$z64$z64$z64$z64$z64$z64 &&
406 clean_fake_sendmail &&
407 cp $patches longline.patch &&
408 echo $z512$z512 >>longline.patch &&
409 test_must_fail git send-email \
410 --from="Example <nobody@example.com>" \
411 --to=nobody@example.com \
412 --smtp-server="$(pwd)/fake.sendmail" \
413 $patches longline.patch \
415 grep longline.patch errors
418 test_expect_success
$PREREQ 'no patch was sent' '
419 ! test -e commandline1
422 test_expect_success
$PREREQ 'Author From: in message body' '
423 clean_fake_sendmail &&
425 --from="Example <nobody@example.com>" \
426 --to=nobody@example.com \
427 --smtp-server="$(pwd)/fake.sendmail" \
429 sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
430 grep "From: A <author@example.com>" msgbody1
433 test_expect_success
$PREREQ 'Author From: not in message body' '
434 clean_fake_sendmail &&
436 --from="A <author@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 'allow long lines with --no-validate' '
446 --from="Example <nobody@example.com>" \
447 --to=nobody@example.com \
448 --smtp-server="$(pwd)/fake.sendmail" \
450 $patches longline.patch \
454 test_expect_success
$PREREQ 'Invalid In-Reply-To' '
455 clean_fake_sendmail &&
457 --from="Example <nobody@example.com>" \
458 --to=nobody@example.com \
460 --smtp-server="$(pwd)/fake.sendmail" \
463 ! grep "^In-Reply-To: < *>" msgtxt1
466 test_expect_success
$PREREQ 'Valid In-Reply-To when prompting' '
467 clean_fake_sendmail &&
468 (echo "From Example <from@example.com>"
469 echo "To Example <to@example.com>"
471 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
472 --smtp-server="$(pwd)/fake.sendmail" \
474 ! grep "^In-Reply-To: < *>" msgtxt1
477 test_expect_success
$PREREQ 'In-Reply-To without --chain-reply-to' '
478 clean_fake_sendmail &&
479 echo "<unique-message-id@example.com>" >expect &&
481 --from="Example <nobody@example.com>" \
482 --to=nobody@example.com \
483 --no-chain-reply-to \
484 --in-reply-to="$(cat expect)" \
485 --smtp-server="$(pwd)/fake.sendmail" \
486 $patches $patches $patches \
488 # The first message is a reply to --in-reply-to
489 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
490 test_cmp expect actual &&
491 # Second and subsequent messages are replies to the first one
492 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
493 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
494 test_cmp expect actual &&
495 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
496 test_cmp expect actual
499 test_expect_success
$PREREQ 'In-Reply-To with --chain-reply-to' '
500 clean_fake_sendmail &&
501 echo "<unique-message-id@example.com>" >expect &&
503 --from="Example <nobody@example.com>" \
504 --to=nobody@example.com \
506 --in-reply-to="$(cat expect)" \
507 --smtp-server="$(pwd)/fake.sendmail" \
508 $patches $patches $patches \
510 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
511 test_cmp expect actual &&
512 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
513 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
514 test_cmp expect actual &&
515 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt2 >expect &&
516 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
517 test_cmp expect actual
520 test_expect_success
$PREREQ 'setup fake editor' '
521 write_script fake-editor <<-\EOF
522 echo fake edit >>"$1"
526 test_set_editor
"$(pwd)/fake-editor"
528 test_expect_success
$PREREQ '--compose works' '
529 clean_fake_sendmail &&
531 --compose --subject foo \
532 --from="Example <nobody@example.com>" \
533 --to=nobody@example.com \
534 --smtp-server="$(pwd)/fake.sendmail" \
539 test_expect_success
$PREREQ 'first message is compose text' '
540 grep "^fake edit" msgtxt1
543 test_expect_success
$PREREQ 'second message is patch' '
544 grep "Subject:.*Second" msgtxt2
547 test_expect_success
$PREREQ 'setup expect' "
548 cat >expected-suppress-sob <<\EOF
550 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
551 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
552 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
554 Server: relay.example.com
555 MAIL FROM:<from@example.com>
556 RCPT TO:<to@example.com>
557 RCPT TO:<cc@example.com>
558 RCPT TO:<author@example.com>
559 RCPT TO:<one@example.com>
560 RCPT TO:<two@example.com>
561 From: Example <from@example.com>
564 A <author@example.com>,
565 One <one@example.com>,
567 Subject: [PATCH 1/1] Second.
569 Message-Id: MESSAGE-ID-STRING
570 X-Mailer: X-MAILER-STRING
576 replace_variable_fields
() {
577 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
578 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
579 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/"
582 test_suppression
() {
585 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
586 --from="Example <from@example.com>" \
587 --to=to@example.com \
588 --smtp-server relay.example.com \
589 $patches | replace_variable_fields \
590 >actual-suppress-
$1${2+"-$2"} &&
591 test_cmp expected-suppress-
$1${2+"-$2"} actual-suppress-
$1${2+"-$2"}
594 test_expect_success
$PREREQ 'sendemail.cc set' '
595 git config sendemail.cc cc@example.com &&
599 test_expect_success
$PREREQ 'setup expect' "
600 cat >expected-suppress-sob <<\EOF
602 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
603 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
604 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
606 Server: relay.example.com
607 MAIL FROM:<from@example.com>
608 RCPT TO:<to@example.com>
609 RCPT TO:<author@example.com>
610 RCPT TO:<one@example.com>
611 RCPT TO:<two@example.com>
612 From: Example <from@example.com>
614 Cc: A <author@example.com>,
615 One <one@example.com>,
617 Subject: [PATCH 1/1] Second.
619 Message-Id: MESSAGE-ID-STRING
620 X-Mailer: X-MAILER-STRING
626 test_expect_success
$PREREQ 'sendemail.cc unset' '
627 git config --unset sendemail.cc &&
631 test_expect_success
$PREREQ 'setup expect' "
632 cat >expected-suppress-cccmd <<\EOF
634 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
635 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
636 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
637 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
639 Server: relay.example.com
640 MAIL FROM:<from@example.com>
641 RCPT TO:<to@example.com>
642 RCPT TO:<author@example.com>
643 RCPT TO:<one@example.com>
644 RCPT TO:<two@example.com>
645 RCPT TO:<committer@example.com>
646 From: Example <from@example.com>
648 Cc: A <author@example.com>,
649 One <one@example.com>,
651 C O Mitter <committer@example.com>
652 Subject: [PATCH 1/1] Second.
654 Message-Id: MESSAGE-ID-STRING
655 X-Mailer: X-MAILER-STRING
661 test_expect_success
$PREREQ 'sendemail.cccmd' '
662 write_script cccmd <<-\EOF &&
663 echo cc-cmd@example.com
665 git config sendemail.cccmd ./cccmd &&
666 test_suppression cccmd
669 test_expect_success
$PREREQ 'setup expect' '
670 cat >expected-suppress-all <<\EOF
673 Server: relay.example.com
674 MAIL FROM:<from@example.com>
675 RCPT TO:<to@example.com>
676 From: Example <from@example.com>
678 Subject: [PATCH 1/1] Second.
680 Message-Id: MESSAGE-ID-STRING
681 X-Mailer: X-MAILER-STRING
687 test_expect_success
$PREREQ '--suppress-cc=all' '
691 test_expect_success
$PREREQ 'setup expect' "
692 cat >expected-suppress-body <<\EOF
694 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
695 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
696 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
697 (cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
699 Server: relay.example.com
700 MAIL FROM:<from@example.com>
701 RCPT TO:<to@example.com>
702 RCPT TO:<author@example.com>
703 RCPT TO:<one@example.com>
704 RCPT TO:<two@example.com>
705 RCPT TO:<cc-cmd@example.com>
706 From: Example <from@example.com>
708 Cc: A <author@example.com>,
709 One <one@example.com>,
712 Subject: [PATCH 1/1] Second.
714 Message-Id: MESSAGE-ID-STRING
715 X-Mailer: X-MAILER-STRING
721 test_expect_success
$PREREQ '--suppress-cc=body' '
722 test_suppression body
725 test_expect_success
$PREREQ 'setup expect' "
726 cat >expected-suppress-body-cccmd <<\EOF
728 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
729 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
730 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
732 Server: relay.example.com
733 MAIL FROM:<from@example.com>
734 RCPT TO:<to@example.com>
735 RCPT TO:<author@example.com>
736 RCPT TO:<one@example.com>
737 RCPT TO:<two@example.com>
738 From: Example <from@example.com>
740 Cc: A <author@example.com>,
741 One <one@example.com>,
743 Subject: [PATCH 1/1] Second.
745 Message-Id: MESSAGE-ID-STRING
746 X-Mailer: X-MAILER-STRING
752 test_expect_success
$PREREQ '--suppress-cc=body --suppress-cc=cccmd' '
753 test_suppression body cccmd
756 test_expect_success
$PREREQ 'setup expect' "
757 cat >expected-suppress-sob <<\EOF
759 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
760 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
761 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
763 Server: relay.example.com
764 MAIL FROM:<from@example.com>
765 RCPT TO:<to@example.com>
766 RCPT TO:<author@example.com>
767 RCPT TO:<one@example.com>
768 RCPT TO:<two@example.com>
769 From: Example <from@example.com>
771 Cc: A <author@example.com>,
772 One <one@example.com>,
774 Subject: [PATCH 1/1] Second.
776 Message-Id: MESSAGE-ID-STRING
777 X-Mailer: X-MAILER-STRING
783 test_expect_success
$PREREQ '--suppress-cc=sob' '
784 test_might_fail git config --unset sendemail.cccmd &&
788 test_expect_success
$PREREQ 'setup expect' "
789 cat >expected-suppress-bodycc <<\EOF
791 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
792 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
793 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
794 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
796 Server: relay.example.com
797 MAIL FROM:<from@example.com>
798 RCPT TO:<to@example.com>
799 RCPT TO:<author@example.com>
800 RCPT TO:<one@example.com>
801 RCPT TO:<two@example.com>
802 RCPT TO:<committer@example.com>
803 From: Example <from@example.com>
805 Cc: A <author@example.com>,
806 One <one@example.com>,
808 C O Mitter <committer@example.com>
809 Subject: [PATCH 1/1] Second.
811 Message-Id: MESSAGE-ID-STRING
812 X-Mailer: X-MAILER-STRING
818 test_expect_success
$PREREQ '--suppress-cc=bodycc' '
819 test_suppression bodycc
822 test_expect_success
$PREREQ 'setup expect' "
823 cat >expected-suppress-cc <<\EOF
825 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
826 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
828 Server: relay.example.com
829 MAIL FROM:<from@example.com>
830 RCPT TO:<to@example.com>
831 RCPT TO:<author@example.com>
832 RCPT TO:<committer@example.com>
833 From: Example <from@example.com>
835 Cc: A <author@example.com>,
836 C O Mitter <committer@example.com>
837 Subject: [PATCH 1/1] Second.
839 Message-Id: MESSAGE-ID-STRING
840 X-Mailer: X-MAILER-STRING
846 test_expect_success
$PREREQ '--suppress-cc=cc' '
852 GIT_SEND_EMAIL_NOTTY
=1 \
854 --from="Example <nobody@example.com>" \
855 --to=nobody@example.com \
856 --smtp-server="$(pwd)/fake.sendmail" \
857 $@
$patches >stdout
&&
858 grep "Send this email" stdout
861 test_expect_success
$PREREQ '--confirm=always' '
862 test_confirm --confirm=always --suppress-cc=all
865 test_expect_success
$PREREQ '--confirm=auto' '
866 test_confirm --confirm=auto
869 test_expect_success
$PREREQ '--confirm=cc' '
870 test_confirm --confirm=cc
873 test_expect_success
$PREREQ '--confirm=compose' '
874 test_confirm --confirm=compose --compose
877 test_expect_success
$PREREQ 'confirm by default (due to cc)' '
878 test_when_finished git config sendemail.confirm never &&
879 git config --unset sendemail.confirm &&
883 test_expect_success
$PREREQ 'confirm by default (due to --compose)' '
884 test_when_finished git config sendemail.confirm never &&
885 git config --unset sendemail.confirm &&
886 test_confirm --suppress-cc=all --compose
889 test_expect_success
$PREREQ 'confirm detects EOF (inform assumes y)' '
890 test_when_finished git config sendemail.confirm never &&
891 git config --unset sendemail.confirm &&
893 git format-patch -2 -o outdir &&
894 GIT_SEND_EMAIL_NOTTY=1 \
896 --from="Example <nobody@example.com>" \
897 --to=nobody@example.com \
898 --smtp-server="$(pwd)/fake.sendmail" \
899 outdir/*.patch </dev/null
902 test_expect_success
$PREREQ 'confirm detects EOF (auto causes failure)' '
903 test_when_finished git config sendemail.confirm never &&
904 git config sendemail.confirm auto &&
905 GIT_SEND_EMAIL_NOTTY=1 &&
906 export GIT_SEND_EMAIL_NOTTY &&
907 test_must_fail git send-email \
908 --from="Example <nobody@example.com>" \
909 --to=nobody@example.com \
910 --smtp-server="$(pwd)/fake.sendmail" \
914 test_expect_success
$PREREQ 'confirm does not loop forever' '
915 test_when_finished git config sendemail.confirm never &&
916 git config sendemail.confirm auto &&
917 GIT_SEND_EMAIL_NOTTY=1 &&
918 export GIT_SEND_EMAIL_NOTTY &&
919 yes "bogus" | test_must_fail git send-email \
920 --from="Example <nobody@example.com>" \
921 --to=nobody@example.com \
922 --smtp-server="$(pwd)/fake.sendmail" \
926 test_expect_success
$PREREQ 'utf8 Cc is rfc2047 encoded' '
927 clean_fake_sendmail &&
929 git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
931 --from="Example <nobody@example.com>" \
932 --to=nobody@example.com \
933 --smtp-server="$(pwd)/fake.sendmail" \
936 grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
939 test_expect_success
$PREREQ '--compose adds MIME for utf8 body' '
940 clean_fake_sendmail &&
941 write_script fake-editor-utf8 <<-\EOF &&
942 echo "utf8 body: àéìöú" >>"$1"
944 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
946 --compose --subject foo \
947 --from="Example <nobody@example.com>" \
948 --to=nobody@example.com \
949 --smtp-server="$(pwd)/fake.sendmail" \
951 grep "^utf8 body" msgtxt1 &&
952 grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
955 test_expect_success
$PREREQ '--compose respects user mime type' '
956 clean_fake_sendmail &&
957 write_script fake-editor-utf8-mime <<-\EOF &&
960 Content-Type: text/plain; charset=iso-8859-1
961 Content-Transfer-Encoding: 8bit
967 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
969 --compose --subject foo \
970 --from="Example <nobody@example.com>" \
971 --to=nobody@example.com \
972 --smtp-server="$(pwd)/fake.sendmail" \
974 grep "^utf8 body" msgtxt1 &&
975 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
976 ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
979 test_expect_success
$PREREQ '--compose adds MIME for utf8 subject' '
980 clean_fake_sendmail &&
981 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
983 --compose --subject utf8-sübjëct \
984 --from="Example <nobody@example.com>" \
985 --to=nobody@example.com \
986 --smtp-server="$(pwd)/fake.sendmail" \
988 grep "^fake edit" msgtxt1 &&
989 grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
992 test_expect_success
$PREREQ 'utf8 author is correctly passed on' '
993 clean_fake_sendmail &&
994 test_commit weird_author &&
995 test_when_finished "git reset --hard HEAD^" &&
996 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
997 git format-patch --stdout -1 >funny_name.patch &&
998 git send-email --from="Example <nobody@example.com>" \
999 --to=nobody@example.com \
1000 --smtp-server="$(pwd)/fake.sendmail" \
1002 grep "^From: Füñný Nâmé <odd_?=mail@example.com>" msgtxt1
1005 test_expect_success
$PREREQ 'utf8 sender is not duplicated' '
1006 clean_fake_sendmail &&
1007 test_commit weird_sender &&
1008 test_when_finished "git reset --hard HEAD^" &&
1009 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
1010 git format-patch --stdout -1 >funny_name.patch &&
1011 git send-email --from="Füñný Nâmé <odd_?=mail@example.com>" \
1012 --to=nobody@example.com \
1013 --smtp-server="$(pwd)/fake.sendmail" \
1015 grep "^From: " msgtxt1 >msgfrom &&
1016 test_line_count = 1 msgfrom
1019 test_expect_success
$PREREQ 'sendemail.composeencoding works' '
1020 clean_fake_sendmail &&
1021 git config sendemail.composeencoding iso-8859-1 &&
1022 write_script fake-editor-utf8 <<-\EOF &&
1023 echo "utf8 body: àéìöú" >>"$1"
1025 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1027 --compose --subject foo \
1028 --from="Example <nobody@example.com>" \
1029 --to=nobody@example.com \
1030 --smtp-server="$(pwd)/fake.sendmail" \
1032 grep "^utf8 body" msgtxt1 &&
1033 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1036 test_expect_success
$PREREQ '--compose-encoding works' '
1037 clean_fake_sendmail &&
1038 write_script fake-editor-utf8 <<-\EOF &&
1039 echo "utf8 body: àéìöú" >>"$1"
1041 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1043 --compose-encoding iso-8859-1 \
1044 --compose --subject foo \
1045 --from="Example <nobody@example.com>" \
1046 --to=nobody@example.com \
1047 --smtp-server="$(pwd)/fake.sendmail" \
1049 grep "^utf8 body" msgtxt1 &&
1050 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1053 test_expect_success
$PREREQ '--compose-encoding overrides sendemail.composeencoding' '
1054 clean_fake_sendmail &&
1055 git config sendemail.composeencoding iso-8859-1 &&
1056 write_script fake-editor-utf8 <<-\EOF &&
1057 echo "utf8 body: àéìöú" >>"$1"
1059 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1061 --compose-encoding iso-8859-2 \
1062 --compose --subject foo \
1063 --from="Example <nobody@example.com>" \
1064 --to=nobody@example.com \
1065 --smtp-server="$(pwd)/fake.sendmail" \
1067 grep "^utf8 body" msgtxt1 &&
1068 grep "^Content-Type: text/plain; charset=iso-8859-2" msgtxt1
1071 test_expect_success
$PREREQ '--compose-encoding adds correct MIME for subject' '
1072 clean_fake_sendmail &&
1073 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
1075 --compose-encoding iso-8859-2 \
1076 --compose --subject utf8-sübjëct \
1077 --from="Example <nobody@example.com>" \
1078 --to=nobody@example.com \
1079 --smtp-server="$(pwd)/fake.sendmail" \
1081 grep "^fake edit" msgtxt1 &&
1082 grep "^Subject: =?iso-8859-2?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
1085 test_expect_success
$PREREQ 'detects ambiguous reference/file conflict' '
1086 echo master >master &&
1088 git commit -m"add master" &&
1089 test_must_fail git send-email --dry-run master 2>errors &&
1090 grep disambiguate errors
1093 test_expect_success
$PREREQ 'feed two files' '
1095 git format-patch -2 -o outdir &&
1098 --from="Example <nobody@example.com>" \
1099 --to=nobody@example.com \
1100 outdir/000?-*.patch 2>errors >out &&
1101 grep "^Subject: " out >subjects &&
1102 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
1103 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"
1106 test_expect_success
$PREREQ 'in-reply-to but no threading' '
1109 --from="Example <nobody@example.com>" \
1110 --to=nobody@example.com \
1111 --in-reply-to="<in-reply-id@example.com>" \
1114 grep "In-Reply-To: <in-reply-id@example.com>"
1117 test_expect_success
$PREREQ 'no in-reply-to and no threading' '
1120 --from="Example <nobody@example.com>" \
1121 --to=nobody@example.com \
1123 $patches $patches >stdout &&
1124 ! grep "In-Reply-To: " stdout
1127 test_expect_success
$PREREQ 'threading but no chain-reply-to' '
1130 --from="Example <nobody@example.com>" \
1131 --to=nobody@example.com \
1133 --no-chain-reply-to \
1134 $patches $patches >stdout &&
1135 grep "In-Reply-To: " stdout
1138 test_expect_success
$PREREQ 'sendemail.to works' '
1139 git config --replace-all sendemail.to "Somebody <somebody@ex.com>" &&
1142 --from="Example <nobody@example.com>" \
1143 $patches $patches >stdout &&
1144 grep "To: Somebody <somebody@ex.com>" stdout
1147 test_expect_success
$PREREQ '--no-to overrides sendemail.to' '
1150 --from="Example <nobody@example.com>" \
1152 --to=nobody@example.com \
1153 $patches $patches >stdout &&
1154 grep "To: nobody@example.com" stdout &&
1155 ! grep "To: Somebody <somebody@ex.com>" stdout
1158 test_expect_success
$PREREQ 'sendemail.cc works' '
1159 git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" &&
1162 --from="Example <nobody@example.com>" \
1163 --to=nobody@example.com \
1164 $patches $patches >stdout &&
1165 grep "Cc: Somebody <somebody@ex.com>" stdout
1168 test_expect_success
$PREREQ '--no-cc overrides sendemail.cc' '
1171 --from="Example <nobody@example.com>" \
1173 --cc=bodies@example.com \
1174 --to=nobody@example.com \
1175 $patches $patches >stdout &&
1176 grep "Cc: bodies@example.com" stdout &&
1177 ! grep "Cc: Somebody <somebody@ex.com>" stdout
1180 test_expect_success
$PREREQ 'sendemail.bcc works' '
1181 git config --replace-all sendemail.bcc "Other <other@ex.com>" &&
1184 --from="Example <nobody@example.com>" \
1185 --to=nobody@example.com \
1186 --smtp-server relay.example.com \
1187 $patches $patches >stdout &&
1188 grep "RCPT TO:<other@ex.com>" stdout
1191 test_expect_success
$PREREQ '--no-bcc overrides sendemail.bcc' '
1194 --from="Example <nobody@example.com>" \
1196 --bcc=bodies@example.com \
1197 --to=nobody@example.com \
1198 --smtp-server relay.example.com \
1199 $patches $patches >stdout &&
1200 grep "RCPT TO:<bodies@example.com>" stdout &&
1201 ! grep "RCPT TO:<other@ex.com>" stdout
1204 test_expect_success
$PREREQ 'patches To headers are used by default' '
1205 patch=$(git format-patch -1 --to="bodies@example.com") &&
1206 test_when_finished "rm $patch" &&
1209 --from="Example <nobody@example.com>" \
1210 --smtp-server relay.example.com \
1212 grep "RCPT TO:<bodies@example.com>" stdout
1215 test_expect_success
$PREREQ 'patches To headers are appended to' '
1216 patch=$(git format-patch -1 --to="bodies@example.com") &&
1217 test_when_finished "rm $patch" &&
1220 --from="Example <nobody@example.com>" \
1221 --to=nobody@example.com \
1222 --smtp-server relay.example.com \
1224 grep "RCPT TO:<bodies@example.com>" stdout &&
1225 grep "RCPT TO:<nobody@example.com>" stdout
1228 test_expect_success
$PREREQ 'To headers from files reset each patch' '
1229 patch1=$(git format-patch -1 --to="bodies@example.com") &&
1230 patch2=$(git format-patch -1 --to="other@example.com" HEAD~) &&
1231 test_when_finished "rm $patch1 && rm $patch2" &&
1234 --from="Example <nobody@example.com>" \
1235 --to="nobody@example.com" \
1236 --smtp-server relay.example.com \
1237 $patch1 $patch2 >stdout &&
1238 test $(grep -c "RCPT TO:<bodies@example.com>" stdout) = 1 &&
1239 test $(grep -c "RCPT TO:<nobody@example.com>" stdout) = 2 &&
1240 test $(grep -c "RCPT TO:<other@example.com>" stdout) = 1
1243 test_expect_success
$PREREQ 'setup expect' '
1244 cat >email-using-8bit <<\EOF
1245 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1246 Message-Id: <bogus-message-id@example.com>
1247 From: author@example.com
1248 Date: Sat, 12 Jun 2010 15:53:58 +0200
1249 Subject: subject goes here
1251 Dieser deutsche Text enthält einen Umlaut!
1255 test_expect_success
$PREREQ 'setup expect' '
1256 echo "Subject: subject goes here" >expected
1259 test_expect_success
$PREREQ 'ASCII subject is not RFC2047 quoted' '
1260 clean_fake_sendmail &&
1262 git send-email --from=author@example.com --to=nobody@example.com \
1263 --smtp-server="$(pwd)/fake.sendmail" \
1264 --8bit-encoding=UTF-8 \
1265 email-using-8bit >stdout &&
1266 grep "Subject" msgtxt1 >actual &&
1267 test_cmp expected actual
1270 test_expect_success
$PREREQ 'setup expect' '
1271 cat >content-type-decl <<-\EOF
1273 Content-Type: text/plain; charset=UTF-8
1274 Content-Transfer-Encoding: 8bit
1278 test_expect_success
$PREREQ 'asks about and fixes 8bit encodings' '
1279 clean_fake_sendmail &&
1281 git send-email --from=author@example.com --to=nobody@example.com \
1282 --smtp-server="$(pwd)/fake.sendmail" \
1283 email-using-8bit >stdout &&
1284 grep "do not declare a Content-Transfer-Encoding" stdout &&
1285 grep email-using-8bit stdout &&
1286 grep "Which 8bit encoding" stdout &&
1287 egrep "Content|MIME" msgtxt1 >actual &&
1288 test_cmp content-type-decl actual
1291 test_expect_success
$PREREQ 'sendemail.8bitEncoding works' '
1292 clean_fake_sendmail &&
1293 git config sendemail.assume8bitEncoding UTF-8 &&
1295 git send-email --from=author@example.com --to=nobody@example.com \
1296 --smtp-server="$(pwd)/fake.sendmail" \
1297 email-using-8bit >stdout &&
1298 egrep "Content|MIME" msgtxt1 >actual &&
1299 test_cmp content-type-decl actual
1302 test_expect_success
$PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
1303 clean_fake_sendmail &&
1304 git config sendemail.assume8bitEncoding "bogus too" &&
1306 git send-email --from=author@example.com --to=nobody@example.com \
1307 --smtp-server="$(pwd)/fake.sendmail" \
1308 --8bit-encoding=UTF-8 \
1309 email-using-8bit >stdout &&
1310 egrep "Content|MIME" msgtxt1 >actual &&
1311 test_cmp content-type-decl actual
1314 test_expect_success
$PREREQ 'setup expect' '
1315 cat >email-using-8bit <<-\EOF
1316 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1317 Message-Id: <bogus-message-id@example.com>
1318 From: author@example.com
1319 Date: Sat, 12 Jun 2010 15:53:58 +0200
1320 Subject: Dieser Betreff enthält auch einen Umlaut!
1322 Nothing to see here.
1326 test_expect_success
$PREREQ 'setup expect' '
1327 cat >expected <<-\EOF
1328 Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
1332 test_expect_success
$PREREQ '--8bit-encoding also treats subject' '
1333 clean_fake_sendmail &&
1335 git send-email --from=author@example.com --to=nobody@example.com \
1336 --smtp-server="$(pwd)/fake.sendmail" \
1337 --8bit-encoding=UTF-8 \
1338 email-using-8bit >stdout &&
1339 grep "Subject" msgtxt1 >actual &&
1340 test_cmp expected actual
1343 test_expect_success
$PREREQ 'setup expect' '
1344 cat >email-using-8bit <<-\EOF
1345 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1346 Message-Id: <bogus-message-id@example.com>
1347 From: A U Thor <author@example.com>
1348 Date: Sat, 12 Jun 2010 15:53:58 +0200
1349 Content-Type: text/plain; charset=UTF-8
1350 Subject: Nothing to see here.
1352 Dieser Betreff enthält auch einen Umlaut!
1356 test_expect_success
$PREREQ 'sendemail.transferencoding=7bit fails on 8bit data' '
1357 clean_fake_sendmail &&
1358 git config sendemail.transferEncoding 7bit &&
1359 test_must_fail git send-email \
1360 --transfer-encoding=7bit \
1361 --smtp-server="$(pwd)/fake.sendmail" \
1364 grep "cannot send message as 7bit" errors &&
1365 test -z "$(ls msgtxt*)"
1368 test_expect_success
$PREREQ '--transfer-encoding overrides sendemail.transferEncoding' '
1369 clean_fake_sendmail &&
1370 git config sendemail.transferEncoding 8bit &&
1371 test_must_fail git send-email \
1372 --transfer-encoding=7bit \
1373 --smtp-server="$(pwd)/fake.sendmail" \
1376 grep "cannot send message as 7bit" errors &&
1377 test -z "$(ls msgtxt*)"
1380 test_expect_success
$PREREQ 'sendemail.transferencoding=8bit' '
1381 clean_fake_sendmail &&
1383 --transfer-encoding=8bit \
1384 --smtp-server="$(pwd)/fake.sendmail" \
1387 sed '1,/^$
/d
' msgtxt1 >actual &&
1388 sed '1,/^$
/d
' email-using-8bit >expected &&
1389 test_cmp expected actual
1392 test_expect_success
$PREREQ 'setup expect' '
1393 cat >expected <<-\EOF
1394 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1398 test_expect_success
$PREREQ '8-bit and sendemail.transferencoding=quoted-printable' '
1399 clean_fake_sendmail &&
1401 --transfer-encoding=quoted-printable \
1402 --smtp-server="$(pwd)/fake.sendmail" \
1405 sed '1,/^$
/d
' msgtxt1 >actual &&
1406 test_cmp expected actual
1409 test_expect_success
$PREREQ 'setup expect' '
1410 cat >expected <<-\EOF
1411 RGllc2VyIEJldHJlZmYgZW50aMOkbHQgYXVjaCBlaW5lbiBVbWxhdXQhCg==
1415 test_expect_success
$PREREQ '8-bit and sendemail.transferencoding=base64' '
1416 clean_fake_sendmail &&
1418 --transfer-encoding=base64 \
1419 --smtp-server="$(pwd)/fake.sendmail" \
1422 sed '1,/^$
/d
' msgtxt1 >actual &&
1423 test_cmp expected actual
1426 test_expect_success
$PREREQ 'setup expect' '
1427 cat >email-using-qp <<-\EOF
1428 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1429 Message-Id: <bogus-message-id@example.com>
1430 From: A U Thor <author@example.com>
1431 Date: Sat, 12 Jun 2010 15:53:58 +0200
1433 Content-Transfer-Encoding: quoted-printable
1434 Content-Type: text/plain; charset=UTF-8
1435 Subject: Nothing to see here.
1437 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1441 test_expect_success
$PREREQ 'convert from quoted-printable to base64' '
1442 clean_fake_sendmail &&
1444 --transfer-encoding=base64 \
1445 --smtp-server="$(pwd)/fake.sendmail" \
1448 sed '1,/^$
/d
' msgtxt1 >actual &&
1449 test_cmp expected actual
1452 test_expect_success
$PREREQ 'setup expect' "
1453 tr -d '\\015' | tr '%' '\\015' >email-using-crlf <<EOF
1454 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1455 Message-Id: <bogus-message-id@example.com>
1456 From: A U Thor <author@example.com>
1457 Date: Sat, 12 Jun 2010 15:53:58 +0200
1458 Content-Type: text/plain; charset=UTF-8
1459 Subject: Nothing to see here.
1461 Look, I have a CRLF and an = sign!%
1465 test_expect_success
$PREREQ 'setup expect' '
1466 cat >expected <<-\EOF
1467 Look, I have a CRLF and an =3D sign!=0D
1471 test_expect_success
$PREREQ 'CRLF and sendemail.transferencoding=quoted-printable' '
1472 clean_fake_sendmail &&
1474 --transfer-encoding=quoted-printable \
1475 --smtp-server="$(pwd)/fake.sendmail" \
1478 sed '1,/^$
/d
' msgtxt1 >actual &&
1479 test_cmp expected actual
1482 test_expect_success
$PREREQ 'setup expect' '
1483 cat >expected <<-\EOF
1484 TG9vaywgSSBoYXZlIGEgQ1JMRiBhbmQgYW4gPSBzaWduIQ0K
1488 test_expect_success
$PREREQ 'CRLF and sendemail.transferencoding=base64' '
1489 clean_fake_sendmail &&
1491 --transfer-encoding=base64 \
1492 --smtp-server="$(pwd)/fake.sendmail" \
1495 sed '1,/^$
/d
' msgtxt1 >actual &&
1496 test_cmp expected actual
1500 # Note that the patches in this test are deliberately out of order; we
1501 # want to make sure it works even if the cover-letter is not in the
1503 test_expect_success
$PREREQ 'refusing to send cover letter template' '
1504 clean_fake_sendmail &&
1506 git format-patch --cover-letter -2 -o outdir &&
1507 test_must_fail git send-email \
1508 --from="Example <nobody@example.com>" \
1509 --to=nobody@example.com \
1510 --smtp-server="$(pwd)/fake.sendmail" \
1511 outdir/0002-*.patch \
1512 outdir/0000-*.patch \
1513 outdir/0001-*.patch \
1515 grep "SUBJECT HERE" errors &&
1516 test -z "$(ls msgtxt*)"
1519 test_expect_success
$PREREQ '--force sends cover letter template anyway' '
1520 clean_fake_sendmail &&
1522 git format-patch --cover-letter -2 -o outdir &&
1525 --from="Example <nobody@example.com>" \
1526 --to=nobody@example.com \
1527 --smtp-server="$(pwd)/fake.sendmail" \
1528 outdir/0002-*.patch \
1529 outdir/0000-*.patch \
1530 outdir/0001-*.patch \
1532 ! grep "SUBJECT HERE" errors &&
1533 test -n "$(ls msgtxt*)"
1536 test_cover_addresses
() {
1539 clean_fake_sendmail
&&
1541 git format-patch
--cover-letter -2 -o outdir
&&
1542 cover
=$
(echo outdir
/0000-*.
patch) &&
1543 mv $cover cover-to-edit.
patch &&
1544 perl
-pe "s/^From:/$header: extra\@address.com\nFrom:/" cover-to-edit.
patch >"$cover" &&
1547 --from="Example <nobody@example.com>" \
1550 --smtp-server="$(pwd)/fake.sendmail" \
1551 outdir
/0000-*.
patch \
1552 outdir
/0001-*.
patch \
1553 outdir
/0002-*.
patch \
1555 grep "^$header: extra@address.com" msgtxt1
>to1
&&
1556 grep "^$header: extra@address.com" msgtxt2
>to2
&&
1557 grep "^$header: extra@address.com" msgtxt3
>to3
&&
1558 test_line_count
= 1 to1
&&
1559 test_line_count
= 1 to2
&&
1560 test_line_count
= 1 to3
1563 test_expect_success
$PREREQ 'to-cover adds To to all mail' '
1564 test_cover_addresses "To" --to-cover
1567 test_expect_success
$PREREQ 'cc-cover adds Cc to all mail' '
1568 test_cover_addresses "Cc" --cc-cover
1571 test_expect_success
$PREREQ 'tocover adds To to all mail' '
1572 test_config sendemail.tocover true &&
1573 test_cover_addresses "To"
1576 test_expect_success
$PREREQ 'cccover adds Cc to all mail' '
1577 test_config sendemail.cccover true &&
1578 test_cover_addresses "Cc"
1581 test_expect_success
$PREREQ 'escaped quotes in sendemail.aliasfiletype=mutt' '
1582 clean_fake_sendmail &&
1583 echo "alias sbd \\\"Dot U. Sir\\\" <somebody@example.org>" >.mutt &&
1584 git config --replace-all sendemail.aliasesfile "$(pwd)/.mutt" &&
1585 git config sendemail.aliasfiletype mutt &&
1587 --from="Example <nobody@example.com>" \
1589 --smtp-server="$(pwd)/fake.sendmail" \
1590 outdir/0001-*.patch \
1592 grep "^!somebody@example\.org!$" commandline1 &&
1593 grep -F "To: \"Dot U. Sir\" <somebody@example.org>" out
1596 test_expect_success
$PREREQ 'sendemail.aliasfiletype=mailrc' '
1597 clean_fake_sendmail &&
1598 echo "alias sbd somebody@example.org" >.mailrc &&
1599 git config --replace-all sendemail.aliasesfile "$(pwd)/.mailrc" &&
1600 git config sendemail.aliasfiletype mailrc &&
1602 --from="Example <nobody@example.com>" \
1604 --smtp-server="$(pwd)/fake.sendmail" \
1605 outdir/0001-*.patch \
1607 grep "^!somebody@example\.org!$" commandline1
1610 test_expect_success
$PREREQ 'sendemail.aliasfile=~/.mailrc' '
1611 clean_fake_sendmail &&
1612 echo "alias sbd someone@example.org" >"$HOME/.mailrc" &&
1613 git config --replace-all sendemail.aliasesfile "~/.mailrc" &&
1614 git config sendemail.aliasfiletype mailrc &&
1616 --from="Example <nobody@example.com>" \
1618 --smtp-server="$(pwd)/fake.sendmail" \
1619 outdir/0001-*.patch \
1621 grep "^!someone@example\.org!$" commandline1
1624 test_dump_aliases
() {
1625 msg
="$1" && shift &&
1626 filetype
="$1" && shift &&
1627 printf '%s\n' "$@" >expect
&&
1628 cat >.tmp-email-aliases
&&
1630 test_expect_success
$PREREQ "$msg" '
1631 clean_fake_sendmail && rm -fr outdir &&
1632 git config --replace-all sendemail.aliasesfile \
1633 "$(pwd)/.tmp-email-aliases" &&
1634 git config sendemail.aliasfiletype "$filetype" &&
1635 git send-email --dump-aliases 2>errors >actual &&
1636 test_cmp expect actual
1640 test_dump_aliases
'--dump-aliases sendmail format' \
1647 alice: Alice W Land <awol@example.com>
1648 bob: Robert Bobbyton <bob@example.com>
1649 chloe: chloe@example.com
1651 bcgrp: bob, chloe, Other <o@example.com>
1654 test_dump_aliases '--dump-aliases mutt format' \
1660 alias alice Alice W Land <awol@example.com>
1661 alias donald Donald C Carlton <donc@example.com>
1662 alias bob Robert Bobbyton <bob@example.com>
1663 alias chloe chloe@example.com
1666 test_dump_aliases '--dump-aliases mailrc format' \
1672 alias alice Alice W Land <awol@example.com>
1673 alias eve Eve <eve@example.com>
1674 alias bob Robert Bobbyton <bob@example.com>
1675 alias chloe chloe@example.com
1678 test_dump_aliases '--dump-aliases pine format' \
1684 alice Alice W Land <awol@example.com>
1685 eve Eve <eve@example.com>
1686 bob Robert Bobbyton <bob@example.com>
1687 chloe chloe@example.com
1690 test_dump_aliases '--dump-aliases gnus format' \
1696 (define-mail-alias "alice" "awol@example.com")
1697 (define-mail-alias "eve" "eve@example.com")
1698 (define-mail-alias "bob" "bob@example.com")
1699 (define-mail-alias "chloe" "chloe@example.com")
1702 test_expect_success '--dump-aliases must be used alone' '
1703 test_must_fail git send-email --dump-aliases --to=janice@example.com -1 refs/heads/accounting
1706 test_sendmail_aliases () {
1707 msg="$1" && shift &&
1709 cat >.tmp-email-aliases &&
1711 test_expect_success $PREREQ "$msg" '
1712 clean_fake_sendmail && rm -fr outdir &&
1713 git format-patch -1 -o outdir &&
1714 git config --replace-all sendemail.aliasesfile \
1715 "$(pwd)/.tmp-email-aliases" &&
1716 git config sendemail.aliasfiletype sendmail &&
1718 --from="Example <nobody@example.com>" \
1719 --to=alice --to=bcgrp \
1720 --smtp-server="$(pwd)/fake.sendmail" \
1721 outdir/0001-*.
patch \
1725 grep "^!$i!$" commandline1 ||
return 1
1730 test_sendmail_aliases 'sendemail.aliasfiletype
=sendmail
' \
1731 'awol@example\.com
' \
1732 'bob@example\.com
' \
1733 'chloe@example\.com
' \
1734 'o@example\.com
' <<-\EOF
1735 alice: Alice W Land <awol@example.com>
1736 bob: Robert Bobbyton <bob@example.com>
1738 # this is also a comment
1739 chloe: chloe@example.com
1741 bcgrp: bob, chloe, Other <o@example.com>
1744 test_sendmail_aliases 'sendmail aliases line folding
' \
1748 darla1 darla2 darla3 \
1749 elton1 elton2 elton3 \
1766 bcgrp: bob, chuck, darla, elton, fred, greg
1769 test_sendmail_aliases 'sendmail aliases tolerate bogus line folding
' \
1775 test_sendmail_aliases 'sendmail aliases empty
' alice bcgrp <<-\EOF
1778 test_expect_success $PREREQ 'alias support
in To header
' '
1779 clean_fake_sendmail
&&
1780 echo "alias sbd someone@example.org" >.mailrc
&&
1781 test_config sendemail.aliasesfile
".mailrc" &&
1782 test_config sendemail.aliasfiletype mailrc
&&
1783 git format-patch
--stdout -1 --to=sbd
>aliased.
patch &&
1785 --from="Example <nobody@example.com>" \
1786 --smtp-server="$(pwd)/fake.sendmail" \
1789 grep "^!someone@example\.org!$" commandline1
1792 test_expect_success $PREREQ 'alias support
in Cc header
' '
1793 clean_fake_sendmail
&&
1794 echo "alias sbd someone@example.org" >.mailrc
&&
1795 test_config sendemail.aliasesfile
".mailrc" &&
1796 test_config sendemail.aliasfiletype mailrc
&&
1797 git format-patch
--stdout -1 --cc=sbd
>aliased.
patch &&
1799 --from="Example <nobody@example.com>" \
1800 --smtp-server="$(pwd)/fake.sendmail" \
1803 grep "^!someone@example\.org!$" commandline1
1806 test_expect_success $PREREQ 'tocmd works with aliases
' '
1807 clean_fake_sendmail
&&
1808 echo "alias sbd someone@example.org" >.mailrc
&&
1809 test_config sendemail.aliasesfile
".mailrc" &&
1810 test_config sendemail.aliasfiletype mailrc
&&
1811 git format-patch
--stdout -1 >tocmd.
patch &&
1812 echo tocmd--sbd
>>tocmd.
patch &&
1814 --from="Example <nobody@example.com>" \
1815 --to-cmd=.
/tocmd-sed \
1816 --smtp-server="$(pwd)/fake.sendmail" \
1819 grep "^!someone@example\.org!$" commandline1
1822 test_expect_success $PREREQ 'cccmd works with aliases
' '
1823 clean_fake_sendmail
&&
1824 echo "alias sbd someone@example.org" >.mailrc
&&
1825 test_config sendemail.aliasesfile
".mailrc" &&
1826 test_config sendemail.aliasfiletype mailrc
&&
1827 git format-patch
--stdout -1 >cccmd.
patch &&
1828 echo cccmd--sbd
>>cccmd.
patch &&
1830 --from="Example <nobody@example.com>" \
1831 --cc-cmd=.
/cccmd-sed \
1832 --smtp-server="$(pwd)/fake.sendmail" \
1835 grep "^!someone@example\.org!$" commandline1
1838 do_xmailer_test () {
1839 expected=$1 params=$2 &&
1840 git format-patch -1 &&
1842 --from="Example <nobody@example.com>" \
1843 --to=someone@example.com \
1844 --smtp-server="$(pwd)/fake.sendmail" \
1848 { grep '^X-Mailer
:' out || :; } >mailer &&
1849 test_line_count = $expected mailer
1852 test_expect_success $PREREQ '--[no-
]xmailer without any configuration
' '
1853 do_xmailer_test
1 "--xmailer" &&
1854 do_xmailer_test
0 "--no-xmailer"
1857 test_expect_success $PREREQ '--[no-
]xmailer with sendemail.xmailer
=true
' '
1858 test_config sendemail.xmailer true
&&
1859 do_xmailer_test
1 "" &&
1860 do_xmailer_test
0 "--no-xmailer" &&
1861 do_xmailer_test
1 "--xmailer"
1864 test_expect_success $PREREQ '--[no-
]xmailer with sendemail.xmailer
=false
' '
1865 test_config sendemail.xmailer false
&&
1866 do_xmailer_test
0 "" &&
1867 do_xmailer_test
0 "--no-xmailer" &&
1868 do_xmailer_test
1 "--xmailer"
1871 test_expect_success $PREREQ 'setup expected-list
' '
1874 --from="Example <from@example.com>" \
1875 --to="To 1 <to1@example.com>" \
1876 --to="to2@example.com" \
1877 --to="to3@example.com" \
1878 --cc="Cc 1 <cc1@example.com>" \
1879 --cc="Cc2 <cc2@example.com>" \
1880 --bcc="bcc1@example.com" \
1881 --bcc="bcc2@example.com" \
1882 0001-add-master.
patch | replace_variable_fields \
1886 test_expect_success $PREREQ 'use email list
in --cc --to and
--bcc' '
1889 --from="Example <from@example.com>" \
1890 --to="To 1 <to1@example.com>, to2@example.com" \
1891 --to="to3@example.com" \
1892 --cc="Cc 1 <cc1@example.com>, Cc2 <cc2@example.com>" \
1893 --bcc="bcc1@example.com, bcc2@example.com" \
1894 0001-add-master.
patch | replace_variable_fields \
1896 test_cmp expected-list actual-list
1899 test_expect_success $PREREQ 'aliases work with email list
' '
1900 echo "alias to2 to2@example.com" >.mutt
&&
1901 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt
&&
1902 test_config sendemail.aliasesfile
".mutt" &&
1903 test_config sendemail.aliasfiletype mutt
&&
1906 --from="Example <from@example.com>" \
1907 --to="To 1 <to1@example.com>, to2, to3@example.com" \
1908 --cc="cc1, Cc2 <cc2@example.com>" \
1909 --bcc="bcc1@example.com, bcc2@example.com" \
1910 0001-add-master.
patch | replace_variable_fields \
1912 test_cmp expected-list actual-list
1915 test_expect_success $PREREQ 'leading and trailing whitespaces are removed
' '
1916 echo "alias to2 to2@example.com" >.mutt
&&
1917 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt
&&
1918 test_config sendemail.aliasesfile
".mutt" &&
1919 test_config sendemail.aliasfiletype mutt
&&
1920 TO1
=$
(echo "QTo 1 <to1@example.com>" | q_to_tab
) &&
1921 TO2
=$
(echo "QZto2" | qz_to_tab_space
) &&
1922 CC1
=$
(echo "cc1" | append_cr
) &&
1923 BCC1
=$
(echo "Q bcc1@example.com Q" | q_to_nul
) &&
1926 --from=" Example <from@example.com>" \
1929 --to=" to3@example.com " \
1931 --cc="Cc2 <cc2@example.com>" \
1933 --bcc="bcc2@example.com" \
1934 0001-add-master.
patch | replace_variable_fields \
1936 test_cmp expected-list actual-list
1939 test_expect_success $PREREQ 'invoke hook
' '
1940 mkdir
-p .git
/hooks
&&
1942 write_script .git
/hooks
/sendemail-validate
<<-\EOF &&
1943 # test that we have the correct environment variable, pwd, and
1953 test -f 0001-add-master.patch &&
1954 grep "add master" "$1"
1959 # Test that it works even if we are not at the root of the
1963 --from="Example <nobody@example.com>" \
1964 --to=nobody@example.com \
1965 --smtp-server="$(pwd)/../fake.sendmail" \
1966 ../0001-add-master.patch &&
1968 # Verify error message when a patch is rejected by the hook
1969 sed -e "s/add master/x/" ../0001-add-master.patch >../another.patch &&
1971 --from="Example <nobody@example.com>" \
1972 --to=nobody@example.com \
1973 --smtp-server="$(pwd)/../fake.sendmail" \
1974 ../another.patch 2>err
1975 test_i18ngrep "rejected by sendemail-validate hook" err
1979 test_expect_success $PREREQ 'test that send-email works outside a repo' '
1980 nongit git send-email \
1981 --from="Example <nobody@example.com>" \
1982 --to=nobody@example.com \
1983 --smtp-server="$(pwd)/fake.sendmail" \
1984 "$(pwd)/0001-add-master.patch"