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>
232 test_suppress_self
() {
234 test_when_finished
"git reset --hard HEAD^" &&
236 write_script cccmd-sed
<<-EOF &&
237 sed -n -e s/^cccmd--//p "\$1"
240 git commit
--amend --author="$1 <$2>" -F - &&
241 clean_fake_sendmail
&&
242 git format-patch
--stdout -1 >"suppress-self-$3.patch" &&
244 git send-email
--from="$1 <$2>" \
245 --to=nobody@example.com \
246 --cc-cmd=.
/cccmd-sed \
248 --smtp-server="$(pwd)/fake.sendmail" \
249 suppress-self-
$3.
patch &&
251 mv msgtxt1 msgtxt1-
$3 &&
252 sed -e '/^$/q' msgtxt1-
$3 >"msghdr1-$3" &&
253 >"expected-no-cc-$3" &&
255 (grep '^Cc:' msghdr1-
$3 >"actual-no-cc-$3";
256 test_cmp expected-no-cc-
$3 actual-no-cc-
$3)
259 test_suppress_self_unquoted
() {
260 test_suppress_self
"$1" "$2" "unquoted-$3" <<-EOF
261 test suppress-cc.self unquoted-$3 with name $1 email $2
268 Signed-off-by: $1 <$2>
272 test_suppress_self_quoted
() {
273 test_suppress_self
"$1" "$2" "quoted-$3" <<-EOF
274 test suppress-cc.self quoted-$3 with name $1 email $2
282 Signed-off-by: $1 <$2>
283 Signed-off-by: "$1" <$2>
287 test_expect_success
$PREREQ 'self name is suppressed' "
288 test_suppress_self_unquoted 'A U Thor' 'author@example.com' \
289 'self_name_suppressed'
292 test_expect_success
$PREREQ 'self name with dot is suppressed' "
293 test_suppress_self_quoted 'A U. Thor' 'author@example.com' \
294 'self_name_dot_suppressed'
297 test_expect_success
$PREREQ 'non-ascii self name is suppressed' "
298 test_suppress_self_quoted 'Füñný Nâmé' 'odd_?=mail@example.com' \
299 'non_ascii_self_suppressed'
302 # This name is long enough to force format-patch to split it into multiple
303 # encoded-words, assuming it uses UTF-8 with the "Q" encoding.
304 test_expect_success
$PREREQ 'long non-ascii self name is suppressed' "
305 test_suppress_self_quoted 'Ƒüñníęř €. Nâṁé' 'odd_?=mail@example.com' \
306 'long_non_ascii_self_suppressed'
309 test_expect_success
$PREREQ 'sanitized self name is suppressed' "
310 test_suppress_self_unquoted '\"A U. Thor\"' 'author@example.com' \
311 'self_name_sanitized_suppressed'
314 test_expect_success
$PREREQ 'Show all headers' '
318 --from="Example <from@example.com>" \
319 --to=to@example.com \
320 --cc=cc@example.com \
321 --bcc=bcc@example.com \
322 --in-reply-to="<unique-message-id@example.com>" \
323 --smtp-server relay.example.com \
324 $patches | replace_variable_fields \
325 >actual-show-all-headers &&
326 test_cmp expected-show-all-headers actual-show-all-headers
329 test_expect_success
$PREREQ 'Prompting works' '
330 clean_fake_sendmail &&
331 (echo "to@example.com"
333 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
334 --smtp-server="$(pwd)/fake.sendmail" \
337 grep "^From: A U Thor <author@example.com>\$" msgtxt1 &&
338 grep "^To: to@example.com\$" msgtxt1
341 test_expect_success
$PREREQ,AUTOIDENT
'implicit ident is allowed' '
342 clean_fake_sendmail &&
343 (sane_unset GIT_AUTHOR_NAME &&
344 sane_unset GIT_AUTHOR_EMAIL &&
345 sane_unset GIT_COMMITTER_NAME &&
346 sane_unset GIT_COMMITTER_EMAIL &&
347 GIT_SEND_EMAIL_NOTTY=1 git send-email \
348 --smtp-server="$(pwd)/fake.sendmail" \
349 --to=to@example.com \
350 $patches </dev/null 2>errors
354 test_expect_success
$PREREQ,!AUTOIDENT
'broken implicit ident aborts send-email' '
355 clean_fake_sendmail &&
356 (sane_unset GIT_AUTHOR_NAME &&
357 sane_unset GIT_AUTHOR_EMAIL &&
358 sane_unset GIT_COMMITTER_NAME &&
359 sane_unset GIT_COMMITTER_EMAIL &&
360 GIT_SEND_EMAIL_NOTTY=1 && export GIT_SEND_EMAIL_NOTTY &&
361 test_must_fail git send-email \
362 --smtp-server="$(pwd)/fake.sendmail" \
363 --to=to@example.com \
364 $patches </dev/null 2>errors &&
365 test_i18ngrep "tell me who you are" errors
369 test_expect_success
$PREREQ 'setup tocmd and cccmd scripts' '
370 write_script tocmd-sed <<-\EOF &&
371 sed -n -e "s/^tocmd--//p" "$1"
373 write_script cccmd-sed <<-\EOF
374 sed -n -e "s/^cccmd--//p" "$1"
378 test_expect_success
$PREREQ 'tocmd works' '
379 clean_fake_sendmail &&
380 cp $patches tocmd.patch &&
381 echo tocmd--tocmd@example.com >>tocmd.patch &&
383 --from="Example <nobody@example.com>" \
384 --to-cmd=./tocmd-sed \
385 --smtp-server="$(pwd)/fake.sendmail" \
388 grep "^To: tocmd@example.com" msgtxt1
391 test_expect_success
$PREREQ 'cccmd works' '
392 clean_fake_sendmail &&
393 cp $patches cccmd.patch &&
394 echo "cccmd-- cccmd@example.com" >>cccmd.patch &&
396 --from="Example <nobody@example.com>" \
397 --to=nobody@example.com \
398 --cc-cmd=./cccmd-sed \
399 --smtp-server="$(pwd)/fake.sendmail" \
402 grep "^ cccmd@example.com" msgtxt1
405 test_expect_success
$PREREQ 'reject long lines' '
407 z64=$z8$z8$z8$z8$z8$z8$z8$z8 &&
408 z512=$z64$z64$z64$z64$z64$z64$z64$z64 &&
409 clean_fake_sendmail &&
410 cp $patches longline.patch &&
411 echo $z512$z512 >>longline.patch &&
412 test_must_fail git send-email \
413 --from="Example <nobody@example.com>" \
414 --to=nobody@example.com \
415 --smtp-server="$(pwd)/fake.sendmail" \
416 $patches longline.patch \
418 grep longline.patch errors
421 test_expect_success
$PREREQ 'no patch was sent' '
422 ! test -e commandline1
425 test_expect_success
$PREREQ 'Author From: in message body' '
426 clean_fake_sendmail &&
428 --from="Example <nobody@example.com>" \
429 --to=nobody@example.com \
430 --smtp-server="$(pwd)/fake.sendmail" \
432 sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
433 grep "From: A <author@example.com>" msgbody1
436 test_expect_success
$PREREQ 'Author From: not in message body' '
437 clean_fake_sendmail &&
439 --from="A <author@example.com>" \
440 --to=nobody@example.com \
441 --smtp-server="$(pwd)/fake.sendmail" \
443 sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
444 ! grep "From: A <author@example.com>" msgbody1
447 test_expect_success
$PREREQ 'allow long lines with --no-validate' '
449 --from="Example <nobody@example.com>" \
450 --to=nobody@example.com \
451 --smtp-server="$(pwd)/fake.sendmail" \
453 $patches longline.patch \
457 test_expect_success
$PREREQ 'Invalid In-Reply-To' '
458 clean_fake_sendmail &&
460 --from="Example <nobody@example.com>" \
461 --to=nobody@example.com \
463 --smtp-server="$(pwd)/fake.sendmail" \
466 ! grep "^In-Reply-To: < *>" msgtxt1
469 test_expect_success
$PREREQ 'Valid In-Reply-To when prompting' '
470 clean_fake_sendmail &&
471 (echo "From Example <from@example.com>"
472 echo "To Example <to@example.com>"
474 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
475 --smtp-server="$(pwd)/fake.sendmail" \
477 ! grep "^In-Reply-To: < *>" msgtxt1
480 test_expect_success
$PREREQ 'In-Reply-To without --chain-reply-to' '
481 clean_fake_sendmail &&
482 echo "<unique-message-id@example.com>" >expect &&
484 --from="Example <nobody@example.com>" \
485 --to=nobody@example.com \
486 --no-chain-reply-to \
487 --in-reply-to="$(cat expect)" \
488 --smtp-server="$(pwd)/fake.sendmail" \
489 $patches $patches $patches \
491 # The first message is a reply to --in-reply-to
492 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
493 test_cmp expect actual &&
494 # Second and subsequent messages are replies to the first one
495 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
496 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
497 test_cmp expect actual &&
498 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
499 test_cmp expect actual
502 test_expect_success
$PREREQ 'In-Reply-To with --chain-reply-to' '
503 clean_fake_sendmail &&
504 echo "<unique-message-id@example.com>" >expect &&
506 --from="Example <nobody@example.com>" \
507 --to=nobody@example.com \
509 --in-reply-to="$(cat expect)" \
510 --smtp-server="$(pwd)/fake.sendmail" \
511 $patches $patches $patches \
513 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
514 test_cmp expect actual &&
515 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
516 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
517 test_cmp expect actual &&
518 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt2 >expect &&
519 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
520 test_cmp expect actual
523 test_expect_success
$PREREQ 'setup fake editor' '
524 write_script fake-editor <<-\EOF
525 echo fake edit >>"$1"
529 test_set_editor
"$(pwd)/fake-editor"
531 test_expect_success
$PREREQ '--compose works' '
532 clean_fake_sendmail &&
534 --compose --subject foo \
535 --from="Example <nobody@example.com>" \
536 --to=nobody@example.com \
537 --smtp-server="$(pwd)/fake.sendmail" \
542 test_expect_success
$PREREQ 'first message is compose text' '
543 grep "^fake edit" msgtxt1
546 test_expect_success
$PREREQ 'second message is patch' '
547 grep "Subject:.*Second" msgtxt2
550 test_expect_success
$PREREQ 'setup expect' "
551 cat >expected-suppress-sob <<\EOF
553 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
554 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
555 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
557 Server: relay.example.com
558 MAIL FROM:<from@example.com>
559 RCPT TO:<to@example.com>
560 RCPT TO:<cc@example.com>
561 RCPT TO:<author@example.com>
562 RCPT TO:<one@example.com>
563 RCPT TO:<two@example.com>
564 From: Example <from@example.com>
567 A <author@example.com>,
568 One <one@example.com>,
570 Subject: [PATCH 1/1] Second.
572 Message-Id: MESSAGE-ID-STRING
573 X-Mailer: X-MAILER-STRING
579 test_suppression
() {
582 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
583 --from="Example <from@example.com>" \
584 --to=to@example.com \
585 --smtp-server relay.example.com \
586 $patches | replace_variable_fields \
587 >actual-suppress-
$1${2+"-$2"} &&
588 test_cmp expected-suppress-
$1${2+"-$2"} actual-suppress-
$1${2+"-$2"}
591 test_expect_success
$PREREQ 'sendemail.cc set' '
592 git config sendemail.cc cc@example.com &&
596 test_expect_success
$PREREQ 'setup expect' "
597 cat >expected-suppress-sob <<\EOF
599 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
600 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
601 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
603 Server: relay.example.com
604 MAIL FROM:<from@example.com>
605 RCPT TO:<to@example.com>
606 RCPT TO:<author@example.com>
607 RCPT TO:<one@example.com>
608 RCPT TO:<two@example.com>
609 From: Example <from@example.com>
611 Cc: A <author@example.com>,
612 One <one@example.com>,
614 Subject: [PATCH 1/1] Second.
616 Message-Id: MESSAGE-ID-STRING
617 X-Mailer: X-MAILER-STRING
623 test_expect_success
$PREREQ 'sendemail.cc unset' '
624 git config --unset sendemail.cc &&
628 test_expect_success
$PREREQ 'setup expect' "
629 cat >expected-suppress-cccmd <<\EOF
631 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
632 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
633 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
634 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
636 Server: relay.example.com
637 MAIL FROM:<from@example.com>
638 RCPT TO:<to@example.com>
639 RCPT TO:<author@example.com>
640 RCPT TO:<one@example.com>
641 RCPT TO:<two@example.com>
642 RCPT TO:<committer@example.com>
643 From: Example <from@example.com>
645 Cc: A <author@example.com>,
646 One <one@example.com>,
648 C O Mitter <committer@example.com>
649 Subject: [PATCH 1/1] Second.
651 Message-Id: MESSAGE-ID-STRING
652 X-Mailer: X-MAILER-STRING
658 test_expect_success
$PREREQ 'sendemail.cccmd' '
659 write_script cccmd <<-\EOF &&
660 echo cc-cmd@example.com
662 git config sendemail.cccmd ./cccmd &&
663 test_suppression cccmd
666 test_expect_success
$PREREQ 'setup expect' '
667 cat >expected-suppress-all <<\EOF
670 Server: relay.example.com
671 MAIL FROM:<from@example.com>
672 RCPT TO:<to@example.com>
673 From: Example <from@example.com>
675 Subject: [PATCH 1/1] Second.
677 Message-Id: MESSAGE-ID-STRING
678 X-Mailer: X-MAILER-STRING
684 test_expect_success
$PREREQ '--suppress-cc=all' '
688 test_expect_success
$PREREQ 'setup expect' "
689 cat >expected-suppress-body <<\EOF
691 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
692 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
693 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
694 (cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
696 Server: relay.example.com
697 MAIL FROM:<from@example.com>
698 RCPT TO:<to@example.com>
699 RCPT TO:<author@example.com>
700 RCPT TO:<one@example.com>
701 RCPT TO:<two@example.com>
702 RCPT TO:<cc-cmd@example.com>
703 From: Example <from@example.com>
705 Cc: A <author@example.com>,
706 One <one@example.com>,
709 Subject: [PATCH 1/1] Second.
711 Message-Id: MESSAGE-ID-STRING
712 X-Mailer: X-MAILER-STRING
718 test_expect_success
$PREREQ '--suppress-cc=body' '
719 test_suppression body
722 test_expect_success
$PREREQ 'setup expect' "
723 cat >expected-suppress-body-cccmd <<\EOF
725 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
726 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
727 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
729 Server: relay.example.com
730 MAIL FROM:<from@example.com>
731 RCPT TO:<to@example.com>
732 RCPT TO:<author@example.com>
733 RCPT TO:<one@example.com>
734 RCPT TO:<two@example.com>
735 From: Example <from@example.com>
737 Cc: A <author@example.com>,
738 One <one@example.com>,
740 Subject: [PATCH 1/1] Second.
742 Message-Id: MESSAGE-ID-STRING
743 X-Mailer: X-MAILER-STRING
749 test_expect_success
$PREREQ '--suppress-cc=body --suppress-cc=cccmd' '
750 test_suppression body cccmd
753 test_expect_success
$PREREQ 'setup expect' "
754 cat >expected-suppress-sob <<\EOF
756 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
757 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
758 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
760 Server: relay.example.com
761 MAIL FROM:<from@example.com>
762 RCPT TO:<to@example.com>
763 RCPT TO:<author@example.com>
764 RCPT TO:<one@example.com>
765 RCPT TO:<two@example.com>
766 From: Example <from@example.com>
768 Cc: A <author@example.com>,
769 One <one@example.com>,
771 Subject: [PATCH 1/1] Second.
773 Message-Id: MESSAGE-ID-STRING
774 X-Mailer: X-MAILER-STRING
780 test_expect_success
$PREREQ '--suppress-cc=sob' '
781 test_might_fail git config --unset sendemail.cccmd &&
785 test_expect_success
$PREREQ 'setup expect' "
786 cat >expected-suppress-bodycc <<\EOF
788 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
789 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
790 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
791 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
793 Server: relay.example.com
794 MAIL FROM:<from@example.com>
795 RCPT TO:<to@example.com>
796 RCPT TO:<author@example.com>
797 RCPT TO:<one@example.com>
798 RCPT TO:<two@example.com>
799 RCPT TO:<committer@example.com>
800 From: Example <from@example.com>
802 Cc: A <author@example.com>,
803 One <one@example.com>,
805 C O Mitter <committer@example.com>
806 Subject: [PATCH 1/1] Second.
808 Message-Id: MESSAGE-ID-STRING
809 X-Mailer: X-MAILER-STRING
815 test_expect_success
$PREREQ '--suppress-cc=bodycc' '
816 test_suppression bodycc
819 test_expect_success
$PREREQ 'setup expect' "
820 cat >expected-suppress-cc <<\EOF
822 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
823 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
825 Server: relay.example.com
826 MAIL FROM:<from@example.com>
827 RCPT TO:<to@example.com>
828 RCPT TO:<author@example.com>
829 RCPT TO:<committer@example.com>
830 From: Example <from@example.com>
832 Cc: A <author@example.com>,
833 C O Mitter <committer@example.com>
834 Subject: [PATCH 1/1] Second.
836 Message-Id: MESSAGE-ID-STRING
837 X-Mailer: X-MAILER-STRING
843 test_expect_success
$PREREQ '--suppress-cc=cc' '
849 GIT_SEND_EMAIL_NOTTY
=1 \
851 --from="Example <nobody@example.com>" \
852 --to=nobody@example.com \
853 --smtp-server="$(pwd)/fake.sendmail" \
854 $@
$patches >stdout
&&
855 grep "Send this email" stdout
858 test_expect_success
$PREREQ '--confirm=always' '
859 test_confirm --confirm=always --suppress-cc=all
862 test_expect_success
$PREREQ '--confirm=auto' '
863 test_confirm --confirm=auto
866 test_expect_success
$PREREQ '--confirm=cc' '
867 test_confirm --confirm=cc
870 test_expect_success
$PREREQ '--confirm=compose' '
871 test_confirm --confirm=compose --compose
874 test_expect_success
$PREREQ 'confirm by default (due to cc)' '
875 test_when_finished git config sendemail.confirm never &&
876 git config --unset sendemail.confirm &&
880 test_expect_success
$PREREQ 'confirm by default (due to --compose)' '
881 test_when_finished git config sendemail.confirm never &&
882 git config --unset sendemail.confirm &&
883 test_confirm --suppress-cc=all --compose
886 test_expect_success
$PREREQ 'confirm detects EOF (inform assumes y)' '
887 test_when_finished git config sendemail.confirm never &&
888 git config --unset sendemail.confirm &&
890 git format-patch -2 -o outdir &&
891 GIT_SEND_EMAIL_NOTTY=1 \
893 --from="Example <nobody@example.com>" \
894 --to=nobody@example.com \
895 --smtp-server="$(pwd)/fake.sendmail" \
896 outdir/*.patch </dev/null
899 test_expect_success
$PREREQ 'confirm detects EOF (auto causes failure)' '
900 test_when_finished git config sendemail.confirm never &&
901 git config sendemail.confirm auto &&
902 GIT_SEND_EMAIL_NOTTY=1 &&
903 export GIT_SEND_EMAIL_NOTTY &&
904 test_must_fail git send-email \
905 --from="Example <nobody@example.com>" \
906 --to=nobody@example.com \
907 --smtp-server="$(pwd)/fake.sendmail" \
911 test_expect_success
$PREREQ 'confirm does not loop forever' '
912 test_when_finished git config sendemail.confirm never &&
913 git config sendemail.confirm auto &&
914 GIT_SEND_EMAIL_NOTTY=1 &&
915 export GIT_SEND_EMAIL_NOTTY &&
916 yes "bogus" | test_must_fail git send-email \
917 --from="Example <nobody@example.com>" \
918 --to=nobody@example.com \
919 --smtp-server="$(pwd)/fake.sendmail" \
923 test_expect_success
$PREREQ 'utf8 Cc is rfc2047 encoded' '
924 clean_fake_sendmail &&
926 git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
928 --from="Example <nobody@example.com>" \
929 --to=nobody@example.com \
930 --smtp-server="$(pwd)/fake.sendmail" \
933 grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
936 test_expect_success
$PREREQ '--compose adds MIME for utf8 body' '
937 clean_fake_sendmail &&
938 write_script fake-editor-utf8 <<-\EOF &&
939 echo "utf8 body: àéìöú" >>"$1"
941 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
943 --compose --subject foo \
944 --from="Example <nobody@example.com>" \
945 --to=nobody@example.com \
946 --smtp-server="$(pwd)/fake.sendmail" \
948 grep "^utf8 body" msgtxt1 &&
949 grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
952 test_expect_success
$PREREQ '--compose respects user mime type' '
953 clean_fake_sendmail &&
954 write_script fake-editor-utf8-mime <<-\EOF &&
957 Content-Type: text/plain; charset=iso-8859-1
958 Content-Transfer-Encoding: 8bit
964 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
966 --compose --subject foo \
967 --from="Example <nobody@example.com>" \
968 --to=nobody@example.com \
969 --smtp-server="$(pwd)/fake.sendmail" \
971 grep "^utf8 body" msgtxt1 &&
972 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
973 ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
976 test_expect_success
$PREREQ '--compose adds MIME for utf8 subject' '
977 clean_fake_sendmail &&
978 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
980 --compose --subject utf8-sübjëct \
981 --from="Example <nobody@example.com>" \
982 --to=nobody@example.com \
983 --smtp-server="$(pwd)/fake.sendmail" \
985 grep "^fake edit" msgtxt1 &&
986 grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
989 test_expect_success
$PREREQ 'utf8 author is correctly passed on' '
990 clean_fake_sendmail &&
991 test_commit weird_author &&
992 test_when_finished "git reset --hard HEAD^" &&
993 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
994 git format-patch --stdout -1 >funny_name.patch &&
995 git send-email --from="Example <nobody@example.com>" \
996 --to=nobody@example.com \
997 --smtp-server="$(pwd)/fake.sendmail" \
999 grep "^From: Füñný Nâmé <odd_?=mail@example.com>" msgtxt1
1002 test_expect_success
$PREREQ 'utf8 sender is not duplicated' '
1003 clean_fake_sendmail &&
1004 test_commit weird_sender &&
1005 test_when_finished "git reset --hard HEAD^" &&
1006 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
1007 git format-patch --stdout -1 >funny_name.patch &&
1008 git send-email --from="Füñný Nâmé <odd_?=mail@example.com>" \
1009 --to=nobody@example.com \
1010 --smtp-server="$(pwd)/fake.sendmail" \
1012 grep "^From: " msgtxt1 >msgfrom &&
1013 test_line_count = 1 msgfrom
1016 test_expect_success
$PREREQ 'sendemail.composeencoding works' '
1017 clean_fake_sendmail &&
1018 git config sendemail.composeencoding iso-8859-1 &&
1019 write_script fake-editor-utf8 <<-\EOF &&
1020 echo "utf8 body: àéìöú" >>"$1"
1022 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1024 --compose --subject foo \
1025 --from="Example <nobody@example.com>" \
1026 --to=nobody@example.com \
1027 --smtp-server="$(pwd)/fake.sendmail" \
1029 grep "^utf8 body" msgtxt1 &&
1030 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1033 test_expect_success
$PREREQ '--compose-encoding works' '
1034 clean_fake_sendmail &&
1035 write_script fake-editor-utf8 <<-\EOF &&
1036 echo "utf8 body: àéìöú" >>"$1"
1038 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1040 --compose-encoding iso-8859-1 \
1041 --compose --subject foo \
1042 --from="Example <nobody@example.com>" \
1043 --to=nobody@example.com \
1044 --smtp-server="$(pwd)/fake.sendmail" \
1046 grep "^utf8 body" msgtxt1 &&
1047 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1050 test_expect_success
$PREREQ '--compose-encoding overrides sendemail.composeencoding' '
1051 clean_fake_sendmail &&
1052 git config sendemail.composeencoding iso-8859-1 &&
1053 write_script fake-editor-utf8 <<-\EOF &&
1054 echo "utf8 body: àéìöú" >>"$1"
1056 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1058 --compose-encoding iso-8859-2 \
1059 --compose --subject foo \
1060 --from="Example <nobody@example.com>" \
1061 --to=nobody@example.com \
1062 --smtp-server="$(pwd)/fake.sendmail" \
1064 grep "^utf8 body" msgtxt1 &&
1065 grep "^Content-Type: text/plain; charset=iso-8859-2" msgtxt1
1068 test_expect_success
$PREREQ '--compose-encoding adds correct MIME for subject' '
1069 clean_fake_sendmail &&
1070 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
1072 --compose-encoding iso-8859-2 \
1073 --compose --subject utf8-sübjëct \
1074 --from="Example <nobody@example.com>" \
1075 --to=nobody@example.com \
1076 --smtp-server="$(pwd)/fake.sendmail" \
1078 grep "^fake edit" msgtxt1 &&
1079 grep "^Subject: =?iso-8859-2?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
1082 test_expect_success
$PREREQ 'detects ambiguous reference/file conflict' '
1083 echo master >master &&
1085 git commit -m"add master" &&
1086 test_must_fail git send-email --dry-run master 2>errors &&
1087 grep disambiguate errors
1090 test_expect_success
$PREREQ 'feed two files' '
1092 git format-patch -2 -o outdir &&
1095 --from="Example <nobody@example.com>" \
1096 --to=nobody@example.com \
1097 outdir/000?-*.patch 2>errors >out &&
1098 grep "^Subject: " out >subjects &&
1099 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
1100 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"
1103 test_expect_success
$PREREQ 'in-reply-to but no threading' '
1106 --from="Example <nobody@example.com>" \
1107 --to=nobody@example.com \
1108 --in-reply-to="<in-reply-id@example.com>" \
1111 grep "In-Reply-To: <in-reply-id@example.com>"
1114 test_expect_success
$PREREQ 'no in-reply-to and no threading' '
1117 --from="Example <nobody@example.com>" \
1118 --to=nobody@example.com \
1120 $patches $patches >stdout &&
1121 ! grep "In-Reply-To: " stdout
1124 test_expect_success
$PREREQ 'threading but no chain-reply-to' '
1127 --from="Example <nobody@example.com>" \
1128 --to=nobody@example.com \
1130 --no-chain-reply-to \
1131 $patches $patches >stdout &&
1132 grep "In-Reply-To: " stdout
1135 test_expect_success
$PREREQ 'sendemail.to works' '
1136 git config --replace-all sendemail.to "Somebody <somebody@ex.com>" &&
1139 --from="Example <nobody@example.com>" \
1140 $patches $patches >stdout &&
1141 grep "To: Somebody <somebody@ex.com>" stdout
1144 test_expect_success
$PREREQ '--no-to overrides sendemail.to' '
1147 --from="Example <nobody@example.com>" \
1149 --to=nobody@example.com \
1150 $patches $patches >stdout &&
1151 grep "To: nobody@example.com" stdout &&
1152 ! grep "To: Somebody <somebody@ex.com>" stdout
1155 test_expect_success
$PREREQ 'sendemail.cc works' '
1156 git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" &&
1159 --from="Example <nobody@example.com>" \
1160 --to=nobody@example.com \
1161 $patches $patches >stdout &&
1162 grep "Cc: Somebody <somebody@ex.com>" stdout
1165 test_expect_success
$PREREQ '--no-cc overrides sendemail.cc' '
1168 --from="Example <nobody@example.com>" \
1170 --cc=bodies@example.com \
1171 --to=nobody@example.com \
1172 $patches $patches >stdout &&
1173 grep "Cc: bodies@example.com" stdout &&
1174 ! grep "Cc: Somebody <somebody@ex.com>" stdout
1177 test_expect_success
$PREREQ 'sendemail.bcc works' '
1178 git config --replace-all sendemail.bcc "Other <other@ex.com>" &&
1181 --from="Example <nobody@example.com>" \
1182 --to=nobody@example.com \
1183 --smtp-server relay.example.com \
1184 $patches $patches >stdout &&
1185 grep "RCPT TO:<other@ex.com>" stdout
1188 test_expect_success
$PREREQ '--no-bcc overrides sendemail.bcc' '
1191 --from="Example <nobody@example.com>" \
1193 --bcc=bodies@example.com \
1194 --to=nobody@example.com \
1195 --smtp-server relay.example.com \
1196 $patches $patches >stdout &&
1197 grep "RCPT TO:<bodies@example.com>" stdout &&
1198 ! grep "RCPT TO:<other@ex.com>" stdout
1201 test_expect_success
$PREREQ 'patches To headers are used by default' '
1202 patch=$(git format-patch -1 --to="bodies@example.com") &&
1203 test_when_finished "rm $patch" &&
1206 --from="Example <nobody@example.com>" \
1207 --smtp-server relay.example.com \
1209 grep "RCPT TO:<bodies@example.com>" stdout
1212 test_expect_success
$PREREQ 'patches To headers are appended to' '
1213 patch=$(git format-patch -1 --to="bodies@example.com") &&
1214 test_when_finished "rm $patch" &&
1217 --from="Example <nobody@example.com>" \
1218 --to=nobody@example.com \
1219 --smtp-server relay.example.com \
1221 grep "RCPT TO:<bodies@example.com>" stdout &&
1222 grep "RCPT TO:<nobody@example.com>" stdout
1225 test_expect_success
$PREREQ 'To headers from files reset each patch' '
1226 patch1=$(git format-patch -1 --to="bodies@example.com") &&
1227 patch2=$(git format-patch -1 --to="other@example.com" HEAD~) &&
1228 test_when_finished "rm $patch1 && rm $patch2" &&
1231 --from="Example <nobody@example.com>" \
1232 --to="nobody@example.com" \
1233 --smtp-server relay.example.com \
1234 $patch1 $patch2 >stdout &&
1235 test $(grep -c "RCPT TO:<bodies@example.com>" stdout) = 1 &&
1236 test $(grep -c "RCPT TO:<nobody@example.com>" stdout) = 2 &&
1237 test $(grep -c "RCPT TO:<other@example.com>" stdout) = 1
1240 test_expect_success
$PREREQ 'setup expect' '
1241 cat >email-using-8bit <<\EOF
1242 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1243 Message-Id: <bogus-message-id@example.com>
1244 From: author@example.com
1245 Date: Sat, 12 Jun 2010 15:53:58 +0200
1246 Subject: subject goes here
1248 Dieser deutsche Text enthält einen Umlaut!
1252 test_expect_success
$PREREQ 'setup expect' '
1253 echo "Subject: subject goes here" >expected
1256 test_expect_success
$PREREQ 'ASCII subject is not RFC2047 quoted' '
1257 clean_fake_sendmail &&
1259 git send-email --from=author@example.com --to=nobody@example.com \
1260 --smtp-server="$(pwd)/fake.sendmail" \
1261 --8bit-encoding=UTF-8 \
1262 email-using-8bit >stdout &&
1263 grep "Subject" msgtxt1 >actual &&
1264 test_cmp expected actual
1267 test_expect_success
$PREREQ 'setup expect' '
1268 cat >content-type-decl <<-\EOF
1270 Content-Type: text/plain; charset=UTF-8
1271 Content-Transfer-Encoding: 8bit
1275 test_expect_success
$PREREQ 'asks about and fixes 8bit encodings' '
1276 clean_fake_sendmail &&
1278 git send-email --from=author@example.com --to=nobody@example.com \
1279 --smtp-server="$(pwd)/fake.sendmail" \
1280 email-using-8bit >stdout &&
1281 grep "do not declare a Content-Transfer-Encoding" stdout &&
1282 grep email-using-8bit stdout &&
1283 grep "Which 8bit encoding" stdout &&
1284 egrep "Content|MIME" msgtxt1 >actual &&
1285 test_cmp content-type-decl actual
1288 test_expect_success
$PREREQ 'sendemail.8bitEncoding works' '
1289 clean_fake_sendmail &&
1290 git config sendemail.assume8bitEncoding UTF-8 &&
1292 git send-email --from=author@example.com --to=nobody@example.com \
1293 --smtp-server="$(pwd)/fake.sendmail" \
1294 email-using-8bit >stdout &&
1295 egrep "Content|MIME" msgtxt1 >actual &&
1296 test_cmp content-type-decl actual
1299 test_expect_success
$PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
1300 clean_fake_sendmail &&
1301 git config sendemail.assume8bitEncoding "bogus too" &&
1303 git send-email --from=author@example.com --to=nobody@example.com \
1304 --smtp-server="$(pwd)/fake.sendmail" \
1305 --8bit-encoding=UTF-8 \
1306 email-using-8bit >stdout &&
1307 egrep "Content|MIME" msgtxt1 >actual &&
1308 test_cmp content-type-decl actual
1311 test_expect_success
$PREREQ 'setup expect' '
1312 cat >email-using-8bit <<-\EOF
1313 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1314 Message-Id: <bogus-message-id@example.com>
1315 From: author@example.com
1316 Date: Sat, 12 Jun 2010 15:53:58 +0200
1317 Subject: Dieser Betreff enthält auch einen Umlaut!
1319 Nothing to see here.
1323 test_expect_success
$PREREQ 'setup expect' '
1324 cat >expected <<-\EOF
1325 Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
1329 test_expect_success
$PREREQ '--8bit-encoding also treats subject' '
1330 clean_fake_sendmail &&
1332 git send-email --from=author@example.com --to=nobody@example.com \
1333 --smtp-server="$(pwd)/fake.sendmail" \
1334 --8bit-encoding=UTF-8 \
1335 email-using-8bit >stdout &&
1336 grep "Subject" msgtxt1 >actual &&
1337 test_cmp expected actual
1340 test_expect_success
$PREREQ 'setup expect' '
1341 cat >email-using-8bit <<-\EOF
1342 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1343 Message-Id: <bogus-message-id@example.com>
1344 From: A U Thor <author@example.com>
1345 Date: Sat, 12 Jun 2010 15:53:58 +0200
1346 Content-Type: text/plain; charset=UTF-8
1347 Subject: Nothing to see here.
1349 Dieser Betreff enthält auch einen Umlaut!
1353 test_expect_success
$PREREQ 'sendemail.transferencoding=7bit fails on 8bit data' '
1354 clean_fake_sendmail &&
1355 git config sendemail.transferEncoding 7bit &&
1356 test_must_fail git send-email \
1357 --transfer-encoding=7bit \
1358 --smtp-server="$(pwd)/fake.sendmail" \
1361 grep "cannot send message as 7bit" errors &&
1362 test -z "$(ls msgtxt*)"
1365 test_expect_success
$PREREQ '--transfer-encoding overrides sendemail.transferEncoding' '
1366 clean_fake_sendmail &&
1367 git config sendemail.transferEncoding 8bit &&
1368 test_must_fail git send-email \
1369 --transfer-encoding=7bit \
1370 --smtp-server="$(pwd)/fake.sendmail" \
1373 grep "cannot send message as 7bit" errors &&
1374 test -z "$(ls msgtxt*)"
1377 test_expect_success
$PREREQ 'sendemail.transferencoding=8bit' '
1378 clean_fake_sendmail &&
1380 --transfer-encoding=8bit \
1381 --smtp-server="$(pwd)/fake.sendmail" \
1384 sed '1,/^$
/d
' msgtxt1 >actual &&
1385 sed '1,/^$
/d
' email-using-8bit >expected &&
1386 test_cmp expected actual
1389 test_expect_success
$PREREQ 'setup expect' '
1390 cat >expected <<-\EOF
1391 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1395 test_expect_success
$PREREQ '8-bit and sendemail.transferencoding=quoted-printable' '
1396 clean_fake_sendmail &&
1398 --transfer-encoding=quoted-printable \
1399 --smtp-server="$(pwd)/fake.sendmail" \
1402 sed '1,/^$
/d
' msgtxt1 >actual &&
1403 test_cmp expected actual
1406 test_expect_success
$PREREQ 'setup expect' '
1407 cat >expected <<-\EOF
1408 RGllc2VyIEJldHJlZmYgZW50aMOkbHQgYXVjaCBlaW5lbiBVbWxhdXQhCg==
1412 test_expect_success
$PREREQ '8-bit and sendemail.transferencoding=base64' '
1413 clean_fake_sendmail &&
1415 --transfer-encoding=base64 \
1416 --smtp-server="$(pwd)/fake.sendmail" \
1419 sed '1,/^$
/d
' msgtxt1 >actual &&
1420 test_cmp expected actual
1423 test_expect_success
$PREREQ 'setup expect' '
1424 cat >email-using-qp <<-\EOF
1425 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1426 Message-Id: <bogus-message-id@example.com>
1427 From: A U Thor <author@example.com>
1428 Date: Sat, 12 Jun 2010 15:53:58 +0200
1430 Content-Transfer-Encoding: quoted-printable
1431 Content-Type: text/plain; charset=UTF-8
1432 Subject: Nothing to see here.
1434 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1438 test_expect_success
$PREREQ 'convert from quoted-printable to base64' '
1439 clean_fake_sendmail &&
1441 --transfer-encoding=base64 \
1442 --smtp-server="$(pwd)/fake.sendmail" \
1445 sed '1,/^$
/d
' msgtxt1 >actual &&
1446 test_cmp expected actual
1449 test_expect_success
$PREREQ 'setup expect' "
1450 tr -d '\\015' | tr '%' '\\015' >email-using-crlf <<EOF
1451 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1452 Message-Id: <bogus-message-id@example.com>
1453 From: A U Thor <author@example.com>
1454 Date: Sat, 12 Jun 2010 15:53:58 +0200
1455 Content-Type: text/plain; charset=UTF-8
1456 Subject: Nothing to see here.
1458 Look, I have a CRLF and an = sign!%
1462 test_expect_success
$PREREQ 'setup expect' '
1463 cat >expected <<-\EOF
1464 Look, I have a CRLF and an =3D sign!=0D
1468 test_expect_success
$PREREQ 'CRLF and sendemail.transferencoding=quoted-printable' '
1469 clean_fake_sendmail &&
1471 --transfer-encoding=quoted-printable \
1472 --smtp-server="$(pwd)/fake.sendmail" \
1475 sed '1,/^$
/d
' msgtxt1 >actual &&
1476 test_cmp expected actual
1479 test_expect_success
$PREREQ 'setup expect' '
1480 cat >expected <<-\EOF
1481 TG9vaywgSSBoYXZlIGEgQ1JMRiBhbmQgYW4gPSBzaWduIQ0K
1485 test_expect_success
$PREREQ 'CRLF and sendemail.transferencoding=base64' '
1486 clean_fake_sendmail &&
1488 --transfer-encoding=base64 \
1489 --smtp-server="$(pwd)/fake.sendmail" \
1492 sed '1,/^$
/d
' msgtxt1 >actual &&
1493 test_cmp expected actual
1497 # Note that the patches in this test are deliberately out of order; we
1498 # want to make sure it works even if the cover-letter is not in the
1500 test_expect_success
$PREREQ 'refusing to send cover letter template' '
1501 clean_fake_sendmail &&
1503 git format-patch --cover-letter -2 -o outdir &&
1504 test_must_fail git send-email \
1505 --from="Example <nobody@example.com>" \
1506 --to=nobody@example.com \
1507 --smtp-server="$(pwd)/fake.sendmail" \
1508 outdir/0002-*.patch \
1509 outdir/0000-*.patch \
1510 outdir/0001-*.patch \
1512 grep "SUBJECT HERE" errors &&
1513 test -z "$(ls msgtxt*)"
1516 test_expect_success
$PREREQ '--force sends cover letter template anyway' '
1517 clean_fake_sendmail &&
1519 git format-patch --cover-letter -2 -o outdir &&
1522 --from="Example <nobody@example.com>" \
1523 --to=nobody@example.com \
1524 --smtp-server="$(pwd)/fake.sendmail" \
1525 outdir/0002-*.patch \
1526 outdir/0000-*.patch \
1527 outdir/0001-*.patch \
1529 ! grep "SUBJECT HERE" errors &&
1530 test -n "$(ls msgtxt*)"
1533 test_cover_addresses
() {
1536 clean_fake_sendmail
&&
1538 git format-patch
--cover-letter -2 -o outdir
&&
1539 cover
=$
(echo outdir
/0000-*.
patch) &&
1540 mv $cover cover-to-edit.
patch &&
1541 perl
-pe "s/^From:/$header: extra\@address.com\nFrom:/" cover-to-edit.
patch >"$cover" &&
1544 --from="Example <nobody@example.com>" \
1547 --smtp-server="$(pwd)/fake.sendmail" \
1548 outdir
/0000-*.
patch \
1549 outdir
/0001-*.
patch \
1550 outdir
/0002-*.
patch \
1552 grep "^$header: extra@address.com" msgtxt1
>to1
&&
1553 grep "^$header: extra@address.com" msgtxt2
>to2
&&
1554 grep "^$header: extra@address.com" msgtxt3
>to3
&&
1555 test_line_count
= 1 to1
&&
1556 test_line_count
= 1 to2
&&
1557 test_line_count
= 1 to3
1560 test_expect_success
$PREREQ 'to-cover adds To to all mail' '
1561 test_cover_addresses "To" --to-cover
1564 test_expect_success
$PREREQ 'cc-cover adds Cc to all mail' '
1565 test_cover_addresses "Cc" --cc-cover
1568 test_expect_success
$PREREQ 'tocover adds To to all mail' '
1569 test_config sendemail.tocover true &&
1570 test_cover_addresses "To"
1573 test_expect_success
$PREREQ 'cccover adds Cc to all mail' '
1574 test_config sendemail.cccover true &&
1575 test_cover_addresses "Cc"
1578 test_expect_success
$PREREQ 'escaped quotes in sendemail.aliasfiletype=mutt' '
1579 clean_fake_sendmail &&
1580 echo "alias sbd \\\"Dot U. Sir\\\" <somebody@example.org>" >.mutt &&
1581 git config --replace-all sendemail.aliasesfile "$(pwd)/.mutt" &&
1582 git config sendemail.aliasfiletype mutt &&
1584 --from="Example <nobody@example.com>" \
1586 --smtp-server="$(pwd)/fake.sendmail" \
1587 outdir/0001-*.patch \
1589 grep "^!somebody@example\.org!$" commandline1 &&
1590 grep -F "To: \"Dot U. Sir\" <somebody@example.org>" out
1593 test_expect_success
$PREREQ 'sendemail.aliasfiletype=mailrc' '
1594 clean_fake_sendmail &&
1595 echo "alias sbd somebody@example.org" >.mailrc &&
1596 git config --replace-all sendemail.aliasesfile "$(pwd)/.mailrc" &&
1597 git config sendemail.aliasfiletype mailrc &&
1599 --from="Example <nobody@example.com>" \
1601 --smtp-server="$(pwd)/fake.sendmail" \
1602 outdir/0001-*.patch \
1604 grep "^!somebody@example\.org!$" commandline1
1607 test_expect_success
$PREREQ 'sendemail.aliasfile=~/.mailrc' '
1608 clean_fake_sendmail &&
1609 echo "alias sbd someone@example.org" >"$HOME/.mailrc" &&
1610 git config --replace-all sendemail.aliasesfile "~/.mailrc" &&
1611 git config sendemail.aliasfiletype mailrc &&
1613 --from="Example <nobody@example.com>" \
1615 --smtp-server="$(pwd)/fake.sendmail" \
1616 outdir/0001-*.patch \
1618 grep "^!someone@example\.org!$" commandline1
1621 test_dump_aliases
() {
1622 msg
="$1" && shift &&
1623 filetype
="$1" && shift &&
1624 printf '%s\n' "$@" >expect
&&
1625 cat >.tmp-email-aliases
&&
1627 test_expect_success
$PREREQ "$msg" '
1628 clean_fake_sendmail && rm -fr outdir &&
1629 git config --replace-all sendemail.aliasesfile \
1630 "$(pwd)/.tmp-email-aliases" &&
1631 git config sendemail.aliasfiletype "$filetype" &&
1632 git send-email --dump-aliases 2>errors >actual &&
1633 test_cmp expect actual
1637 test_dump_aliases
'--dump-aliases sendmail format' \
1644 alice: Alice W Land <awol@example.com>
1645 bob: Robert Bobbyton <bob@example.com>
1646 chloe: chloe@example.com
1648 bcgrp: bob, chloe, Other <o@example.com>
1651 test_dump_aliases '--dump-aliases mutt format' \
1657 alias alice Alice W Land <awol@example.com>
1658 alias donald Donald C Carlton <donc@example.com>
1659 alias bob Robert Bobbyton <bob@example.com>
1660 alias chloe chloe@example.com
1663 test_dump_aliases '--dump-aliases mailrc format' \
1669 alias alice Alice W Land <awol@example.com>
1670 alias eve Eve <eve@example.com>
1671 alias bob Robert Bobbyton <bob@example.com>
1672 alias chloe chloe@example.com
1675 test_dump_aliases '--dump-aliases pine format' \
1681 alice Alice W Land <awol@example.com>
1682 eve Eve <eve@example.com>
1683 bob Robert Bobbyton <bob@example.com>
1684 chloe chloe@example.com
1687 test_dump_aliases '--dump-aliases gnus format' \
1693 (define-mail-alias "alice" "awol@example.com")
1694 (define-mail-alias "eve" "eve@example.com")
1695 (define-mail-alias "bob" "bob@example.com")
1696 (define-mail-alias "chloe" "chloe@example.com")
1699 test_expect_success '--dump-aliases must be used alone' '
1700 test_must_fail git send-email --dump-aliases --to=janice@example.com -1 refs/heads/accounting
1703 test_sendmail_aliases () {
1704 msg="$1" && shift &&
1706 cat >.tmp-email-aliases &&
1708 test_expect_success $PREREQ "$msg" '
1709 clean_fake_sendmail && rm -fr outdir &&
1710 git format-patch -1 -o outdir &&
1711 git config --replace-all sendemail.aliasesfile \
1712 "$(pwd)/.tmp-email-aliases" &&
1713 git config sendemail.aliasfiletype sendmail &&
1715 --from="Example <nobody@example.com>" \
1716 --to=alice --to=bcgrp \
1717 --smtp-server="$(pwd)/fake.sendmail" \
1718 outdir/0001-*.
patch \
1722 grep "^!$i!$" commandline1 ||
return 1
1727 test_sendmail_aliases 'sendemail.aliasfiletype
=sendmail
' \
1728 'awol@example\.com
' \
1729 'bob@example\.com
' \
1730 'chloe@example\.com
' \
1731 'o@example\.com
' <<-\EOF
1732 alice: Alice W Land <awol@example.com>
1733 bob: Robert Bobbyton <bob@example.com>
1735 # this is also a comment
1736 chloe: chloe@example.com
1738 bcgrp: bob, chloe, Other <o@example.com>
1741 test_sendmail_aliases 'sendmail aliases line folding
' \
1745 darla1 darla2 darla3 \
1746 elton1 elton2 elton3 \
1763 bcgrp: bob, chuck, darla, elton, fred, greg
1766 test_sendmail_aliases 'sendmail aliases tolerate bogus line folding
' \
1772 test_sendmail_aliases 'sendmail aliases empty
' alice bcgrp <<-\EOF
1775 test_expect_success $PREREQ 'alias support
in To header
' '
1776 clean_fake_sendmail
&&
1777 echo "alias sbd someone@example.org" >.mailrc
&&
1778 test_config sendemail.aliasesfile
".mailrc" &&
1779 test_config sendemail.aliasfiletype mailrc
&&
1780 git format-patch
--stdout -1 --to=sbd
>aliased.
patch &&
1782 --from="Example <nobody@example.com>" \
1783 --smtp-server="$(pwd)/fake.sendmail" \
1786 grep "^!someone@example\.org!$" commandline1
1789 test_expect_success $PREREQ 'alias support
in Cc header
' '
1790 clean_fake_sendmail
&&
1791 echo "alias sbd someone@example.org" >.mailrc
&&
1792 test_config sendemail.aliasesfile
".mailrc" &&
1793 test_config sendemail.aliasfiletype mailrc
&&
1794 git format-patch
--stdout -1 --cc=sbd
>aliased.
patch &&
1796 --from="Example <nobody@example.com>" \
1797 --smtp-server="$(pwd)/fake.sendmail" \
1800 grep "^!someone@example\.org!$" commandline1
1803 test_expect_success $PREREQ 'tocmd works with aliases
' '
1804 clean_fake_sendmail
&&
1805 echo "alias sbd someone@example.org" >.mailrc
&&
1806 test_config sendemail.aliasesfile
".mailrc" &&
1807 test_config sendemail.aliasfiletype mailrc
&&
1808 git format-patch
--stdout -1 >tocmd.
patch &&
1809 echo tocmd--sbd
>>tocmd.
patch &&
1811 --from="Example <nobody@example.com>" \
1812 --to-cmd=.
/tocmd-sed \
1813 --smtp-server="$(pwd)/fake.sendmail" \
1816 grep "^!someone@example\.org!$" commandline1
1819 test_expect_success $PREREQ 'cccmd works with aliases
' '
1820 clean_fake_sendmail
&&
1821 echo "alias sbd someone@example.org" >.mailrc
&&
1822 test_config sendemail.aliasesfile
".mailrc" &&
1823 test_config sendemail.aliasfiletype mailrc
&&
1824 git format-patch
--stdout -1 >cccmd.
patch &&
1825 echo cccmd--sbd
>>cccmd.
patch &&
1827 --from="Example <nobody@example.com>" \
1828 --cc-cmd=.
/cccmd-sed \
1829 --smtp-server="$(pwd)/fake.sendmail" \
1832 grep "^!someone@example\.org!$" commandline1
1835 do_xmailer_test () {
1836 expected=$1 params=$2 &&
1837 git format-patch -1 &&
1839 --from="Example <nobody@example.com>" \
1840 --to=someone@example.com \
1841 --smtp-server="$(pwd)/fake.sendmail" \
1845 { grep '^X-Mailer
:' out || :; } >mailer &&
1846 test_line_count = $expected mailer
1849 test_expect_success $PREREQ '--[no-
]xmailer without any configuration
' '
1850 do_xmailer_test
1 "--xmailer" &&
1851 do_xmailer_test
0 "--no-xmailer"
1854 test_expect_success $PREREQ '--[no-
]xmailer with sendemail.xmailer
=true
' '
1855 test_config sendemail.xmailer true
&&
1856 do_xmailer_test
1 "" &&
1857 do_xmailer_test
0 "--no-xmailer" &&
1858 do_xmailer_test
1 "--xmailer"
1861 test_expect_success $PREREQ '--[no-
]xmailer with sendemail.xmailer
=false
' '
1862 test_config sendemail.xmailer false
&&
1863 do_xmailer_test
0 "" &&
1864 do_xmailer_test
0 "--no-xmailer" &&
1865 do_xmailer_test
1 "--xmailer"
1868 test_expect_success $PREREQ 'setup expected-list
' '
1871 --from="Example <from@example.com>" \
1872 --to="To 1 <to1@example.com>" \
1873 --to="to2@example.com" \
1874 --to="to3@example.com" \
1875 --cc="Cc 1 <cc1@example.com>" \
1876 --cc="Cc2 <cc2@example.com>" \
1877 --bcc="bcc1@example.com" \
1878 --bcc="bcc2@example.com" \
1879 0001-add-master.
patch | replace_variable_fields \
1883 test_expect_success $PREREQ 'use email list
in --cc --to and
--bcc' '
1886 --from="Example <from@example.com>" \
1887 --to="To 1 <to1@example.com>, to2@example.com" \
1888 --to="to3@example.com" \
1889 --cc="Cc 1 <cc1@example.com>, Cc2 <cc2@example.com>" \
1890 --bcc="bcc1@example.com, bcc2@example.com" \
1891 0001-add-master.
patch | replace_variable_fields \
1893 test_cmp expected-list actual-list
1896 test_expect_success $PREREQ 'aliases work with email list
' '
1897 echo "alias to2 to2@example.com" >.mutt
&&
1898 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt
&&
1899 test_config sendemail.aliasesfile
".mutt" &&
1900 test_config sendemail.aliasfiletype mutt
&&
1903 --from="Example <from@example.com>" \
1904 --to="To 1 <to1@example.com>, to2, to3@example.com" \
1905 --cc="cc1, Cc2 <cc2@example.com>" \
1906 --bcc="bcc1@example.com, bcc2@example.com" \
1907 0001-add-master.
patch | replace_variable_fields \
1909 test_cmp expected-list actual-list
1912 test_expect_success $PREREQ 'leading and trailing whitespaces are removed
' '
1913 echo "alias to2 to2@example.com" >.mutt
&&
1914 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt
&&
1915 test_config sendemail.aliasesfile
".mutt" &&
1916 test_config sendemail.aliasfiletype mutt
&&
1917 TO1
=$
(echo "QTo 1 <to1@example.com>" | q_to_tab
) &&
1918 TO2
=$
(echo "QZto2" | qz_to_tab_space
) &&
1919 CC1
=$
(echo "cc1" | append_cr
) &&
1920 BCC1
=$
(echo "Q bcc1@example.com Q" | q_to_nul
) &&
1923 --from=" Example <from@example.com>" \
1926 --to=" to3@example.com " \
1928 --cc="Cc2 <cc2@example.com>" \
1930 --bcc="bcc2@example.com" \
1931 0001-add-master.
patch | replace_variable_fields \
1933 test_cmp expected-list actual-list
1936 test_expect_success $PREREQ 'invoke hook
' '
1937 mkdir
-p .git
/hooks
&&
1939 write_script .git
/hooks
/sendemail-validate
<<-\EOF &&
1940 # test that we have the correct environment variable, pwd, and
1950 test -f 0001-add-master.patch &&
1951 grep "add master" "$1"
1956 # Test that it works even if we are not at the root of the
1960 --from="Example <nobody@example.com>" \
1961 --to=nobody@example.com \
1962 --smtp-server="$(pwd)/../fake.sendmail" \
1963 ../0001-add-master.patch &&
1965 # Verify error message when a patch is rejected by the hook
1966 sed -e "s/add master/x/" ../0001-add-master.patch >../another.patch &&
1968 --from="Example <nobody@example.com>" \
1969 --to=nobody@example.com \
1970 --smtp-server="$(pwd)/../fake.sendmail" \
1971 ../another.patch 2>err
1972 test_i18ngrep "rejected by sendemail-validate hook" err
1976 test_expect_success $PREREQ 'test that send-email works outside a repo' '
1977 nongit git send-email \
1978 --from="Example <nobody@example.com>" \
1979 --to=nobody@example.com \
1980 --smtp-server="$(pwd)/fake.sendmail" \
1981 "$(pwd)/0001-add-master.patch"