3 test_description='git send-email'
6 # May be altered later in the test
9 test_expect_success $PREREQ \
10 'prepare reference tree' \
11 'echo "1A quick brown fox jumps over the" >file &&
12 echo "lazy dog" >>file &&
14 GIT_AUTHOR_NAME="A" git commit -a -m "Initial."'
16 test_expect_success $PREREQ \
18 '(echo "#!$SHELL_PATH"
21 echo "while test -f commandline\$output; do output=\$((\$output+1)); done"
24 echo " echo \"!\$a!\""
25 echo "done >commandline\$output"
26 test_have_prereq MINGW && echo "dos2unix commandline\$output"
27 echo "cat > msgtxt\$output"
29 chmod +x ./fake.sendmail &&
30 git add fake.sendmail &&
31 GIT_AUTHOR_NAME="A" git commit -a -m "Second."'
33 clean_fake_sendmail() {
34 rm -f commandline* msgtxt*
37 test_expect_success $PREREQ 'Extract patches' '
38 patches=`git format-patch -s --cc="One <one@example.com>" --cc=two@example.com -n HEAD^1`
41 # Test no confirm early to ensure remaining tests will not hang
45 GIT_SEND_EMAIL_NOTTY=1 \
47 --from="Example <from@example.com>" \
48 --to=nobody@example.com \
49 --smtp-server="$(pwd)/fake.sendmail" \
52 test_must_fail grep "Send this email" stdout &&
56 # Exit immediately to prevent hang if a no-confirm test fails
58 if ! test -f no_confirm_okay
60 say 'confirm test failed; skipping remaining tests to prevent hanging'
61 PREREQ="$PREREQ,CHECK_NO_CONFIRM"
66 test_expect_success $PREREQ 'No confirm with --suppress-cc' '
67 test_no_confirm --suppress-cc=sob &&
72 test_expect_success $PREREQ 'No confirm with --confirm=never' '
73 test_no_confirm --confirm=never &&
77 # leave sendemail.confirm set to never after this so that none of the
78 # remaining tests prompt unintentionally.
79 test_expect_success $PREREQ 'No confirm with sendemail.confirm=never' '
80 git config sendemail.confirm never &&
81 test_no_confirm --compose --subject=foo &&
85 test_expect_success $PREREQ 'Send patches' '
86 git send-email --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
89 test_expect_success $PREREQ 'setup expect' '
98 test_expect_success $PREREQ \
99 'Verify commandline' \
100 'test_cmp expected commandline1'
102 test_expect_success $PREREQ 'Send patches with --envelope-sender' '
103 clean_fake_sendmail &&
104 git send-email --envelope-sender="Patch Contributer <patch@example.com>" --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
107 test_expect_success $PREREQ 'setup expect' '
118 test_expect_success $PREREQ \
119 'Verify commandline' \
120 'test_cmp expected commandline1'
122 test_expect_success $PREREQ 'Send patches with --envelope-sender=auto' '
123 clean_fake_sendmail &&
124 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
127 test_expect_success $PREREQ 'setup expect' '
138 test_expect_success $PREREQ \
139 'Verify commandline' \
140 'test_cmp expected commandline1'
142 test_expect_success $PREREQ 'setup expect' "
143 cat >expected-show-all-headers <<\EOF
145 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
146 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
147 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
149 Server: relay.example.com
150 MAIL FROM:<from@example.com>
151 RCPT TO:<to@example.com>
152 RCPT TO:<cc@example.com>
153 RCPT TO:<author@example.com>
154 RCPT TO:<one@example.com>
155 RCPT TO:<two@example.com>
156 RCPT TO:<bcc@example.com>
157 From: Example <from@example.com>
160 A <author@example.com>,
161 One <one@example.com>,
163 Subject: [PATCH 1/1] Second.
165 Message-Id: MESSAGE-ID-STRING
166 X-Mailer: X-MAILER-STRING
167 In-Reply-To: <unique-message-id@example.com>
168 References: <unique-message-id@example.com>
174 test_expect_success $PREREQ 'Show all headers' '
178 --from="Example <from@example.com>" \
179 --to=to@example.com \
180 --cc=cc@example.com \
181 --bcc=bcc@example.com \
182 --in-reply-to="<unique-message-id@example.com>" \
183 --smtp-server relay.example.com \
185 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
186 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
187 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
188 >actual-show-all-headers &&
189 test_cmp expected-show-all-headers actual-show-all-headers
192 test_expect_success $PREREQ 'Prompting works' '
193 clean_fake_sendmail &&
194 (echo "Example <from@example.com>"
195 echo "to@example.com"
197 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
198 --smtp-server="$(pwd)/fake.sendmail" \
201 grep "^From: Example <from@example.com>\$" msgtxt1 &&
202 grep "^To: to@example.com\$" msgtxt1
205 test_expect_success $PREREQ 'tocmd works' '
206 clean_fake_sendmail &&
207 cp $patches tocmd.patch &&
208 echo tocmd--tocmd@example.com >>tocmd.patch &&
211 echo sed -n -e s/^tocmd--//p \"\$1\"
213 chmod +x tocmd-sed &&
215 --from="Example <nobody@example.com>" \
216 --to-cmd=./tocmd-sed \
217 --smtp-server="$(pwd)/fake.sendmail" \
220 grep "^To: tocmd@example.com" msgtxt1
223 test_expect_success $PREREQ 'cccmd works' '
224 clean_fake_sendmail &&
225 cp $patches cccmd.patch &&
226 echo "cccmd-- cccmd@example.com" >>cccmd.patch &&
229 echo sed -n -e s/^cccmd--//p \"\$1\"
231 chmod +x cccmd-sed &&
233 --from="Example <nobody@example.com>" \
234 --to=nobody@example.com \
235 --cc-cmd=./cccmd-sed \
236 --smtp-server="$(pwd)/fake.sendmail" \
239 grep "^ cccmd@example.com" msgtxt1
242 test_expect_success $PREREQ 'reject long lines' '
244 z64=$z8$z8$z8$z8$z8$z8$z8$z8 &&
245 z512=$z64$z64$z64$z64$z64$z64$z64$z64 &&
246 clean_fake_sendmail &&
247 cp $patches longline.patch &&
248 echo $z512$z512 >>longline.patch &&
249 test_must_fail git send-email \
250 --from="Example <nobody@example.com>" \
251 --to=nobody@example.com \
252 --smtp-server="$(pwd)/fake.sendmail" \
253 $patches longline.patch \
255 grep longline.patch errors
258 test_expect_success $PREREQ 'no patch was sent' '
259 ! test -e commandline1
262 test_expect_success $PREREQ 'Author From: in message body' '
263 clean_fake_sendmail &&
265 --from="Example <nobody@example.com>" \
266 --to=nobody@example.com \
267 --smtp-server="$(pwd)/fake.sendmail" \
269 sed "1,/^\$/d" < msgtxt1 > msgbody1 &&
270 grep "From: A <author@example.com>" msgbody1
273 test_expect_success $PREREQ 'Author From: not in message body' '
274 clean_fake_sendmail &&
276 --from="A <author@example.com>" \
277 --to=nobody@example.com \
278 --smtp-server="$(pwd)/fake.sendmail" \
280 sed "1,/^\$/d" < msgtxt1 > msgbody1 &&
281 ! grep "From: A <author@example.com>" msgbody1
284 test_expect_success $PREREQ 'allow long lines with --no-validate' '
286 --from="Example <nobody@example.com>" \
287 --to=nobody@example.com \
288 --smtp-server="$(pwd)/fake.sendmail" \
290 $patches longline.patch \
294 test_expect_success $PREREQ 'Invalid In-Reply-To' '
295 clean_fake_sendmail &&
297 --from="Example <nobody@example.com>" \
298 --to=nobody@example.com \
300 --smtp-server="$(pwd)/fake.sendmail" \
303 ! grep "^In-Reply-To: < *>" msgtxt1
306 test_expect_success $PREREQ 'Valid In-Reply-To when prompting' '
307 clean_fake_sendmail &&
308 (echo "From Example <from@example.com>"
309 echo "To Example <to@example.com>"
311 ) | env GIT_SEND_EMAIL_NOTTY=1 git send-email \
312 --smtp-server="$(pwd)/fake.sendmail" \
314 ! grep "^In-Reply-To: < *>" msgtxt1
317 test_expect_success $PREREQ 'In-Reply-To without --chain-reply-to' '
318 clean_fake_sendmail &&
319 echo "<unique-message-id@example.com>" >expect &&
321 --from="Example <nobody@example.com>" \
322 --to=nobody@example.com \
324 --in-reply-to="$(cat expect)" \
325 --smtp-server="$(pwd)/fake.sendmail" \
326 $patches $patches $patches \
328 # The first message is a reply to --in-reply-to
329 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
330 test_cmp expect actual &&
331 # Second and subsequent messages are replies to the first one
332 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
333 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
334 test_cmp expect actual &&
335 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
336 test_cmp expect actual
339 test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' '
340 clean_fake_sendmail &&
341 echo "<unique-message-id@example.com>" >expect &&
343 --from="Example <nobody@example.com>" \
344 --to=nobody@example.com \
346 --in-reply-to="$(cat expect)" \
347 --smtp-server="$(pwd)/fake.sendmail" \
348 $patches $patches $patches \
350 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
351 test_cmp expect actual &&
352 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
353 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
354 test_cmp expect actual &&
355 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt2 >expect &&
356 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
357 test_cmp expect actual
360 test_expect_success $PREREQ 'setup fake editor' '
361 (echo "#!$SHELL_PATH" &&
362 echo "echo fake edit >>\"\$1\""
367 test_set_editor "$(pwd)/fake-editor"
369 test_expect_success $PREREQ '--compose works' '
370 clean_fake_sendmail &&
372 --compose --subject foo \
373 --from="Example <nobody@example.com>" \
374 --to=nobody@example.com \
375 --smtp-server="$(pwd)/fake.sendmail" \
380 test_expect_success $PREREQ 'first message is compose text' '
381 grep "^fake edit" msgtxt1
384 test_expect_success $PREREQ 'second message is patch' '
385 grep "Subject:.*Second" msgtxt2
388 test_expect_success $PREREQ 'setup expect' "
389 cat >expected-suppress-sob <<\EOF
391 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
392 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
393 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
395 Server: relay.example.com
396 MAIL FROM:<from@example.com>
397 RCPT TO:<to@example.com>
398 RCPT TO:<cc@example.com>
399 RCPT TO:<author@example.com>
400 RCPT TO:<one@example.com>
401 RCPT TO:<two@example.com>
402 From: Example <from@example.com>
405 A <author@example.com>,
406 One <one@example.com>,
408 Subject: [PATCH 1/1] Second.
410 Message-Id: MESSAGE-ID-STRING
411 X-Mailer: X-MAILER-STRING
417 test_suppression () {
420 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
421 --from="Example <from@example.com>" \
422 --to=to@example.com \
423 --smtp-server relay.example.com \
425 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
426 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
427 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
428 >actual-suppress-$1${2+"-$2"} &&
429 test_cmp expected-suppress-$1${2+"-$2"} actual-suppress-$1${2+"-$2"}
432 test_expect_success $PREREQ 'sendemail.cc set' '
433 git config sendemail.cc cc@example.com &&
437 test_expect_success $PREREQ 'setup expect' "
438 cat >expected-suppress-sob <<\EOF
440 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
441 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
442 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
444 Server: relay.example.com
445 MAIL FROM:<from@example.com>
446 RCPT TO:<to@example.com>
447 RCPT TO:<author@example.com>
448 RCPT TO:<one@example.com>
449 RCPT TO:<two@example.com>
450 From: Example <from@example.com>
452 Cc: A <author@example.com>,
453 One <one@example.com>,
455 Subject: [PATCH 1/1] Second.
457 Message-Id: MESSAGE-ID-STRING
458 X-Mailer: X-MAILER-STRING
464 test_expect_success $PREREQ 'sendemail.cc unset' '
465 git config --unset sendemail.cc &&
469 test_expect_success $PREREQ 'setup expect' "
470 cat >expected-suppress-cccmd <<\EOF
472 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
473 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
474 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
475 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
477 Server: relay.example.com
478 MAIL FROM:<from@example.com>
479 RCPT TO:<to@example.com>
480 RCPT TO:<author@example.com>
481 RCPT TO:<one@example.com>
482 RCPT TO:<two@example.com>
483 RCPT TO:<committer@example.com>
484 From: Example <from@example.com>
486 Cc: A <author@example.com>,
487 One <one@example.com>,
489 C O Mitter <committer@example.com>
490 Subject: [PATCH 1/1] Second.
492 Message-Id: MESSAGE-ID-STRING
493 X-Mailer: X-MAILER-STRING
499 test_expect_success $PREREQ 'sendemail.cccmd' '
500 echo echo cc-cmd@example.com > cccmd &&
502 git config sendemail.cccmd ./cccmd &&
503 test_suppression cccmd
506 test_expect_success $PREREQ 'setup expect' '
507 cat >expected-suppress-all <<\EOF
510 Server: relay.example.com
511 MAIL FROM:<from@example.com>
512 RCPT TO:<to@example.com>
513 From: Example <from@example.com>
515 Subject: [PATCH 1/1] Second.
517 Message-Id: MESSAGE-ID-STRING
518 X-Mailer: X-MAILER-STRING
524 test_expect_success $PREREQ '--suppress-cc=all' '
528 test_expect_success $PREREQ 'setup expect' "
529 cat >expected-suppress-body <<\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'
534 (cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
536 Server: relay.example.com
537 MAIL FROM:<from@example.com>
538 RCPT TO:<to@example.com>
539 RCPT TO:<author@example.com>
540 RCPT TO:<one@example.com>
541 RCPT TO:<two@example.com>
542 RCPT TO:<cc-cmd@example.com>
543 From: Example <from@example.com>
545 Cc: A <author@example.com>,
546 One <one@example.com>,
549 Subject: [PATCH 1/1] Second.
551 Message-Id: MESSAGE-ID-STRING
552 X-Mailer: X-MAILER-STRING
558 test_expect_success $PREREQ '--suppress-cc=body' '
559 test_suppression body
562 test_expect_success $PREREQ 'setup expect' "
563 cat >expected-suppress-body-cccmd <<\EOF
565 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
566 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
567 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
569 Server: relay.example.com
570 MAIL FROM:<from@example.com>
571 RCPT TO:<to@example.com>
572 RCPT TO:<author@example.com>
573 RCPT TO:<one@example.com>
574 RCPT TO:<two@example.com>
575 From: Example <from@example.com>
577 Cc: A <author@example.com>,
578 One <one@example.com>,
580 Subject: [PATCH 1/1] Second.
582 Message-Id: MESSAGE-ID-STRING
583 X-Mailer: X-MAILER-STRING
589 test_expect_success $PREREQ '--suppress-cc=body --suppress-cc=cccmd' '
590 test_suppression body cccmd
593 test_expect_success $PREREQ 'setup expect' "
594 cat >expected-suppress-sob <<\EOF
596 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
597 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
598 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
600 Server: relay.example.com
601 MAIL FROM:<from@example.com>
602 RCPT TO:<to@example.com>
603 RCPT TO:<author@example.com>
604 RCPT TO:<one@example.com>
605 RCPT TO:<two@example.com>
606 From: Example <from@example.com>
608 Cc: A <author@example.com>,
609 One <one@example.com>,
611 Subject: [PATCH 1/1] Second.
613 Message-Id: MESSAGE-ID-STRING
614 X-Mailer: X-MAILER-STRING
620 test_expect_success $PREREQ '--suppress-cc=sob' '
621 test_might_fail git config --unset sendemail.cccmd &&
625 test_expect_success $PREREQ 'setup expect' "
626 cat >expected-suppress-bodycc <<\EOF
628 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
629 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
630 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
631 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
633 Server: relay.example.com
634 MAIL FROM:<from@example.com>
635 RCPT TO:<to@example.com>
636 RCPT TO:<author@example.com>
637 RCPT TO:<one@example.com>
638 RCPT TO:<two@example.com>
639 RCPT TO:<committer@example.com>
640 From: Example <from@example.com>
642 Cc: A <author@example.com>,
643 One <one@example.com>,
645 C O Mitter <committer@example.com>
646 Subject: [PATCH 1/1] Second.
648 Message-Id: MESSAGE-ID-STRING
649 X-Mailer: X-MAILER-STRING
655 test_expect_success $PREREQ '--suppress-cc=bodycc' '
656 test_suppression bodycc
659 test_expect_success $PREREQ 'setup expect' "
660 cat >expected-suppress-cc <<\EOF
662 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
663 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
665 Server: relay.example.com
666 MAIL FROM:<from@example.com>
667 RCPT TO:<to@example.com>
668 RCPT TO:<author@example.com>
669 RCPT TO:<committer@example.com>
670 From: Example <from@example.com>
672 Cc: A <author@example.com>,
673 C O Mitter <committer@example.com>
674 Subject: [PATCH 1/1] Second.
676 Message-Id: MESSAGE-ID-STRING
677 X-Mailer: X-MAILER-STRING
683 test_expect_success $PREREQ '--suppress-cc=cc' '
689 GIT_SEND_EMAIL_NOTTY=1 \
691 --from="Example <nobody@example.com>" \
692 --to=nobody@example.com \
693 --smtp-server="$(pwd)/fake.sendmail" \
694 $@ $patches > stdout &&
695 grep "Send this email" stdout
698 test_expect_success $PREREQ '--confirm=always' '
699 test_confirm --confirm=always --suppress-cc=all
702 test_expect_success $PREREQ '--confirm=auto' '
703 test_confirm --confirm=auto
706 test_expect_success $PREREQ '--confirm=cc' '
707 test_confirm --confirm=cc
710 test_expect_success $PREREQ '--confirm=compose' '
711 test_confirm --confirm=compose --compose
714 test_expect_success $PREREQ 'confirm by default (due to cc)' '
715 CONFIRM=$(git config --get sendemail.confirm) &&
716 git config --unset sendemail.confirm &&
719 git config sendemail.confirm ${CONFIRM:-never}
723 test_expect_success $PREREQ 'confirm by default (due to --compose)' '
724 CONFIRM=$(git config --get sendemail.confirm) &&
725 git config --unset sendemail.confirm &&
726 test_confirm --suppress-cc=all --compose
728 git config sendemail.confirm ${CONFIRM:-never}
732 test_expect_success $PREREQ 'confirm detects EOF (inform assumes y)' '
733 CONFIRM=$(git config --get sendemail.confirm) &&
734 git config --unset sendemail.confirm &&
736 git format-patch -2 -o outdir &&
737 GIT_SEND_EMAIL_NOTTY=1 \
739 --from="Example <nobody@example.com>" \
740 --to=nobody@example.com \
741 --smtp-server="$(pwd)/fake.sendmail" \
742 outdir/*.patch < /dev/null
744 git config sendemail.confirm ${CONFIRM:-never}
748 test_expect_success $PREREQ 'confirm detects EOF (auto causes failure)' '
749 CONFIRM=$(git config --get sendemail.confirm) &&
750 git config sendemail.confirm auto &&
751 GIT_SEND_EMAIL_NOTTY=1 &&
752 export GIT_SEND_EMAIL_NOTTY &&
753 test_must_fail git send-email \
754 --from="Example <nobody@example.com>" \
755 --to=nobody@example.com \
756 --smtp-server="$(pwd)/fake.sendmail" \
759 git config sendemail.confirm ${CONFIRM:-never}
763 test_expect_success $PREREQ 'confirm doesnt loop forever' '
764 CONFIRM=$(git config --get sendemail.confirm) &&
765 git config sendemail.confirm auto &&
766 GIT_SEND_EMAIL_NOTTY=1 &&
767 export GIT_SEND_EMAIL_NOTTY &&
768 yes "bogus" | test_must_fail git send-email \
769 --from="Example <nobody@example.com>" \
770 --to=nobody@example.com \
771 --smtp-server="$(pwd)/fake.sendmail" \
774 git config sendemail.confirm ${CONFIRM:-never}
778 test_expect_success $PREREQ 'utf8 Cc is rfc2047 encoded' '
779 clean_fake_sendmail &&
781 git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
783 --from="Example <nobody@example.com>" \
784 --to=nobody@example.com \
785 --smtp-server="$(pwd)/fake.sendmail" \
788 grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
791 test_expect_success $PREREQ '--compose adds MIME for utf8 body' '
792 clean_fake_sendmail &&
793 (echo "#!$SHELL_PATH" &&
794 echo "echo utf8 body: àéìöú >>\"\$1\""
795 ) >fake-editor-utf8 &&
796 chmod +x fake-editor-utf8 &&
797 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
799 --compose --subject foo \
800 --from="Example <nobody@example.com>" \
801 --to=nobody@example.com \
802 --smtp-server="$(pwd)/fake.sendmail" \
804 grep "^utf8 body" msgtxt1 &&
805 grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
808 test_expect_success $PREREQ '--compose respects user mime type' '
809 clean_fake_sendmail &&
810 (echo "#!$SHELL_PATH" &&
811 echo "(echo MIME-Version: 1.0"
812 echo " echo Content-Type: text/plain\\; charset=iso-8859-1"
813 echo " echo Content-Transfer-Encoding: 8bit"
814 echo " echo Subject: foo"
816 echo " echo utf8 body: àéìöú) >\"\$1\""
817 ) >fake-editor-utf8-mime &&
818 chmod +x fake-editor-utf8-mime &&
819 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
821 --compose --subject foo \
822 --from="Example <nobody@example.com>" \
823 --to=nobody@example.com \
824 --smtp-server="$(pwd)/fake.sendmail" \
826 grep "^utf8 body" msgtxt1 &&
827 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
828 ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
831 test_expect_success $PREREQ '--compose adds MIME for utf8 subject' '
832 clean_fake_sendmail &&
833 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
835 --compose --subject utf8-sübjëct \
836 --from="Example <nobody@example.com>" \
837 --to=nobody@example.com \
838 --smtp-server="$(pwd)/fake.sendmail" \
840 grep "^fake edit" msgtxt1 &&
841 grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
844 test_expect_success $PREREQ 'utf8 author is correctly passed on' '
845 clean_fake_sendmail &&
846 test_commit weird_author &&
847 test_when_finished "git reset --hard HEAD^" &&
848 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
849 git format-patch --stdout -1 >funny_name.patch &&
850 git send-email --from="Example <nobody@example.com>" \
851 --to=nobody@example.com \
852 --smtp-server="$(pwd)/fake.sendmail" \
854 grep "^From: Füñný Nâmé <odd_?=mail@example.com>" msgtxt1
857 test_expect_success $PREREQ 'sendemail.composeencoding works' '
858 clean_fake_sendmail &&
859 git config sendemail.composeencoding iso-8859-1 &&
860 (echo "#!$SHELL_PATH" &&
861 echo "echo utf8 body: àéìöú >>\"\$1\""
862 ) >fake-editor-utf8 &&
863 chmod +x fake-editor-utf8 &&
864 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
866 --compose --subject foo \
867 --from="Example <nobody@example.com>" \
868 --to=nobody@example.com \
869 --smtp-server="$(pwd)/fake.sendmail" \
871 grep "^utf8 body" msgtxt1 &&
872 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
875 test_expect_success $PREREQ '--compose-encoding works' '
876 clean_fake_sendmail &&
877 (echo "#!$SHELL_PATH" &&
878 echo "echo utf8 body: àéìöú >>\"\$1\""
879 ) >fake-editor-utf8 &&
880 chmod +x fake-editor-utf8 &&
881 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
883 --compose-encoding iso-8859-1 \
884 --compose --subject foo \
885 --from="Example <nobody@example.com>" \
886 --to=nobody@example.com \
887 --smtp-server="$(pwd)/fake.sendmail" \
889 grep "^utf8 body" msgtxt1 &&
890 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
893 test_expect_success $PREREQ '--compose-encoding overrides sendemail.composeencoding' '
894 clean_fake_sendmail &&
895 git config sendemail.composeencoding iso-8859-1 &&
896 (echo "#!$SHELL_PATH" &&
897 echo "echo utf8 body: àéìöú >>\"\$1\""
898 ) >fake-editor-utf8 &&
899 chmod +x fake-editor-utf8 &&
900 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
902 --compose-encoding iso-8859-2 \
903 --compose --subject foo \
904 --from="Example <nobody@example.com>" \
905 --to=nobody@example.com \
906 --smtp-server="$(pwd)/fake.sendmail" \
908 grep "^utf8 body" msgtxt1 &&
909 grep "^Content-Type: text/plain; charset=iso-8859-2" msgtxt1
912 test_expect_success $PREREQ '--compose-encoding adds correct MIME for subject' '
913 clean_fake_sendmail &&
914 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
916 --compose-encoding iso-8859-2 \
917 --compose --subject utf8-sübjëct \
918 --from="Example <nobody@example.com>" \
919 --to=nobody@example.com \
920 --smtp-server="$(pwd)/fake.sendmail" \
922 grep "^fake edit" msgtxt1 &&
923 grep "^Subject: =?iso-8859-2?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
926 test_expect_success $PREREQ 'detects ambiguous reference/file conflict' '
927 echo master > master &&
929 git commit -m"add master" &&
930 test_must_fail git send-email --dry-run master 2>errors &&
931 grep disambiguate errors
934 test_expect_success $PREREQ 'feed two files' '
936 git format-patch -2 -o outdir &&
939 --from="Example <nobody@example.com>" \
940 --to=nobody@example.com \
941 outdir/000?-*.patch 2>errors >out &&
942 grep "^Subject: " out >subjects &&
943 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
944 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"
947 test_expect_success $PREREQ 'in-reply-to but no threading' '
950 --from="Example <nobody@example.com>" \
951 --to=nobody@example.com \
952 --in-reply-to="<in-reply-id@example.com>" \
955 grep "In-Reply-To: <in-reply-id@example.com>"
958 test_expect_success $PREREQ 'no in-reply-to and no threading' '
961 --from="Example <nobody@example.com>" \
962 --to=nobody@example.com \
964 $patches $patches >stdout &&
965 ! grep "In-Reply-To: " stdout
968 test_expect_success $PREREQ 'threading but no chain-reply-to' '
971 --from="Example <nobody@example.com>" \
972 --to=nobody@example.com \
975 $patches $patches >stdout &&
976 grep "In-Reply-To: " stdout
979 test_expect_success $PREREQ 'warning with an implicit --chain-reply-to' '
982 --from="Example <nobody@example.com>" \
983 --to=nobody@example.com \
984 outdir/000?-*.patch 2>errors >out &&
985 grep "no-chain-reply-to" errors
988 test_expect_success $PREREQ 'no warning with an explicit --chain-reply-to' '
991 --from="Example <nobody@example.com>" \
992 --to=nobody@example.com \
994 outdir/000?-*.patch 2>errors >out &&
995 ! grep "no-chain-reply-to" errors
998 test_expect_success $PREREQ 'no warning with an explicit --no-chain-reply-to' '
1001 --from="Example <nobody@example.com>" \
1002 --to=nobody@example.com \
1003 --nochain-reply-to \
1004 outdir/000?-*.patch 2>errors >out &&
1005 ! grep "no-chain-reply-to" errors
1008 test_expect_success $PREREQ 'no warning with sendemail.chainreplyto = false' '
1009 git config sendemail.chainreplyto false &&
1012 --from="Example <nobody@example.com>" \
1013 --to=nobody@example.com \
1014 outdir/000?-*.patch 2>errors >out &&
1015 ! grep "no-chain-reply-to" errors
1018 test_expect_success $PREREQ 'no warning with sendemail.chainreplyto = true' '
1019 git config sendemail.chainreplyto true &&
1022 --from="Example <nobody@example.com>" \
1023 --to=nobody@example.com \
1024 outdir/000?-*.patch 2>errors >out &&
1025 ! grep "no-chain-reply-to" errors
1028 test_expect_success $PREREQ 'sendemail.to works' '
1029 git config --replace-all sendemail.to "Somebody <somebody@ex.com>" &&
1032 --from="Example <nobody@example.com>" \
1033 $patches $patches >stdout &&
1034 grep "To: Somebody <somebody@ex.com>" stdout
1037 test_expect_success $PREREQ '--no-to overrides sendemail.to' '
1040 --from="Example <nobody@example.com>" \
1042 --to=nobody@example.com \
1043 $patches $patches >stdout &&
1044 grep "To: nobody@example.com" stdout &&
1045 ! grep "To: Somebody <somebody@ex.com>" stdout
1048 test_expect_success $PREREQ 'sendemail.cc works' '
1049 git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" &&
1052 --from="Example <nobody@example.com>" \
1053 --to=nobody@example.com \
1054 $patches $patches >stdout &&
1055 grep "Cc: Somebody <somebody@ex.com>" stdout
1058 test_expect_success $PREREQ '--no-cc overrides sendemail.cc' '
1061 --from="Example <nobody@example.com>" \
1063 --cc=bodies@example.com \
1064 --to=nobody@example.com \
1065 $patches $patches >stdout &&
1066 grep "Cc: bodies@example.com" stdout &&
1067 ! grep "Cc: Somebody <somebody@ex.com>" stdout
1070 test_expect_success $PREREQ 'sendemail.bcc works' '
1071 git config --replace-all sendemail.bcc "Other <other@ex.com>" &&
1074 --from="Example <nobody@example.com>" \
1075 --to=nobody@example.com \
1076 --smtp-server relay.example.com \
1077 $patches $patches >stdout &&
1078 grep "RCPT TO:<other@ex.com>" stdout
1081 test_expect_success $PREREQ '--no-bcc overrides sendemail.bcc' '
1084 --from="Example <nobody@example.com>" \
1086 --bcc=bodies@example.com \
1087 --to=nobody@example.com \
1088 --smtp-server relay.example.com \
1089 $patches $patches >stdout &&
1090 grep "RCPT TO:<bodies@example.com>" stdout &&
1091 ! grep "RCPT TO:<other@ex.com>" stdout
1094 test_expect_success $PREREQ 'patches To headers are used by default' '
1095 patch=`git format-patch -1 --to="bodies@example.com"` &&
1096 test_when_finished "rm $patch" &&
1099 --from="Example <nobody@example.com>" \
1100 --smtp-server relay.example.com \
1102 grep "RCPT TO:<bodies@example.com>" stdout
1105 test_expect_success $PREREQ 'patches To headers are appended to' '
1106 patch=`git format-patch -1 --to="bodies@example.com"` &&
1107 test_when_finished "rm $patch" &&
1110 --from="Example <nobody@example.com>" \
1111 --to=nobody@example.com \
1112 --smtp-server relay.example.com \
1114 grep "RCPT TO:<bodies@example.com>" stdout &&
1115 grep "RCPT TO:<nobody@example.com>" stdout
1118 test_expect_success $PREREQ 'To headers from files reset each patch' '
1119 patch1=`git format-patch -1 --to="bodies@example.com"` &&
1120 patch2=`git format-patch -1 --to="other@example.com" HEAD~` &&
1121 test_when_finished "rm $patch1 && rm $patch2" &&
1124 --from="Example <nobody@example.com>" \
1125 --to="nobody@example.com" \
1126 --smtp-server relay.example.com \
1127 $patch1 $patch2 >stdout &&
1128 test $(grep -c "RCPT TO:<bodies@example.com>" stdout) = 1 &&
1129 test $(grep -c "RCPT TO:<nobody@example.com>" stdout) = 2 &&
1130 test $(grep -c "RCPT TO:<other@example.com>" stdout) = 1
1133 test_expect_success $PREREQ 'setup expect' '
1134 cat >email-using-8bit <<EOF
1135 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1136 Message-Id: <bogus-message-id@example.com>
1137 From: author@example.com
1138 Date: Sat, 12 Jun 2010 15:53:58 +0200
1139 Subject: subject goes here
1141 Dieser deutsche Text enthält einen Umlaut!
1145 test_expect_success $PREREQ 'setup expect' '
1147 Subject: subject goes here
1151 test_expect_success $PREREQ 'ASCII subject is not RFC2047 quoted' '
1152 clean_fake_sendmail &&
1154 git send-email --from=author@example.com --to=nobody@example.com \
1155 --smtp-server="$(pwd)/fake.sendmail" \
1156 --8bit-encoding=UTF-8 \
1157 email-using-8bit >stdout &&
1158 grep "Subject" msgtxt1 >actual &&
1159 test_cmp expected actual
1162 test_expect_success $PREREQ 'setup expect' '
1163 cat >content-type-decl <<EOF
1165 Content-Type: text/plain; charset=UTF-8
1166 Content-Transfer-Encoding: 8bit
1170 test_expect_success $PREREQ 'asks about and fixes 8bit encodings' '
1171 clean_fake_sendmail &&
1173 git send-email --from=author@example.com --to=nobody@example.com \
1174 --smtp-server="$(pwd)/fake.sendmail" \
1175 email-using-8bit >stdout &&
1176 grep "do not declare a Content-Transfer-Encoding" stdout &&
1177 grep email-using-8bit stdout &&
1178 grep "Which 8bit encoding" stdout &&
1179 egrep "Content|MIME" msgtxt1 >actual &&
1180 test_cmp actual content-type-decl
1183 test_expect_success $PREREQ 'sendemail.8bitEncoding works' '
1184 clean_fake_sendmail &&
1185 git config sendemail.assume8bitEncoding UTF-8 &&
1187 git send-email --from=author@example.com --to=nobody@example.com \
1188 --smtp-server="$(pwd)/fake.sendmail" \
1189 email-using-8bit >stdout &&
1190 egrep "Content|MIME" msgtxt1 >actual &&
1191 test_cmp actual content-type-decl
1194 test_expect_success $PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
1195 clean_fake_sendmail &&
1196 git config sendemail.assume8bitEncoding "bogus too" &&
1198 git send-email --from=author@example.com --to=nobody@example.com \
1199 --smtp-server="$(pwd)/fake.sendmail" \
1200 --8bit-encoding=UTF-8 \
1201 email-using-8bit >stdout &&
1202 egrep "Content|MIME" msgtxt1 >actual &&
1203 test_cmp actual content-type-decl
1206 test_expect_success $PREREQ 'setup expect' '
1207 cat >email-using-8bit <<EOF
1208 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1209 Message-Id: <bogus-message-id@example.com>
1210 From: author@example.com
1211 Date: Sat, 12 Jun 2010 15:53:58 +0200
1212 Subject: Dieser Betreff enthält auch einen Umlaut!
1214 Nothing to see here.
1218 test_expect_success $PREREQ 'setup expect' '
1220 Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
1224 test_expect_success $PREREQ '--8bit-encoding also treats subject' '
1225 clean_fake_sendmail &&
1227 git send-email --from=author@example.com --to=nobody@example.com \
1228 --smtp-server="$(pwd)/fake.sendmail" \
1229 --8bit-encoding=UTF-8 \
1230 email-using-8bit >stdout &&
1231 grep "Subject" msgtxt1 >actual &&
1232 test_cmp expected actual
1235 # Note that the patches in this test are deliberately out of order; we
1236 # want to make sure it works even if the cover-letter is not in the
1238 test_expect_success $PREREQ 'refusing to send cover letter template' '
1239 clean_fake_sendmail &&
1241 git format-patch --cover-letter -2 -o outdir &&
1242 test_must_fail git send-email \
1243 --from="Example <nobody@example.com>" \
1244 --to=nobody@example.com \
1245 --smtp-server="$(pwd)/fake.sendmail" \
1246 outdir/0002-*.patch \
1247 outdir/0000-*.patch \
1248 outdir/0001-*.patch \
1250 grep "SUBJECT HERE" errors &&
1251 test -z "$(ls msgtxt*)"
1254 test_expect_success $PREREQ '--force sends cover letter template anyway' '
1255 clean_fake_sendmail &&
1257 git format-patch --cover-letter -2 -o outdir &&
1260 --from="Example <nobody@example.com>" \
1261 --to=nobody@example.com \
1262 --smtp-server="$(pwd)/fake.sendmail" \
1263 outdir/0002-*.patch \
1264 outdir/0000-*.patch \
1265 outdir/0001-*.patch \
1267 ! grep "SUBJECT HERE" errors &&
1268 test -n "$(ls msgtxt*)"
1271 test_expect_success $PREREQ 'sendemail.aliasfiletype=mailrc' '
1272 clean_fake_sendmail &&
1273 echo "alias sbd somebody@example.org" >.mailrc &&
1274 git config --replace-all sendemail.aliasesfile "$(pwd)/.mailrc" &&
1275 git config sendemail.aliasfiletype mailrc &&
1277 --from="Example <nobody@example.com>" \
1279 --smtp-server="$(pwd)/fake.sendmail" \
1280 outdir/0001-*.patch \
1282 grep "^!somebody@example\.org!$" commandline1
1285 test_expect_success $PREREQ 'sendemail.aliasfile=~/.mailrc' '
1286 clean_fake_sendmail &&
1287 echo "alias sbd someone@example.org" >~/.mailrc &&
1288 git config --replace-all sendemail.aliasesfile "~/.mailrc" &&
1289 git config sendemail.aliasfiletype mailrc &&
1291 --from="Example <nobody@example.com>" \
1293 --smtp-server="$(pwd)/fake.sendmail" \
1294 outdir/0001-*.patch \
1296 grep "^!someone@example\.org!$" commandline1