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 test_must_fail
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' "
144 cat >expected-show-all-headers <<\EOF
146 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
147 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
148 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
150 Server: relay.example.com
151 MAIL FROM:<from@example.com>
152 RCPT TO:<to@example.com>
153 RCPT TO:<cc@example.com>
154 RCPT TO:<author@example.com>
155 RCPT TO:<one@example.com>
156 RCPT TO:<two@example.com>
157 RCPT TO:<bcc@example.com>
158 From: Example <from@example.com>
161 A <author@example.com>,
162 One <one@example.com>,
164 Subject: [PATCH 1/1] Second.
166 Message-Id: MESSAGE-ID-STRING
167 X-Mailer: X-MAILER-STRING
168 In-Reply-To: <unique-message-id@example.com>
169 References: <unique-message-id@example.com>
175 test_suppress_self
() {
177 test_when_finished
"git reset --hard HEAD^" &&
179 write_script cccmd-sed
<<-EOF &&
180 sed -n -e s/^cccmd--//p "\$1"
183 git commit
--amend --author="$1 <$2>" -F - &&
184 clean_fake_sendmail
&&
185 git format-patch
--stdout -1 >"suppress-self-$3.patch" &&
187 git send-email
--from="$1 <$2>" \
188 --to=nobody@example.com \
189 --cc-cmd=.
/cccmd-sed \
191 --smtp-server="$(pwd)/fake.sendmail" \
192 suppress-self-
$3.
patch &&
194 mv msgtxt1 msgtxt1-
$3 &&
195 sed -e '/^$/q' msgtxt1-
$3 >"msghdr1-$3" &&
196 >"expected-no-cc-$3" &&
198 (grep '^Cc:' msghdr1-
$3 >"actual-no-cc-$3";
199 test_cmp expected-no-cc-
$3 actual-no-cc-
$3)
202 test_suppress_self_unquoted
() {
203 test_suppress_self
"$1" "$2" "unquoted-$3" <<-EOF
204 test suppress-cc.self unquoted-$3 with name $1 email $2
211 Signed-off-by: $1 <$2>
215 test_suppress_self_quoted
() {
216 test_suppress_self
"$1" "$2" "quoted-$3" <<-EOF
217 test suppress-cc.self quoted-$3 with name $1 email $2
225 Signed-off-by: $1 <$2>
226 Signed-off-by: "$1" <$2>
230 test_expect_success
$PREREQ 'self name is suppressed' "
231 test_suppress_self_unquoted 'A U Thor' 'author@example.com' \
232 'self_name_suppressed'
235 test_expect_success
$PREREQ 'self name with dot is suppressed' "
236 test_suppress_self_quoted 'A U. Thor' 'author@example.com' \
237 'self_name_dot_suppressed'
240 test_expect_success
$PREREQ 'non-ascii self name is suppressed' "
241 test_suppress_self_quoted 'Füñný Nâmé' 'odd_?=mail@example.com' \
242 'non_ascii_self_suppressed'
245 # This name is long enough to force format-patch to split it into multiple
246 # encoded-words, assuming it uses UTF-8 with the "Q" encoding.
247 test_expect_success
$PREREQ 'long non-ascii self name is suppressed' "
248 test_suppress_self_quoted 'Ƒüñníęř €. Nâṁé' 'odd_?=mail@example.com' \
249 'long_non_ascii_self_suppressed'
252 test_expect_success
$PREREQ 'sanitized self name is suppressed' "
253 test_suppress_self_unquoted '\"A U. Thor\"' 'author@example.com' \
254 'self_name_sanitized_suppressed'
257 test_expect_success
$PREREQ 'Show all headers' '
261 --from="Example <from@example.com>" \
262 --to=to@example.com \
263 --cc=cc@example.com \
264 --bcc=bcc@example.com \
265 --in-reply-to="<unique-message-id@example.com>" \
266 --smtp-server relay.example.com \
268 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
269 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
270 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
271 >actual-show-all-headers &&
272 test_cmp expected-show-all-headers actual-show-all-headers
275 test_expect_success
$PREREQ 'Prompting works' '
276 clean_fake_sendmail &&
277 (echo "to@example.com"
279 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
280 --smtp-server="$(pwd)/fake.sendmail" \
283 grep "^From: A U Thor <author@example.com>\$" msgtxt1 &&
284 grep "^To: to@example.com\$" msgtxt1
287 test_expect_success
$PREREQ,AUTOIDENT
'implicit ident is allowed' '
288 clean_fake_sendmail &&
289 (sane_unset GIT_AUTHOR_NAME &&
290 sane_unset GIT_AUTHOR_EMAIL &&
291 sane_unset GIT_COMMITTER_NAME &&
292 sane_unset GIT_COMMITTER_EMAIL &&
293 GIT_SEND_EMAIL_NOTTY=1 git send-email \
294 --smtp-server="$(pwd)/fake.sendmail" \
295 --to=to@example.com \
296 $patches </dev/null 2>errors
300 test_expect_success
$PREREQ,!AUTOIDENT
'broken implicit ident aborts send-email' '
301 clean_fake_sendmail &&
302 (sane_unset GIT_AUTHOR_NAME &&
303 sane_unset GIT_AUTHOR_EMAIL &&
304 sane_unset GIT_COMMITTER_NAME &&
305 sane_unset GIT_COMMITTER_EMAIL &&
306 GIT_SEND_EMAIL_NOTTY=1 && export GIT_SEND_EMAIL_NOTTY &&
307 test_must_fail git send-email \
308 --smtp-server="$(pwd)/fake.sendmail" \
309 --to=to@example.com \
310 $patches </dev/null 2>errors &&
311 test_i18ngrep "tell me who you are" errors
315 test_expect_success
$PREREQ 'setup tocmd and cccmd scripts' '
316 write_script tocmd-sed <<-\EOF &&
317 sed -n -e "s/^tocmd--//p" "$1"
319 write_script cccmd-sed <<-\EOF
320 sed -n -e "s/^cccmd--//p" "$1"
324 test_expect_success
$PREREQ 'tocmd works' '
325 clean_fake_sendmail &&
326 cp $patches tocmd.patch &&
327 echo tocmd--tocmd@example.com >>tocmd.patch &&
329 --from="Example <nobody@example.com>" \
330 --to-cmd=./tocmd-sed \
331 --smtp-server="$(pwd)/fake.sendmail" \
334 grep "^To: tocmd@example.com" msgtxt1
337 test_expect_success
$PREREQ 'cccmd works' '
338 clean_fake_sendmail &&
339 cp $patches cccmd.patch &&
340 echo "cccmd-- cccmd@example.com" >>cccmd.patch &&
342 --from="Example <nobody@example.com>" \
343 --to=nobody@example.com \
344 --cc-cmd=./cccmd-sed \
345 --smtp-server="$(pwd)/fake.sendmail" \
348 grep "^ cccmd@example.com" msgtxt1
351 test_expect_success
$PREREQ 'reject long lines' '
353 z64=$z8$z8$z8$z8$z8$z8$z8$z8 &&
354 z512=$z64$z64$z64$z64$z64$z64$z64$z64 &&
355 clean_fake_sendmail &&
356 cp $patches longline.patch &&
357 echo $z512$z512 >>longline.patch &&
358 test_must_fail git send-email \
359 --from="Example <nobody@example.com>" \
360 --to=nobody@example.com \
361 --smtp-server="$(pwd)/fake.sendmail" \
362 $patches longline.patch \
364 grep longline.patch errors
367 test_expect_success
$PREREQ 'no patch was sent' '
368 ! test -e commandline1
371 test_expect_success
$PREREQ 'Author From: in message body' '
372 clean_fake_sendmail &&
374 --from="Example <nobody@example.com>" \
375 --to=nobody@example.com \
376 --smtp-server="$(pwd)/fake.sendmail" \
378 sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
379 grep "From: A <author@example.com>" msgbody1
382 test_expect_success
$PREREQ 'Author From: not in message body' '
383 clean_fake_sendmail &&
385 --from="A <author@example.com>" \
386 --to=nobody@example.com \
387 --smtp-server="$(pwd)/fake.sendmail" \
389 sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
390 ! grep "From: A <author@example.com>" msgbody1
393 test_expect_success
$PREREQ 'allow long lines with --no-validate' '
395 --from="Example <nobody@example.com>" \
396 --to=nobody@example.com \
397 --smtp-server="$(pwd)/fake.sendmail" \
399 $patches longline.patch \
403 test_expect_success
$PREREQ 'Invalid In-Reply-To' '
404 clean_fake_sendmail &&
406 --from="Example <nobody@example.com>" \
407 --to=nobody@example.com \
409 --smtp-server="$(pwd)/fake.sendmail" \
412 ! grep "^In-Reply-To: < *>" msgtxt1
415 test_expect_success
$PREREQ 'Valid In-Reply-To when prompting' '
416 clean_fake_sendmail &&
417 (echo "From Example <from@example.com>"
418 echo "To Example <to@example.com>"
420 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
421 --smtp-server="$(pwd)/fake.sendmail" \
423 ! grep "^In-Reply-To: < *>" msgtxt1
426 test_expect_success
$PREREQ 'In-Reply-To without --chain-reply-to' '
427 clean_fake_sendmail &&
428 echo "<unique-message-id@example.com>" >expect &&
430 --from="Example <nobody@example.com>" \
431 --to=nobody@example.com \
432 --no-chain-reply-to \
433 --in-reply-to="$(cat expect)" \
434 --smtp-server="$(pwd)/fake.sendmail" \
435 $patches $patches $patches \
437 # The first message is a reply to --in-reply-to
438 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
439 test_cmp expect actual &&
440 # Second and subsequent messages are replies to the first one
441 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
442 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
443 test_cmp expect actual &&
444 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
445 test_cmp expect actual
448 test_expect_success
$PREREQ 'In-Reply-To with --chain-reply-to' '
449 clean_fake_sendmail &&
450 echo "<unique-message-id@example.com>" >expect &&
452 --from="Example <nobody@example.com>" \
453 --to=nobody@example.com \
455 --in-reply-to="$(cat expect)" \
456 --smtp-server="$(pwd)/fake.sendmail" \
457 $patches $patches $patches \
459 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
460 test_cmp expect actual &&
461 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
462 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
463 test_cmp expect actual &&
464 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt2 >expect &&
465 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
466 test_cmp expect actual
469 test_expect_success
$PREREQ 'setup fake editor' '
470 write_script fake-editor <<-\EOF
471 echo fake edit >>"$1"
475 test_set_editor
"$(pwd)/fake-editor"
477 test_expect_success
$PREREQ '--compose works' '
478 clean_fake_sendmail &&
480 --compose --subject foo \
481 --from="Example <nobody@example.com>" \
482 --to=nobody@example.com \
483 --smtp-server="$(pwd)/fake.sendmail" \
488 test_expect_success
$PREREQ 'first message is compose text' '
489 grep "^fake edit" msgtxt1
492 test_expect_success
$PREREQ 'second message is patch' '
493 grep "Subject:.*Second" msgtxt2
496 test_expect_success
$PREREQ 'setup expect' "
497 cat >expected-suppress-sob <<\EOF
499 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
500 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
501 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
503 Server: relay.example.com
504 MAIL FROM:<from@example.com>
505 RCPT TO:<to@example.com>
506 RCPT TO:<cc@example.com>
507 RCPT TO:<author@example.com>
508 RCPT TO:<one@example.com>
509 RCPT TO:<two@example.com>
510 From: Example <from@example.com>
513 A <author@example.com>,
514 One <one@example.com>,
516 Subject: [PATCH 1/1] Second.
518 Message-Id: MESSAGE-ID-STRING
519 X-Mailer: X-MAILER-STRING
525 replace_variable_fields
() {
526 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
527 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
528 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/"
531 test_suppression
() {
534 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
535 --from="Example <from@example.com>" \
536 --to=to@example.com \
537 --smtp-server relay.example.com \
538 $patches | replace_variable_fields \
539 >actual-suppress-
$1${2+"-$2"} &&
540 test_cmp expected-suppress-
$1${2+"-$2"} actual-suppress-
$1${2+"-$2"}
543 test_expect_success
$PREREQ 'sendemail.cc set' '
544 git config sendemail.cc cc@example.com &&
548 test_expect_success
$PREREQ 'setup expect' "
549 cat >expected-suppress-sob <<\EOF
551 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
552 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
553 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
555 Server: relay.example.com
556 MAIL FROM:<from@example.com>
557 RCPT TO:<to@example.com>
558 RCPT TO:<author@example.com>
559 RCPT TO:<one@example.com>
560 RCPT TO:<two@example.com>
561 From: Example <from@example.com>
563 Cc: A <author@example.com>,
564 One <one@example.com>,
566 Subject: [PATCH 1/1] Second.
568 Message-Id: MESSAGE-ID-STRING
569 X-Mailer: X-MAILER-STRING
575 test_expect_success
$PREREQ 'sendemail.cc unset' '
576 git config --unset sendemail.cc &&
580 test_expect_success
$PREREQ 'setup expect' "
581 cat >expected-suppress-cccmd <<\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'
586 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
588 Server: relay.example.com
589 MAIL FROM:<from@example.com>
590 RCPT TO:<to@example.com>
591 RCPT TO:<author@example.com>
592 RCPT TO:<one@example.com>
593 RCPT TO:<two@example.com>
594 RCPT TO:<committer@example.com>
595 From: Example <from@example.com>
597 Cc: A <author@example.com>,
598 One <one@example.com>,
600 C O Mitter <committer@example.com>
601 Subject: [PATCH 1/1] Second.
603 Message-Id: MESSAGE-ID-STRING
604 X-Mailer: X-MAILER-STRING
610 test_expect_success
$PREREQ 'sendemail.cccmd' '
611 write_script cccmd <<-\EOF &&
612 echo cc-cmd@example.com
614 git config sendemail.cccmd ./cccmd &&
615 test_suppression cccmd
618 test_expect_success
$PREREQ 'setup expect' '
619 cat >expected-suppress-all <<\EOF
622 Server: relay.example.com
623 MAIL FROM:<from@example.com>
624 RCPT TO:<to@example.com>
625 From: Example <from@example.com>
627 Subject: [PATCH 1/1] Second.
629 Message-Id: MESSAGE-ID-STRING
630 X-Mailer: X-MAILER-STRING
636 test_expect_success
$PREREQ '--suppress-cc=all' '
640 test_expect_success
$PREREQ 'setup expect' "
641 cat >expected-suppress-body <<\EOF
643 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
644 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
645 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
646 (cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
648 Server: relay.example.com
649 MAIL FROM:<from@example.com>
650 RCPT TO:<to@example.com>
651 RCPT TO:<author@example.com>
652 RCPT TO:<one@example.com>
653 RCPT TO:<two@example.com>
654 RCPT TO:<cc-cmd@example.com>
655 From: Example <from@example.com>
657 Cc: A <author@example.com>,
658 One <one@example.com>,
661 Subject: [PATCH 1/1] Second.
663 Message-Id: MESSAGE-ID-STRING
664 X-Mailer: X-MAILER-STRING
670 test_expect_success
$PREREQ '--suppress-cc=body' '
671 test_suppression body
674 test_expect_success
$PREREQ 'setup expect' "
675 cat >expected-suppress-body-cccmd <<\EOF
677 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
678 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
679 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
681 Server: relay.example.com
682 MAIL FROM:<from@example.com>
683 RCPT TO:<to@example.com>
684 RCPT TO:<author@example.com>
685 RCPT TO:<one@example.com>
686 RCPT TO:<two@example.com>
687 From: Example <from@example.com>
689 Cc: A <author@example.com>,
690 One <one@example.com>,
692 Subject: [PATCH 1/1] Second.
694 Message-Id: MESSAGE-ID-STRING
695 X-Mailer: X-MAILER-STRING
701 test_expect_success
$PREREQ '--suppress-cc=body --suppress-cc=cccmd' '
702 test_suppression body cccmd
705 test_expect_success
$PREREQ 'setup expect' "
706 cat >expected-suppress-sob <<\EOF
708 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
709 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
710 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
712 Server: relay.example.com
713 MAIL FROM:<from@example.com>
714 RCPT TO:<to@example.com>
715 RCPT TO:<author@example.com>
716 RCPT TO:<one@example.com>
717 RCPT TO:<two@example.com>
718 From: Example <from@example.com>
720 Cc: A <author@example.com>,
721 One <one@example.com>,
723 Subject: [PATCH 1/1] Second.
725 Message-Id: MESSAGE-ID-STRING
726 X-Mailer: X-MAILER-STRING
732 test_expect_success
$PREREQ '--suppress-cc=sob' '
733 test_might_fail git config --unset sendemail.cccmd &&
737 test_expect_success
$PREREQ 'setup expect' "
738 cat >expected-suppress-bodycc <<\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'
743 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
745 Server: relay.example.com
746 MAIL FROM:<from@example.com>
747 RCPT TO:<to@example.com>
748 RCPT TO:<author@example.com>
749 RCPT TO:<one@example.com>
750 RCPT TO:<two@example.com>
751 RCPT TO:<committer@example.com>
752 From: Example <from@example.com>
754 Cc: A <author@example.com>,
755 One <one@example.com>,
757 C O Mitter <committer@example.com>
758 Subject: [PATCH 1/1] Second.
760 Message-Id: MESSAGE-ID-STRING
761 X-Mailer: X-MAILER-STRING
767 test_expect_success
$PREREQ '--suppress-cc=bodycc' '
768 test_suppression bodycc
771 test_expect_success
$PREREQ 'setup expect' "
772 cat >expected-suppress-cc <<\EOF
774 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@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:<committer@example.com>
782 From: Example <from@example.com>
784 Cc: A <author@example.com>,
785 C O Mitter <committer@example.com>
786 Subject: [PATCH 1/1] Second.
788 Message-Id: MESSAGE-ID-STRING
789 X-Mailer: X-MAILER-STRING
795 test_expect_success
$PREREQ '--suppress-cc=cc' '
801 GIT_SEND_EMAIL_NOTTY
=1 \
803 --from="Example <nobody@example.com>" \
804 --to=nobody@example.com \
805 --smtp-server="$(pwd)/fake.sendmail" \
806 $@
$patches >stdout
&&
807 grep "Send this email" stdout
810 test_expect_success
$PREREQ '--confirm=always' '
811 test_confirm --confirm=always --suppress-cc=all
814 test_expect_success
$PREREQ '--confirm=auto' '
815 test_confirm --confirm=auto
818 test_expect_success
$PREREQ '--confirm=cc' '
819 test_confirm --confirm=cc
822 test_expect_success
$PREREQ '--confirm=compose' '
823 test_confirm --confirm=compose --compose
826 test_expect_success
$PREREQ 'confirm by default (due to cc)' '
827 test_when_finished git config sendemail.confirm never &&
828 git config --unset sendemail.confirm &&
832 test_expect_success
$PREREQ 'confirm by default (due to --compose)' '
833 test_when_finished git config sendemail.confirm never &&
834 git config --unset sendemail.confirm &&
835 test_confirm --suppress-cc=all --compose
838 test_expect_success
$PREREQ 'confirm detects EOF (inform assumes y)' '
839 test_when_finished git config sendemail.confirm never &&
840 git config --unset sendemail.confirm &&
842 git format-patch -2 -o outdir &&
843 GIT_SEND_EMAIL_NOTTY=1 \
845 --from="Example <nobody@example.com>" \
846 --to=nobody@example.com \
847 --smtp-server="$(pwd)/fake.sendmail" \
848 outdir/*.patch </dev/null
851 test_expect_success
$PREREQ 'confirm detects EOF (auto causes failure)' '
852 test_when_finished git config sendemail.confirm never &&
853 git config sendemail.confirm auto &&
854 GIT_SEND_EMAIL_NOTTY=1 &&
855 export GIT_SEND_EMAIL_NOTTY &&
856 test_must_fail git send-email \
857 --from="Example <nobody@example.com>" \
858 --to=nobody@example.com \
859 --smtp-server="$(pwd)/fake.sendmail" \
863 test_expect_success
$PREREQ 'confirm does not loop forever' '
864 test_when_finished git config sendemail.confirm never &&
865 git config sendemail.confirm auto &&
866 GIT_SEND_EMAIL_NOTTY=1 &&
867 export GIT_SEND_EMAIL_NOTTY &&
868 yes "bogus" | test_must_fail git send-email \
869 --from="Example <nobody@example.com>" \
870 --to=nobody@example.com \
871 --smtp-server="$(pwd)/fake.sendmail" \
875 test_expect_success
$PREREQ 'utf8 Cc is rfc2047 encoded' '
876 clean_fake_sendmail &&
878 git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
880 --from="Example <nobody@example.com>" \
881 --to=nobody@example.com \
882 --smtp-server="$(pwd)/fake.sendmail" \
885 grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
888 test_expect_success
$PREREQ '--compose adds MIME for utf8 body' '
889 clean_fake_sendmail &&
890 write_script fake-editor-utf8 <<-\EOF &&
891 echo "utf8 body: àéìöú" >>"$1"
893 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
895 --compose --subject foo \
896 --from="Example <nobody@example.com>" \
897 --to=nobody@example.com \
898 --smtp-server="$(pwd)/fake.sendmail" \
900 grep "^utf8 body" msgtxt1 &&
901 grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
904 test_expect_success
$PREREQ '--compose respects user mime type' '
905 clean_fake_sendmail &&
906 write_script fake-editor-utf8-mime <<-\EOF &&
909 Content-Type: text/plain; charset=iso-8859-1
910 Content-Transfer-Encoding: 8bit
916 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
918 --compose --subject foo \
919 --from="Example <nobody@example.com>" \
920 --to=nobody@example.com \
921 --smtp-server="$(pwd)/fake.sendmail" \
923 grep "^utf8 body" msgtxt1 &&
924 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
925 ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
928 test_expect_success
$PREREQ '--compose adds MIME for utf8 subject' '
929 clean_fake_sendmail &&
930 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
932 --compose --subject utf8-sübjëct \
933 --from="Example <nobody@example.com>" \
934 --to=nobody@example.com \
935 --smtp-server="$(pwd)/fake.sendmail" \
937 grep "^fake edit" msgtxt1 &&
938 grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
941 test_expect_success
$PREREQ 'utf8 author is correctly passed on' '
942 clean_fake_sendmail &&
943 test_commit weird_author &&
944 test_when_finished "git reset --hard HEAD^" &&
945 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
946 git format-patch --stdout -1 >funny_name.patch &&
947 git send-email --from="Example <nobody@example.com>" \
948 --to=nobody@example.com \
949 --smtp-server="$(pwd)/fake.sendmail" \
951 grep "^From: Füñný Nâmé <odd_?=mail@example.com>" msgtxt1
954 test_expect_success
$PREREQ 'utf8 sender is not duplicated' '
955 clean_fake_sendmail &&
956 test_commit weird_sender &&
957 test_when_finished "git reset --hard HEAD^" &&
958 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
959 git format-patch --stdout -1 >funny_name.patch &&
960 git send-email --from="Füñný Nâmé <odd_?=mail@example.com>" \
961 --to=nobody@example.com \
962 --smtp-server="$(pwd)/fake.sendmail" \
964 grep "^From: " msgtxt1 >msgfrom &&
965 test_line_count = 1 msgfrom
968 test_expect_success
$PREREQ 'sendemail.composeencoding works' '
969 clean_fake_sendmail &&
970 git config sendemail.composeencoding iso-8859-1 &&
971 write_script fake-editor-utf8 <<-\EOF &&
972 echo "utf8 body: àéìöú" >>"$1"
974 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
976 --compose --subject foo \
977 --from="Example <nobody@example.com>" \
978 --to=nobody@example.com \
979 --smtp-server="$(pwd)/fake.sendmail" \
981 grep "^utf8 body" msgtxt1 &&
982 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
985 test_expect_success
$PREREQ '--compose-encoding works' '
986 clean_fake_sendmail &&
987 write_script fake-editor-utf8 <<-\EOF &&
988 echo "utf8 body: àéìöú" >>"$1"
990 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
992 --compose-encoding iso-8859-1 \
993 --compose --subject foo \
994 --from="Example <nobody@example.com>" \
995 --to=nobody@example.com \
996 --smtp-server="$(pwd)/fake.sendmail" \
998 grep "^utf8 body" msgtxt1 &&
999 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1002 test_expect_success
$PREREQ '--compose-encoding overrides sendemail.composeencoding' '
1003 clean_fake_sendmail &&
1004 git config sendemail.composeencoding iso-8859-1 &&
1005 write_script fake-editor-utf8 <<-\EOF &&
1006 echo "utf8 body: àéìöú" >>"$1"
1008 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1010 --compose-encoding iso-8859-2 \
1011 --compose --subject foo \
1012 --from="Example <nobody@example.com>" \
1013 --to=nobody@example.com \
1014 --smtp-server="$(pwd)/fake.sendmail" \
1016 grep "^utf8 body" msgtxt1 &&
1017 grep "^Content-Type: text/plain; charset=iso-8859-2" msgtxt1
1020 test_expect_success
$PREREQ '--compose-encoding adds correct MIME for subject' '
1021 clean_fake_sendmail &&
1022 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
1024 --compose-encoding iso-8859-2 \
1025 --compose --subject utf8-sübjëct \
1026 --from="Example <nobody@example.com>" \
1027 --to=nobody@example.com \
1028 --smtp-server="$(pwd)/fake.sendmail" \
1030 grep "^fake edit" msgtxt1 &&
1031 grep "^Subject: =?iso-8859-2?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
1034 test_expect_success
$PREREQ 'detects ambiguous reference/file conflict' '
1035 echo master >master &&
1037 git commit -m"add master" &&
1038 test_must_fail git send-email --dry-run master 2>errors &&
1039 grep disambiguate errors
1042 test_expect_success
$PREREQ 'feed two files' '
1044 git format-patch -2 -o outdir &&
1047 --from="Example <nobody@example.com>" \
1048 --to=nobody@example.com \
1049 outdir/000?-*.patch 2>errors >out &&
1050 grep "^Subject: " out >subjects &&
1051 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
1052 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"
1055 test_expect_success
$PREREQ 'in-reply-to but no threading' '
1058 --from="Example <nobody@example.com>" \
1059 --to=nobody@example.com \
1060 --in-reply-to="<in-reply-id@example.com>" \
1063 grep "In-Reply-To: <in-reply-id@example.com>"
1066 test_expect_success
$PREREQ 'no in-reply-to and no threading' '
1069 --from="Example <nobody@example.com>" \
1070 --to=nobody@example.com \
1072 $patches $patches >stdout &&
1073 ! grep "In-Reply-To: " stdout
1076 test_expect_success
$PREREQ 'threading but no chain-reply-to' '
1079 --from="Example <nobody@example.com>" \
1080 --to=nobody@example.com \
1082 --no-chain-reply-to \
1083 $patches $patches >stdout &&
1084 grep "In-Reply-To: " stdout
1087 test_expect_success
$PREREQ 'sendemail.to works' '
1088 git config --replace-all sendemail.to "Somebody <somebody@ex.com>" &&
1091 --from="Example <nobody@example.com>" \
1092 $patches $patches >stdout &&
1093 grep "To: Somebody <somebody@ex.com>" stdout
1096 test_expect_success
$PREREQ '--no-to overrides sendemail.to' '
1099 --from="Example <nobody@example.com>" \
1101 --to=nobody@example.com \
1102 $patches $patches >stdout &&
1103 grep "To: nobody@example.com" stdout &&
1104 ! grep "To: Somebody <somebody@ex.com>" stdout
1107 test_expect_success
$PREREQ 'sendemail.cc works' '
1108 git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" &&
1111 --from="Example <nobody@example.com>" \
1112 --to=nobody@example.com \
1113 $patches $patches >stdout &&
1114 grep "Cc: Somebody <somebody@ex.com>" stdout
1117 test_expect_success
$PREREQ '--no-cc overrides sendemail.cc' '
1120 --from="Example <nobody@example.com>" \
1122 --cc=bodies@example.com \
1123 --to=nobody@example.com \
1124 $patches $patches >stdout &&
1125 grep "Cc: bodies@example.com" stdout &&
1126 ! grep "Cc: Somebody <somebody@ex.com>" stdout
1129 test_expect_success
$PREREQ 'sendemail.bcc works' '
1130 git config --replace-all sendemail.bcc "Other <other@ex.com>" &&
1133 --from="Example <nobody@example.com>" \
1134 --to=nobody@example.com \
1135 --smtp-server relay.example.com \
1136 $patches $patches >stdout &&
1137 grep "RCPT TO:<other@ex.com>" stdout
1140 test_expect_success
$PREREQ '--no-bcc overrides sendemail.bcc' '
1143 --from="Example <nobody@example.com>" \
1145 --bcc=bodies@example.com \
1146 --to=nobody@example.com \
1147 --smtp-server relay.example.com \
1148 $patches $patches >stdout &&
1149 grep "RCPT TO:<bodies@example.com>" stdout &&
1150 ! grep "RCPT TO:<other@ex.com>" stdout
1153 test_expect_success
$PREREQ 'patches To headers are used by default' '
1154 patch=$(git format-patch -1 --to="bodies@example.com") &&
1155 test_when_finished "rm $patch" &&
1158 --from="Example <nobody@example.com>" \
1159 --smtp-server relay.example.com \
1161 grep "RCPT TO:<bodies@example.com>" stdout
1164 test_expect_success
$PREREQ 'patches To headers are appended to' '
1165 patch=$(git format-patch -1 --to="bodies@example.com") &&
1166 test_when_finished "rm $patch" &&
1169 --from="Example <nobody@example.com>" \
1170 --to=nobody@example.com \
1171 --smtp-server relay.example.com \
1173 grep "RCPT TO:<bodies@example.com>" stdout &&
1174 grep "RCPT TO:<nobody@example.com>" stdout
1177 test_expect_success
$PREREQ 'To headers from files reset each patch' '
1178 patch1=$(git format-patch -1 --to="bodies@example.com") &&
1179 patch2=$(git format-patch -1 --to="other@example.com" HEAD~) &&
1180 test_when_finished "rm $patch1 && rm $patch2" &&
1183 --from="Example <nobody@example.com>" \
1184 --to="nobody@example.com" \
1185 --smtp-server relay.example.com \
1186 $patch1 $patch2 >stdout &&
1187 test $(grep -c "RCPT TO:<bodies@example.com>" stdout) = 1 &&
1188 test $(grep -c "RCPT TO:<nobody@example.com>" stdout) = 2 &&
1189 test $(grep -c "RCPT TO:<other@example.com>" stdout) = 1
1192 test_expect_success
$PREREQ 'setup expect' '
1193 cat >email-using-8bit <<\EOF
1194 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1195 Message-Id: <bogus-message-id@example.com>
1196 From: author@example.com
1197 Date: Sat, 12 Jun 2010 15:53:58 +0200
1198 Subject: subject goes here
1200 Dieser deutsche Text enthält einen Umlaut!
1204 test_expect_success
$PREREQ 'setup expect' '
1205 echo "Subject: subject goes here" >expected
1208 test_expect_success
$PREREQ 'ASCII subject is not RFC2047 quoted' '
1209 clean_fake_sendmail &&
1211 git send-email --from=author@example.com --to=nobody@example.com \
1212 --smtp-server="$(pwd)/fake.sendmail" \
1213 --8bit-encoding=UTF-8 \
1214 email-using-8bit >stdout &&
1215 grep "Subject" msgtxt1 >actual &&
1216 test_cmp expected actual
1219 test_expect_success
$PREREQ 'setup expect' '
1220 cat >content-type-decl <<-\EOF
1222 Content-Type: text/plain; charset=UTF-8
1223 Content-Transfer-Encoding: 8bit
1227 test_expect_success
$PREREQ 'asks about and fixes 8bit encodings' '
1228 clean_fake_sendmail &&
1230 git send-email --from=author@example.com --to=nobody@example.com \
1231 --smtp-server="$(pwd)/fake.sendmail" \
1232 email-using-8bit >stdout &&
1233 grep "do not declare a Content-Transfer-Encoding" stdout &&
1234 grep email-using-8bit stdout &&
1235 grep "Which 8bit encoding" stdout &&
1236 egrep "Content|MIME" msgtxt1 >actual &&
1237 test_cmp actual content-type-decl
1240 test_expect_success
$PREREQ 'sendemail.8bitEncoding works' '
1241 clean_fake_sendmail &&
1242 git config sendemail.assume8bitEncoding UTF-8 &&
1244 git send-email --from=author@example.com --to=nobody@example.com \
1245 --smtp-server="$(pwd)/fake.sendmail" \
1246 email-using-8bit >stdout &&
1247 egrep "Content|MIME" msgtxt1 >actual &&
1248 test_cmp actual content-type-decl
1251 test_expect_success
$PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
1252 clean_fake_sendmail &&
1253 git config sendemail.assume8bitEncoding "bogus too" &&
1255 git send-email --from=author@example.com --to=nobody@example.com \
1256 --smtp-server="$(pwd)/fake.sendmail" \
1257 --8bit-encoding=UTF-8 \
1258 email-using-8bit >stdout &&
1259 egrep "Content|MIME" msgtxt1 >actual &&
1260 test_cmp actual content-type-decl
1263 test_expect_success
$PREREQ 'setup expect' '
1264 cat >email-using-8bit <<-\EOF
1265 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1266 Message-Id: <bogus-message-id@example.com>
1267 From: author@example.com
1268 Date: Sat, 12 Jun 2010 15:53:58 +0200
1269 Subject: Dieser Betreff enthält auch einen Umlaut!
1271 Nothing to see here.
1275 test_expect_success
$PREREQ 'setup expect' '
1276 cat >expected <<-\EOF
1277 Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
1281 test_expect_success
$PREREQ '--8bit-encoding also treats subject' '
1282 clean_fake_sendmail &&
1284 git send-email --from=author@example.com --to=nobody@example.com \
1285 --smtp-server="$(pwd)/fake.sendmail" \
1286 --8bit-encoding=UTF-8 \
1287 email-using-8bit >stdout &&
1288 grep "Subject" msgtxt1 >actual &&
1289 test_cmp expected actual
1292 test_expect_success
$PREREQ 'setup expect' '
1293 cat >email-using-8bit <<-\EOF
1294 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1295 Message-Id: <bogus-message-id@example.com>
1296 From: A U Thor <author@example.com>
1297 Date: Sat, 12 Jun 2010 15:53:58 +0200
1298 Content-Type: text/plain; charset=UTF-8
1299 Subject: Nothing to see here.
1301 Dieser Betreff enthält auch einen Umlaut!
1305 test_expect_success
$PREREQ 'sendemail.transferencoding=7bit fails on 8bit data' '
1306 clean_fake_sendmail &&
1307 git config sendemail.transferEncoding 7bit &&
1308 test_must_fail git send-email \
1309 --transfer-encoding=7bit \
1310 --smtp-server="$(pwd)/fake.sendmail" \
1313 grep "cannot send message as 7bit" errors &&
1314 test -z "$(ls msgtxt*)"
1317 test_expect_success
$PREREQ '--transfer-encoding overrides sendemail.transferEncoding' '
1318 clean_fake_sendmail &&
1319 git config sendemail.transferEncoding 8bit &&
1320 test_must_fail git send-email \
1321 --transfer-encoding=7bit \
1322 --smtp-server="$(pwd)/fake.sendmail" \
1325 grep "cannot send message as 7bit" errors &&
1326 test -z "$(ls msgtxt*)"
1329 test_expect_success
$PREREQ 'sendemail.transferencoding=8bit' '
1330 clean_fake_sendmail &&
1332 --transfer-encoding=8bit \
1333 --smtp-server="$(pwd)/fake.sendmail" \
1336 sed '1,/^$
/d
' msgtxt1 >actual &&
1337 sed '1,/^$
/d
' email-using-8bit >expected &&
1338 test_cmp expected actual
1341 test_expect_success
$PREREQ 'setup expect' '
1342 cat >expected <<-\EOF
1343 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1347 test_expect_success
$PREREQ '8-bit and sendemail.transferencoding=quoted-printable' '
1348 clean_fake_sendmail &&
1350 --transfer-encoding=quoted-printable \
1351 --smtp-server="$(pwd)/fake.sendmail" \
1354 sed '1,/^$
/d
' msgtxt1 >actual &&
1355 test_cmp expected actual
1358 test_expect_success
$PREREQ 'setup expect' '
1359 cat >expected <<-\EOF
1360 RGllc2VyIEJldHJlZmYgZW50aMOkbHQgYXVjaCBlaW5lbiBVbWxhdXQhCg==
1364 test_expect_success
$PREREQ '8-bit and sendemail.transferencoding=base64' '
1365 clean_fake_sendmail &&
1367 --transfer-encoding=base64 \
1368 --smtp-server="$(pwd)/fake.sendmail" \
1371 sed '1,/^$
/d
' msgtxt1 >actual &&
1372 test_cmp expected actual
1375 test_expect_success
$PREREQ 'setup expect' '
1376 cat >email-using-qp <<-\EOF
1377 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1378 Message-Id: <bogus-message-id@example.com>
1379 From: A U Thor <author@example.com>
1380 Date: Sat, 12 Jun 2010 15:53:58 +0200
1382 Content-Transfer-Encoding: quoted-printable
1383 Content-Type: text/plain; charset=UTF-8
1384 Subject: Nothing to see here.
1386 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1390 test_expect_success
$PREREQ 'convert from quoted-printable to base64' '
1391 clean_fake_sendmail &&
1393 --transfer-encoding=base64 \
1394 --smtp-server="$(pwd)/fake.sendmail" \
1397 sed '1,/^$
/d
' msgtxt1 >actual &&
1398 test_cmp expected actual
1401 test_expect_success
$PREREQ 'setup expect' "
1402 tr -d '\\015' | tr '%' '\\015' >email-using-crlf <<EOF
1403 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1404 Message-Id: <bogus-message-id@example.com>
1405 From: A U Thor <author@example.com>
1406 Date: Sat, 12 Jun 2010 15:53:58 +0200
1407 Content-Type: text/plain; charset=UTF-8
1408 Subject: Nothing to see here.
1410 Look, I have a CRLF and an = sign!%
1414 test_expect_success
$PREREQ 'setup expect' '
1415 cat >expected <<-\EOF
1416 Look, I have a CRLF and an =3D sign!=0D
1420 test_expect_success
$PREREQ 'CRLF and sendemail.transferencoding=quoted-printable' '
1421 clean_fake_sendmail &&
1423 --transfer-encoding=quoted-printable \
1424 --smtp-server="$(pwd)/fake.sendmail" \
1427 sed '1,/^$
/d
' msgtxt1 >actual &&
1428 test_cmp expected actual
1431 test_expect_success
$PREREQ 'setup expect' '
1432 cat >expected <<-\EOF
1433 TG9vaywgSSBoYXZlIGEgQ1JMRiBhbmQgYW4gPSBzaWduIQ0K
1437 test_expect_success
$PREREQ 'CRLF and sendemail.transferencoding=base64' '
1438 clean_fake_sendmail &&
1440 --transfer-encoding=base64 \
1441 --smtp-server="$(pwd)/fake.sendmail" \
1444 sed '1,/^$
/d
' msgtxt1 >actual &&
1445 test_cmp expected actual
1449 # Note that the patches in this test are deliberately out of order; we
1450 # want to make sure it works even if the cover-letter is not in the
1452 test_expect_success
$PREREQ 'refusing to send cover letter template' '
1453 clean_fake_sendmail &&
1455 git format-patch --cover-letter -2 -o outdir &&
1456 test_must_fail git send-email \
1457 --from="Example <nobody@example.com>" \
1458 --to=nobody@example.com \
1459 --smtp-server="$(pwd)/fake.sendmail" \
1460 outdir/0002-*.patch \
1461 outdir/0000-*.patch \
1462 outdir/0001-*.patch \
1464 grep "SUBJECT HERE" errors &&
1465 test -z "$(ls msgtxt*)"
1468 test_expect_success
$PREREQ '--force sends cover letter template anyway' '
1469 clean_fake_sendmail &&
1471 git format-patch --cover-letter -2 -o outdir &&
1474 --from="Example <nobody@example.com>" \
1475 --to=nobody@example.com \
1476 --smtp-server="$(pwd)/fake.sendmail" \
1477 outdir/0002-*.patch \
1478 outdir/0000-*.patch \
1479 outdir/0001-*.patch \
1481 ! grep "SUBJECT HERE" errors &&
1482 test -n "$(ls msgtxt*)"
1485 test_cover_addresses
() {
1488 clean_fake_sendmail
&&
1490 git format-patch
--cover-letter -2 -o outdir
&&
1491 cover
=$
(echo outdir
/0000-*.
patch) &&
1492 mv $cover cover-to-edit.
patch &&
1493 perl
-pe "s/^From:/$header: extra\@address.com\nFrom:/" cover-to-edit.
patch >"$cover" &&
1496 --from="Example <nobody@example.com>" \
1499 --smtp-server="$(pwd)/fake.sendmail" \
1500 outdir
/0000-*.
patch \
1501 outdir
/0001-*.
patch \
1502 outdir
/0002-*.
patch \
1504 grep "^$header: extra@address.com" msgtxt1
>to1
&&
1505 grep "^$header: extra@address.com" msgtxt2
>to2
&&
1506 grep "^$header: extra@address.com" msgtxt3
>to3
&&
1507 test_line_count
= 1 to1
&&
1508 test_line_count
= 1 to2
&&
1509 test_line_count
= 1 to3
1512 test_expect_success
$PREREQ 'to-cover adds To to all mail' '
1513 test_cover_addresses "To" --to-cover
1516 test_expect_success
$PREREQ 'cc-cover adds Cc to all mail' '
1517 test_cover_addresses "Cc" --cc-cover
1520 test_expect_success
$PREREQ 'tocover adds To to all mail' '
1521 test_config sendemail.tocover true &&
1522 test_cover_addresses "To"
1525 test_expect_success
$PREREQ 'cccover adds Cc to all mail' '
1526 test_config sendemail.cccover true &&
1527 test_cover_addresses "Cc"
1530 test_expect_success
$PREREQ 'escaped quotes in sendemail.aliasfiletype=mutt' '
1531 clean_fake_sendmail &&
1532 echo "alias sbd \\\"Dot U. Sir\\\" <somebody@example.org>" >.mutt &&
1533 git config --replace-all sendemail.aliasesfile "$(pwd)/.mutt" &&
1534 git config sendemail.aliasfiletype mutt &&
1536 --from="Example <nobody@example.com>" \
1538 --smtp-server="$(pwd)/fake.sendmail" \
1539 outdir/0001-*.patch \
1541 grep "^!somebody@example\.org!$" commandline1 &&
1542 grep -F "To: \"Dot U. Sir\" <somebody@example.org>" out
1545 test_expect_success
$PREREQ 'sendemail.aliasfiletype=mailrc' '
1546 clean_fake_sendmail &&
1547 echo "alias sbd somebody@example.org" >.mailrc &&
1548 git config --replace-all sendemail.aliasesfile "$(pwd)/.mailrc" &&
1549 git config sendemail.aliasfiletype mailrc &&
1551 --from="Example <nobody@example.com>" \
1553 --smtp-server="$(pwd)/fake.sendmail" \
1554 outdir/0001-*.patch \
1556 grep "^!somebody@example\.org!$" commandline1
1559 test_expect_success
$PREREQ 'sendemail.aliasfile=~/.mailrc' '
1560 clean_fake_sendmail &&
1561 echo "alias sbd someone@example.org" >"$HOME/.mailrc" &&
1562 git config --replace-all sendemail.aliasesfile "~/.mailrc" &&
1563 git config sendemail.aliasfiletype mailrc &&
1565 --from="Example <nobody@example.com>" \
1567 --smtp-server="$(pwd)/fake.sendmail" \
1568 outdir/0001-*.patch \
1570 grep "^!someone@example\.org!$" commandline1
1573 test_dump_aliases
() {
1574 msg
="$1" && shift &&
1575 filetype
="$1" && shift &&
1576 printf '%s\n' "$@" >expect
&&
1577 cat >.tmp-email-aliases
&&
1579 test_expect_success
$PREREQ "$msg" '
1580 clean_fake_sendmail && rm -fr outdir &&
1581 git config --replace-all sendemail.aliasesfile \
1582 "$(pwd)/.tmp-email-aliases" &&
1583 git config sendemail.aliasfiletype "$filetype" &&
1584 git send-email --dump-aliases 2>errors >actual &&
1585 test_cmp expect actual
1589 test_dump_aliases
'--dump-aliases sendmail format' \
1596 alice: Alice W Land <awol@example.com>
1597 bob: Robert Bobbyton <bob@example.com>
1598 chloe: chloe@example.com
1600 bcgrp: bob, chloe, Other <o@example.com>
1603 test_dump_aliases '--dump-aliases mutt format' \
1609 alias alice Alice W Land <awol@example.com>
1610 alias donald Donald C Carlton <donc@example.com>
1611 alias bob Robert Bobbyton <bob@example.com>
1612 alias chloe chloe@example.com
1615 test_dump_aliases '--dump-aliases mailrc format' \
1621 alias alice Alice W Land <awol@example.com>
1622 alias eve Eve <eve@example.com>
1623 alias bob Robert Bobbyton <bob@example.com>
1624 alias chloe chloe@example.com
1627 test_dump_aliases '--dump-aliases pine format' \
1633 alice Alice W Land <awol@example.com>
1634 eve Eve <eve@example.com>
1635 bob Robert Bobbyton <bob@example.com>
1636 chloe chloe@example.com
1639 test_dump_aliases '--dump-aliases gnus format' \
1645 (define-mail-alias "alice" "awol@example.com")
1646 (define-mail-alias "eve" "eve@example.com")
1647 (define-mail-alias "bob" "bob@example.com")
1648 (define-mail-alias "chloe" "chloe@example.com")
1651 test_expect_success '--dump-aliases must be used alone' '
1652 test_must_fail git send-email --dump-aliases --to=janice@example.com -1 refs/heads/accounting
1655 test_sendmail_aliases () {
1656 msg="$1" && shift &&
1658 cat >.tmp-email-aliases &&
1660 test_expect_success $PREREQ "$msg" '
1661 clean_fake_sendmail && rm -fr outdir &&
1662 git format-patch -1 -o outdir &&
1663 git config --replace-all sendemail.aliasesfile \
1664 "$(pwd)/.tmp-email-aliases" &&
1665 git config sendemail.aliasfiletype sendmail &&
1667 --from="Example <nobody@example.com>" \
1668 --to=alice --to=bcgrp \
1669 --smtp-server="$(pwd)/fake.sendmail" \
1670 outdir/0001-*.
patch \
1674 grep "^!$i!$" commandline1 ||
return 1
1679 test_sendmail_aliases 'sendemail.aliasfiletype
=sendmail
' \
1680 'awol@example\.com
' \
1681 'bob@example\.com
' \
1682 'chloe@example\.com
' \
1683 'o@example\.com
' <<-\EOF
1684 alice: Alice W Land <awol@example.com>
1685 bob: Robert Bobbyton <bob@example.com>
1687 # this is also a comment
1688 chloe: chloe@example.com
1690 bcgrp: bob, chloe, Other <o@example.com>
1693 test_sendmail_aliases 'sendmail aliases line folding
' \
1697 darla1 darla2 darla3 \
1698 elton1 elton2 elton3 \
1715 bcgrp: bob, chuck, darla, elton, fred, greg
1718 test_sendmail_aliases 'sendmail aliases tolerate bogus line folding
' \
1724 test_sendmail_aliases 'sendmail aliases empty
' alice bcgrp <<-\EOF
1727 test_expect_success $PREREQ 'alias support
in To header
' '
1728 clean_fake_sendmail
&&
1729 echo "alias sbd someone@example.org" >.mailrc
&&
1730 test_config sendemail.aliasesfile
".mailrc" &&
1731 test_config sendemail.aliasfiletype mailrc
&&
1732 git format-patch
--stdout -1 --to=sbd
>aliased.
patch &&
1734 --from="Example <nobody@example.com>" \
1735 --smtp-server="$(pwd)/fake.sendmail" \
1738 grep "^!someone@example\.org!$" commandline1
1741 test_expect_success $PREREQ 'alias support
in Cc header
' '
1742 clean_fake_sendmail
&&
1743 echo "alias sbd someone@example.org" >.mailrc
&&
1744 test_config sendemail.aliasesfile
".mailrc" &&
1745 test_config sendemail.aliasfiletype mailrc
&&
1746 git format-patch
--stdout -1 --cc=sbd
>aliased.
patch &&
1748 --from="Example <nobody@example.com>" \
1749 --smtp-server="$(pwd)/fake.sendmail" \
1752 grep "^!someone@example\.org!$" commandline1
1755 test_expect_success $PREREQ 'tocmd works with aliases
' '
1756 clean_fake_sendmail
&&
1757 echo "alias sbd someone@example.org" >.mailrc
&&
1758 test_config sendemail.aliasesfile
".mailrc" &&
1759 test_config sendemail.aliasfiletype mailrc
&&
1760 git format-patch
--stdout -1 >tocmd.
patch &&
1761 echo tocmd--sbd
>>tocmd.
patch &&
1763 --from="Example <nobody@example.com>" \
1764 --to-cmd=.
/tocmd-sed \
1765 --smtp-server="$(pwd)/fake.sendmail" \
1768 grep "^!someone@example\.org!$" commandline1
1771 test_expect_success $PREREQ 'cccmd works with aliases
' '
1772 clean_fake_sendmail
&&
1773 echo "alias sbd someone@example.org" >.mailrc
&&
1774 test_config sendemail.aliasesfile
".mailrc" &&
1775 test_config sendemail.aliasfiletype mailrc
&&
1776 git format-patch
--stdout -1 >cccmd.
patch &&
1777 echo cccmd--sbd
>>cccmd.
patch &&
1779 --from="Example <nobody@example.com>" \
1780 --cc-cmd=.
/cccmd-sed \
1781 --smtp-server="$(pwd)/fake.sendmail" \
1784 grep "^!someone@example\.org!$" commandline1
1787 do_xmailer_test () {
1788 expected=$1 params=$2 &&
1789 git format-patch -1 &&
1791 --from="Example <nobody@example.com>" \
1792 --to=someone@example.com \
1793 --smtp-server="$(pwd)/fake.sendmail" \
1797 { grep '^X-Mailer
:' out || :; } >mailer &&
1798 test_line_count = $expected mailer
1801 test_expect_success $PREREQ '--[no-
]xmailer without any configuration
' '
1802 do_xmailer_test
1 "--xmailer" &&
1803 do_xmailer_test
0 "--no-xmailer"
1806 test_expect_success $PREREQ '--[no-
]xmailer with sendemail.xmailer
=true
' '
1807 test_config sendemail.xmailer true
&&
1808 do_xmailer_test
1 "" &&
1809 do_xmailer_test
0 "--no-xmailer" &&
1810 do_xmailer_test
1 "--xmailer"
1813 test_expect_success $PREREQ '--[no-
]xmailer with sendemail.xmailer
=false
' '
1814 test_config sendemail.xmailer false
&&
1815 do_xmailer_test
0 "" &&
1816 do_xmailer_test
0 "--no-xmailer" &&
1817 do_xmailer_test
1 "--xmailer"
1820 test_expect_success $PREREQ 'setup expected-list
' '
1823 --from="Example <from@example.com>" \
1824 --to="To 1 <to1@example.com>" \
1825 --to="to2@example.com" \
1826 --to="to3@example.com" \
1827 --cc="Cc 1 <cc1@example.com>" \
1828 --cc="Cc2 <cc2@example.com>" \
1829 --bcc="bcc1@example.com" \
1830 --bcc="bcc2@example.com" \
1831 0001-add-master.
patch | replace_variable_fields \
1835 test_expect_success $PREREQ 'use email list
in --cc --to and
--bcc' '
1838 --from="Example <from@example.com>" \
1839 --to="To 1 <to1@example.com>, to2@example.com" \
1840 --to="to3@example.com" \
1841 --cc="Cc 1 <cc1@example.com>, Cc2 <cc2@example.com>" \
1842 --bcc="bcc1@example.com, bcc2@example.com" \
1843 0001-add-master.
patch | replace_variable_fields \
1845 test_cmp expected-list actual-list
1848 test_expect_success $PREREQ 'aliases work with email list
' '
1849 echo "alias to2 to2@example.com" >.mutt
&&
1850 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt
&&
1851 test_config sendemail.aliasesfile
".mutt" &&
1852 test_config sendemail.aliasfiletype mutt
&&
1855 --from="Example <from@example.com>" \
1856 --to="To 1 <to1@example.com>, to2, to3@example.com" \
1857 --cc="cc1, Cc2 <cc2@example.com>" \
1858 --bcc="bcc1@example.com, bcc2@example.com" \
1859 0001-add-master.
patch | replace_variable_fields \
1861 test_cmp expected-list actual-list
1864 test_expect_success $PREREQ 'leading and trailing whitespaces are removed
' '
1865 echo "alias to2 to2@example.com" >.mutt
&&
1866 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt
&&
1867 test_config sendemail.aliasesfile
".mutt" &&
1868 test_config sendemail.aliasfiletype mutt
&&
1869 TO1
=$
(echo "QTo 1 <to1@example.com>" | q_to_tab
) &&
1870 TO2
=$
(echo "QZto2" | qz_to_tab_space
) &&
1871 CC1
=$
(echo "cc1" | append_cr
) &&
1872 BCC1
=$
(echo "Q bcc1@example.com Q" | q_to_nul
) &&
1875 --from=" Example <from@example.com>" \
1878 --to=" to3@example.com " \
1880 --cc="Cc2 <cc2@example.com>" \
1882 --bcc="bcc2@example.com" \
1883 0001-add-master.
patch | replace_variable_fields \
1885 test_cmp expected-list actual-list