Merge branch 'es/doc-gitsubmodules-markup'
[git/raj.git] / t / t9001-send-email.sh
blob1e3ac3c3846342ac84baa096ab00ed602e4cdf27
1 #!/bin/sh
3 test_description='git send-email'
4 . ./test-lib.sh
6 # May be altered later in the test
7 PREREQ="PERL"
9 replace_variable_fields () {
10 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
11 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
12 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/"
15 test_expect_success $PREREQ 'prepare reference tree' '
16 echo "1A quick brown fox jumps over the" >file &&
17 echo "lazy dog" >>file &&
18 git add file &&
19 GIT_AUTHOR_NAME="A" git commit -a -m "Initial."
22 test_expect_success $PREREQ 'Setup helper tool' '
23 write_script fake.sendmail <<-\EOF &&
24 shift
25 output=1
26 while test -f commandline$output
28 output=$(($output+1))
29 done
30 for a
32 echo "!$a!"
33 done >commandline$output
34 cat >"msgtxt$output"
35 EOF
36 git add fake.sendmail &&
37 GIT_AUTHOR_NAME="A" git commit -a -m "Second."
40 clean_fake_sendmail () {
41 rm -f commandline* msgtxt*
44 test_expect_success $PREREQ 'Extract patches' '
45 patches=$(git format-patch -s --cc="One <one@example.com>" --cc=two@example.com -n HEAD^1)
48 # Test no confirm early to ensure remaining tests will not hang
49 test_no_confirm () {
50 rm -f no_confirm_okay
51 echo n | \
52 GIT_SEND_EMAIL_NOTTY=1 \
53 git send-email \
54 --from="Example <from@example.com>" \
55 --to=nobody@example.com \
56 --smtp-server="$(pwd)/fake.sendmail" \
57 $@ \
58 $patches >stdout &&
59 ! grep "Send this email" stdout &&
60 >no_confirm_okay
63 # Exit immediately to prevent hang if a no-confirm test fails
64 check_no_confirm () {
65 if ! test -f no_confirm_okay
66 then
67 say 'confirm test failed; skipping remaining tests to prevent hanging'
68 PREREQ="$PREREQ,CHECK_NO_CONFIRM"
70 return 0
73 test_expect_success $PREREQ 'No confirm with --suppress-cc' '
74 test_no_confirm --suppress-cc=sob &&
75 check_no_confirm
79 test_expect_success $PREREQ 'No confirm with --confirm=never' '
80 test_no_confirm --confirm=never &&
81 check_no_confirm
84 # leave sendemail.confirm set to never after this so that none of the
85 # remaining tests prompt unintentionally.
86 test_expect_success $PREREQ 'No confirm with sendemail.confirm=never' '
87 git config sendemail.confirm never &&
88 test_no_confirm --compose --subject=foo &&
89 check_no_confirm
92 test_expect_success $PREREQ 'Send patches' '
93 git send-email --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
96 test_expect_success $PREREQ 'setup expect' '
97 cat >expected <<-\EOF
98 !nobody@example.com!
99 !author@example.com!
100 !one@example.com!
101 !two@example.com!
105 test_expect_success $PREREQ 'Verify commandline' '
106 test_cmp expected commandline1
109 test_expect_success $PREREQ 'Send patches with --envelope-sender' '
110 clean_fake_sendmail &&
111 git send-email --envelope-sender="Patch Contributor <patch@example.com>" --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
114 test_expect_success $PREREQ 'setup expect' '
115 cat >expected <<-\EOF
116 !patch@example.com!
117 !-i!
118 !nobody@example.com!
119 !author@example.com!
120 !one@example.com!
121 !two@example.com!
125 test_expect_success $PREREQ 'Verify commandline' '
126 test_cmp expected commandline1
129 test_expect_success $PREREQ 'Send patches with --envelope-sender=auto' '
130 clean_fake_sendmail &&
131 git send-email --envelope-sender=auto --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
134 test_expect_success $PREREQ 'setup expect' '
135 cat >expected <<-\EOF
136 !nobody@example.com!
137 !-i!
138 !nobody@example.com!
139 !author@example.com!
140 !one@example.com!
141 !two@example.com!
145 test_expect_success $PREREQ 'Verify commandline' '
146 test_cmp expected commandline1
149 test_expect_success $PREREQ 'setup expect for cc trailer' "
150 cat >expected-cc <<\EOF
151 !recipient@example.com!
152 !author@example.com!
153 !one@example.com!
154 !two@example.com!
155 !three@example.com!
156 !four@example.com!
157 !five@example.com!
158 !six@example.com!
162 test_expect_success $PREREQ 'cc trailer with various syntax' '
163 test_commit cc-trailer &&
164 test_when_finished "git reset --hard HEAD^" &&
165 git commit --amend -F - <<-EOF &&
166 Test Cc: trailers.
168 Cc: one@example.com
169 Cc: <two@example.com> # trailing comments are ignored
170 Cc: <three@example.com>, <not.four@example.com> one address per line
171 Cc: "Some # Body" <four@example.com> [ <also.a.comment> ]
172 Cc: five@example.com # not.six@example.com
173 Cc: six@example.com, not.seven@example.com
175 clean_fake_sendmail &&
176 git send-email -1 --to=recipient@example.com \
177 --smtp-server="$(pwd)/fake.sendmail" &&
178 test_cmp expected-cc commandline1
181 test_expect_success $PREREQ 'setup fake get_maintainer.pl script for cc trailer' "
182 write_script expected-cc-script.sh <<-EOF
183 echo 'One Person <one@example.com> (supporter:THIS (FOO/bar))'
184 echo 'Two Person <two@example.com> (maintainer:THIS THING)'
185 echo 'Third List <three@example.com> (moderated list:THIS THING (FOO/bar))'
186 echo '<four@example.com> (moderated list:FOR THING)'
187 echo 'five@example.com (open list:FOR THING (FOO/bar))'
188 echo 'six@example.com (open list)'
192 test_expect_success $PREREQ 'cc trailer with get_maintainer.pl output' '
193 clean_fake_sendmail &&
194 git send-email -1 --to=recipient@example.com \
195 --cc-cmd=./expected-cc-script.sh \
196 --smtp-server="$(pwd)/fake.sendmail" &&
197 test_cmp expected-cc commandline1
200 test_expect_success $PREREQ 'setup expect' "
201 cat >expected-show-all-headers <<\EOF
202 0001-Second.patch
203 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
204 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
205 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
206 Dry-OK. Log says:
207 Server: relay.example.com
208 MAIL FROM:<from@example.com>
209 RCPT TO:<to@example.com>
210 RCPT TO:<cc@example.com>
211 RCPT TO:<author@example.com>
212 RCPT TO:<one@example.com>
213 RCPT TO:<two@example.com>
214 RCPT TO:<bcc@example.com>
215 From: Example <from@example.com>
216 To: to@example.com
217 Cc: cc@example.com,
218 A <author@example.com>,
219 One <one@example.com>,
220 two@example.com
221 Subject: [PATCH 1/1] Second.
222 Date: DATE-STRING
223 Message-Id: MESSAGE-ID-STRING
224 X-Mailer: X-MAILER-STRING
225 In-Reply-To: <unique-message-id@example.com>
226 References: <unique-message-id@example.com>
227 Reply-To: Reply <reply@example.com>
228 MIME-Version: 1.0
229 Content-Transfer-Encoding: 8bit
231 Result: OK
235 test_suppress_self () {
236 test_commit $3 &&
237 test_when_finished "git reset --hard HEAD^" &&
239 write_script cccmd-sed <<-EOF &&
240 sed -n -e s/^cccmd--//p "\$1"
243 git commit --amend --author="$1 <$2>" -F - &&
244 clean_fake_sendmail &&
245 git format-patch --stdout -1 >"suppress-self-$3.patch" &&
247 git send-email --from="$1 <$2>" \
248 --to=nobody@example.com \
249 --cc-cmd=./cccmd-sed \
250 --suppress-cc=self \
251 --smtp-server="$(pwd)/fake.sendmail" \
252 suppress-self-$3.patch &&
254 mv msgtxt1 msgtxt1-$3 &&
255 sed -e '/^$/q' msgtxt1-$3 >"msghdr1-$3" &&
257 (grep '^Cc:' msghdr1-$3 >"actual-no-cc-$3";
258 test_must_be_empty actual-no-cc-$3)
261 test_suppress_self_unquoted () {
262 test_suppress_self "$1" "$2" "unquoted-$3" <<-EOF
263 test suppress-cc.self unquoted-$3 with name $1 email $2
265 unquoted-$3
267 cccmd--$1 <$2>
269 Cc: $1 <$2>
270 Signed-off-by: $1 <$2>
274 test_suppress_self_quoted () {
275 test_suppress_self "$1" "$2" "quoted-$3" <<-EOF
276 test suppress-cc.self quoted-$3 with name $1 email $2
278 quoted-$3
280 cccmd--"$1" <$2>
282 Cc: $1 <$2>
283 Cc: "$1" <$2>
284 Signed-off-by: $1 <$2>
285 Signed-off-by: "$1" <$2>
289 test_expect_success $PREREQ 'self name is suppressed' "
290 test_suppress_self_unquoted 'A U Thor' 'author@example.com' \
291 'self_name_suppressed'
294 test_expect_success $PREREQ 'self name with dot is suppressed' "
295 test_suppress_self_quoted 'A U. Thor' 'author@example.com' \
296 'self_name_dot_suppressed'
299 test_expect_success $PREREQ 'non-ascii self name is suppressed' "
300 test_suppress_self_quoted 'Füñný Nâmé' 'odd_?=mail@example.com' \
301 'non_ascii_self_suppressed'
304 # This name is long enough to force format-patch to split it into multiple
305 # encoded-words, assuming it uses UTF-8 with the "Q" encoding.
306 test_expect_success $PREREQ 'long non-ascii self name is suppressed' "
307 test_suppress_self_quoted 'Ƒüñníęř €. Nâṁé' 'odd_?=mail@example.com' \
308 'long_non_ascii_self_suppressed'
311 test_expect_success $PREREQ 'sanitized self name is suppressed' "
312 test_suppress_self_unquoted '\"A U. Thor\"' 'author@example.com' \
313 'self_name_sanitized_suppressed'
316 test_expect_success $PREREQ 'Show all headers' '
317 git send-email \
318 --dry-run \
319 --suppress-cc=sob \
320 --from="Example <from@example.com>" \
321 --reply-to="Reply <reply@example.com>" \
322 --to=to@example.com \
323 --cc=cc@example.com \
324 --bcc=bcc@example.com \
325 --in-reply-to="<unique-message-id@example.com>" \
326 --smtp-server relay.example.com \
327 $patches | replace_variable_fields \
328 >actual-show-all-headers &&
329 test_cmp expected-show-all-headers actual-show-all-headers
332 test_expect_success $PREREQ 'Prompting works' '
333 clean_fake_sendmail &&
334 (echo "to@example.com" &&
335 echo ""
336 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
337 --smtp-server="$(pwd)/fake.sendmail" \
338 $patches \
339 2>errors &&
340 grep "^From: A U Thor <author@example.com>\$" msgtxt1 &&
341 grep "^To: to@example.com\$" msgtxt1
344 test_expect_success $PREREQ,AUTOIDENT 'implicit ident is allowed' '
345 clean_fake_sendmail &&
346 (sane_unset GIT_AUTHOR_NAME &&
347 sane_unset GIT_AUTHOR_EMAIL &&
348 sane_unset GIT_COMMITTER_NAME &&
349 sane_unset GIT_COMMITTER_EMAIL &&
350 GIT_SEND_EMAIL_NOTTY=1 git send-email \
351 --smtp-server="$(pwd)/fake.sendmail" \
352 --to=to@example.com \
353 $patches </dev/null 2>errors
357 test_expect_success $PREREQ,!AUTOIDENT 'broken implicit ident aborts send-email' '
358 clean_fake_sendmail &&
359 (sane_unset GIT_AUTHOR_NAME &&
360 sane_unset GIT_AUTHOR_EMAIL &&
361 sane_unset GIT_COMMITTER_NAME &&
362 sane_unset GIT_COMMITTER_EMAIL &&
363 GIT_SEND_EMAIL_NOTTY=1 && export GIT_SEND_EMAIL_NOTTY &&
364 test_must_fail git send-email \
365 --smtp-server="$(pwd)/fake.sendmail" \
366 --to=to@example.com \
367 $patches </dev/null 2>errors &&
368 test_i18ngrep "tell me who you are" errors
372 test_expect_success $PREREQ 'setup tocmd and cccmd scripts' '
373 write_script tocmd-sed <<-\EOF &&
374 sed -n -e "s/^tocmd--//p" "$1"
376 write_script cccmd-sed <<-\EOF
377 sed -n -e "s/^cccmd--//p" "$1"
381 test_expect_success $PREREQ 'tocmd works' '
382 clean_fake_sendmail &&
383 cp $patches tocmd.patch &&
384 echo tocmd--tocmd@example.com >>tocmd.patch &&
385 git send-email \
386 --from="Example <nobody@example.com>" \
387 --to-cmd=./tocmd-sed \
388 --smtp-server="$(pwd)/fake.sendmail" \
389 tocmd.patch \
391 grep "^To: tocmd@example.com" msgtxt1
394 test_expect_success $PREREQ 'cccmd works' '
395 clean_fake_sendmail &&
396 cp $patches cccmd.patch &&
397 echo "cccmd-- cccmd@example.com" >>cccmd.patch &&
398 git send-email \
399 --from="Example <nobody@example.com>" \
400 --to=nobody@example.com \
401 --cc-cmd=./cccmd-sed \
402 --smtp-server="$(pwd)/fake.sendmail" \
403 cccmd.patch \
405 grep "^ cccmd@example.com" msgtxt1
408 test_expect_success $PREREQ 'reject long lines' '
409 z8=zzzzzzzz &&
410 z64=$z8$z8$z8$z8$z8$z8$z8$z8 &&
411 z512=$z64$z64$z64$z64$z64$z64$z64$z64 &&
412 clean_fake_sendmail &&
413 cp $patches longline.patch &&
414 echo $z512$z512 >>longline.patch &&
415 test_must_fail git send-email \
416 --from="Example <nobody@example.com>" \
417 --to=nobody@example.com \
418 --smtp-server="$(pwd)/fake.sendmail" \
419 --transfer-encoding=8bit \
420 $patches longline.patch \
421 2>errors &&
422 grep longline.patch errors
425 test_expect_success $PREREQ 'no patch was sent' '
426 ! test -e commandline1
429 test_expect_success $PREREQ 'Author From: in message body' '
430 clean_fake_sendmail &&
431 git send-email \
432 --from="Example <nobody@example.com>" \
433 --to=nobody@example.com \
434 --smtp-server="$(pwd)/fake.sendmail" \
435 $patches &&
436 sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
437 grep "From: A <author@example.com>" msgbody1
440 test_expect_success $PREREQ 'Author From: not in message body' '
441 clean_fake_sendmail &&
442 git send-email \
443 --from="A <author@example.com>" \
444 --to=nobody@example.com \
445 --smtp-server="$(pwd)/fake.sendmail" \
446 $patches &&
447 sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
448 ! grep "From: A <author@example.com>" msgbody1
451 test_expect_success $PREREQ 'allow long lines with --no-validate' '
452 git send-email \
453 --from="Example <nobody@example.com>" \
454 --to=nobody@example.com \
455 --smtp-server="$(pwd)/fake.sendmail" \
456 --no-validate \
457 $patches longline.patch \
458 2>errors
461 test_expect_success $PREREQ 'short lines with auto encoding are 8bit' '
462 clean_fake_sendmail &&
463 git send-email \
464 --from="A <author@example.com>" \
465 --to=nobody@example.com \
466 --smtp-server="$(pwd)/fake.sendmail" \
467 --transfer-encoding=auto \
468 $patches &&
469 grep "Content-Transfer-Encoding: 8bit" msgtxt1
472 test_expect_success $PREREQ 'long lines with auto encoding are quoted-printable' '
473 clean_fake_sendmail &&
474 git send-email \
475 --from="Example <nobody@example.com>" \
476 --to=nobody@example.com \
477 --smtp-server="$(pwd)/fake.sendmail" \
478 --transfer-encoding=auto \
479 --no-validate \
480 longline.patch &&
481 grep "Content-Transfer-Encoding: quoted-printable" msgtxt1
484 test_expect_success $PREREQ 'carriage returns with auto encoding are quoted-printable' '
485 clean_fake_sendmail &&
486 cp $patches cr.patch &&
487 printf "this is a line\r\n" >>cr.patch &&
488 git send-email \
489 --from="Example <nobody@example.com>" \
490 --to=nobody@example.com \
491 --smtp-server="$(pwd)/fake.sendmail" \
492 --transfer-encoding=auto \
493 --no-validate \
494 cr.patch &&
495 grep "Content-Transfer-Encoding: quoted-printable" msgtxt1
498 for enc in auto quoted-printable base64
500 test_expect_success $PREREQ "--validate passes with encoding $enc" '
501 git send-email \
502 --from="Example <nobody@example.com>" \
503 --to=nobody@example.com \
504 --smtp-server="$(pwd)/fake.sendmail" \
505 --transfer-encoding=$enc \
506 --validate \
507 $patches longline.patch
510 done
512 for enc in 7bit 8bit quoted-printable base64
514 test_expect_success $PREREQ "--transfer-encoding=$enc produces correct header" '
515 clean_fake_sendmail &&
516 git send-email \
517 --from="Example <nobody@example.com>" \
518 --to=nobody@example.com \
519 --smtp-server="$(pwd)/fake.sendmail" \
520 --transfer-encoding=$enc \
521 $patches &&
522 grep "Content-Transfer-Encoding: $enc" msgtxt1
524 done
526 test_expect_success $PREREQ 'Invalid In-Reply-To' '
527 clean_fake_sendmail &&
528 git send-email \
529 --from="Example <nobody@example.com>" \
530 --to=nobody@example.com \
531 --in-reply-to=" " \
532 --smtp-server="$(pwd)/fake.sendmail" \
533 $patches \
534 2>errors &&
535 ! grep "^In-Reply-To: < *>" msgtxt1
538 test_expect_success $PREREQ 'Valid In-Reply-To when prompting' '
539 clean_fake_sendmail &&
540 (echo "From Example <from@example.com>" &&
541 echo "To Example <to@example.com>" &&
542 echo ""
543 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
544 --smtp-server="$(pwd)/fake.sendmail" \
545 $patches 2>errors &&
546 ! grep "^In-Reply-To: < *>" msgtxt1
549 test_expect_success $PREREQ 'In-Reply-To without --chain-reply-to' '
550 clean_fake_sendmail &&
551 echo "<unique-message-id@example.com>" >expect &&
552 git send-email \
553 --from="Example <nobody@example.com>" \
554 --to=nobody@example.com \
555 --no-chain-reply-to \
556 --in-reply-to="$(cat expect)" \
557 --smtp-server="$(pwd)/fake.sendmail" \
558 $patches $patches $patches \
559 2>errors &&
560 # The first message is a reply to --in-reply-to
561 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
562 test_cmp expect actual &&
563 # Second and subsequent messages are replies to the first one
564 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
565 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
566 test_cmp expect actual &&
567 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
568 test_cmp expect actual
571 test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' '
572 clean_fake_sendmail &&
573 echo "<unique-message-id@example.com>" >expect &&
574 git send-email \
575 --from="Example <nobody@example.com>" \
576 --to=nobody@example.com \
577 --chain-reply-to \
578 --in-reply-to="$(cat expect)" \
579 --smtp-server="$(pwd)/fake.sendmail" \
580 $patches $patches $patches \
581 2>errors &&
582 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
583 test_cmp expect actual &&
584 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
585 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
586 test_cmp expect actual &&
587 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt2 >expect &&
588 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
589 test_cmp expect actual
592 test_expect_success $PREREQ 'setup fake editor' '
593 write_script fake-editor <<-\EOF
594 echo fake edit >>"$1"
598 test_set_editor "$(pwd)/fake-editor"
600 test_expect_success $PREREQ '--compose works' '
601 clean_fake_sendmail &&
602 git send-email \
603 --compose --subject foo \
604 --from="Example <nobody@example.com>" \
605 --to=nobody@example.com \
606 --smtp-server="$(pwd)/fake.sendmail" \
607 $patches \
608 2>errors
611 test_expect_success $PREREQ 'first message is compose text' '
612 grep "^fake edit" msgtxt1
615 test_expect_success $PREREQ 'second message is patch' '
616 grep "Subject:.*Second" msgtxt2
619 test_expect_success $PREREQ 'setup expect' "
620 cat >expected-suppress-sob <<\EOF
621 0001-Second.patch
622 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
623 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
624 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
625 Dry-OK. Log says:
626 Server: relay.example.com
627 MAIL FROM:<from@example.com>
628 RCPT TO:<to@example.com>
629 RCPT TO:<cc@example.com>
630 RCPT TO:<author@example.com>
631 RCPT TO:<one@example.com>
632 RCPT TO:<two@example.com>
633 From: Example <from@example.com>
634 To: to@example.com
635 Cc: cc@example.com,
636 A <author@example.com>,
637 One <one@example.com>,
638 two@example.com
639 Subject: [PATCH 1/1] Second.
640 Date: DATE-STRING
641 Message-Id: MESSAGE-ID-STRING
642 X-Mailer: X-MAILER-STRING
643 MIME-Version: 1.0
644 Content-Transfer-Encoding: 8bit
646 Result: OK
650 test_suppression () {
651 git send-email \
652 --dry-run \
653 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
654 --from="Example <from@example.com>" \
655 --to=to@example.com \
656 --smtp-server relay.example.com \
657 $patches | replace_variable_fields \
658 >actual-suppress-$1${2+"-$2"} &&
659 test_cmp expected-suppress-$1${2+"-$2"} actual-suppress-$1${2+"-$2"}
662 test_expect_success $PREREQ 'sendemail.cc set' '
663 git config sendemail.cc cc@example.com &&
664 test_suppression sob
667 test_expect_success $PREREQ 'setup expect' "
668 cat >expected-suppress-sob <<\EOF
669 0001-Second.patch
670 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
671 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
672 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
673 Dry-OK. Log says:
674 Server: relay.example.com
675 MAIL FROM:<from@example.com>
676 RCPT TO:<to@example.com>
677 RCPT TO:<author@example.com>
678 RCPT TO:<one@example.com>
679 RCPT TO:<two@example.com>
680 From: Example <from@example.com>
681 To: to@example.com
682 Cc: A <author@example.com>,
683 One <one@example.com>,
684 two@example.com
685 Subject: [PATCH 1/1] Second.
686 Date: DATE-STRING
687 Message-Id: MESSAGE-ID-STRING
688 X-Mailer: X-MAILER-STRING
689 MIME-Version: 1.0
690 Content-Transfer-Encoding: 8bit
692 Result: OK
696 test_expect_success $PREREQ 'sendemail.cc unset' '
697 git config --unset sendemail.cc &&
698 test_suppression sob
701 test_expect_success $PREREQ 'setup expect' "
702 cat >expected-suppress-cccmd <<\EOF
703 0001-Second.patch
704 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
705 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
706 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
707 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
708 Dry-OK. Log says:
709 Server: relay.example.com
710 MAIL FROM:<from@example.com>
711 RCPT TO:<to@example.com>
712 RCPT TO:<author@example.com>
713 RCPT TO:<one@example.com>
714 RCPT TO:<two@example.com>
715 RCPT TO:<committer@example.com>
716 From: Example <from@example.com>
717 To: to@example.com
718 Cc: A <author@example.com>,
719 One <one@example.com>,
720 two@example.com,
721 C O Mitter <committer@example.com>
722 Subject: [PATCH 1/1] Second.
723 Date: DATE-STRING
724 Message-Id: MESSAGE-ID-STRING
725 X-Mailer: X-MAILER-STRING
726 MIME-Version: 1.0
727 Content-Transfer-Encoding: 8bit
729 Result: OK
733 test_expect_success $PREREQ 'sendemail.cccmd' '
734 write_script cccmd <<-\EOF &&
735 echo cc-cmd@example.com
737 git config sendemail.cccmd ./cccmd &&
738 test_suppression cccmd
741 test_expect_success $PREREQ 'setup expect' '
742 cat >expected-suppress-all <<\EOF
743 0001-Second.patch
744 Dry-OK. Log says:
745 Server: relay.example.com
746 MAIL FROM:<from@example.com>
747 RCPT TO:<to@example.com>
748 From: Example <from@example.com>
749 To: to@example.com
750 Subject: [PATCH 1/1] Second.
751 Date: DATE-STRING
752 Message-Id: MESSAGE-ID-STRING
753 X-Mailer: X-MAILER-STRING
754 MIME-Version: 1.0
755 Content-Transfer-Encoding: 8bit
757 Result: OK
761 test_expect_success $PREREQ '--suppress-cc=all' '
762 test_suppression all
765 test_expect_success $PREREQ 'setup expect' "
766 cat >expected-suppress-body <<\EOF
767 0001-Second.patch
768 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
769 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
770 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
771 (cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
772 Dry-OK. Log says:
773 Server: relay.example.com
774 MAIL FROM:<from@example.com>
775 RCPT TO:<to@example.com>
776 RCPT TO:<author@example.com>
777 RCPT TO:<one@example.com>
778 RCPT TO:<two@example.com>
779 RCPT TO:<cc-cmd@example.com>
780 From: Example <from@example.com>
781 To: to@example.com
782 Cc: A <author@example.com>,
783 One <one@example.com>,
784 two@example.com,
785 cc-cmd@example.com
786 Subject: [PATCH 1/1] Second.
787 Date: DATE-STRING
788 Message-Id: MESSAGE-ID-STRING
789 X-Mailer: X-MAILER-STRING
790 MIME-Version: 1.0
791 Content-Transfer-Encoding: 8bit
793 Result: OK
797 test_expect_success $PREREQ '--suppress-cc=body' '
798 test_suppression body
801 test_expect_success $PREREQ 'setup expect' "
802 cat >expected-suppress-body-cccmd <<\EOF
803 0001-Second.patch
804 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
805 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
806 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
807 Dry-OK. Log says:
808 Server: relay.example.com
809 MAIL FROM:<from@example.com>
810 RCPT TO:<to@example.com>
811 RCPT TO:<author@example.com>
812 RCPT TO:<one@example.com>
813 RCPT TO:<two@example.com>
814 From: Example <from@example.com>
815 To: to@example.com
816 Cc: A <author@example.com>,
817 One <one@example.com>,
818 two@example.com
819 Subject: [PATCH 1/1] Second.
820 Date: DATE-STRING
821 Message-Id: MESSAGE-ID-STRING
822 X-Mailer: X-MAILER-STRING
823 MIME-Version: 1.0
824 Content-Transfer-Encoding: 8bit
826 Result: OK
830 test_expect_success $PREREQ '--suppress-cc=body --suppress-cc=cccmd' '
831 test_suppression body cccmd
834 test_expect_success $PREREQ 'setup expect' "
835 cat >expected-suppress-sob <<\EOF
836 0001-Second.patch
837 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
838 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
839 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
840 Dry-OK. Log says:
841 Server: relay.example.com
842 MAIL FROM:<from@example.com>
843 RCPT TO:<to@example.com>
844 RCPT TO:<author@example.com>
845 RCPT TO:<one@example.com>
846 RCPT TO:<two@example.com>
847 From: Example <from@example.com>
848 To: to@example.com
849 Cc: A <author@example.com>,
850 One <one@example.com>,
851 two@example.com
852 Subject: [PATCH 1/1] Second.
853 Date: DATE-STRING
854 Message-Id: MESSAGE-ID-STRING
855 X-Mailer: X-MAILER-STRING
856 MIME-Version: 1.0
857 Content-Transfer-Encoding: 8bit
859 Result: OK
863 test_expect_success $PREREQ '--suppress-cc=sob' '
864 test_might_fail git config --unset sendemail.cccmd &&
865 test_suppression sob
868 test_expect_success $PREREQ 'setup expect' "
869 cat >expected-suppress-bodycc <<\EOF
870 0001-Second.patch
871 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
872 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
873 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
874 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
875 Dry-OK. Log says:
876 Server: relay.example.com
877 MAIL FROM:<from@example.com>
878 RCPT TO:<to@example.com>
879 RCPT TO:<author@example.com>
880 RCPT TO:<one@example.com>
881 RCPT TO:<two@example.com>
882 RCPT TO:<committer@example.com>
883 From: Example <from@example.com>
884 To: to@example.com
885 Cc: A <author@example.com>,
886 One <one@example.com>,
887 two@example.com,
888 C O Mitter <committer@example.com>
889 Subject: [PATCH 1/1] Second.
890 Date: DATE-STRING
891 Message-Id: MESSAGE-ID-STRING
892 X-Mailer: X-MAILER-STRING
893 MIME-Version: 1.0
894 Content-Transfer-Encoding: 8bit
896 Result: OK
900 test_expect_success $PREREQ '--suppress-cc=bodycc' '
901 test_suppression bodycc
904 test_expect_success $PREREQ 'setup expect' "
905 cat >expected-suppress-cc <<\EOF
906 0001-Second.patch
907 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
908 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
909 Dry-OK. Log says:
910 Server: relay.example.com
911 MAIL FROM:<from@example.com>
912 RCPT TO:<to@example.com>
913 RCPT TO:<author@example.com>
914 RCPT TO:<committer@example.com>
915 From: Example <from@example.com>
916 To: to@example.com
917 Cc: A <author@example.com>,
918 C O Mitter <committer@example.com>
919 Subject: [PATCH 1/1] Second.
920 Date: DATE-STRING
921 Message-Id: MESSAGE-ID-STRING
922 X-Mailer: X-MAILER-STRING
923 MIME-Version: 1.0
924 Content-Transfer-Encoding: 8bit
926 Result: OK
930 test_expect_success $PREREQ '--suppress-cc=cc' '
931 test_suppression cc
934 test_confirm () {
935 echo y | \
936 GIT_SEND_EMAIL_NOTTY=1 \
937 git send-email \
938 --from="Example <nobody@example.com>" \
939 --to=nobody@example.com \
940 --smtp-server="$(pwd)/fake.sendmail" \
941 $@ $patches >stdout &&
942 grep "Send this email" stdout
945 test_expect_success $PREREQ '--confirm=always' '
946 test_confirm --confirm=always --suppress-cc=all
949 test_expect_success $PREREQ '--confirm=auto' '
950 test_confirm --confirm=auto
953 test_expect_success $PREREQ '--confirm=cc' '
954 test_confirm --confirm=cc
957 test_expect_success $PREREQ '--confirm=compose' '
958 test_confirm --confirm=compose --compose
961 test_expect_success $PREREQ 'confirm by default (due to cc)' '
962 test_when_finished git config sendemail.confirm never &&
963 git config --unset sendemail.confirm &&
964 test_confirm
967 test_expect_success $PREREQ 'confirm by default (due to --compose)' '
968 test_when_finished git config sendemail.confirm never &&
969 git config --unset sendemail.confirm &&
970 test_confirm --suppress-cc=all --compose
973 test_expect_success $PREREQ 'confirm detects EOF (inform assumes y)' '
974 test_when_finished git config sendemail.confirm never &&
975 git config --unset sendemail.confirm &&
976 rm -fr outdir &&
977 git format-patch -2 -o outdir &&
978 GIT_SEND_EMAIL_NOTTY=1 \
979 git send-email \
980 --from="Example <nobody@example.com>" \
981 --to=nobody@example.com \
982 --smtp-server="$(pwd)/fake.sendmail" \
983 outdir/*.patch </dev/null
986 test_expect_success $PREREQ 'confirm detects EOF (auto causes failure)' '
987 test_when_finished git config sendemail.confirm never &&
988 git config sendemail.confirm auto &&
989 GIT_SEND_EMAIL_NOTTY=1 &&
990 export GIT_SEND_EMAIL_NOTTY &&
991 test_must_fail git send-email \
992 --from="Example <nobody@example.com>" \
993 --to=nobody@example.com \
994 --smtp-server="$(pwd)/fake.sendmail" \
995 $patches </dev/null
998 test_expect_success $PREREQ 'confirm does not loop forever' '
999 test_when_finished git config sendemail.confirm never &&
1000 git config sendemail.confirm auto &&
1001 GIT_SEND_EMAIL_NOTTY=1 &&
1002 export GIT_SEND_EMAIL_NOTTY &&
1003 yes "bogus" | test_must_fail git send-email \
1004 --from="Example <nobody@example.com>" \
1005 --to=nobody@example.com \
1006 --smtp-server="$(pwd)/fake.sendmail" \
1007 $patches
1010 test_expect_success $PREREQ 'utf8 Cc is rfc2047 encoded' '
1011 clean_fake_sendmail &&
1012 rm -fr outdir &&
1013 git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
1014 git send-email \
1015 --from="Example <nobody@example.com>" \
1016 --to=nobody@example.com \
1017 --smtp-server="$(pwd)/fake.sendmail" \
1018 outdir/*.patch &&
1019 grep "^ " msgtxt1 |
1020 grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
1023 test_expect_success $PREREQ '--compose adds MIME for utf8 body' '
1024 clean_fake_sendmail &&
1025 write_script fake-editor-utf8 <<-\EOF &&
1026 echo "utf8 body: àéìöú" >>"$1"
1028 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1029 git send-email \
1030 --compose --subject foo \
1031 --from="Example <nobody@example.com>" \
1032 --to=nobody@example.com \
1033 --smtp-server="$(pwd)/fake.sendmail" \
1034 $patches &&
1035 grep "^utf8 body" msgtxt1 &&
1036 grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
1039 test_expect_success $PREREQ '--compose respects user mime type' '
1040 clean_fake_sendmail &&
1041 write_script fake-editor-utf8-mime <<-\EOF &&
1042 cat >"$1" <<-\EOM
1043 MIME-Version: 1.0
1044 Content-Type: text/plain; charset=iso-8859-1
1045 Content-Transfer-Encoding: 8bit
1046 Subject: foo
1048 utf8 body: àéìöú
1051 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
1052 git send-email \
1053 --compose --subject foo \
1054 --from="Example <nobody@example.com>" \
1055 --to=nobody@example.com \
1056 --smtp-server="$(pwd)/fake.sendmail" \
1057 $patches &&
1058 grep "^utf8 body" msgtxt1 &&
1059 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
1060 ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
1063 test_expect_success $PREREQ '--compose adds MIME for utf8 subject' '
1064 clean_fake_sendmail &&
1065 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
1066 git send-email \
1067 --compose --subject utf8-sübjëct \
1068 --from="Example <nobody@example.com>" \
1069 --to=nobody@example.com \
1070 --smtp-server="$(pwd)/fake.sendmail" \
1071 $patches &&
1072 grep "^fake edit" msgtxt1 &&
1073 grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
1076 test_expect_success $PREREQ 'utf8 author is correctly passed on' '
1077 clean_fake_sendmail &&
1078 test_commit weird_author &&
1079 test_when_finished "git reset --hard HEAD^" &&
1080 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
1081 git format-patch --stdout -1 >funny_name.patch &&
1082 git send-email --from="Example <nobody@example.com>" \
1083 --to=nobody@example.com \
1084 --smtp-server="$(pwd)/fake.sendmail" \
1085 funny_name.patch &&
1086 grep "^From: Füñný Nâmé <odd_?=mail@example.com>" msgtxt1
1089 test_expect_success $PREREQ 'utf8 sender is not duplicated' '
1090 clean_fake_sendmail &&
1091 test_commit weird_sender &&
1092 test_when_finished "git reset --hard HEAD^" &&
1093 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
1094 git format-patch --stdout -1 >funny_name.patch &&
1095 git send-email --from="Füñný Nâmé <odd_?=mail@example.com>" \
1096 --to=nobody@example.com \
1097 --smtp-server="$(pwd)/fake.sendmail" \
1098 funny_name.patch &&
1099 grep "^From: " msgtxt1 >msgfrom &&
1100 test_line_count = 1 msgfrom
1103 test_expect_success $PREREQ 'sendemail.composeencoding works' '
1104 clean_fake_sendmail &&
1105 git config sendemail.composeencoding iso-8859-1 &&
1106 write_script fake-editor-utf8 <<-\EOF &&
1107 echo "utf8 body: àéìöú" >>"$1"
1109 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1110 git send-email \
1111 --compose --subject foo \
1112 --from="Example <nobody@example.com>" \
1113 --to=nobody@example.com \
1114 --smtp-server="$(pwd)/fake.sendmail" \
1115 $patches &&
1116 grep "^utf8 body" msgtxt1 &&
1117 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1120 test_expect_success $PREREQ '--compose-encoding works' '
1121 clean_fake_sendmail &&
1122 write_script fake-editor-utf8 <<-\EOF &&
1123 echo "utf8 body: àéìöú" >>"$1"
1125 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1126 git send-email \
1127 --compose-encoding iso-8859-1 \
1128 --compose --subject foo \
1129 --from="Example <nobody@example.com>" \
1130 --to=nobody@example.com \
1131 --smtp-server="$(pwd)/fake.sendmail" \
1132 $patches &&
1133 grep "^utf8 body" msgtxt1 &&
1134 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1137 test_expect_success $PREREQ '--compose-encoding overrides sendemail.composeencoding' '
1138 clean_fake_sendmail &&
1139 git config sendemail.composeencoding iso-8859-1 &&
1140 write_script fake-editor-utf8 <<-\EOF &&
1141 echo "utf8 body: àéìöú" >>"$1"
1143 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1144 git send-email \
1145 --compose-encoding iso-8859-2 \
1146 --compose --subject foo \
1147 --from="Example <nobody@example.com>" \
1148 --to=nobody@example.com \
1149 --smtp-server="$(pwd)/fake.sendmail" \
1150 $patches &&
1151 grep "^utf8 body" msgtxt1 &&
1152 grep "^Content-Type: text/plain; charset=iso-8859-2" msgtxt1
1155 test_expect_success $PREREQ '--compose-encoding adds correct MIME for subject' '
1156 clean_fake_sendmail &&
1157 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
1158 git send-email \
1159 --compose-encoding iso-8859-2 \
1160 --compose --subject utf8-sübjëct \
1161 --from="Example <nobody@example.com>" \
1162 --to=nobody@example.com \
1163 --smtp-server="$(pwd)/fake.sendmail" \
1164 $patches &&
1165 grep "^fake edit" msgtxt1 &&
1166 grep "^Subject: =?iso-8859-2?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
1169 test_expect_success $PREREQ 'detects ambiguous reference/file conflict' '
1170 echo master >master &&
1171 git add master &&
1172 git commit -m"add master" &&
1173 test_must_fail git send-email --dry-run master 2>errors &&
1174 grep disambiguate errors
1177 test_expect_success $PREREQ 'feed two files' '
1178 rm -fr outdir &&
1179 git format-patch -2 -o outdir &&
1180 git send-email \
1181 --dry-run \
1182 --from="Example <nobody@example.com>" \
1183 --to=nobody@example.com \
1184 outdir/000?-*.patch 2>errors >out &&
1185 grep "^Subject: " out >subjects &&
1186 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
1187 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"
1190 test_expect_success $PREREQ 'in-reply-to but no threading' '
1191 git send-email \
1192 --dry-run \
1193 --from="Example <nobody@example.com>" \
1194 --to=nobody@example.com \
1195 --in-reply-to="<in-reply-id@example.com>" \
1196 --no-thread \
1197 $patches |
1198 grep "In-Reply-To: <in-reply-id@example.com>"
1201 test_expect_success $PREREQ 'no in-reply-to and no threading' '
1202 git send-email \
1203 --dry-run \
1204 --from="Example <nobody@example.com>" \
1205 --to=nobody@example.com \
1206 --no-thread \
1207 $patches $patches >stdout &&
1208 ! grep "In-Reply-To: " stdout
1211 test_expect_success $PREREQ 'threading but no chain-reply-to' '
1212 git send-email \
1213 --dry-run \
1214 --from="Example <nobody@example.com>" \
1215 --to=nobody@example.com \
1216 --thread \
1217 --no-chain-reply-to \
1218 $patches $patches >stdout &&
1219 grep "In-Reply-To: " stdout
1222 test_expect_success $PREREQ 'sendemail.to works' '
1223 git config --replace-all sendemail.to "Somebody <somebody@ex.com>" &&
1224 git send-email \
1225 --dry-run \
1226 --from="Example <nobody@example.com>" \
1227 $patches $patches >stdout &&
1228 grep "To: Somebody <somebody@ex.com>" stdout
1231 test_expect_success $PREREQ '--no-to overrides sendemail.to' '
1232 git send-email \
1233 --dry-run \
1234 --from="Example <nobody@example.com>" \
1235 --no-to \
1236 --to=nobody@example.com \
1237 $patches $patches >stdout &&
1238 grep "To: nobody@example.com" stdout &&
1239 ! grep "To: Somebody <somebody@ex.com>" stdout
1242 test_expect_success $PREREQ 'sendemail.cc works' '
1243 git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" &&
1244 git send-email \
1245 --dry-run \
1246 --from="Example <nobody@example.com>" \
1247 --to=nobody@example.com \
1248 $patches $patches >stdout &&
1249 grep "Cc: Somebody <somebody@ex.com>" stdout
1252 test_expect_success $PREREQ '--no-cc overrides sendemail.cc' '
1253 git send-email \
1254 --dry-run \
1255 --from="Example <nobody@example.com>" \
1256 --no-cc \
1257 --cc=bodies@example.com \
1258 --to=nobody@example.com \
1259 $patches $patches >stdout &&
1260 grep "Cc: bodies@example.com" stdout &&
1261 ! grep "Cc: Somebody <somebody@ex.com>" stdout
1264 test_expect_success $PREREQ 'sendemail.bcc works' '
1265 git config --replace-all sendemail.bcc "Other <other@ex.com>" &&
1266 git send-email \
1267 --dry-run \
1268 --from="Example <nobody@example.com>" \
1269 --to=nobody@example.com \
1270 --smtp-server relay.example.com \
1271 $patches $patches >stdout &&
1272 grep "RCPT TO:<other@ex.com>" stdout
1275 test_expect_success $PREREQ '--no-bcc overrides sendemail.bcc' '
1276 git send-email \
1277 --dry-run \
1278 --from="Example <nobody@example.com>" \
1279 --no-bcc \
1280 --bcc=bodies@example.com \
1281 --to=nobody@example.com \
1282 --smtp-server relay.example.com \
1283 $patches $patches >stdout &&
1284 grep "RCPT TO:<bodies@example.com>" stdout &&
1285 ! grep "RCPT TO:<other@ex.com>" stdout
1288 test_expect_success $PREREQ 'patches To headers are used by default' '
1289 patch=$(git format-patch -1 --to="bodies@example.com") &&
1290 test_when_finished "rm $patch" &&
1291 git send-email \
1292 --dry-run \
1293 --from="Example <nobody@example.com>" \
1294 --smtp-server relay.example.com \
1295 $patch >stdout &&
1296 grep "RCPT TO:<bodies@example.com>" stdout
1299 test_expect_success $PREREQ 'patches To headers are appended to' '
1300 patch=$(git format-patch -1 --to="bodies@example.com") &&
1301 test_when_finished "rm $patch" &&
1302 git send-email \
1303 --dry-run \
1304 --from="Example <nobody@example.com>" \
1305 --to=nobody@example.com \
1306 --smtp-server relay.example.com \
1307 $patch >stdout &&
1308 grep "RCPT TO:<bodies@example.com>" stdout &&
1309 grep "RCPT TO:<nobody@example.com>" stdout
1312 test_expect_success $PREREQ 'To headers from files reset each patch' '
1313 patch1=$(git format-patch -1 --to="bodies@example.com") &&
1314 patch2=$(git format-patch -1 --to="other@example.com" HEAD~) &&
1315 test_when_finished "rm $patch1 && rm $patch2" &&
1316 git send-email \
1317 --dry-run \
1318 --from="Example <nobody@example.com>" \
1319 --to="nobody@example.com" \
1320 --smtp-server relay.example.com \
1321 $patch1 $patch2 >stdout &&
1322 test $(grep -c "RCPT TO:<bodies@example.com>" stdout) = 1 &&
1323 test $(grep -c "RCPT TO:<nobody@example.com>" stdout) = 2 &&
1324 test $(grep -c "RCPT TO:<other@example.com>" stdout) = 1
1327 test_expect_success $PREREQ 'setup expect' '
1328 cat >email-using-8bit <<\EOF
1329 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1330 Message-Id: <bogus-message-id@example.com>
1331 From: author@example.com
1332 Date: Sat, 12 Jun 2010 15:53:58 +0200
1333 Subject: subject goes here
1335 Dieser deutsche Text enthält einen Umlaut!
1339 test_expect_success $PREREQ 'setup expect' '
1340 echo "Subject: subject goes here" >expected
1343 test_expect_success $PREREQ 'ASCII subject is not RFC2047 quoted' '
1344 clean_fake_sendmail &&
1345 echo bogus |
1346 git send-email --from=author@example.com --to=nobody@example.com \
1347 --smtp-server="$(pwd)/fake.sendmail" \
1348 --8bit-encoding=UTF-8 \
1349 email-using-8bit >stdout &&
1350 grep "Subject" msgtxt1 >actual &&
1351 test_cmp expected actual
1354 test_expect_success $PREREQ 'setup expect' '
1355 cat >content-type-decl <<-\EOF
1356 MIME-Version: 1.0
1357 Content-Type: text/plain; charset=UTF-8
1358 Content-Transfer-Encoding: 8bit
1362 test_expect_success $PREREQ 'asks about and fixes 8bit encodings' '
1363 clean_fake_sendmail &&
1364 echo |
1365 git send-email --from=author@example.com --to=nobody@example.com \
1366 --smtp-server="$(pwd)/fake.sendmail" \
1367 email-using-8bit >stdout &&
1368 grep "do not declare a Content-Transfer-Encoding" stdout &&
1369 grep email-using-8bit stdout &&
1370 grep "Which 8bit encoding" stdout &&
1371 egrep "Content|MIME" msgtxt1 >actual &&
1372 test_cmp content-type-decl actual
1375 test_expect_success $PREREQ 'sendemail.8bitEncoding works' '
1376 clean_fake_sendmail &&
1377 git config sendemail.assume8bitEncoding UTF-8 &&
1378 echo bogus |
1379 git send-email --from=author@example.com --to=nobody@example.com \
1380 --smtp-server="$(pwd)/fake.sendmail" \
1381 email-using-8bit >stdout &&
1382 egrep "Content|MIME" msgtxt1 >actual &&
1383 test_cmp content-type-decl actual
1386 test_expect_success $PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
1387 clean_fake_sendmail &&
1388 git config sendemail.assume8bitEncoding "bogus too" &&
1389 echo bogus |
1390 git send-email --from=author@example.com --to=nobody@example.com \
1391 --smtp-server="$(pwd)/fake.sendmail" \
1392 --8bit-encoding=UTF-8 \
1393 email-using-8bit >stdout &&
1394 egrep "Content|MIME" msgtxt1 >actual &&
1395 test_cmp content-type-decl actual
1398 test_expect_success $PREREQ 'setup expect' '
1399 cat >email-using-8bit <<-\EOF
1400 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1401 Message-Id: <bogus-message-id@example.com>
1402 From: author@example.com
1403 Date: Sat, 12 Jun 2010 15:53:58 +0200
1404 Subject: Dieser Betreff enthält auch einen Umlaut!
1406 Nothing to see here.
1410 test_expect_success $PREREQ 'setup expect' '
1411 cat >expected <<-\EOF
1412 Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
1416 test_expect_success $PREREQ '--8bit-encoding also treats subject' '
1417 clean_fake_sendmail &&
1418 echo bogus |
1419 git send-email --from=author@example.com --to=nobody@example.com \
1420 --smtp-server="$(pwd)/fake.sendmail" \
1421 --8bit-encoding=UTF-8 \
1422 email-using-8bit >stdout &&
1423 grep "Subject" msgtxt1 >actual &&
1424 test_cmp expected actual
1427 test_expect_success $PREREQ 'setup expect' '
1428 cat >email-using-8bit <<-\EOF
1429 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1430 Message-Id: <bogus-message-id@example.com>
1431 From: A U Thor <author@example.com>
1432 Date: Sat, 12 Jun 2010 15:53:58 +0200
1433 Content-Type: text/plain; charset=UTF-8
1434 Subject: Nothing to see here.
1436 Dieser Betreff enthält auch einen Umlaut!
1440 test_expect_success $PREREQ 'sendemail.transferencoding=7bit fails on 8bit data' '
1441 clean_fake_sendmail &&
1442 git config sendemail.transferEncoding 7bit &&
1443 test_must_fail git send-email \
1444 --transfer-encoding=7bit \
1445 --smtp-server="$(pwd)/fake.sendmail" \
1446 email-using-8bit \
1447 2>errors >out &&
1448 grep "cannot send message as 7bit" errors &&
1449 test -z "$(ls msgtxt*)"
1452 test_expect_success $PREREQ '--transfer-encoding overrides sendemail.transferEncoding' '
1453 clean_fake_sendmail &&
1454 git config sendemail.transferEncoding 8bit &&
1455 test_must_fail git send-email \
1456 --transfer-encoding=7bit \
1457 --smtp-server="$(pwd)/fake.sendmail" \
1458 email-using-8bit \
1459 2>errors >out &&
1460 grep "cannot send message as 7bit" errors &&
1461 test -z "$(ls msgtxt*)"
1464 test_expect_success $PREREQ 'sendemail.transferencoding=8bit' '
1465 clean_fake_sendmail &&
1466 git send-email \
1467 --transfer-encoding=8bit \
1468 --smtp-server="$(pwd)/fake.sendmail" \
1469 email-using-8bit \
1470 2>errors >out &&
1471 sed '1,/^$/d' msgtxt1 >actual &&
1472 sed '1,/^$/d' email-using-8bit >expected &&
1473 test_cmp expected actual
1476 test_expect_success $PREREQ 'setup expect' '
1477 cat >expected <<-\EOF
1478 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1482 test_expect_success $PREREQ '8-bit and sendemail.transferencoding=quoted-printable' '
1483 clean_fake_sendmail &&
1484 git send-email \
1485 --transfer-encoding=quoted-printable \
1486 --smtp-server="$(pwd)/fake.sendmail" \
1487 email-using-8bit \
1488 2>errors >out &&
1489 sed '1,/^$/d' msgtxt1 >actual &&
1490 test_cmp expected actual
1493 test_expect_success $PREREQ 'setup expect' '
1494 cat >expected <<-\EOF
1495 RGllc2VyIEJldHJlZmYgZW50aMOkbHQgYXVjaCBlaW5lbiBVbWxhdXQhCg==
1499 test_expect_success $PREREQ '8-bit and sendemail.transferencoding=base64' '
1500 clean_fake_sendmail &&
1501 git send-email \
1502 --transfer-encoding=base64 \
1503 --smtp-server="$(pwd)/fake.sendmail" \
1504 email-using-8bit \
1505 2>errors >out &&
1506 sed '1,/^$/d' msgtxt1 >actual &&
1507 test_cmp expected actual
1510 test_expect_success $PREREQ 'setup expect' '
1511 cat >email-using-qp <<-\EOF
1512 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1513 Message-Id: <bogus-message-id@example.com>
1514 From: A U Thor <author@example.com>
1515 Date: Sat, 12 Jun 2010 15:53:58 +0200
1516 MIME-Version: 1.0
1517 Content-Transfer-Encoding: quoted-printable
1518 Content-Type: text/plain; charset=UTF-8
1519 Subject: Nothing to see here.
1521 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1525 test_expect_success $PREREQ 'convert from quoted-printable to base64' '
1526 clean_fake_sendmail &&
1527 git send-email \
1528 --transfer-encoding=base64 \
1529 --smtp-server="$(pwd)/fake.sendmail" \
1530 email-using-qp \
1531 2>errors >out &&
1532 sed '1,/^$/d' msgtxt1 >actual &&
1533 test_cmp expected actual
1536 test_expect_success $PREREQ 'setup expect' "
1537 tr -d '\\015' | tr '%' '\\015' >email-using-crlf <<EOF
1538 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1539 Message-Id: <bogus-message-id@example.com>
1540 From: A U Thor <author@example.com>
1541 Date: Sat, 12 Jun 2010 15:53:58 +0200
1542 Content-Type: text/plain; charset=UTF-8
1543 Subject: Nothing to see here.
1545 Look, I have a CRLF and an = sign!%
1549 test_expect_success $PREREQ 'setup expect' '
1550 cat >expected <<-\EOF
1551 Look, I have a CRLF and an =3D sign!=0D
1555 test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=quoted-printable' '
1556 clean_fake_sendmail &&
1557 git send-email \
1558 --transfer-encoding=quoted-printable \
1559 --smtp-server="$(pwd)/fake.sendmail" \
1560 email-using-crlf \
1561 2>errors >out &&
1562 sed '1,/^$/d' msgtxt1 >actual &&
1563 test_cmp expected actual
1566 test_expect_success $PREREQ 'setup expect' '
1567 cat >expected <<-\EOF
1568 TG9vaywgSSBoYXZlIGEgQ1JMRiBhbmQgYW4gPSBzaWduIQ0K
1572 test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=base64' '
1573 clean_fake_sendmail &&
1574 git send-email \
1575 --transfer-encoding=base64 \
1576 --smtp-server="$(pwd)/fake.sendmail" \
1577 email-using-crlf \
1578 2>errors >out &&
1579 sed '1,/^$/d' msgtxt1 >actual &&
1580 test_cmp expected actual
1584 # Note that the patches in this test are deliberately out of order; we
1585 # want to make sure it works even if the cover-letter is not in the
1586 # first mail.
1587 test_expect_success $PREREQ 'refusing to send cover letter template' '
1588 clean_fake_sendmail &&
1589 rm -fr outdir &&
1590 git format-patch --cover-letter -2 -o outdir &&
1591 test_must_fail git send-email \
1592 --from="Example <nobody@example.com>" \
1593 --to=nobody@example.com \
1594 --smtp-server="$(pwd)/fake.sendmail" \
1595 outdir/0002-*.patch \
1596 outdir/0000-*.patch \
1597 outdir/0001-*.patch \
1598 2>errors >out &&
1599 grep "SUBJECT HERE" errors &&
1600 test -z "$(ls msgtxt*)"
1603 test_expect_success $PREREQ '--force sends cover letter template anyway' '
1604 clean_fake_sendmail &&
1605 rm -fr outdir &&
1606 git format-patch --cover-letter -2 -o outdir &&
1607 git send-email \
1608 --force \
1609 --from="Example <nobody@example.com>" \
1610 --to=nobody@example.com \
1611 --smtp-server="$(pwd)/fake.sendmail" \
1612 outdir/0002-*.patch \
1613 outdir/0000-*.patch \
1614 outdir/0001-*.patch \
1615 2>errors >out &&
1616 ! grep "SUBJECT HERE" errors &&
1617 test -n "$(ls msgtxt*)"
1620 test_cover_addresses () {
1621 header="$1"
1622 shift
1623 clean_fake_sendmail &&
1624 rm -fr outdir &&
1625 git format-patch --cover-letter -2 -o outdir &&
1626 cover=$(echo outdir/0000-*.patch) &&
1627 mv $cover cover-to-edit.patch &&
1628 perl -pe "s/^From:/$header: extra\@address.com\nFrom:/" cover-to-edit.patch >"$cover" &&
1629 git send-email \
1630 --force \
1631 --from="Example <nobody@example.com>" \
1632 --no-to --no-cc \
1633 "$@" \
1634 --smtp-server="$(pwd)/fake.sendmail" \
1635 outdir/0000-*.patch \
1636 outdir/0001-*.patch \
1637 outdir/0002-*.patch \
1638 2>errors >out &&
1639 grep "^$header: extra@address.com" msgtxt1 >to1 &&
1640 grep "^$header: extra@address.com" msgtxt2 >to2 &&
1641 grep "^$header: extra@address.com" msgtxt3 >to3 &&
1642 test_line_count = 1 to1 &&
1643 test_line_count = 1 to2 &&
1644 test_line_count = 1 to3
1647 test_expect_success $PREREQ 'to-cover adds To to all mail' '
1648 test_cover_addresses "To" --to-cover
1651 test_expect_success $PREREQ 'cc-cover adds Cc to all mail' '
1652 test_cover_addresses "Cc" --cc-cover
1655 test_expect_success $PREREQ 'tocover adds To to all mail' '
1656 test_config sendemail.tocover true &&
1657 test_cover_addresses "To"
1660 test_expect_success $PREREQ 'cccover adds Cc to all mail' '
1661 test_config sendemail.cccover true &&
1662 test_cover_addresses "Cc"
1665 test_expect_success $PREREQ 'escaped quotes in sendemail.aliasfiletype=mutt' '
1666 clean_fake_sendmail &&
1667 echo "alias sbd \\\"Dot U. Sir\\\" <somebody@example.org>" >.mutt &&
1668 git config --replace-all sendemail.aliasesfile "$(pwd)/.mutt" &&
1669 git config sendemail.aliasfiletype mutt &&
1670 git send-email \
1671 --from="Example <nobody@example.com>" \
1672 --to=sbd \
1673 --smtp-server="$(pwd)/fake.sendmail" \
1674 outdir/0001-*.patch \
1675 2>errors >out &&
1676 grep "^!somebody@example\.org!$" commandline1 &&
1677 grep -F "To: \"Dot U. Sir\" <somebody@example.org>" out
1680 test_expect_success $PREREQ 'sendemail.aliasfiletype=mailrc' '
1681 clean_fake_sendmail &&
1682 echo "alias sbd somebody@example.org" >.mailrc &&
1683 git config --replace-all sendemail.aliasesfile "$(pwd)/.mailrc" &&
1684 git config sendemail.aliasfiletype mailrc &&
1685 git send-email \
1686 --from="Example <nobody@example.com>" \
1687 --to=sbd \
1688 --smtp-server="$(pwd)/fake.sendmail" \
1689 outdir/0001-*.patch \
1690 2>errors >out &&
1691 grep "^!somebody@example\.org!$" commandline1
1694 test_expect_success $PREREQ 'sendemail.aliasfile=~/.mailrc' '
1695 clean_fake_sendmail &&
1696 echo "alias sbd someone@example.org" >"$HOME/.mailrc" &&
1697 git config --replace-all sendemail.aliasesfile "~/.mailrc" &&
1698 git config sendemail.aliasfiletype mailrc &&
1699 git send-email \
1700 --from="Example <nobody@example.com>" \
1701 --to=sbd \
1702 --smtp-server="$(pwd)/fake.sendmail" \
1703 outdir/0001-*.patch \
1704 2>errors >out &&
1705 grep "^!someone@example\.org!$" commandline1
1708 test_dump_aliases () {
1709 msg="$1" && shift &&
1710 filetype="$1" && shift &&
1711 printf '%s\n' "$@" >expect &&
1712 cat >.tmp-email-aliases &&
1714 test_expect_success $PREREQ "$msg" '
1715 clean_fake_sendmail && rm -fr outdir &&
1716 git config --replace-all sendemail.aliasesfile \
1717 "$(pwd)/.tmp-email-aliases" &&
1718 git config sendemail.aliasfiletype "$filetype" &&
1719 git send-email --dump-aliases 2>errors >actual &&
1720 test_cmp expect actual
1724 test_dump_aliases '--dump-aliases sendmail format' \
1725 'sendmail' \
1726 'abgroup' \
1727 'alice' \
1728 'bcgrp' \
1729 'bob' \
1730 'chloe' <<-\EOF
1731 alice: Alice W Land <awol@example.com>
1732 bob: Robert Bobbyton <bob@example.com>
1733 chloe: chloe@example.com
1734 abgroup: alice, bob
1735 bcgrp: bob, chloe, Other <o@example.com>
1738 test_dump_aliases '--dump-aliases mutt format' \
1739 'mutt' \
1740 'alice' \
1741 'bob' \
1742 'chloe' \
1743 'donald' <<-\EOF
1744 alias alice Alice W Land <awol@example.com>
1745 alias donald Donald C Carlton <donc@example.com>
1746 alias bob Robert Bobbyton <bob@example.com>
1747 alias chloe chloe@example.com
1750 test_dump_aliases '--dump-aliases mailrc format' \
1751 'mailrc' \
1752 'alice' \
1753 'bob' \
1754 'chloe' \
1755 'eve' <<-\EOF
1756 alias alice Alice W Land <awol@example.com>
1757 alias eve Eve <eve@example.com>
1758 alias bob Robert Bobbyton <bob@example.com>
1759 alias chloe chloe@example.com
1762 test_dump_aliases '--dump-aliases pine format' \
1763 'pine' \
1764 'alice' \
1765 'bob' \
1766 'chloe' \
1767 'eve' <<-\EOF
1768 alice Alice W Land <awol@example.com>
1769 eve Eve <eve@example.com>
1770 bob Robert Bobbyton <bob@example.com>
1771 chloe chloe@example.com
1774 test_dump_aliases '--dump-aliases gnus format' \
1775 'gnus' \
1776 'alice' \
1777 'bob' \
1778 'chloe' \
1779 'eve' <<-\EOF
1780 (define-mail-alias "alice" "awol@example.com")
1781 (define-mail-alias "eve" "eve@example.com")
1782 (define-mail-alias "bob" "bob@example.com")
1783 (define-mail-alias "chloe" "chloe@example.com")
1786 test_expect_success '--dump-aliases must be used alone' '
1787 test_must_fail git send-email --dump-aliases --to=janice@example.com -1 refs/heads/accounting
1790 test_sendmail_aliases () {
1791 msg="$1" && shift &&
1792 expect="$@" &&
1793 cat >.tmp-email-aliases &&
1795 test_expect_success $PREREQ "$msg" '
1796 clean_fake_sendmail && rm -fr outdir &&
1797 git format-patch -1 -o outdir &&
1798 git config --replace-all sendemail.aliasesfile \
1799 "$(pwd)/.tmp-email-aliases" &&
1800 git config sendemail.aliasfiletype sendmail &&
1801 git send-email \
1802 --from="Example <nobody@example.com>" \
1803 --to=alice --to=bcgrp \
1804 --smtp-server="$(pwd)/fake.sendmail" \
1805 outdir/0001-*.patch \
1806 2>errors >out &&
1807 for i in $expect
1809 grep "^!$i!$" commandline1 || return 1
1810 done
1814 test_sendmail_aliases 'sendemail.aliasfiletype=sendmail' \
1815 'awol@example\.com' \
1816 'bob@example\.com' \
1817 'chloe@example\.com' \
1818 'o@example\.com' <<-\EOF
1819 alice: Alice W Land <awol@example.com>
1820 bob: Robert Bobbyton <bob@example.com>
1821 # this is a comment
1822 # this is also a comment
1823 chloe: chloe@example.com
1824 abgroup: alice, bob
1825 bcgrp: bob, chloe, Other <o@example.com>
1828 test_sendmail_aliases 'sendmail aliases line folding' \
1829 alice1 \
1830 bob1 bob2 \
1831 chuck1 chuck2 \
1832 darla1 darla2 darla3 \
1833 elton1 elton2 elton3 \
1834 fred1 fred2 \
1835 greg1 <<-\EOF
1836 alice: alice1
1837 bob: bob1,\
1838 bob2
1839 chuck: chuck1,
1840 chuck2
1841 darla: darla1,\
1842 darla2,
1843 darla3
1844 elton: elton1,
1845 elton2,\
1846 elton3
1847 fred: fred1,\
1848 fred2
1849 greg: greg1
1850 bcgrp: bob, chuck, darla, elton, fred, greg
1853 test_sendmail_aliases 'sendmail aliases tolerate bogus line folding' \
1854 alice1 bob1 <<-\EOF
1855 alice: alice1
1856 bcgrp: bob1\
1859 test_sendmail_aliases 'sendmail aliases empty' alice bcgrp <<-\EOF
1862 test_expect_success $PREREQ 'alias support in To header' '
1863 clean_fake_sendmail &&
1864 echo "alias sbd someone@example.org" >.mailrc &&
1865 test_config sendemail.aliasesfile ".mailrc" &&
1866 test_config sendemail.aliasfiletype mailrc &&
1867 git format-patch --stdout -1 --to=sbd >aliased.patch &&
1868 git send-email \
1869 --from="Example <nobody@example.com>" \
1870 --smtp-server="$(pwd)/fake.sendmail" \
1871 aliased.patch \
1872 2>errors >out &&
1873 grep "^!someone@example\.org!$" commandline1
1876 test_expect_success $PREREQ 'alias support in Cc header' '
1877 clean_fake_sendmail &&
1878 echo "alias sbd someone@example.org" >.mailrc &&
1879 test_config sendemail.aliasesfile ".mailrc" &&
1880 test_config sendemail.aliasfiletype mailrc &&
1881 git format-patch --stdout -1 --cc=sbd >aliased.patch &&
1882 git send-email \
1883 --from="Example <nobody@example.com>" \
1884 --smtp-server="$(pwd)/fake.sendmail" \
1885 aliased.patch \
1886 2>errors >out &&
1887 grep "^!someone@example\.org!$" commandline1
1890 test_expect_success $PREREQ 'tocmd works with aliases' '
1891 clean_fake_sendmail &&
1892 echo "alias sbd someone@example.org" >.mailrc &&
1893 test_config sendemail.aliasesfile ".mailrc" &&
1894 test_config sendemail.aliasfiletype mailrc &&
1895 git format-patch --stdout -1 >tocmd.patch &&
1896 echo tocmd--sbd >>tocmd.patch &&
1897 git send-email \
1898 --from="Example <nobody@example.com>" \
1899 --to-cmd=./tocmd-sed \
1900 --smtp-server="$(pwd)/fake.sendmail" \
1901 tocmd.patch \
1902 2>errors >out &&
1903 grep "^!someone@example\.org!$" commandline1
1906 test_expect_success $PREREQ 'cccmd works with aliases' '
1907 clean_fake_sendmail &&
1908 echo "alias sbd someone@example.org" >.mailrc &&
1909 test_config sendemail.aliasesfile ".mailrc" &&
1910 test_config sendemail.aliasfiletype mailrc &&
1911 git format-patch --stdout -1 >cccmd.patch &&
1912 echo cccmd--sbd >>cccmd.patch &&
1913 git send-email \
1914 --from="Example <nobody@example.com>" \
1915 --cc-cmd=./cccmd-sed \
1916 --smtp-server="$(pwd)/fake.sendmail" \
1917 cccmd.patch \
1918 2>errors >out &&
1919 grep "^!someone@example\.org!$" commandline1
1922 do_xmailer_test () {
1923 expected=$1 params=$2 &&
1924 git format-patch -1 &&
1925 git send-email \
1926 --from="Example <nobody@example.com>" \
1927 --to=someone@example.com \
1928 --smtp-server="$(pwd)/fake.sendmail" \
1929 $params \
1930 0001-*.patch \
1931 2>errors >out &&
1932 { grep '^X-Mailer:' out || :; } >mailer &&
1933 test_line_count = $expected mailer
1936 test_expect_success $PREREQ '--[no-]xmailer without any configuration' '
1937 do_xmailer_test 1 "--xmailer" &&
1938 do_xmailer_test 0 "--no-xmailer"
1941 test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=true' '
1942 test_config sendemail.xmailer true &&
1943 do_xmailer_test 1 "" &&
1944 do_xmailer_test 0 "--no-xmailer" &&
1945 do_xmailer_test 1 "--xmailer"
1948 test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=false' '
1949 test_config sendemail.xmailer false &&
1950 do_xmailer_test 0 "" &&
1951 do_xmailer_test 0 "--no-xmailer" &&
1952 do_xmailer_test 1 "--xmailer"
1955 test_expect_success $PREREQ 'setup expected-list' '
1956 git send-email \
1957 --dry-run \
1958 --from="Example <from@example.com>" \
1959 --to="To 1 <to1@example.com>" \
1960 --to="to2@example.com" \
1961 --to="to3@example.com" \
1962 --cc="Cc 1 <cc1@example.com>" \
1963 --cc="Cc2 <cc2@example.com>" \
1964 --bcc="bcc1@example.com" \
1965 --bcc="bcc2@example.com" \
1966 0001-add-master.patch | replace_variable_fields \
1967 >expected-list
1970 test_expect_success $PREREQ 'use email list in --cc --to and --bcc' '
1971 git send-email \
1972 --dry-run \
1973 --from="Example <from@example.com>" \
1974 --to="To 1 <to1@example.com>, to2@example.com" \
1975 --to="to3@example.com" \
1976 --cc="Cc 1 <cc1@example.com>, Cc2 <cc2@example.com>" \
1977 --bcc="bcc1@example.com, bcc2@example.com" \
1978 0001-add-master.patch | replace_variable_fields \
1979 >actual-list &&
1980 test_cmp expected-list actual-list
1983 test_expect_success $PREREQ 'aliases work with email list' '
1984 echo "alias to2 to2@example.com" >.mutt &&
1985 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt &&
1986 test_config sendemail.aliasesfile ".mutt" &&
1987 test_config sendemail.aliasfiletype mutt &&
1988 git send-email \
1989 --dry-run \
1990 --from="Example <from@example.com>" \
1991 --to="To 1 <to1@example.com>, to2, to3@example.com" \
1992 --cc="cc1, Cc2 <cc2@example.com>" \
1993 --bcc="bcc1@example.com, bcc2@example.com" \
1994 0001-add-master.patch | replace_variable_fields \
1995 >actual-list &&
1996 test_cmp expected-list actual-list
1999 test_expect_success $PREREQ 'leading and trailing whitespaces are removed' '
2000 echo "alias to2 to2@example.com" >.mutt &&
2001 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt &&
2002 test_config sendemail.aliasesfile ".mutt" &&
2003 test_config sendemail.aliasfiletype mutt &&
2004 TO1=$(echo "QTo 1 <to1@example.com>" | q_to_tab) &&
2005 TO2=$(echo "QZto2" | qz_to_tab_space) &&
2006 CC1=$(echo "cc1" | append_cr) &&
2007 BCC1=$(echo "Q bcc1@example.com Q" | q_to_nul) &&
2008 git send-email \
2009 --dry-run \
2010 --from=" Example <from@example.com>" \
2011 --to="$TO1" \
2012 --to="$TO2" \
2013 --to=" to3@example.com " \
2014 --cc="$CC1" \
2015 --cc="Cc2 <cc2@example.com>" \
2016 --bcc="$BCC1" \
2017 --bcc="bcc2@example.com" \
2018 0001-add-master.patch | replace_variable_fields \
2019 >actual-list &&
2020 test_cmp expected-list actual-list
2023 test_expect_success $PREREQ 'invoke hook' '
2024 mkdir -p .git/hooks &&
2026 write_script .git/hooks/sendemail-validate <<-\EOF &&
2027 # test that we have the correct environment variable, pwd, and
2028 # argument
2029 case "$GIT_DIR" in
2030 *.git)
2031 true
2034 false
2036 esac &&
2037 test -f 0001-add-master.patch &&
2038 grep "add master" "$1"
2041 mkdir subdir &&
2043 # Test that it works even if we are not at the root of the
2044 # working tree
2045 cd subdir &&
2046 git send-email \
2047 --from="Example <nobody@example.com>" \
2048 --to=nobody@example.com \
2049 --smtp-server="$(pwd)/../fake.sendmail" \
2050 ../0001-add-master.patch &&
2052 # Verify error message when a patch is rejected by the hook
2053 sed -e "s/add master/x/" ../0001-add-master.patch >../another.patch &&
2054 test_must_fail git send-email \
2055 --from="Example <nobody@example.com>" \
2056 --to=nobody@example.com \
2057 --smtp-server="$(pwd)/../fake.sendmail" \
2058 ../another.patch 2>err &&
2059 test_i18ngrep "rejected by sendemail-validate hook" err
2063 test_expect_success $PREREQ 'test that send-email works outside a repo' '
2064 nongit git send-email \
2065 --from="Example <nobody@example.com>" \
2066 --to=nobody@example.com \
2067 --smtp-server="$(pwd)/fake.sendmail" \
2068 "$(pwd)/0001-add-master.patch"
2071 test_done