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>
233 test_suppress_self
() {
235 test_when_finished
"git reset --hard HEAD^" &&
237 write_script cccmd-sed
<<-EOF &&
238 sed -n -e s/^cccmd--//p "\$1"
241 git commit
--amend --author="$1 <$2>" -F - &&
242 clean_fake_sendmail
&&
243 git format-patch
--stdout -1 >"suppress-self-$3.patch" &&
245 git send-email
--from="$1 <$2>" \
246 --to=nobody@example.com \
247 --cc-cmd=.
/cccmd-sed \
249 --smtp-server="$(pwd)/fake.sendmail" \
250 suppress-self-
$3.
patch &&
252 mv msgtxt1 msgtxt1-
$3 &&
253 sed -e '/^$/q' msgtxt1-
$3 >"msghdr1-$3" &&
254 >"expected-no-cc-$3" &&
256 (grep '^Cc:' msghdr1-
$3 >"actual-no-cc-$3";
257 test_cmp expected-no-cc-
$3 actual-no-cc-
$3)
260 test_suppress_self_unquoted
() {
261 test_suppress_self
"$1" "$2" "unquoted-$3" <<-EOF
262 test suppress-cc.self unquoted-$3 with name $1 email $2
269 Signed-off-by: $1 <$2>
273 test_suppress_self_quoted
() {
274 test_suppress_self
"$1" "$2" "quoted-$3" <<-EOF
275 test suppress-cc.self quoted-$3 with name $1 email $2
283 Signed-off-by: $1 <$2>
284 Signed-off-by: "$1" <$2>
288 test_expect_success
$PREREQ 'self name is suppressed' "
289 test_suppress_self_unquoted 'A U Thor' 'author@example.com' \
290 'self_name_suppressed'
293 test_expect_success
$PREREQ 'self name with dot is suppressed' "
294 test_suppress_self_quoted 'A U. Thor' 'author@example.com' \
295 'self_name_dot_suppressed'
298 test_expect_success
$PREREQ 'non-ascii self name is suppressed' "
299 test_suppress_self_quoted 'Füñný Nâmé' 'odd_?=mail@example.com' \
300 'non_ascii_self_suppressed'
303 # This name is long enough to force format-patch to split it into multiple
304 # encoded-words, assuming it uses UTF-8 with the "Q" encoding.
305 test_expect_success
$PREREQ 'long non-ascii self name is suppressed' "
306 test_suppress_self_quoted 'Ƒüñníęř €. Nâṁé' 'odd_?=mail@example.com' \
307 'long_non_ascii_self_suppressed'
310 test_expect_success
$PREREQ 'sanitized self name is suppressed' "
311 test_suppress_self_unquoted '\"A U. Thor\"' 'author@example.com' \
312 'self_name_sanitized_suppressed'
315 test_expect_success
$PREREQ 'Show all headers' '
319 --from="Example <from@example.com>" \
320 --reply-to="Reply <reply@example.com>" \
321 --to=to@example.com \
322 --cc=cc@example.com \
323 --bcc=bcc@example.com \
324 --in-reply-to="<unique-message-id@example.com>" \
325 --smtp-server relay.example.com \
326 $patches | replace_variable_fields \
327 >actual-show-all-headers &&
328 test_cmp expected-show-all-headers actual-show-all-headers
331 test_expect_success
$PREREQ 'Prompting works' '
332 clean_fake_sendmail &&
333 (echo "to@example.com"
335 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
336 --smtp-server="$(pwd)/fake.sendmail" \
339 grep "^From: A U Thor <author@example.com>\$" msgtxt1 &&
340 grep "^To: to@example.com\$" msgtxt1
343 test_expect_success
$PREREQ,AUTOIDENT
'implicit ident is allowed' '
344 clean_fake_sendmail &&
345 (sane_unset GIT_AUTHOR_NAME &&
346 sane_unset GIT_AUTHOR_EMAIL &&
347 sane_unset GIT_COMMITTER_NAME &&
348 sane_unset GIT_COMMITTER_EMAIL &&
349 GIT_SEND_EMAIL_NOTTY=1 git send-email \
350 --smtp-server="$(pwd)/fake.sendmail" \
351 --to=to@example.com \
352 $patches </dev/null 2>errors
356 test_expect_success
$PREREQ,!AUTOIDENT
'broken implicit ident aborts send-email' '
357 clean_fake_sendmail &&
358 (sane_unset GIT_AUTHOR_NAME &&
359 sane_unset GIT_AUTHOR_EMAIL &&
360 sane_unset GIT_COMMITTER_NAME &&
361 sane_unset GIT_COMMITTER_EMAIL &&
362 GIT_SEND_EMAIL_NOTTY=1 && export GIT_SEND_EMAIL_NOTTY &&
363 test_must_fail git send-email \
364 --smtp-server="$(pwd)/fake.sendmail" \
365 --to=to@example.com \
366 $patches </dev/null 2>errors &&
367 test_i18ngrep "tell me who you are" errors
371 test_expect_success
$PREREQ 'setup tocmd and cccmd scripts' '
372 write_script tocmd-sed <<-\EOF &&
373 sed -n -e "s/^tocmd--//p" "$1"
375 write_script cccmd-sed <<-\EOF
376 sed -n -e "s/^cccmd--//p" "$1"
380 test_expect_success
$PREREQ 'tocmd works' '
381 clean_fake_sendmail &&
382 cp $patches tocmd.patch &&
383 echo tocmd--tocmd@example.com >>tocmd.patch &&
385 --from="Example <nobody@example.com>" \
386 --to-cmd=./tocmd-sed \
387 --smtp-server="$(pwd)/fake.sendmail" \
390 grep "^To: tocmd@example.com" msgtxt1
393 test_expect_success
$PREREQ 'cccmd works' '
394 clean_fake_sendmail &&
395 cp $patches cccmd.patch &&
396 echo "cccmd-- cccmd@example.com" >>cccmd.patch &&
398 --from="Example <nobody@example.com>" \
399 --to=nobody@example.com \
400 --cc-cmd=./cccmd-sed \
401 --smtp-server="$(pwd)/fake.sendmail" \
404 grep "^ cccmd@example.com" msgtxt1
407 test_expect_success
$PREREQ 'reject long lines' '
409 z64=$z8$z8$z8$z8$z8$z8$z8$z8 &&
410 z512=$z64$z64$z64$z64$z64$z64$z64$z64 &&
411 clean_fake_sendmail &&
412 cp $patches longline.patch &&
413 echo $z512$z512 >>longline.patch &&
414 test_must_fail git send-email \
415 --from="Example <nobody@example.com>" \
416 --to=nobody@example.com \
417 --smtp-server="$(pwd)/fake.sendmail" \
418 $patches longline.patch \
420 grep longline.patch errors
423 test_expect_success
$PREREQ 'no patch was sent' '
424 ! test -e commandline1
427 test_expect_success
$PREREQ 'Author From: in message body' '
428 clean_fake_sendmail &&
430 --from="Example <nobody@example.com>" \
431 --to=nobody@example.com \
432 --smtp-server="$(pwd)/fake.sendmail" \
434 sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
435 grep "From: A <author@example.com>" msgbody1
438 test_expect_success
$PREREQ 'Author From: not in message body' '
439 clean_fake_sendmail &&
441 --from="A <author@example.com>" \
442 --to=nobody@example.com \
443 --smtp-server="$(pwd)/fake.sendmail" \
445 sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
446 ! grep "From: A <author@example.com>" msgbody1
449 test_expect_success
$PREREQ 'allow long lines with --no-validate' '
451 --from="Example <nobody@example.com>" \
452 --to=nobody@example.com \
453 --smtp-server="$(pwd)/fake.sendmail" \
455 $patches longline.patch \
459 test_expect_success
$PREREQ 'Invalid In-Reply-To' '
460 clean_fake_sendmail &&
462 --from="Example <nobody@example.com>" \
463 --to=nobody@example.com \
465 --smtp-server="$(pwd)/fake.sendmail" \
468 ! grep "^In-Reply-To: < *>" msgtxt1
471 test_expect_success
$PREREQ 'Valid In-Reply-To when prompting' '
472 clean_fake_sendmail &&
473 (echo "From Example <from@example.com>"
474 echo "To Example <to@example.com>"
476 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
477 --smtp-server="$(pwd)/fake.sendmail" \
479 ! grep "^In-Reply-To: < *>" msgtxt1
482 test_expect_success
$PREREQ 'In-Reply-To without --chain-reply-to' '
483 clean_fake_sendmail &&
484 echo "<unique-message-id@example.com>" >expect &&
486 --from="Example <nobody@example.com>" \
487 --to=nobody@example.com \
488 --no-chain-reply-to \
489 --in-reply-to="$(cat expect)" \
490 --smtp-server="$(pwd)/fake.sendmail" \
491 $patches $patches $patches \
493 # The first message is a reply to --in-reply-to
494 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
495 test_cmp expect actual &&
496 # Second and subsequent messages are replies to the first one
497 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
498 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
499 test_cmp expect actual &&
500 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
501 test_cmp expect actual
504 test_expect_success
$PREREQ 'In-Reply-To with --chain-reply-to' '
505 clean_fake_sendmail &&
506 echo "<unique-message-id@example.com>" >expect &&
508 --from="Example <nobody@example.com>" \
509 --to=nobody@example.com \
511 --in-reply-to="$(cat expect)" \
512 --smtp-server="$(pwd)/fake.sendmail" \
513 $patches $patches $patches \
515 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
516 test_cmp expect actual &&
517 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
518 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
519 test_cmp expect actual &&
520 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt2 >expect &&
521 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
522 test_cmp expect actual
525 test_expect_success
$PREREQ 'setup fake editor' '
526 write_script fake-editor <<-\EOF
527 echo fake edit >>"$1"
531 test_set_editor
"$(pwd)/fake-editor"
533 test_expect_success
$PREREQ '--compose works' '
534 clean_fake_sendmail &&
536 --compose --subject foo \
537 --from="Example <nobody@example.com>" \
538 --to=nobody@example.com \
539 --smtp-server="$(pwd)/fake.sendmail" \
544 test_expect_success
$PREREQ 'first message is compose text' '
545 grep "^fake edit" msgtxt1
548 test_expect_success
$PREREQ 'second message is patch' '
549 grep "Subject:.*Second" msgtxt2
552 test_expect_success
$PREREQ 'setup expect' "
553 cat >expected-suppress-sob <<\EOF
555 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
556 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
557 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
559 Server: relay.example.com
560 MAIL FROM:<from@example.com>
561 RCPT TO:<to@example.com>
562 RCPT TO:<cc@example.com>
563 RCPT TO:<author@example.com>
564 RCPT TO:<one@example.com>
565 RCPT TO:<two@example.com>
566 From: Example <from@example.com>
569 A <author@example.com>,
570 One <one@example.com>,
572 Subject: [PATCH 1/1] Second.
574 Message-Id: MESSAGE-ID-STRING
575 X-Mailer: X-MAILER-STRING
581 test_suppression
() {
584 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
585 --from="Example <from@example.com>" \
586 --to=to@example.com \
587 --smtp-server relay.example.com \
588 $patches | replace_variable_fields \
589 >actual-suppress-
$1${2+"-$2"} &&
590 test_cmp expected-suppress-
$1${2+"-$2"} actual-suppress-
$1${2+"-$2"}
593 test_expect_success
$PREREQ 'sendemail.cc set' '
594 git config sendemail.cc cc@example.com &&
598 test_expect_success
$PREREQ 'setup expect' "
599 cat >expected-suppress-sob <<\EOF
601 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
602 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
603 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
605 Server: relay.example.com
606 MAIL FROM:<from@example.com>
607 RCPT TO:<to@example.com>
608 RCPT TO:<author@example.com>
609 RCPT TO:<one@example.com>
610 RCPT TO:<two@example.com>
611 From: Example <from@example.com>
613 Cc: A <author@example.com>,
614 One <one@example.com>,
616 Subject: [PATCH 1/1] Second.
618 Message-Id: MESSAGE-ID-STRING
619 X-Mailer: X-MAILER-STRING
625 test_expect_success
$PREREQ 'sendemail.cc unset' '
626 git config --unset sendemail.cc &&
630 test_expect_success
$PREREQ 'setup expect' "
631 cat >expected-suppress-cccmd <<\EOF
633 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
634 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
635 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
636 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
638 Server: relay.example.com
639 MAIL FROM:<from@example.com>
640 RCPT TO:<to@example.com>
641 RCPT TO:<author@example.com>
642 RCPT TO:<one@example.com>
643 RCPT TO:<two@example.com>
644 RCPT TO:<committer@example.com>
645 From: Example <from@example.com>
647 Cc: A <author@example.com>,
648 One <one@example.com>,
650 C O Mitter <committer@example.com>
651 Subject: [PATCH 1/1] Second.
653 Message-Id: MESSAGE-ID-STRING
654 X-Mailer: X-MAILER-STRING
660 test_expect_success
$PREREQ 'sendemail.cccmd' '
661 write_script cccmd <<-\EOF &&
662 echo cc-cmd@example.com
664 git config sendemail.cccmd ./cccmd &&
665 test_suppression cccmd
668 test_expect_success
$PREREQ 'setup expect' '
669 cat >expected-suppress-all <<\EOF
672 Server: relay.example.com
673 MAIL FROM:<from@example.com>
674 RCPT TO:<to@example.com>
675 From: Example <from@example.com>
677 Subject: [PATCH 1/1] Second.
679 Message-Id: MESSAGE-ID-STRING
680 X-Mailer: X-MAILER-STRING
686 test_expect_success
$PREREQ '--suppress-cc=all' '
690 test_expect_success
$PREREQ 'setup expect' "
691 cat >expected-suppress-body <<\EOF
693 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
694 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
695 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
696 (cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
698 Server: relay.example.com
699 MAIL FROM:<from@example.com>
700 RCPT TO:<to@example.com>
701 RCPT TO:<author@example.com>
702 RCPT TO:<one@example.com>
703 RCPT TO:<two@example.com>
704 RCPT TO:<cc-cmd@example.com>
705 From: Example <from@example.com>
707 Cc: A <author@example.com>,
708 One <one@example.com>,
711 Subject: [PATCH 1/1] Second.
713 Message-Id: MESSAGE-ID-STRING
714 X-Mailer: X-MAILER-STRING
720 test_expect_success
$PREREQ '--suppress-cc=body' '
721 test_suppression body
724 test_expect_success
$PREREQ 'setup expect' "
725 cat >expected-suppress-body-cccmd <<\EOF
727 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
728 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
729 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
731 Server: relay.example.com
732 MAIL FROM:<from@example.com>
733 RCPT TO:<to@example.com>
734 RCPT TO:<author@example.com>
735 RCPT TO:<one@example.com>
736 RCPT TO:<two@example.com>
737 From: Example <from@example.com>
739 Cc: A <author@example.com>,
740 One <one@example.com>,
742 Subject: [PATCH 1/1] Second.
744 Message-Id: MESSAGE-ID-STRING
745 X-Mailer: X-MAILER-STRING
751 test_expect_success
$PREREQ '--suppress-cc=body --suppress-cc=cccmd' '
752 test_suppression body cccmd
755 test_expect_success
$PREREQ 'setup expect' "
756 cat >expected-suppress-sob <<\EOF
758 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
759 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
760 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
762 Server: relay.example.com
763 MAIL FROM:<from@example.com>
764 RCPT TO:<to@example.com>
765 RCPT TO:<author@example.com>
766 RCPT TO:<one@example.com>
767 RCPT TO:<two@example.com>
768 From: Example <from@example.com>
770 Cc: A <author@example.com>,
771 One <one@example.com>,
773 Subject: [PATCH 1/1] Second.
775 Message-Id: MESSAGE-ID-STRING
776 X-Mailer: X-MAILER-STRING
782 test_expect_success
$PREREQ '--suppress-cc=sob' '
783 test_might_fail git config --unset sendemail.cccmd &&
787 test_expect_success
$PREREQ 'setup expect' "
788 cat >expected-suppress-bodycc <<\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'
793 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
795 Server: relay.example.com
796 MAIL FROM:<from@example.com>
797 RCPT TO:<to@example.com>
798 RCPT TO:<author@example.com>
799 RCPT TO:<one@example.com>
800 RCPT TO:<two@example.com>
801 RCPT TO:<committer@example.com>
802 From: Example <from@example.com>
804 Cc: A <author@example.com>,
805 One <one@example.com>,
807 C O Mitter <committer@example.com>
808 Subject: [PATCH 1/1] Second.
810 Message-Id: MESSAGE-ID-STRING
811 X-Mailer: X-MAILER-STRING
817 test_expect_success
$PREREQ '--suppress-cc=bodycc' '
818 test_suppression bodycc
821 test_expect_success
$PREREQ 'setup expect' "
822 cat >expected-suppress-cc <<\EOF
824 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
825 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@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:<committer@example.com>
832 From: Example <from@example.com>
834 Cc: A <author@example.com>,
835 C O Mitter <committer@example.com>
836 Subject: [PATCH 1/1] Second.
838 Message-Id: MESSAGE-ID-STRING
839 X-Mailer: X-MAILER-STRING
845 test_expect_success
$PREREQ '--suppress-cc=cc' '
851 GIT_SEND_EMAIL_NOTTY
=1 \
853 --from="Example <nobody@example.com>" \
854 --to=nobody@example.com \
855 --smtp-server="$(pwd)/fake.sendmail" \
856 $@
$patches >stdout
&&
857 grep "Send this email" stdout
860 test_expect_success
$PREREQ '--confirm=always' '
861 test_confirm --confirm=always --suppress-cc=all
864 test_expect_success
$PREREQ '--confirm=auto' '
865 test_confirm --confirm=auto
868 test_expect_success
$PREREQ '--confirm=cc' '
869 test_confirm --confirm=cc
872 test_expect_success
$PREREQ '--confirm=compose' '
873 test_confirm --confirm=compose --compose
876 test_expect_success
$PREREQ 'confirm by default (due to cc)' '
877 test_when_finished git config sendemail.confirm never &&
878 git config --unset sendemail.confirm &&
882 test_expect_success
$PREREQ 'confirm by default (due to --compose)' '
883 test_when_finished git config sendemail.confirm never &&
884 git config --unset sendemail.confirm &&
885 test_confirm --suppress-cc=all --compose
888 test_expect_success
$PREREQ 'confirm detects EOF (inform assumes y)' '
889 test_when_finished git config sendemail.confirm never &&
890 git config --unset sendemail.confirm &&
892 git format-patch -2 -o outdir &&
893 GIT_SEND_EMAIL_NOTTY=1 \
895 --from="Example <nobody@example.com>" \
896 --to=nobody@example.com \
897 --smtp-server="$(pwd)/fake.sendmail" \
898 outdir/*.patch </dev/null
901 test_expect_success
$PREREQ 'confirm detects EOF (auto causes failure)' '
902 test_when_finished git config sendemail.confirm never &&
903 git config sendemail.confirm auto &&
904 GIT_SEND_EMAIL_NOTTY=1 &&
905 export GIT_SEND_EMAIL_NOTTY &&
906 test_must_fail git send-email \
907 --from="Example <nobody@example.com>" \
908 --to=nobody@example.com \
909 --smtp-server="$(pwd)/fake.sendmail" \
913 test_expect_success
$PREREQ 'confirm does not loop forever' '
914 test_when_finished git config sendemail.confirm never &&
915 git config sendemail.confirm auto &&
916 GIT_SEND_EMAIL_NOTTY=1 &&
917 export GIT_SEND_EMAIL_NOTTY &&
918 yes "bogus" | test_must_fail git send-email \
919 --from="Example <nobody@example.com>" \
920 --to=nobody@example.com \
921 --smtp-server="$(pwd)/fake.sendmail" \
925 test_expect_success
$PREREQ 'utf8 Cc is rfc2047 encoded' '
926 clean_fake_sendmail &&
928 git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
930 --from="Example <nobody@example.com>" \
931 --to=nobody@example.com \
932 --smtp-server="$(pwd)/fake.sendmail" \
935 grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
938 test_expect_success
$PREREQ '--compose adds MIME for utf8 body' '
939 clean_fake_sendmail &&
940 write_script fake-editor-utf8 <<-\EOF &&
941 echo "utf8 body: àéìöú" >>"$1"
943 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
945 --compose --subject foo \
946 --from="Example <nobody@example.com>" \
947 --to=nobody@example.com \
948 --smtp-server="$(pwd)/fake.sendmail" \
950 grep "^utf8 body" msgtxt1 &&
951 grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
954 test_expect_success
$PREREQ '--compose respects user mime type' '
955 clean_fake_sendmail &&
956 write_script fake-editor-utf8-mime <<-\EOF &&
959 Content-Type: text/plain; charset=iso-8859-1
960 Content-Transfer-Encoding: 8bit
966 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
968 --compose --subject foo \
969 --from="Example <nobody@example.com>" \
970 --to=nobody@example.com \
971 --smtp-server="$(pwd)/fake.sendmail" \
973 grep "^utf8 body" msgtxt1 &&
974 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
975 ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
978 test_expect_success
$PREREQ '--compose adds MIME for utf8 subject' '
979 clean_fake_sendmail &&
980 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
982 --compose --subject utf8-sübjëct \
983 --from="Example <nobody@example.com>" \
984 --to=nobody@example.com \
985 --smtp-server="$(pwd)/fake.sendmail" \
987 grep "^fake edit" msgtxt1 &&
988 grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
991 test_expect_success
$PREREQ 'utf8 author is correctly passed on' '
992 clean_fake_sendmail &&
993 test_commit weird_author &&
994 test_when_finished "git reset --hard HEAD^" &&
995 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
996 git format-patch --stdout -1 >funny_name.patch &&
997 git send-email --from="Example <nobody@example.com>" \
998 --to=nobody@example.com \
999 --smtp-server="$(pwd)/fake.sendmail" \
1001 grep "^From: Füñný Nâmé <odd_?=mail@example.com>" msgtxt1
1004 test_expect_success
$PREREQ 'utf8 sender is not duplicated' '
1005 clean_fake_sendmail &&
1006 test_commit weird_sender &&
1007 test_when_finished "git reset --hard HEAD^" &&
1008 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
1009 git format-patch --stdout -1 >funny_name.patch &&
1010 git send-email --from="Füñný Nâmé <odd_?=mail@example.com>" \
1011 --to=nobody@example.com \
1012 --smtp-server="$(pwd)/fake.sendmail" \
1014 grep "^From: " msgtxt1 >msgfrom &&
1015 test_line_count = 1 msgfrom
1018 test_expect_success
$PREREQ 'sendemail.composeencoding works' '
1019 clean_fake_sendmail &&
1020 git config sendemail.composeencoding iso-8859-1 &&
1021 write_script fake-editor-utf8 <<-\EOF &&
1022 echo "utf8 body: àéìöú" >>"$1"
1024 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1026 --compose --subject foo \
1027 --from="Example <nobody@example.com>" \
1028 --to=nobody@example.com \
1029 --smtp-server="$(pwd)/fake.sendmail" \
1031 grep "^utf8 body" msgtxt1 &&
1032 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1035 test_expect_success
$PREREQ '--compose-encoding works' '
1036 clean_fake_sendmail &&
1037 write_script fake-editor-utf8 <<-\EOF &&
1038 echo "utf8 body: àéìöú" >>"$1"
1040 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1042 --compose-encoding iso-8859-1 \
1043 --compose --subject foo \
1044 --from="Example <nobody@example.com>" \
1045 --to=nobody@example.com \
1046 --smtp-server="$(pwd)/fake.sendmail" \
1048 grep "^utf8 body" msgtxt1 &&
1049 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1052 test_expect_success
$PREREQ '--compose-encoding overrides sendemail.composeencoding' '
1053 clean_fake_sendmail &&
1054 git config sendemail.composeencoding iso-8859-1 &&
1055 write_script fake-editor-utf8 <<-\EOF &&
1056 echo "utf8 body: àéìöú" >>"$1"
1058 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1060 --compose-encoding iso-8859-2 \
1061 --compose --subject foo \
1062 --from="Example <nobody@example.com>" \
1063 --to=nobody@example.com \
1064 --smtp-server="$(pwd)/fake.sendmail" \
1066 grep "^utf8 body" msgtxt1 &&
1067 grep "^Content-Type: text/plain; charset=iso-8859-2" msgtxt1
1070 test_expect_success
$PREREQ '--compose-encoding adds correct MIME for subject' '
1071 clean_fake_sendmail &&
1072 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
1074 --compose-encoding iso-8859-2 \
1075 --compose --subject utf8-sübjëct \
1076 --from="Example <nobody@example.com>" \
1077 --to=nobody@example.com \
1078 --smtp-server="$(pwd)/fake.sendmail" \
1080 grep "^fake edit" msgtxt1 &&
1081 grep "^Subject: =?iso-8859-2?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
1084 test_expect_success
$PREREQ 'detects ambiguous reference/file conflict' '
1085 echo master >master &&
1087 git commit -m"add master" &&
1088 test_must_fail git send-email --dry-run master 2>errors &&
1089 grep disambiguate errors
1092 test_expect_success
$PREREQ 'feed two files' '
1094 git format-patch -2 -o outdir &&
1097 --from="Example <nobody@example.com>" \
1098 --to=nobody@example.com \
1099 outdir/000?-*.patch 2>errors >out &&
1100 grep "^Subject: " out >subjects &&
1101 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
1102 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"
1105 test_expect_success
$PREREQ 'in-reply-to but no threading' '
1108 --from="Example <nobody@example.com>" \
1109 --to=nobody@example.com \
1110 --in-reply-to="<in-reply-id@example.com>" \
1113 grep "In-Reply-To: <in-reply-id@example.com>"
1116 test_expect_success
$PREREQ 'no in-reply-to and no threading' '
1119 --from="Example <nobody@example.com>" \
1120 --to=nobody@example.com \
1122 $patches $patches >stdout &&
1123 ! grep "In-Reply-To: " stdout
1126 test_expect_success
$PREREQ 'threading but no chain-reply-to' '
1129 --from="Example <nobody@example.com>" \
1130 --to=nobody@example.com \
1132 --no-chain-reply-to \
1133 $patches $patches >stdout &&
1134 grep "In-Reply-To: " stdout
1137 test_expect_success
$PREREQ 'sendemail.to works' '
1138 git config --replace-all sendemail.to "Somebody <somebody@ex.com>" &&
1141 --from="Example <nobody@example.com>" \
1142 $patches $patches >stdout &&
1143 grep "To: Somebody <somebody@ex.com>" stdout
1146 test_expect_success
$PREREQ '--no-to overrides sendemail.to' '
1149 --from="Example <nobody@example.com>" \
1151 --to=nobody@example.com \
1152 $patches $patches >stdout &&
1153 grep "To: nobody@example.com" stdout &&
1154 ! grep "To: Somebody <somebody@ex.com>" stdout
1157 test_expect_success
$PREREQ 'sendemail.cc works' '
1158 git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" &&
1161 --from="Example <nobody@example.com>" \
1162 --to=nobody@example.com \
1163 $patches $patches >stdout &&
1164 grep "Cc: Somebody <somebody@ex.com>" stdout
1167 test_expect_success
$PREREQ '--no-cc overrides sendemail.cc' '
1170 --from="Example <nobody@example.com>" \
1172 --cc=bodies@example.com \
1173 --to=nobody@example.com \
1174 $patches $patches >stdout &&
1175 grep "Cc: bodies@example.com" stdout &&
1176 ! grep "Cc: Somebody <somebody@ex.com>" stdout
1179 test_expect_success
$PREREQ 'sendemail.bcc works' '
1180 git config --replace-all sendemail.bcc "Other <other@ex.com>" &&
1183 --from="Example <nobody@example.com>" \
1184 --to=nobody@example.com \
1185 --smtp-server relay.example.com \
1186 $patches $patches >stdout &&
1187 grep "RCPT TO:<other@ex.com>" stdout
1190 test_expect_success
$PREREQ '--no-bcc overrides sendemail.bcc' '
1193 --from="Example <nobody@example.com>" \
1195 --bcc=bodies@example.com \
1196 --to=nobody@example.com \
1197 --smtp-server relay.example.com \
1198 $patches $patches >stdout &&
1199 grep "RCPT TO:<bodies@example.com>" stdout &&
1200 ! grep "RCPT TO:<other@ex.com>" stdout
1203 test_expect_success
$PREREQ 'patches To headers are used by default' '
1204 patch=$(git format-patch -1 --to="bodies@example.com") &&
1205 test_when_finished "rm $patch" &&
1208 --from="Example <nobody@example.com>" \
1209 --smtp-server relay.example.com \
1211 grep "RCPT TO:<bodies@example.com>" stdout
1214 test_expect_success
$PREREQ 'patches To headers are appended to' '
1215 patch=$(git format-patch -1 --to="bodies@example.com") &&
1216 test_when_finished "rm $patch" &&
1219 --from="Example <nobody@example.com>" \
1220 --to=nobody@example.com \
1221 --smtp-server relay.example.com \
1223 grep "RCPT TO:<bodies@example.com>" stdout &&
1224 grep "RCPT TO:<nobody@example.com>" stdout
1227 test_expect_success
$PREREQ 'To headers from files reset each patch' '
1228 patch1=$(git format-patch -1 --to="bodies@example.com") &&
1229 patch2=$(git format-patch -1 --to="other@example.com" HEAD~) &&
1230 test_when_finished "rm $patch1 && rm $patch2" &&
1233 --from="Example <nobody@example.com>" \
1234 --to="nobody@example.com" \
1235 --smtp-server relay.example.com \
1236 $patch1 $patch2 >stdout &&
1237 test $(grep -c "RCPT TO:<bodies@example.com>" stdout) = 1 &&
1238 test $(grep -c "RCPT TO:<nobody@example.com>" stdout) = 2 &&
1239 test $(grep -c "RCPT TO:<other@example.com>" stdout) = 1
1242 test_expect_success
$PREREQ 'setup expect' '
1243 cat >email-using-8bit <<\EOF
1244 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1245 Message-Id: <bogus-message-id@example.com>
1246 From: author@example.com
1247 Date: Sat, 12 Jun 2010 15:53:58 +0200
1248 Subject: subject goes here
1250 Dieser deutsche Text enthält einen Umlaut!
1254 test_expect_success
$PREREQ 'setup expect' '
1255 echo "Subject: subject goes here" >expected
1258 test_expect_success
$PREREQ 'ASCII subject is not RFC2047 quoted' '
1259 clean_fake_sendmail &&
1261 git send-email --from=author@example.com --to=nobody@example.com \
1262 --smtp-server="$(pwd)/fake.sendmail" \
1263 --8bit-encoding=UTF-8 \
1264 email-using-8bit >stdout &&
1265 grep "Subject" msgtxt1 >actual &&
1266 test_cmp expected actual
1269 test_expect_success
$PREREQ 'setup expect' '
1270 cat >content-type-decl <<-\EOF
1272 Content-Type: text/plain; charset=UTF-8
1273 Content-Transfer-Encoding: 8bit
1277 test_expect_success
$PREREQ 'asks about and fixes 8bit encodings' '
1278 clean_fake_sendmail &&
1280 git send-email --from=author@example.com --to=nobody@example.com \
1281 --smtp-server="$(pwd)/fake.sendmail" \
1282 email-using-8bit >stdout &&
1283 grep "do not declare a Content-Transfer-Encoding" stdout &&
1284 grep email-using-8bit stdout &&
1285 grep "Which 8bit encoding" stdout &&
1286 egrep "Content|MIME" msgtxt1 >actual &&
1287 test_cmp content-type-decl actual
1290 test_expect_success
$PREREQ 'sendemail.8bitEncoding works' '
1291 clean_fake_sendmail &&
1292 git config sendemail.assume8bitEncoding UTF-8 &&
1294 git send-email --from=author@example.com --to=nobody@example.com \
1295 --smtp-server="$(pwd)/fake.sendmail" \
1296 email-using-8bit >stdout &&
1297 egrep "Content|MIME" msgtxt1 >actual &&
1298 test_cmp content-type-decl actual
1301 test_expect_success
$PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
1302 clean_fake_sendmail &&
1303 git config sendemail.assume8bitEncoding "bogus too" &&
1305 git send-email --from=author@example.com --to=nobody@example.com \
1306 --smtp-server="$(pwd)/fake.sendmail" \
1307 --8bit-encoding=UTF-8 \
1308 email-using-8bit >stdout &&
1309 egrep "Content|MIME" msgtxt1 >actual &&
1310 test_cmp content-type-decl actual
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: Dieser Betreff enthält auch einen Umlaut!
1321 Nothing to see here.
1325 test_expect_success
$PREREQ 'setup expect' '
1326 cat >expected <<-\EOF
1327 Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
1331 test_expect_success
$PREREQ '--8bit-encoding also treats subject' '
1332 clean_fake_sendmail &&
1334 git send-email --from=author@example.com --to=nobody@example.com \
1335 --smtp-server="$(pwd)/fake.sendmail" \
1336 --8bit-encoding=UTF-8 \
1337 email-using-8bit >stdout &&
1338 grep "Subject" msgtxt1 >actual &&
1339 test_cmp expected actual
1342 test_expect_success
$PREREQ 'setup expect' '
1343 cat >email-using-8bit <<-\EOF
1344 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1345 Message-Id: <bogus-message-id@example.com>
1346 From: A U Thor <author@example.com>
1347 Date: Sat, 12 Jun 2010 15:53:58 +0200
1348 Content-Type: text/plain; charset=UTF-8
1349 Subject: Nothing to see here.
1351 Dieser Betreff enthält auch einen Umlaut!
1355 test_expect_success
$PREREQ 'sendemail.transferencoding=7bit fails on 8bit data' '
1356 clean_fake_sendmail &&
1357 git config sendemail.transferEncoding 7bit &&
1358 test_must_fail git send-email \
1359 --transfer-encoding=7bit \
1360 --smtp-server="$(pwd)/fake.sendmail" \
1363 grep "cannot send message as 7bit" errors &&
1364 test -z "$(ls msgtxt*)"
1367 test_expect_success
$PREREQ '--transfer-encoding overrides sendemail.transferEncoding' '
1368 clean_fake_sendmail &&
1369 git config sendemail.transferEncoding 8bit &&
1370 test_must_fail git send-email \
1371 --transfer-encoding=7bit \
1372 --smtp-server="$(pwd)/fake.sendmail" \
1375 grep "cannot send message as 7bit" errors &&
1376 test -z "$(ls msgtxt*)"
1379 test_expect_success
$PREREQ 'sendemail.transferencoding=8bit' '
1380 clean_fake_sendmail &&
1382 --transfer-encoding=8bit \
1383 --smtp-server="$(pwd)/fake.sendmail" \
1386 sed '1,/^$
/d
' msgtxt1 >actual &&
1387 sed '1,/^$
/d
' email-using-8bit >expected &&
1388 test_cmp expected actual
1391 test_expect_success
$PREREQ 'setup expect' '
1392 cat >expected <<-\EOF
1393 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1397 test_expect_success
$PREREQ '8-bit and sendemail.transferencoding=quoted-printable' '
1398 clean_fake_sendmail &&
1400 --transfer-encoding=quoted-printable \
1401 --smtp-server="$(pwd)/fake.sendmail" \
1404 sed '1,/^$
/d
' msgtxt1 >actual &&
1405 test_cmp expected actual
1408 test_expect_success
$PREREQ 'setup expect' '
1409 cat >expected <<-\EOF
1410 RGllc2VyIEJldHJlZmYgZW50aMOkbHQgYXVjaCBlaW5lbiBVbWxhdXQhCg==
1414 test_expect_success
$PREREQ '8-bit and sendemail.transferencoding=base64' '
1415 clean_fake_sendmail &&
1417 --transfer-encoding=base64 \
1418 --smtp-server="$(pwd)/fake.sendmail" \
1421 sed '1,/^$
/d
' msgtxt1 >actual &&
1422 test_cmp expected actual
1425 test_expect_success
$PREREQ 'setup expect' '
1426 cat >email-using-qp <<-\EOF
1427 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1428 Message-Id: <bogus-message-id@example.com>
1429 From: A U Thor <author@example.com>
1430 Date: Sat, 12 Jun 2010 15:53:58 +0200
1432 Content-Transfer-Encoding: quoted-printable
1433 Content-Type: text/plain; charset=UTF-8
1434 Subject: Nothing to see here.
1436 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1440 test_expect_success
$PREREQ 'convert from quoted-printable to base64' '
1441 clean_fake_sendmail &&
1443 --transfer-encoding=base64 \
1444 --smtp-server="$(pwd)/fake.sendmail" \
1447 sed '1,/^$
/d
' msgtxt1 >actual &&
1448 test_cmp expected actual
1451 test_expect_success
$PREREQ 'setup expect' "
1452 tr -d '\\015' | tr '%' '\\015' >email-using-crlf <<EOF
1453 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1454 Message-Id: <bogus-message-id@example.com>
1455 From: A U Thor <author@example.com>
1456 Date: Sat, 12 Jun 2010 15:53:58 +0200
1457 Content-Type: text/plain; charset=UTF-8
1458 Subject: Nothing to see here.
1460 Look, I have a CRLF and an = sign!%
1464 test_expect_success
$PREREQ 'setup expect' '
1465 cat >expected <<-\EOF
1466 Look, I have a CRLF and an =3D sign!=0D
1470 test_expect_success
$PREREQ 'CRLF and sendemail.transferencoding=quoted-printable' '
1471 clean_fake_sendmail &&
1473 --transfer-encoding=quoted-printable \
1474 --smtp-server="$(pwd)/fake.sendmail" \
1477 sed '1,/^$
/d
' msgtxt1 >actual &&
1478 test_cmp expected actual
1481 test_expect_success
$PREREQ 'setup expect' '
1482 cat >expected <<-\EOF
1483 TG9vaywgSSBoYXZlIGEgQ1JMRiBhbmQgYW4gPSBzaWduIQ0K
1487 test_expect_success
$PREREQ 'CRLF and sendemail.transferencoding=base64' '
1488 clean_fake_sendmail &&
1490 --transfer-encoding=base64 \
1491 --smtp-server="$(pwd)/fake.sendmail" \
1494 sed '1,/^$
/d
' msgtxt1 >actual &&
1495 test_cmp expected actual
1499 # Note that the patches in this test are deliberately out of order; we
1500 # want to make sure it works even if the cover-letter is not in the
1502 test_expect_success
$PREREQ 'refusing to send cover letter template' '
1503 clean_fake_sendmail &&
1505 git format-patch --cover-letter -2 -o outdir &&
1506 test_must_fail git send-email \
1507 --from="Example <nobody@example.com>" \
1508 --to=nobody@example.com \
1509 --smtp-server="$(pwd)/fake.sendmail" \
1510 outdir/0002-*.patch \
1511 outdir/0000-*.patch \
1512 outdir/0001-*.patch \
1514 grep "SUBJECT HERE" errors &&
1515 test -z "$(ls msgtxt*)"
1518 test_expect_success
$PREREQ '--force sends cover letter template anyway' '
1519 clean_fake_sendmail &&
1521 git format-patch --cover-letter -2 -o outdir &&
1524 --from="Example <nobody@example.com>" \
1525 --to=nobody@example.com \
1526 --smtp-server="$(pwd)/fake.sendmail" \
1527 outdir/0002-*.patch \
1528 outdir/0000-*.patch \
1529 outdir/0001-*.patch \
1531 ! grep "SUBJECT HERE" errors &&
1532 test -n "$(ls msgtxt*)"
1535 test_cover_addresses
() {
1538 clean_fake_sendmail
&&
1540 git format-patch
--cover-letter -2 -o outdir
&&
1541 cover
=$
(echo outdir
/0000-*.
patch) &&
1542 mv $cover cover-to-edit.
patch &&
1543 perl
-pe "s/^From:/$header: extra\@address.com\nFrom:/" cover-to-edit.
patch >"$cover" &&
1546 --from="Example <nobody@example.com>" \
1549 --smtp-server="$(pwd)/fake.sendmail" \
1550 outdir
/0000-*.
patch \
1551 outdir
/0001-*.
patch \
1552 outdir
/0002-*.
patch \
1554 grep "^$header: extra@address.com" msgtxt1
>to1
&&
1555 grep "^$header: extra@address.com" msgtxt2
>to2
&&
1556 grep "^$header: extra@address.com" msgtxt3
>to3
&&
1557 test_line_count
= 1 to1
&&
1558 test_line_count
= 1 to2
&&
1559 test_line_count
= 1 to3
1562 test_expect_success
$PREREQ 'to-cover adds To to all mail' '
1563 test_cover_addresses "To" --to-cover
1566 test_expect_success
$PREREQ 'cc-cover adds Cc to all mail' '
1567 test_cover_addresses "Cc" --cc-cover
1570 test_expect_success
$PREREQ 'tocover adds To to all mail' '
1571 test_config sendemail.tocover true &&
1572 test_cover_addresses "To"
1575 test_expect_success
$PREREQ 'cccover adds Cc to all mail' '
1576 test_config sendemail.cccover true &&
1577 test_cover_addresses "Cc"
1580 test_expect_success
$PREREQ 'escaped quotes in sendemail.aliasfiletype=mutt' '
1581 clean_fake_sendmail &&
1582 echo "alias sbd \\\"Dot U. Sir\\\" <somebody@example.org>" >.mutt &&
1583 git config --replace-all sendemail.aliasesfile "$(pwd)/.mutt" &&
1584 git config sendemail.aliasfiletype mutt &&
1586 --from="Example <nobody@example.com>" \
1588 --smtp-server="$(pwd)/fake.sendmail" \
1589 outdir/0001-*.patch \
1591 grep "^!somebody@example\.org!$" commandline1 &&
1592 grep -F "To: \"Dot U. Sir\" <somebody@example.org>" out
1595 test_expect_success
$PREREQ 'sendemail.aliasfiletype=mailrc' '
1596 clean_fake_sendmail &&
1597 echo "alias sbd somebody@example.org" >.mailrc &&
1598 git config --replace-all sendemail.aliasesfile "$(pwd)/.mailrc" &&
1599 git config sendemail.aliasfiletype mailrc &&
1601 --from="Example <nobody@example.com>" \
1603 --smtp-server="$(pwd)/fake.sendmail" \
1604 outdir/0001-*.patch \
1606 grep "^!somebody@example\.org!$" commandline1
1609 test_expect_success
$PREREQ 'sendemail.aliasfile=~/.mailrc' '
1610 clean_fake_sendmail &&
1611 echo "alias sbd someone@example.org" >"$HOME/.mailrc" &&
1612 git config --replace-all sendemail.aliasesfile "~/.mailrc" &&
1613 git config sendemail.aliasfiletype mailrc &&
1615 --from="Example <nobody@example.com>" \
1617 --smtp-server="$(pwd)/fake.sendmail" \
1618 outdir/0001-*.patch \
1620 grep "^!someone@example\.org!$" commandline1
1623 test_dump_aliases
() {
1624 msg
="$1" && shift &&
1625 filetype
="$1" && shift &&
1626 printf '%s\n' "$@" >expect
&&
1627 cat >.tmp-email-aliases
&&
1629 test_expect_success
$PREREQ "$msg" '
1630 clean_fake_sendmail && rm -fr outdir &&
1631 git config --replace-all sendemail.aliasesfile \
1632 "$(pwd)/.tmp-email-aliases" &&
1633 git config sendemail.aliasfiletype "$filetype" &&
1634 git send-email --dump-aliases 2>errors >actual &&
1635 test_cmp expect actual
1639 test_dump_aliases
'--dump-aliases sendmail format' \
1646 alice: Alice W Land <awol@example.com>
1647 bob: Robert Bobbyton <bob@example.com>
1648 chloe: chloe@example.com
1650 bcgrp: bob, chloe, Other <o@example.com>
1653 test_dump_aliases '--dump-aliases mutt format' \
1659 alias alice Alice W Land <awol@example.com>
1660 alias donald Donald C Carlton <donc@example.com>
1661 alias bob Robert Bobbyton <bob@example.com>
1662 alias chloe chloe@example.com
1665 test_dump_aliases '--dump-aliases mailrc format' \
1671 alias alice Alice W Land <awol@example.com>
1672 alias eve Eve <eve@example.com>
1673 alias bob Robert Bobbyton <bob@example.com>
1674 alias chloe chloe@example.com
1677 test_dump_aliases '--dump-aliases pine format' \
1683 alice Alice W Land <awol@example.com>
1684 eve Eve <eve@example.com>
1685 bob Robert Bobbyton <bob@example.com>
1686 chloe chloe@example.com
1689 test_dump_aliases '--dump-aliases gnus format' \
1695 (define-mail-alias "alice" "awol@example.com")
1696 (define-mail-alias "eve" "eve@example.com")
1697 (define-mail-alias "bob" "bob@example.com")
1698 (define-mail-alias "chloe" "chloe@example.com")
1701 test_expect_success '--dump-aliases must be used alone' '
1702 test_must_fail git send-email --dump-aliases --to=janice@example.com -1 refs/heads/accounting
1705 test_sendmail_aliases () {
1706 msg="$1" && shift &&
1708 cat >.tmp-email-aliases &&
1710 test_expect_success $PREREQ "$msg" '
1711 clean_fake_sendmail && rm -fr outdir &&
1712 git format-patch -1 -o outdir &&
1713 git config --replace-all sendemail.aliasesfile \
1714 "$(pwd)/.tmp-email-aliases" &&
1715 git config sendemail.aliasfiletype sendmail &&
1717 --from="Example <nobody@example.com>" \
1718 --to=alice --to=bcgrp \
1719 --smtp-server="$(pwd)/fake.sendmail" \
1720 outdir/0001-*.
patch \
1724 grep "^!$i!$" commandline1 ||
return 1
1729 test_sendmail_aliases 'sendemail.aliasfiletype
=sendmail
' \
1730 'awol@example\.com
' \
1731 'bob@example\.com
' \
1732 'chloe@example\.com
' \
1733 'o@example\.com
' <<-\EOF
1734 alice: Alice W Land <awol@example.com>
1735 bob: Robert Bobbyton <bob@example.com>
1737 # this is also a comment
1738 chloe: chloe@example.com
1740 bcgrp: bob, chloe, Other <o@example.com>
1743 test_sendmail_aliases 'sendmail aliases line folding
' \
1747 darla1 darla2 darla3 \
1748 elton1 elton2 elton3 \
1765 bcgrp: bob, chuck, darla, elton, fred, greg
1768 test_sendmail_aliases 'sendmail aliases tolerate bogus line folding
' \
1774 test_sendmail_aliases 'sendmail aliases empty
' alice bcgrp <<-\EOF
1777 test_expect_success $PREREQ 'alias support
in To header
' '
1778 clean_fake_sendmail
&&
1779 echo "alias sbd someone@example.org" >.mailrc
&&
1780 test_config sendemail.aliasesfile
".mailrc" &&
1781 test_config sendemail.aliasfiletype mailrc
&&
1782 git format-patch
--stdout -1 --to=sbd
>aliased.
patch &&
1784 --from="Example <nobody@example.com>" \
1785 --smtp-server="$(pwd)/fake.sendmail" \
1788 grep "^!someone@example\.org!$" commandline1
1791 test_expect_success $PREREQ 'alias support
in Cc header
' '
1792 clean_fake_sendmail
&&
1793 echo "alias sbd someone@example.org" >.mailrc
&&
1794 test_config sendemail.aliasesfile
".mailrc" &&
1795 test_config sendemail.aliasfiletype mailrc
&&
1796 git format-patch
--stdout -1 --cc=sbd
>aliased.
patch &&
1798 --from="Example <nobody@example.com>" \
1799 --smtp-server="$(pwd)/fake.sendmail" \
1802 grep "^!someone@example\.org!$" commandline1
1805 test_expect_success $PREREQ 'tocmd works with aliases
' '
1806 clean_fake_sendmail
&&
1807 echo "alias sbd someone@example.org" >.mailrc
&&
1808 test_config sendemail.aliasesfile
".mailrc" &&
1809 test_config sendemail.aliasfiletype mailrc
&&
1810 git format-patch
--stdout -1 >tocmd.
patch &&
1811 echo tocmd--sbd
>>tocmd.
patch &&
1813 --from="Example <nobody@example.com>" \
1814 --to-cmd=.
/tocmd-sed \
1815 --smtp-server="$(pwd)/fake.sendmail" \
1818 grep "^!someone@example\.org!$" commandline1
1821 test_expect_success $PREREQ 'cccmd works with aliases
' '
1822 clean_fake_sendmail
&&
1823 echo "alias sbd someone@example.org" >.mailrc
&&
1824 test_config sendemail.aliasesfile
".mailrc" &&
1825 test_config sendemail.aliasfiletype mailrc
&&
1826 git format-patch
--stdout -1 >cccmd.
patch &&
1827 echo cccmd--sbd
>>cccmd.
patch &&
1829 --from="Example <nobody@example.com>" \
1830 --cc-cmd=.
/cccmd-sed \
1831 --smtp-server="$(pwd)/fake.sendmail" \
1834 grep "^!someone@example\.org!$" commandline1
1837 do_xmailer_test () {
1838 expected=$1 params=$2 &&
1839 git format-patch -1 &&
1841 --from="Example <nobody@example.com>" \
1842 --to=someone@example.com \
1843 --smtp-server="$(pwd)/fake.sendmail" \
1847 { grep '^X-Mailer
:' out || :; } >mailer &&
1848 test_line_count = $expected mailer
1851 test_expect_success $PREREQ '--[no-
]xmailer without any configuration
' '
1852 do_xmailer_test
1 "--xmailer" &&
1853 do_xmailer_test
0 "--no-xmailer"
1856 test_expect_success $PREREQ '--[no-
]xmailer with sendemail.xmailer
=true
' '
1857 test_config sendemail.xmailer true
&&
1858 do_xmailer_test
1 "" &&
1859 do_xmailer_test
0 "--no-xmailer" &&
1860 do_xmailer_test
1 "--xmailer"
1863 test_expect_success $PREREQ '--[no-
]xmailer with sendemail.xmailer
=false
' '
1864 test_config sendemail.xmailer false
&&
1865 do_xmailer_test
0 "" &&
1866 do_xmailer_test
0 "--no-xmailer" &&
1867 do_xmailer_test
1 "--xmailer"
1870 test_expect_success $PREREQ 'setup expected-list
' '
1873 --from="Example <from@example.com>" \
1874 --to="To 1 <to1@example.com>" \
1875 --to="to2@example.com" \
1876 --to="to3@example.com" \
1877 --cc="Cc 1 <cc1@example.com>" \
1878 --cc="Cc2 <cc2@example.com>" \
1879 --bcc="bcc1@example.com" \
1880 --bcc="bcc2@example.com" \
1881 0001-add-master.
patch | replace_variable_fields \
1885 test_expect_success $PREREQ 'use email list
in --cc --to and
--bcc' '
1888 --from="Example <from@example.com>" \
1889 --to="To 1 <to1@example.com>, to2@example.com" \
1890 --to="to3@example.com" \
1891 --cc="Cc 1 <cc1@example.com>, Cc2 <cc2@example.com>" \
1892 --bcc="bcc1@example.com, bcc2@example.com" \
1893 0001-add-master.
patch | replace_variable_fields \
1895 test_cmp expected-list actual-list
1898 test_expect_success $PREREQ 'aliases work with email list
' '
1899 echo "alias to2 to2@example.com" >.mutt
&&
1900 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt
&&
1901 test_config sendemail.aliasesfile
".mutt" &&
1902 test_config sendemail.aliasfiletype mutt
&&
1905 --from="Example <from@example.com>" \
1906 --to="To 1 <to1@example.com>, to2, to3@example.com" \
1907 --cc="cc1, Cc2 <cc2@example.com>" \
1908 --bcc="bcc1@example.com, bcc2@example.com" \
1909 0001-add-master.
patch | replace_variable_fields \
1911 test_cmp expected-list actual-list
1914 test_expect_success $PREREQ 'leading and trailing whitespaces are removed
' '
1915 echo "alias to2 to2@example.com" >.mutt
&&
1916 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt
&&
1917 test_config sendemail.aliasesfile
".mutt" &&
1918 test_config sendemail.aliasfiletype mutt
&&
1919 TO1
=$
(echo "QTo 1 <to1@example.com>" | q_to_tab
) &&
1920 TO2
=$
(echo "QZto2" | qz_to_tab_space
) &&
1921 CC1
=$
(echo "cc1" | append_cr
) &&
1922 BCC1
=$
(echo "Q bcc1@example.com Q" | q_to_nul
) &&
1925 --from=" Example <from@example.com>" \
1928 --to=" to3@example.com " \
1930 --cc="Cc2 <cc2@example.com>" \
1932 --bcc="bcc2@example.com" \
1933 0001-add-master.
patch | replace_variable_fields \
1935 test_cmp expected-list actual-list
1938 test_expect_success $PREREQ 'invoke hook
' '
1939 mkdir
-p .git
/hooks
&&
1941 write_script .git
/hooks
/sendemail-validate
<<-\EOF &&
1942 # test that we have the correct environment variable, pwd, and
1952 test -f 0001-add-master.patch &&
1953 grep "add master" "$1"
1958 # Test that it works even if we are not at the root of the
1962 --from="Example <nobody@example.com>" \
1963 --to=nobody@example.com \
1964 --smtp-server="$(pwd)/../fake.sendmail" \
1965 ../0001-add-master.patch &&
1967 # Verify error message when a patch is rejected by the hook
1968 sed -e "s/add master/x/" ../0001-add-master.patch >../another.patch &&
1970 --from="Example <nobody@example.com>" \
1971 --to=nobody@example.com \
1972 --smtp-server="$(pwd)/../fake.sendmail" \
1973 ../another.patch 2>err
1974 test_i18ngrep "rejected by sendemail-validate hook" err
1978 test_expect_success $PREREQ 'test that send-email works outside a repo' '
1979 nongit git send-email \
1980 --from="Example <nobody@example.com>" \
1981 --to=nobody@example.com \
1982 --smtp-server="$(pwd)/fake.sendmail" \
1983 "$(pwd)/0001-add-master.patch"