3 test_description='git send-email'
6 # May be altered later in the test
9 test_expect_success $PREREQ 'prepare reference tree' '
10 echo "1A quick brown fox jumps over the" >file &&
11 echo "lazy dog" >>file &&
13 GIT_AUTHOR_NAME="A" git commit -a -m "Initial."
16 test_expect_success $PREREQ 'Setup helper tool' '
17 write_script fake.sendmail <<-\EOF &&
20 while test -f commandline$output
27 done >commandline$output
30 git add fake.sendmail &&
31 GIT_AUTHOR_NAME="A" git commit -a -m "Second."
34 clean_fake_sendmail () {
35 rm -f commandline* msgtxt*
38 test_expect_success $PREREQ 'Extract patches' '
39 patches=$(git format-patch -s --cc="One <one@example.com>" --cc=two@example.com -n HEAD^1)
42 # Test no confirm early to ensure remaining tests will not hang
46 GIT_SEND_EMAIL_NOTTY=1 \
48 --from="Example <from@example.com>" \
49 --to=nobody@example.com \
50 --smtp-server="$(pwd)/fake.sendmail" \
53 ! grep "Send this email" stdout &&
57 # Exit immediately to prevent hang if a no-confirm test fails
59 if ! test -f no_confirm_okay
61 say 'confirm test failed; skipping remaining tests to prevent hanging'
62 PREREQ="$PREREQ,CHECK_NO_CONFIRM"
67 test_expect_success $PREREQ 'No confirm with --suppress-cc' '
68 test_no_confirm --suppress-cc=sob &&
73 test_expect_success $PREREQ 'No confirm with --confirm=never' '
74 test_no_confirm --confirm=never &&
78 # leave sendemail.confirm set to never after this so that none of the
79 # remaining tests prompt unintentionally.
80 test_expect_success $PREREQ 'No confirm with sendemail.confirm=never' '
81 git config sendemail.confirm never &&
82 test_no_confirm --compose --subject=foo &&
86 test_expect_success $PREREQ 'Send patches' '
87 git send-email --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
90 test_expect_success $PREREQ 'setup expect' '
99 test_expect_success $PREREQ 'Verify commandline' '
100 test_cmp expected commandline1
103 test_expect_success $PREREQ 'Send patches with --envelope-sender' '
104 clean_fake_sendmail &&
105 git send-email --envelope-sender="Patch Contributor <patch@example.com>" --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
108 test_expect_success $PREREQ 'setup expect' '
109 cat >expected <<-\EOF
119 test_expect_success $PREREQ 'Verify commandline' '
120 test_cmp expected commandline1
123 test_expect_success $PREREQ 'Send patches with --envelope-sender=auto' '
124 clean_fake_sendmail &&
125 git send-email --envelope-sender=auto --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
128 test_expect_success $PREREQ 'setup expect' '
129 cat >expected <<-\EOF
139 test_expect_success $PREREQ 'Verify commandline' '
140 test_cmp expected commandline1
143 test_expect_success $PREREQ 'setup expect for cc trailer' "
144 cat >expected-cc <<\EOF
145 !recipient@example.com!
156 test_expect_success $PREREQ 'cc trailer with various syntax' '
157 test_commit cc-trailer &&
158 test_when_finished "git reset --hard HEAD^" &&
159 git commit --amend -F - <<-EOF &&
163 Cc: <two@example.com> # trailing comments are ignored
164 Cc: <three@example.com>, <not.four@example.com> one address per line
165 Cc: "Some # Body" <four@example.com> [ <also.a.comment> ]
166 Cc: five@example.com # not.six@example.com
167 Cc: six@example.com, not.seven@example.com
169 clean_fake_sendmail &&
170 git send-email -1 --to=recipient@example.com \
171 --smtp-server="$(pwd)/fake.sendmail" &&
172 test_cmp expected-cc commandline1
175 test_expect_success $PREREQ 'setup expect' "
176 cat >expected-show-all-headers <<\EOF
178 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
179 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
180 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
182 Server: relay.example.com
183 MAIL FROM:<from@example.com>
184 RCPT TO:<to@example.com>
185 RCPT TO:<cc@example.com>
186 RCPT TO:<author@example.com>
187 RCPT TO:<one@example.com>
188 RCPT TO:<two@example.com>
189 RCPT TO:<bcc@example.com>
190 From: Example <from@example.com>
193 A <author@example.com>,
194 One <one@example.com>,
196 Subject: [PATCH 1/1] Second.
198 Message-Id: MESSAGE-ID-STRING
199 X-Mailer: X-MAILER-STRING
200 In-Reply-To: <unique-message-id@example.com>
201 References: <unique-message-id@example.com>
207 test_suppress_self () {
209 test_when_finished "git reset --hard HEAD^" &&
211 write_script cccmd-sed <<-EOF &&
212 sed -n -e s/^cccmd--//p "\$1"
215 git commit --amend --author="$1 <$2>" -F - &&
216 clean_fake_sendmail &&
217 git format-patch --stdout -1 >"suppress-self-$3.patch" &&
219 git send-email --from="$1 <$2>" \
220 --to=nobody@example.com \
221 --cc-cmd=./cccmd-sed \
223 --smtp-server="$(pwd)/fake.sendmail" \
224 suppress-self-$3.patch &&
226 mv msgtxt1 msgtxt1-$3 &&
227 sed -e '/^$/q' msgtxt1-$3 >"msghdr1-$3" &&
228 >"expected-no-cc-$3" &&
230 (grep '^Cc:' msghdr1-$3 >"actual-no-cc-$3";
231 test_cmp expected-no-cc-$3 actual-no-cc-$3)
234 test_suppress_self_unquoted () {
235 test_suppress_self "$1" "$2" "unquoted-$3" <<-EOF
236 test suppress-cc.self unquoted-$3 with name $1 email $2
243 Signed-off-by: $1 <$2>
247 test_suppress_self_quoted () {
248 test_suppress_self "$1" "$2" "quoted-$3" <<-EOF
249 test suppress-cc.self quoted-$3 with name $1 email $2
257 Signed-off-by: $1 <$2>
258 Signed-off-by: "$1" <$2>
262 test_expect_success $PREREQ 'self name is suppressed' "
263 test_suppress_self_unquoted 'A U Thor' 'author@example.com' \
264 'self_name_suppressed'
267 test_expect_success $PREREQ 'self name with dot is suppressed' "
268 test_suppress_self_quoted 'A U. Thor' 'author@example.com' \
269 'self_name_dot_suppressed'
272 test_expect_success $PREREQ 'non-ascii self name is suppressed' "
273 test_suppress_self_quoted 'Füñný Nâmé' 'odd_?=mail@example.com' \
274 'non_ascii_self_suppressed'
277 # This name is long enough to force format-patch to split it into multiple
278 # encoded-words, assuming it uses UTF-8 with the "Q" encoding.
279 test_expect_success $PREREQ 'long non-ascii self name is suppressed' "
280 test_suppress_self_quoted 'Ƒüñníęř €. Nâṁé' 'odd_?=mail@example.com' \
281 'long_non_ascii_self_suppressed'
284 test_expect_success $PREREQ 'sanitized self name is suppressed' "
285 test_suppress_self_unquoted '\"A U. Thor\"' 'author@example.com' \
286 'self_name_sanitized_suppressed'
289 test_expect_success $PREREQ 'Show all headers' '
293 --from="Example <from@example.com>" \
294 --to=to@example.com \
295 --cc=cc@example.com \
296 --bcc=bcc@example.com \
297 --in-reply-to="<unique-message-id@example.com>" \
298 --smtp-server relay.example.com \
300 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
301 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
302 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
303 >actual-show-all-headers &&
304 test_cmp expected-show-all-headers actual-show-all-headers
307 test_expect_success $PREREQ 'Prompting works' '
308 clean_fake_sendmail &&
309 (echo "to@example.com"
311 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
312 --smtp-server="$(pwd)/fake.sendmail" \
315 grep "^From: A U Thor <author@example.com>\$" msgtxt1 &&
316 grep "^To: to@example.com\$" msgtxt1
319 test_expect_success $PREREQ,AUTOIDENT 'implicit ident is allowed' '
320 clean_fake_sendmail &&
321 (sane_unset GIT_AUTHOR_NAME &&
322 sane_unset GIT_AUTHOR_EMAIL &&
323 sane_unset GIT_COMMITTER_NAME &&
324 sane_unset GIT_COMMITTER_EMAIL &&
325 GIT_SEND_EMAIL_NOTTY=1 git send-email \
326 --smtp-server="$(pwd)/fake.sendmail" \
327 --to=to@example.com \
328 $patches </dev/null 2>errors
332 test_expect_success $PREREQ,!AUTOIDENT 'broken implicit ident aborts send-email' '
333 clean_fake_sendmail &&
334 (sane_unset GIT_AUTHOR_NAME &&
335 sane_unset GIT_AUTHOR_EMAIL &&
336 sane_unset GIT_COMMITTER_NAME &&
337 sane_unset GIT_COMMITTER_EMAIL &&
338 GIT_SEND_EMAIL_NOTTY=1 && export GIT_SEND_EMAIL_NOTTY &&
339 test_must_fail git send-email \
340 --smtp-server="$(pwd)/fake.sendmail" \
341 --to=to@example.com \
342 $patches </dev/null 2>errors &&
343 test_i18ngrep "tell me who you are" errors
347 test_expect_success $PREREQ 'setup tocmd and cccmd scripts' '
348 write_script tocmd-sed <<-\EOF &&
349 sed -n -e "s/^tocmd--//p" "$1"
351 write_script cccmd-sed <<-\EOF
352 sed -n -e "s/^cccmd--//p" "$1"
356 test_expect_success $PREREQ 'tocmd works' '
357 clean_fake_sendmail &&
358 cp $patches tocmd.patch &&
359 echo tocmd--tocmd@example.com >>tocmd.patch &&
361 --from="Example <nobody@example.com>" \
362 --to-cmd=./tocmd-sed \
363 --smtp-server="$(pwd)/fake.sendmail" \
366 grep "^To: tocmd@example.com" msgtxt1
369 test_expect_success $PREREQ 'cccmd works' '
370 clean_fake_sendmail &&
371 cp $patches cccmd.patch &&
372 echo "cccmd-- cccmd@example.com" >>cccmd.patch &&
374 --from="Example <nobody@example.com>" \
375 --to=nobody@example.com \
376 --cc-cmd=./cccmd-sed \
377 --smtp-server="$(pwd)/fake.sendmail" \
380 grep "^ cccmd@example.com" msgtxt1
383 test_expect_success $PREREQ 'reject long lines' '
385 z64=$z8$z8$z8$z8$z8$z8$z8$z8 &&
386 z512=$z64$z64$z64$z64$z64$z64$z64$z64 &&
387 clean_fake_sendmail &&
388 cp $patches longline.patch &&
389 echo $z512$z512 >>longline.patch &&
390 test_must_fail git send-email \
391 --from="Example <nobody@example.com>" \
392 --to=nobody@example.com \
393 --smtp-server="$(pwd)/fake.sendmail" \
394 $patches longline.patch \
396 grep longline.patch errors
399 test_expect_success $PREREQ 'no patch was sent' '
400 ! test -e commandline1
403 test_expect_success $PREREQ 'Author From: in message body' '
404 clean_fake_sendmail &&
406 --from="Example <nobody@example.com>" \
407 --to=nobody@example.com \
408 --smtp-server="$(pwd)/fake.sendmail" \
410 sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
411 grep "From: A <author@example.com>" msgbody1
414 test_expect_success $PREREQ 'Author From: not in message body' '
415 clean_fake_sendmail &&
417 --from="A <author@example.com>" \
418 --to=nobody@example.com \
419 --smtp-server="$(pwd)/fake.sendmail" \
421 sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
422 ! grep "From: A <author@example.com>" msgbody1
425 test_expect_success $PREREQ 'allow long lines with --no-validate' '
427 --from="Example <nobody@example.com>" \
428 --to=nobody@example.com \
429 --smtp-server="$(pwd)/fake.sendmail" \
431 $patches longline.patch \
435 test_expect_success $PREREQ 'Invalid In-Reply-To' '
436 clean_fake_sendmail &&
438 --from="Example <nobody@example.com>" \
439 --to=nobody@example.com \
441 --smtp-server="$(pwd)/fake.sendmail" \
444 ! grep "^In-Reply-To: < *>" msgtxt1
447 test_expect_success $PREREQ 'Valid In-Reply-To when prompting' '
448 clean_fake_sendmail &&
449 (echo "From Example <from@example.com>"
450 echo "To Example <to@example.com>"
452 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
453 --smtp-server="$(pwd)/fake.sendmail" \
455 ! grep "^In-Reply-To: < *>" msgtxt1
458 test_expect_success $PREREQ 'In-Reply-To without --chain-reply-to' '
459 clean_fake_sendmail &&
460 echo "<unique-message-id@example.com>" >expect &&
462 --from="Example <nobody@example.com>" \
463 --to=nobody@example.com \
464 --no-chain-reply-to \
465 --in-reply-to="$(cat expect)" \
466 --smtp-server="$(pwd)/fake.sendmail" \
467 $patches $patches $patches \
469 # The first message is a reply to --in-reply-to
470 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
471 test_cmp expect actual &&
472 # Second and subsequent messages are replies to the first one
473 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
474 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
475 test_cmp expect actual &&
476 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
477 test_cmp expect actual
480 test_expect_success $PREREQ 'In-Reply-To with --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 \
487 --in-reply-to="$(cat expect)" \
488 --smtp-server="$(pwd)/fake.sendmail" \
489 $patches $patches $patches \
491 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
492 test_cmp expect actual &&
493 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
494 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
495 test_cmp expect actual &&
496 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt2 >expect &&
497 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
498 test_cmp expect actual
501 test_expect_success $PREREQ 'setup fake editor' '
502 write_script fake-editor <<-\EOF
503 echo fake edit >>"$1"
507 test_set_editor "$(pwd)/fake-editor"
509 test_expect_success $PREREQ '--compose works' '
510 clean_fake_sendmail &&
512 --compose --subject foo \
513 --from="Example <nobody@example.com>" \
514 --to=nobody@example.com \
515 --smtp-server="$(pwd)/fake.sendmail" \
520 test_expect_success $PREREQ 'first message is compose text' '
521 grep "^fake edit" msgtxt1
524 test_expect_success $PREREQ 'second message is patch' '
525 grep "Subject:.*Second" msgtxt2
528 test_expect_success $PREREQ 'setup expect' "
529 cat >expected-suppress-sob <<\EOF
531 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
532 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
533 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
535 Server: relay.example.com
536 MAIL FROM:<from@example.com>
537 RCPT TO:<to@example.com>
538 RCPT TO:<cc@example.com>
539 RCPT TO:<author@example.com>
540 RCPT TO:<one@example.com>
541 RCPT TO:<two@example.com>
542 From: Example <from@example.com>
545 A <author@example.com>,
546 One <one@example.com>,
548 Subject: [PATCH 1/1] Second.
550 Message-Id: MESSAGE-ID-STRING
551 X-Mailer: X-MAILER-STRING
557 replace_variable_fields () {
558 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
559 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
560 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/"
563 test_suppression () {
566 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
567 --from="Example <from@example.com>" \
568 --to=to@example.com \
569 --smtp-server relay.example.com \
570 $patches | replace_variable_fields \
571 >actual-suppress-$1${2+"-$2"} &&
572 test_cmp expected-suppress-$1${2+"-$2"} actual-suppress-$1${2+"-$2"}
575 test_expect_success $PREREQ 'sendemail.cc set' '
576 git config sendemail.cc cc@example.com &&
580 test_expect_success $PREREQ 'setup expect' "
581 cat >expected-suppress-sob <<\EOF
583 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
584 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
585 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
587 Server: relay.example.com
588 MAIL FROM:<from@example.com>
589 RCPT TO:<to@example.com>
590 RCPT TO:<author@example.com>
591 RCPT TO:<one@example.com>
592 RCPT TO:<two@example.com>
593 From: Example <from@example.com>
595 Cc: A <author@example.com>,
596 One <one@example.com>,
598 Subject: [PATCH 1/1] Second.
600 Message-Id: MESSAGE-ID-STRING
601 X-Mailer: X-MAILER-STRING
607 test_expect_success $PREREQ 'sendemail.cc unset' '
608 git config --unset sendemail.cc &&
612 test_expect_success $PREREQ 'setup expect' "
613 cat >expected-suppress-cccmd <<\EOF
615 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
616 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
617 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
618 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
620 Server: relay.example.com
621 MAIL FROM:<from@example.com>
622 RCPT TO:<to@example.com>
623 RCPT TO:<author@example.com>
624 RCPT TO:<one@example.com>
625 RCPT TO:<two@example.com>
626 RCPT TO:<committer@example.com>
627 From: Example <from@example.com>
629 Cc: A <author@example.com>,
630 One <one@example.com>,
632 C O Mitter <committer@example.com>
633 Subject: [PATCH 1/1] Second.
635 Message-Id: MESSAGE-ID-STRING
636 X-Mailer: X-MAILER-STRING
642 test_expect_success $PREREQ 'sendemail.cccmd' '
643 write_script cccmd <<-\EOF &&
644 echo cc-cmd@example.com
646 git config sendemail.cccmd ./cccmd &&
647 test_suppression cccmd
650 test_expect_success $PREREQ 'setup expect' '
651 cat >expected-suppress-all <<\EOF
654 Server: relay.example.com
655 MAIL FROM:<from@example.com>
656 RCPT TO:<to@example.com>
657 From: Example <from@example.com>
659 Subject: [PATCH 1/1] Second.
661 Message-Id: MESSAGE-ID-STRING
662 X-Mailer: X-MAILER-STRING
668 test_expect_success $PREREQ '--suppress-cc=all' '
672 test_expect_success $PREREQ 'setup expect' "
673 cat >expected-suppress-body <<\EOF
675 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
676 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
677 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
678 (cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
680 Server: relay.example.com
681 MAIL FROM:<from@example.com>
682 RCPT TO:<to@example.com>
683 RCPT TO:<author@example.com>
684 RCPT TO:<one@example.com>
685 RCPT TO:<two@example.com>
686 RCPT TO:<cc-cmd@example.com>
687 From: Example <from@example.com>
689 Cc: A <author@example.com>,
690 One <one@example.com>,
693 Subject: [PATCH 1/1] Second.
695 Message-Id: MESSAGE-ID-STRING
696 X-Mailer: X-MAILER-STRING
702 test_expect_success $PREREQ '--suppress-cc=body' '
703 test_suppression body
706 test_expect_success $PREREQ 'setup expect' "
707 cat >expected-suppress-body-cccmd <<\EOF
709 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
710 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
711 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
713 Server: relay.example.com
714 MAIL FROM:<from@example.com>
715 RCPT TO:<to@example.com>
716 RCPT TO:<author@example.com>
717 RCPT TO:<one@example.com>
718 RCPT TO:<two@example.com>
719 From: Example <from@example.com>
721 Cc: A <author@example.com>,
722 One <one@example.com>,
724 Subject: [PATCH 1/1] Second.
726 Message-Id: MESSAGE-ID-STRING
727 X-Mailer: X-MAILER-STRING
733 test_expect_success $PREREQ '--suppress-cc=body --suppress-cc=cccmd' '
734 test_suppression body cccmd
737 test_expect_success $PREREQ 'setup expect' "
738 cat >expected-suppress-sob <<\EOF
740 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
741 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
742 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
744 Server: relay.example.com
745 MAIL FROM:<from@example.com>
746 RCPT TO:<to@example.com>
747 RCPT TO:<author@example.com>
748 RCPT TO:<one@example.com>
749 RCPT TO:<two@example.com>
750 From: Example <from@example.com>
752 Cc: A <author@example.com>,
753 One <one@example.com>,
755 Subject: [PATCH 1/1] Second.
757 Message-Id: MESSAGE-ID-STRING
758 X-Mailer: X-MAILER-STRING
764 test_expect_success $PREREQ '--suppress-cc=sob' '
765 test_might_fail git config --unset sendemail.cccmd &&
769 test_expect_success $PREREQ 'setup expect' "
770 cat >expected-suppress-bodycc <<\EOF
772 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
773 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
774 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
775 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
777 Server: relay.example.com
778 MAIL FROM:<from@example.com>
779 RCPT TO:<to@example.com>
780 RCPT TO:<author@example.com>
781 RCPT TO:<one@example.com>
782 RCPT TO:<two@example.com>
783 RCPT TO:<committer@example.com>
784 From: Example <from@example.com>
786 Cc: A <author@example.com>,
787 One <one@example.com>,
789 C O Mitter <committer@example.com>
790 Subject: [PATCH 1/1] Second.
792 Message-Id: MESSAGE-ID-STRING
793 X-Mailer: X-MAILER-STRING
799 test_expect_success $PREREQ '--suppress-cc=bodycc' '
800 test_suppression bodycc
803 test_expect_success $PREREQ 'setup expect' "
804 cat >expected-suppress-cc <<\EOF
806 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
807 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
809 Server: relay.example.com
810 MAIL FROM:<from@example.com>
811 RCPT TO:<to@example.com>
812 RCPT TO:<author@example.com>
813 RCPT TO:<committer@example.com>
814 From: Example <from@example.com>
816 Cc: A <author@example.com>,
817 C O Mitter <committer@example.com>
818 Subject: [PATCH 1/1] Second.
820 Message-Id: MESSAGE-ID-STRING
821 X-Mailer: X-MAILER-STRING
827 test_expect_success $PREREQ '--suppress-cc=cc' '
833 GIT_SEND_EMAIL_NOTTY=1 \
835 --from="Example <nobody@example.com>" \
836 --to=nobody@example.com \
837 --smtp-server="$(pwd)/fake.sendmail" \
838 $@ $patches >stdout &&
839 grep "Send this email" stdout
842 test_expect_success $PREREQ '--confirm=always' '
843 test_confirm --confirm=always --suppress-cc=all
846 test_expect_success $PREREQ '--confirm=auto' '
847 test_confirm --confirm=auto
850 test_expect_success $PREREQ '--confirm=cc' '
851 test_confirm --confirm=cc
854 test_expect_success $PREREQ '--confirm=compose' '
855 test_confirm --confirm=compose --compose
858 test_expect_success $PREREQ 'confirm by default (due to cc)' '
859 test_when_finished git config sendemail.confirm never &&
860 git config --unset sendemail.confirm &&
864 test_expect_success $PREREQ 'confirm by default (due to --compose)' '
865 test_when_finished git config sendemail.confirm never &&
866 git config --unset sendemail.confirm &&
867 test_confirm --suppress-cc=all --compose
870 test_expect_success $PREREQ 'confirm detects EOF (inform assumes y)' '
871 test_when_finished git config sendemail.confirm never &&
872 git config --unset sendemail.confirm &&
874 git format-patch -2 -o outdir &&
875 GIT_SEND_EMAIL_NOTTY=1 \
877 --from="Example <nobody@example.com>" \
878 --to=nobody@example.com \
879 --smtp-server="$(pwd)/fake.sendmail" \
880 outdir/*.patch </dev/null
883 test_expect_success $PREREQ 'confirm detects EOF (auto causes failure)' '
884 test_when_finished git config sendemail.confirm never &&
885 git config sendemail.confirm auto &&
886 GIT_SEND_EMAIL_NOTTY=1 &&
887 export GIT_SEND_EMAIL_NOTTY &&
888 test_must_fail git send-email \
889 --from="Example <nobody@example.com>" \
890 --to=nobody@example.com \
891 --smtp-server="$(pwd)/fake.sendmail" \
895 test_expect_success $PREREQ 'confirm does not loop forever' '
896 test_when_finished git config sendemail.confirm never &&
897 git config sendemail.confirm auto &&
898 GIT_SEND_EMAIL_NOTTY=1 &&
899 export GIT_SEND_EMAIL_NOTTY &&
900 yes "bogus" | test_must_fail git send-email \
901 --from="Example <nobody@example.com>" \
902 --to=nobody@example.com \
903 --smtp-server="$(pwd)/fake.sendmail" \
907 test_expect_success $PREREQ 'utf8 Cc is rfc2047 encoded' '
908 clean_fake_sendmail &&
910 git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
912 --from="Example <nobody@example.com>" \
913 --to=nobody@example.com \
914 --smtp-server="$(pwd)/fake.sendmail" \
917 grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
920 test_expect_success $PREREQ '--compose adds MIME for utf8 body' '
921 clean_fake_sendmail &&
922 write_script fake-editor-utf8 <<-\EOF &&
923 echo "utf8 body: àéìöú" >>"$1"
925 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
927 --compose --subject foo \
928 --from="Example <nobody@example.com>" \
929 --to=nobody@example.com \
930 --smtp-server="$(pwd)/fake.sendmail" \
932 grep "^utf8 body" msgtxt1 &&
933 grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
936 test_expect_success $PREREQ '--compose respects user mime type' '
937 clean_fake_sendmail &&
938 write_script fake-editor-utf8-mime <<-\EOF &&
941 Content-Type: text/plain; charset=iso-8859-1
942 Content-Transfer-Encoding: 8bit
948 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
950 --compose --subject foo \
951 --from="Example <nobody@example.com>" \
952 --to=nobody@example.com \
953 --smtp-server="$(pwd)/fake.sendmail" \
955 grep "^utf8 body" msgtxt1 &&
956 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
957 ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
960 test_expect_success $PREREQ '--compose adds MIME for utf8 subject' '
961 clean_fake_sendmail &&
962 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
964 --compose --subject utf8-sübjëct \
965 --from="Example <nobody@example.com>" \
966 --to=nobody@example.com \
967 --smtp-server="$(pwd)/fake.sendmail" \
969 grep "^fake edit" msgtxt1 &&
970 grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
973 test_expect_success $PREREQ 'utf8 author is correctly passed on' '
974 clean_fake_sendmail &&
975 test_commit weird_author &&
976 test_when_finished "git reset --hard HEAD^" &&
977 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
978 git format-patch --stdout -1 >funny_name.patch &&
979 git send-email --from="Example <nobody@example.com>" \
980 --to=nobody@example.com \
981 --smtp-server="$(pwd)/fake.sendmail" \
983 grep "^From: Füñný Nâmé <odd_?=mail@example.com>" msgtxt1
986 test_expect_success $PREREQ 'utf8 sender is not duplicated' '
987 clean_fake_sendmail &&
988 test_commit weird_sender &&
989 test_when_finished "git reset --hard HEAD^" &&
990 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
991 git format-patch --stdout -1 >funny_name.patch &&
992 git send-email --from="Füñný Nâmé <odd_?=mail@example.com>" \
993 --to=nobody@example.com \
994 --smtp-server="$(pwd)/fake.sendmail" \
996 grep "^From: " msgtxt1 >msgfrom &&
997 test_line_count = 1 msgfrom
1000 test_expect_success $PREREQ 'sendemail.composeencoding works' '
1001 clean_fake_sendmail &&
1002 git config sendemail.composeencoding iso-8859-1 &&
1003 write_script fake-editor-utf8 <<-\EOF &&
1004 echo "utf8 body: àéìöú" >>"$1"
1006 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1008 --compose --subject foo \
1009 --from="Example <nobody@example.com>" \
1010 --to=nobody@example.com \
1011 --smtp-server="$(pwd)/fake.sendmail" \
1013 grep "^utf8 body" msgtxt1 &&
1014 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1017 test_expect_success $PREREQ '--compose-encoding works' '
1018 clean_fake_sendmail &&
1019 write_script fake-editor-utf8 <<-\EOF &&
1020 echo "utf8 body: àéìöú" >>"$1"
1022 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1024 --compose-encoding iso-8859-1 \
1025 --compose --subject foo \
1026 --from="Example <nobody@example.com>" \
1027 --to=nobody@example.com \
1028 --smtp-server="$(pwd)/fake.sendmail" \
1030 grep "^utf8 body" msgtxt1 &&
1031 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1034 test_expect_success $PREREQ '--compose-encoding overrides sendemail.composeencoding' '
1035 clean_fake_sendmail &&
1036 git config sendemail.composeencoding iso-8859-1 &&
1037 write_script fake-editor-utf8 <<-\EOF &&
1038 echo "utf8 body: àéìöú" >>"$1"
1040 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1042 --compose-encoding iso-8859-2 \
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-2" msgtxt1
1052 test_expect_success $PREREQ '--compose-encoding adds correct MIME for subject' '
1053 clean_fake_sendmail &&
1054 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
1056 --compose-encoding iso-8859-2 \
1057 --compose --subject utf8-sübjëct \
1058 --from="Example <nobody@example.com>" \
1059 --to=nobody@example.com \
1060 --smtp-server="$(pwd)/fake.sendmail" \
1062 grep "^fake edit" msgtxt1 &&
1063 grep "^Subject: =?iso-8859-2?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
1066 test_expect_success $PREREQ 'detects ambiguous reference/file conflict' '
1067 echo master >master &&
1069 git commit -m"add master" &&
1070 test_must_fail git send-email --dry-run master 2>errors &&
1071 grep disambiguate errors
1074 test_expect_success $PREREQ 'feed two files' '
1076 git format-patch -2 -o outdir &&
1079 --from="Example <nobody@example.com>" \
1080 --to=nobody@example.com \
1081 outdir/000?-*.patch 2>errors >out &&
1082 grep "^Subject: " out >subjects &&
1083 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
1084 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"
1087 test_expect_success $PREREQ 'in-reply-to but no threading' '
1090 --from="Example <nobody@example.com>" \
1091 --to=nobody@example.com \
1092 --in-reply-to="<in-reply-id@example.com>" \
1095 grep "In-Reply-To: <in-reply-id@example.com>"
1098 test_expect_success $PREREQ 'no in-reply-to and no threading' '
1101 --from="Example <nobody@example.com>" \
1102 --to=nobody@example.com \
1104 $patches $patches >stdout &&
1105 ! grep "In-Reply-To: " stdout
1108 test_expect_success $PREREQ 'threading but no chain-reply-to' '
1111 --from="Example <nobody@example.com>" \
1112 --to=nobody@example.com \
1114 --no-chain-reply-to \
1115 $patches $patches >stdout &&
1116 grep "In-Reply-To: " stdout
1119 test_expect_success $PREREQ 'sendemail.to works' '
1120 git config --replace-all sendemail.to "Somebody <somebody@ex.com>" &&
1123 --from="Example <nobody@example.com>" \
1124 $patches $patches >stdout &&
1125 grep "To: Somebody <somebody@ex.com>" stdout
1128 test_expect_success $PREREQ '--no-to overrides sendemail.to' '
1131 --from="Example <nobody@example.com>" \
1133 --to=nobody@example.com \
1134 $patches $patches >stdout &&
1135 grep "To: nobody@example.com" stdout &&
1136 ! grep "To: Somebody <somebody@ex.com>" stdout
1139 test_expect_success $PREREQ 'sendemail.cc works' '
1140 git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" &&
1143 --from="Example <nobody@example.com>" \
1144 --to=nobody@example.com \
1145 $patches $patches >stdout &&
1146 grep "Cc: Somebody <somebody@ex.com>" stdout
1149 test_expect_success $PREREQ '--no-cc overrides sendemail.cc' '
1152 --from="Example <nobody@example.com>" \
1154 --cc=bodies@example.com \
1155 --to=nobody@example.com \
1156 $patches $patches >stdout &&
1157 grep "Cc: bodies@example.com" stdout &&
1158 ! grep "Cc: Somebody <somebody@ex.com>" stdout
1161 test_expect_success $PREREQ 'sendemail.bcc works' '
1162 git config --replace-all sendemail.bcc "Other <other@ex.com>" &&
1165 --from="Example <nobody@example.com>" \
1166 --to=nobody@example.com \
1167 --smtp-server relay.example.com \
1168 $patches $patches >stdout &&
1169 grep "RCPT TO:<other@ex.com>" stdout
1172 test_expect_success $PREREQ '--no-bcc overrides sendemail.bcc' '
1175 --from="Example <nobody@example.com>" \
1177 --bcc=bodies@example.com \
1178 --to=nobody@example.com \
1179 --smtp-server relay.example.com \
1180 $patches $patches >stdout &&
1181 grep "RCPT TO:<bodies@example.com>" stdout &&
1182 ! grep "RCPT TO:<other@ex.com>" stdout
1185 test_expect_success $PREREQ 'patches To headers are used by default' '
1186 patch=$(git format-patch -1 --to="bodies@example.com") &&
1187 test_when_finished "rm $patch" &&
1190 --from="Example <nobody@example.com>" \
1191 --smtp-server relay.example.com \
1193 grep "RCPT TO:<bodies@example.com>" stdout
1196 test_expect_success $PREREQ 'patches To headers are appended to' '
1197 patch=$(git format-patch -1 --to="bodies@example.com") &&
1198 test_when_finished "rm $patch" &&
1201 --from="Example <nobody@example.com>" \
1202 --to=nobody@example.com \
1203 --smtp-server relay.example.com \
1205 grep "RCPT TO:<bodies@example.com>" stdout &&
1206 grep "RCPT TO:<nobody@example.com>" stdout
1209 test_expect_success $PREREQ 'To headers from files reset each patch' '
1210 patch1=$(git format-patch -1 --to="bodies@example.com") &&
1211 patch2=$(git format-patch -1 --to="other@example.com" HEAD~) &&
1212 test_when_finished "rm $patch1 && rm $patch2" &&
1215 --from="Example <nobody@example.com>" \
1216 --to="nobody@example.com" \
1217 --smtp-server relay.example.com \
1218 $patch1 $patch2 >stdout &&
1219 test $(grep -c "RCPT TO:<bodies@example.com>" stdout) = 1 &&
1220 test $(grep -c "RCPT TO:<nobody@example.com>" stdout) = 2 &&
1221 test $(grep -c "RCPT TO:<other@example.com>" stdout) = 1
1224 test_expect_success $PREREQ 'setup expect' '
1225 cat >email-using-8bit <<\EOF
1226 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1227 Message-Id: <bogus-message-id@example.com>
1228 From: author@example.com
1229 Date: Sat, 12 Jun 2010 15:53:58 +0200
1230 Subject: subject goes here
1232 Dieser deutsche Text enthält einen Umlaut!
1236 test_expect_success $PREREQ 'setup expect' '
1237 echo "Subject: subject goes here" >expected
1240 test_expect_success $PREREQ 'ASCII subject is not RFC2047 quoted' '
1241 clean_fake_sendmail &&
1243 git send-email --from=author@example.com --to=nobody@example.com \
1244 --smtp-server="$(pwd)/fake.sendmail" \
1245 --8bit-encoding=UTF-8 \
1246 email-using-8bit >stdout &&
1247 grep "Subject" msgtxt1 >actual &&
1248 test_cmp expected actual
1251 test_expect_success $PREREQ 'setup expect' '
1252 cat >content-type-decl <<-\EOF
1254 Content-Type: text/plain; charset=UTF-8
1255 Content-Transfer-Encoding: 8bit
1259 test_expect_success $PREREQ 'asks about and fixes 8bit encodings' '
1260 clean_fake_sendmail &&
1262 git send-email --from=author@example.com --to=nobody@example.com \
1263 --smtp-server="$(pwd)/fake.sendmail" \
1264 email-using-8bit >stdout &&
1265 grep "do not declare a Content-Transfer-Encoding" stdout &&
1266 grep email-using-8bit stdout &&
1267 grep "Which 8bit encoding" stdout &&
1268 egrep "Content|MIME" msgtxt1 >actual &&
1269 test_cmp actual content-type-decl
1272 test_expect_success $PREREQ 'sendemail.8bitEncoding works' '
1273 clean_fake_sendmail &&
1274 git config sendemail.assume8bitEncoding UTF-8 &&
1276 git send-email --from=author@example.com --to=nobody@example.com \
1277 --smtp-server="$(pwd)/fake.sendmail" \
1278 email-using-8bit >stdout &&
1279 egrep "Content|MIME" msgtxt1 >actual &&
1280 test_cmp actual content-type-decl
1283 test_expect_success $PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
1284 clean_fake_sendmail &&
1285 git config sendemail.assume8bitEncoding "bogus too" &&
1287 git send-email --from=author@example.com --to=nobody@example.com \
1288 --smtp-server="$(pwd)/fake.sendmail" \
1289 --8bit-encoding=UTF-8 \
1290 email-using-8bit >stdout &&
1291 egrep "Content|MIME" msgtxt1 >actual &&
1292 test_cmp actual content-type-decl
1295 test_expect_success $PREREQ 'setup expect' '
1296 cat >email-using-8bit <<-\EOF
1297 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1298 Message-Id: <bogus-message-id@example.com>
1299 From: author@example.com
1300 Date: Sat, 12 Jun 2010 15:53:58 +0200
1301 Subject: Dieser Betreff enthält auch einen Umlaut!
1303 Nothing to see here.
1307 test_expect_success $PREREQ 'setup expect' '
1308 cat >expected <<-\EOF
1309 Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
1313 test_expect_success $PREREQ '--8bit-encoding also treats subject' '
1314 clean_fake_sendmail &&
1316 git send-email --from=author@example.com --to=nobody@example.com \
1317 --smtp-server="$(pwd)/fake.sendmail" \
1318 --8bit-encoding=UTF-8 \
1319 email-using-8bit >stdout &&
1320 grep "Subject" msgtxt1 >actual &&
1321 test_cmp expected actual
1324 test_expect_success $PREREQ 'setup expect' '
1325 cat >email-using-8bit <<-\EOF
1326 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1327 Message-Id: <bogus-message-id@example.com>
1328 From: A U Thor <author@example.com>
1329 Date: Sat, 12 Jun 2010 15:53:58 +0200
1330 Content-Type: text/plain; charset=UTF-8
1331 Subject: Nothing to see here.
1333 Dieser Betreff enthält auch einen Umlaut!
1337 test_expect_success $PREREQ 'sendemail.transferencoding=7bit fails on 8bit data' '
1338 clean_fake_sendmail &&
1339 git config sendemail.transferEncoding 7bit &&
1340 test_must_fail git send-email \
1341 --transfer-encoding=7bit \
1342 --smtp-server="$(pwd)/fake.sendmail" \
1345 grep "cannot send message as 7bit" errors &&
1346 test -z "$(ls msgtxt*)"
1349 test_expect_success $PREREQ '--transfer-encoding overrides sendemail.transferEncoding' '
1350 clean_fake_sendmail &&
1351 git config sendemail.transferEncoding 8bit &&
1352 test_must_fail git send-email \
1353 --transfer-encoding=7bit \
1354 --smtp-server="$(pwd)/fake.sendmail" \
1357 grep "cannot send message as 7bit" errors &&
1358 test -z "$(ls msgtxt*)"
1361 test_expect_success $PREREQ 'sendemail.transferencoding=8bit' '
1362 clean_fake_sendmail &&
1364 --transfer-encoding=8bit \
1365 --smtp-server="$(pwd)/fake.sendmail" \
1368 sed '1,/^$/d' msgtxt1 >actual &&
1369 sed '1,/^$/d' email-using-8bit >expected &&
1370 test_cmp expected actual
1373 test_expect_success $PREREQ 'setup expect' '
1374 cat >expected <<-\EOF
1375 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1379 test_expect_success $PREREQ '8-bit and sendemail.transferencoding=quoted-printable' '
1380 clean_fake_sendmail &&
1382 --transfer-encoding=quoted-printable \
1383 --smtp-server="$(pwd)/fake.sendmail" \
1386 sed '1,/^$/d' msgtxt1 >actual &&
1387 test_cmp expected actual
1390 test_expect_success $PREREQ 'setup expect' '
1391 cat >expected <<-\EOF
1392 RGllc2VyIEJldHJlZmYgZW50aMOkbHQgYXVjaCBlaW5lbiBVbWxhdXQhCg==
1396 test_expect_success $PREREQ '8-bit and sendemail.transferencoding=base64' '
1397 clean_fake_sendmail &&
1399 --transfer-encoding=base64 \
1400 --smtp-server="$(pwd)/fake.sendmail" \
1403 sed '1,/^$/d' msgtxt1 >actual &&
1404 test_cmp expected actual
1407 test_expect_success $PREREQ 'setup expect' '
1408 cat >email-using-qp <<-\EOF
1409 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1410 Message-Id: <bogus-message-id@example.com>
1411 From: A U Thor <author@example.com>
1412 Date: Sat, 12 Jun 2010 15:53:58 +0200
1414 Content-Transfer-Encoding: quoted-printable
1415 Content-Type: text/plain; charset=UTF-8
1416 Subject: Nothing to see here.
1418 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1422 test_expect_success $PREREQ 'convert from quoted-printable to base64' '
1423 clean_fake_sendmail &&
1425 --transfer-encoding=base64 \
1426 --smtp-server="$(pwd)/fake.sendmail" \
1429 sed '1,/^$/d' msgtxt1 >actual &&
1430 test_cmp expected actual
1433 test_expect_success $PREREQ 'setup expect' "
1434 tr -d '\\015' | tr '%' '\\015' >email-using-crlf <<EOF
1435 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1436 Message-Id: <bogus-message-id@example.com>
1437 From: A U Thor <author@example.com>
1438 Date: Sat, 12 Jun 2010 15:53:58 +0200
1439 Content-Type: text/plain; charset=UTF-8
1440 Subject: Nothing to see here.
1442 Look, I have a CRLF and an = sign!%
1446 test_expect_success $PREREQ 'setup expect' '
1447 cat >expected <<-\EOF
1448 Look, I have a CRLF and an =3D sign!=0D
1452 test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=quoted-printable' '
1453 clean_fake_sendmail &&
1455 --transfer-encoding=quoted-printable \
1456 --smtp-server="$(pwd)/fake.sendmail" \
1459 sed '1,/^$/d' msgtxt1 >actual &&
1460 test_cmp expected actual
1463 test_expect_success $PREREQ 'setup expect' '
1464 cat >expected <<-\EOF
1465 TG9vaywgSSBoYXZlIGEgQ1JMRiBhbmQgYW4gPSBzaWduIQ0K
1469 test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=base64' '
1470 clean_fake_sendmail &&
1472 --transfer-encoding=base64 \
1473 --smtp-server="$(pwd)/fake.sendmail" \
1476 sed '1,/^$/d' msgtxt1 >actual &&
1477 test_cmp expected actual
1481 # Note that the patches in this test are deliberately out of order; we
1482 # want to make sure it works even if the cover-letter is not in the
1484 test_expect_success $PREREQ 'refusing to send cover letter template' '
1485 clean_fake_sendmail &&
1487 git format-patch --cover-letter -2 -o outdir &&
1488 test_must_fail git send-email \
1489 --from="Example <nobody@example.com>" \
1490 --to=nobody@example.com \
1491 --smtp-server="$(pwd)/fake.sendmail" \
1492 outdir/0002-*.patch \
1493 outdir/0000-*.patch \
1494 outdir/0001-*.patch \
1496 grep "SUBJECT HERE" errors &&
1497 test -z "$(ls msgtxt*)"
1500 test_expect_success $PREREQ '--force sends cover letter template anyway' '
1501 clean_fake_sendmail &&
1503 git format-patch --cover-letter -2 -o outdir &&
1506 --from="Example <nobody@example.com>" \
1507 --to=nobody@example.com \
1508 --smtp-server="$(pwd)/fake.sendmail" \
1509 outdir/0002-*.patch \
1510 outdir/0000-*.patch \
1511 outdir/0001-*.patch \
1513 ! grep "SUBJECT HERE" errors &&
1514 test -n "$(ls msgtxt*)"
1517 test_cover_addresses () {
1520 clean_fake_sendmail &&
1522 git format-patch --cover-letter -2 -o outdir &&
1523 cover=$(echo outdir/0000-*.patch) &&
1524 mv $cover cover-to-edit.patch &&
1525 perl -pe "s/^From:/$header: extra\@address.com\nFrom:/" cover-to-edit.patch >"$cover" &&
1528 --from="Example <nobody@example.com>" \
1531 --smtp-server="$(pwd)/fake.sendmail" \
1532 outdir/0000-*.patch \
1533 outdir/0001-*.patch \
1534 outdir/0002-*.patch \
1536 grep "^$header: extra@address.com" msgtxt1 >to1 &&
1537 grep "^$header: extra@address.com" msgtxt2 >to2 &&
1538 grep "^$header: extra@address.com" msgtxt3 >to3 &&
1539 test_line_count = 1 to1 &&
1540 test_line_count = 1 to2 &&
1541 test_line_count = 1 to3
1544 test_expect_success $PREREQ 'to-cover adds To to all mail' '
1545 test_cover_addresses "To" --to-cover
1548 test_expect_success $PREREQ 'cc-cover adds Cc to all mail' '
1549 test_cover_addresses "Cc" --cc-cover
1552 test_expect_success $PREREQ 'tocover adds To to all mail' '
1553 test_config sendemail.tocover true &&
1554 test_cover_addresses "To"
1557 test_expect_success $PREREQ 'cccover adds Cc to all mail' '
1558 test_config sendemail.cccover true &&
1559 test_cover_addresses "Cc"
1562 test_expect_success $PREREQ 'escaped quotes in sendemail.aliasfiletype=mutt' '
1563 clean_fake_sendmail &&
1564 echo "alias sbd \\\"Dot U. Sir\\\" <somebody@example.org>" >.mutt &&
1565 git config --replace-all sendemail.aliasesfile "$(pwd)/.mutt" &&
1566 git config sendemail.aliasfiletype mutt &&
1568 --from="Example <nobody@example.com>" \
1570 --smtp-server="$(pwd)/fake.sendmail" \
1571 outdir/0001-*.patch \
1573 grep "^!somebody@example\.org!$" commandline1 &&
1574 grep -F "To: \"Dot U. Sir\" <somebody@example.org>" out
1577 test_expect_success $PREREQ 'sendemail.aliasfiletype=mailrc' '
1578 clean_fake_sendmail &&
1579 echo "alias sbd somebody@example.org" >.mailrc &&
1580 git config --replace-all sendemail.aliasesfile "$(pwd)/.mailrc" &&
1581 git config sendemail.aliasfiletype mailrc &&
1583 --from="Example <nobody@example.com>" \
1585 --smtp-server="$(pwd)/fake.sendmail" \
1586 outdir/0001-*.patch \
1588 grep "^!somebody@example\.org!$" commandline1
1591 test_expect_success $PREREQ 'sendemail.aliasfile=~/.mailrc' '
1592 clean_fake_sendmail &&
1593 echo "alias sbd someone@example.org" >"$HOME/.mailrc" &&
1594 git config --replace-all sendemail.aliasesfile "~/.mailrc" &&
1595 git config sendemail.aliasfiletype mailrc &&
1597 --from="Example <nobody@example.com>" \
1599 --smtp-server="$(pwd)/fake.sendmail" \
1600 outdir/0001-*.patch \
1602 grep "^!someone@example\.org!$" commandline1
1605 test_dump_aliases () {
1606 msg="$1" && shift &&
1607 filetype="$1" && shift &&
1608 printf '%s\n' "$@" >expect &&
1609 cat >.tmp-email-aliases &&
1611 test_expect_success $PREREQ "$msg" '
1612 clean_fake_sendmail && rm -fr outdir &&
1613 git config --replace-all sendemail.aliasesfile \
1614 "$(pwd)/.tmp-email-aliases" &&
1615 git config sendemail.aliasfiletype "$filetype" &&
1616 git send-email --dump-aliases 2>errors >actual &&
1617 test_cmp expect actual
1621 test_dump_aliases '--dump-aliases sendmail format' \
1628 alice: Alice W Land <awol@example.com>
1629 bob: Robert Bobbyton <bob@example.com>
1630 chloe: chloe@example.com
1632 bcgrp: bob, chloe, Other <o@example.com>
1635 test_dump_aliases '--dump-aliases mutt format' \
1641 alias alice Alice W Land <awol@example.com>
1642 alias donald Donald C Carlton <donc@example.com>
1643 alias bob Robert Bobbyton <bob@example.com>
1644 alias chloe chloe@example.com
1647 test_dump_aliases '--dump-aliases mailrc format' \
1653 alias alice Alice W Land <awol@example.com>
1654 alias eve Eve <eve@example.com>
1655 alias bob Robert Bobbyton <bob@example.com>
1656 alias chloe chloe@example.com
1659 test_dump_aliases '--dump-aliases pine format' \
1665 alice Alice W Land <awol@example.com>
1666 eve Eve <eve@example.com>
1667 bob Robert Bobbyton <bob@example.com>
1668 chloe chloe@example.com
1671 test_dump_aliases '--dump-aliases gnus format' \
1677 (define-mail-alias "alice" "awol@example.com")
1678 (define-mail-alias "eve" "eve@example.com")
1679 (define-mail-alias "bob" "bob@example.com")
1680 (define-mail-alias "chloe" "chloe@example.com")
1683 test_expect_success '--dump-aliases must be used alone' '
1684 test_must_fail git send-email --dump-aliases --to=janice@example.com -1 refs/heads/accounting
1687 test_sendmail_aliases () {
1688 msg="$1" && shift &&
1690 cat >.tmp-email-aliases &&
1692 test_expect_success $PREREQ "$msg" '
1693 clean_fake_sendmail && rm -fr outdir &&
1694 git format-patch -1 -o outdir &&
1695 git config --replace-all sendemail.aliasesfile \
1696 "$(pwd)/.tmp-email-aliases" &&
1697 git config sendemail.aliasfiletype sendmail &&
1699 --from="Example <nobody@example.com>" \
1700 --to=alice --to=bcgrp \
1701 --smtp-server="$(pwd)/fake.sendmail" \
1702 outdir/0001-*.patch \
1706 grep "^!$i!$" commandline1 || return 1
1711 test_sendmail_aliases 'sendemail.aliasfiletype=sendmail' \
1712 'awol@example\.com' \
1713 'bob@example\.com' \
1714 'chloe@example\.com' \
1715 'o@example\.com' <<-\EOF
1716 alice: Alice W Land <awol@example.com>
1717 bob: Robert Bobbyton <bob@example.com>
1719 # this is also a comment
1720 chloe: chloe@example.com
1722 bcgrp: bob, chloe, Other <o@example.com>
1725 test_sendmail_aliases 'sendmail aliases line folding' \
1729 darla1 darla2 darla3 \
1730 elton1 elton2 elton3 \
1747 bcgrp: bob, chuck, darla, elton, fred, greg
1750 test_sendmail_aliases 'sendmail aliases tolerate bogus line folding' \
1756 test_sendmail_aliases 'sendmail aliases empty' alice bcgrp <<-\EOF
1759 test_expect_success $PREREQ 'alias support in To header' '
1760 clean_fake_sendmail &&
1761 echo "alias sbd someone@example.org" >.mailrc &&
1762 test_config sendemail.aliasesfile ".mailrc" &&
1763 test_config sendemail.aliasfiletype mailrc &&
1764 git format-patch --stdout -1 --to=sbd >aliased.patch &&
1766 --from="Example <nobody@example.com>" \
1767 --smtp-server="$(pwd)/fake.sendmail" \
1770 grep "^!someone@example\.org!$" commandline1
1773 test_expect_success $PREREQ 'alias support in Cc header' '
1774 clean_fake_sendmail &&
1775 echo "alias sbd someone@example.org" >.mailrc &&
1776 test_config sendemail.aliasesfile ".mailrc" &&
1777 test_config sendemail.aliasfiletype mailrc &&
1778 git format-patch --stdout -1 --cc=sbd >aliased.patch &&
1780 --from="Example <nobody@example.com>" \
1781 --smtp-server="$(pwd)/fake.sendmail" \
1784 grep "^!someone@example\.org!$" commandline1
1787 test_expect_success $PREREQ 'tocmd works with aliases' '
1788 clean_fake_sendmail &&
1789 echo "alias sbd someone@example.org" >.mailrc &&
1790 test_config sendemail.aliasesfile ".mailrc" &&
1791 test_config sendemail.aliasfiletype mailrc &&
1792 git format-patch --stdout -1 >tocmd.patch &&
1793 echo tocmd--sbd >>tocmd.patch &&
1795 --from="Example <nobody@example.com>" \
1796 --to-cmd=./tocmd-sed \
1797 --smtp-server="$(pwd)/fake.sendmail" \
1800 grep "^!someone@example\.org!$" commandline1
1803 test_expect_success $PREREQ 'cccmd 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 >cccmd.patch &&
1809 echo cccmd--sbd >>cccmd.patch &&
1811 --from="Example <nobody@example.com>" \
1812 --cc-cmd=./cccmd-sed \
1813 --smtp-server="$(pwd)/fake.sendmail" \
1816 grep "^!someone@example\.org!$" commandline1
1819 do_xmailer_test () {
1820 expected=$1 params=$2 &&
1821 git format-patch -1 &&
1823 --from="Example <nobody@example.com>" \
1824 --to=someone@example.com \
1825 --smtp-server="$(pwd)/fake.sendmail" \
1829 { grep '^X-Mailer:' out || :; } >mailer &&
1830 test_line_count = $expected mailer
1833 test_expect_success $PREREQ '--[no-]xmailer without any configuration' '
1834 do_xmailer_test 1 "--xmailer" &&
1835 do_xmailer_test 0 "--no-xmailer"
1838 test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=true' '
1839 test_config sendemail.xmailer true &&
1840 do_xmailer_test 1 "" &&
1841 do_xmailer_test 0 "--no-xmailer" &&
1842 do_xmailer_test 1 "--xmailer"
1845 test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=false' '
1846 test_config sendemail.xmailer false &&
1847 do_xmailer_test 0 "" &&
1848 do_xmailer_test 0 "--no-xmailer" &&
1849 do_xmailer_test 1 "--xmailer"
1852 test_expect_success $PREREQ 'setup expected-list' '
1855 --from="Example <from@example.com>" \
1856 --to="To 1 <to1@example.com>" \
1857 --to="to2@example.com" \
1858 --to="to3@example.com" \
1859 --cc="Cc 1 <cc1@example.com>" \
1860 --cc="Cc2 <cc2@example.com>" \
1861 --bcc="bcc1@example.com" \
1862 --bcc="bcc2@example.com" \
1863 0001-add-master.patch | replace_variable_fields \
1867 test_expect_success $PREREQ 'use email list in --cc --to and --bcc' '
1870 --from="Example <from@example.com>" \
1871 --to="To 1 <to1@example.com>, to2@example.com" \
1872 --to="to3@example.com" \
1873 --cc="Cc 1 <cc1@example.com>, Cc2 <cc2@example.com>" \
1874 --bcc="bcc1@example.com, bcc2@example.com" \
1875 0001-add-master.patch | replace_variable_fields \
1877 test_cmp expected-list actual-list
1880 test_expect_success $PREREQ 'aliases work with email list' '
1881 echo "alias to2 to2@example.com" >.mutt &&
1882 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt &&
1883 test_config sendemail.aliasesfile ".mutt" &&
1884 test_config sendemail.aliasfiletype mutt &&
1887 --from="Example <from@example.com>" \
1888 --to="To 1 <to1@example.com>, to2, to3@example.com" \
1889 --cc="cc1, 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 'leading and trailing whitespaces are removed' '
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 &&
1901 TO1=$(echo "QTo 1 <to1@example.com>" | q_to_tab) &&
1902 TO2=$(echo "QZto2" | qz_to_tab_space) &&
1903 CC1=$(echo "cc1" | append_cr) &&
1904 BCC1=$(echo "Q bcc1@example.com Q" | q_to_nul) &&
1907 --from=" Example <from@example.com>" \
1910 --to=" to3@example.com " \
1912 --cc="Cc2 <cc2@example.com>" \
1914 --bcc="bcc2@example.com" \
1915 0001-add-master.patch | replace_variable_fields \
1917 test_cmp expected-list actual-list
1920 test_expect_success $PREREQ 'invoke hook' '
1921 mkdir -p .git/hooks &&
1923 write_script .git/hooks/sendemail-validate <<-\EOF &&
1924 # test that we have the correct environment variable, pwd, and
1934 test -f 0001-add-master.patch &&
1935 grep "add master" "$1"
1940 # Test that it works even if we are not at the root of the
1944 --from="Example <nobody@example.com>" \
1945 --to=nobody@example.com \
1946 --smtp-server="$(pwd)/../fake.sendmail" \
1947 ../0001-add-master.patch &&
1949 # Verify error message when a patch is rejected by the hook
1950 sed -e "s/add master/x/" ../0001-add-master.patch >../another.patch &&
1952 --from="Example <nobody@example.com>" \
1953 --to=nobody@example.com \
1954 --smtp-server="$(pwd)/../fake.sendmail" \
1955 ../another.patch 2>err
1956 test_i18ngrep "rejected by sendemail-validate hook" err
1960 test_expect_success $PREREQ 'test that send-email works outside a repo' '
1961 nongit git send-email \
1962 --from="Example <nobody@example.com>" \
1963 --to=nobody@example.com \
1964 --smtp-server="$(pwd)/fake.sendmail" \
1965 "$(pwd)/0001-add-master.patch"