Merge branch 'md/list-lazy-objects-fix'
[git.git] / t / t9001-send-email.sh
blobee1efcc59dcddfdb7e1b448999531e2c1937444a
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 for enc in auto quoted-printable base64
486 test_expect_success $PREREQ "--validate passes with encoding $enc" '
487 git send-email \
488 --from="Example <nobody@example.com>" \
489 --to=nobody@example.com \
490 --smtp-server="$(pwd)/fake.sendmail" \
491 --transfer-encoding=$enc \
492 --validate \
493 $patches longline.patch
496 done
498 for enc in 7bit 8bit quoted-printable base64
500 test_expect_success $PREREQ "--transfer-encoding=$enc produces correct header" '
501 clean_fake_sendmail &&
502 git send-email \
503 --from="Example <nobody@example.com>" \
504 --to=nobody@example.com \
505 --smtp-server="$(pwd)/fake.sendmail" \
506 --transfer-encoding=$enc \
507 $patches &&
508 grep "Content-Transfer-Encoding: $enc" msgtxt1
510 done
512 test_expect_success $PREREQ 'Invalid In-Reply-To' '
513 clean_fake_sendmail &&
514 git send-email \
515 --from="Example <nobody@example.com>" \
516 --to=nobody@example.com \
517 --in-reply-to=" " \
518 --smtp-server="$(pwd)/fake.sendmail" \
519 $patches \
520 2>errors &&
521 ! grep "^In-Reply-To: < *>" msgtxt1
524 test_expect_success $PREREQ 'Valid In-Reply-To when prompting' '
525 clean_fake_sendmail &&
526 (echo "From Example <from@example.com>" &&
527 echo "To Example <to@example.com>" &&
528 echo ""
529 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
530 --smtp-server="$(pwd)/fake.sendmail" \
531 $patches 2>errors &&
532 ! grep "^In-Reply-To: < *>" msgtxt1
535 test_expect_success $PREREQ 'In-Reply-To without --chain-reply-to' '
536 clean_fake_sendmail &&
537 echo "<unique-message-id@example.com>" >expect &&
538 git send-email \
539 --from="Example <nobody@example.com>" \
540 --to=nobody@example.com \
541 --no-chain-reply-to \
542 --in-reply-to="$(cat expect)" \
543 --smtp-server="$(pwd)/fake.sendmail" \
544 $patches $patches $patches \
545 2>errors &&
546 # The first message is a reply to --in-reply-to
547 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
548 test_cmp expect actual &&
549 # Second and subsequent messages are replies to the first one
550 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
551 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
552 test_cmp expect actual &&
553 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
554 test_cmp expect actual
557 test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' '
558 clean_fake_sendmail &&
559 echo "<unique-message-id@example.com>" >expect &&
560 git send-email \
561 --from="Example <nobody@example.com>" \
562 --to=nobody@example.com \
563 --chain-reply-to \
564 --in-reply-to="$(cat expect)" \
565 --smtp-server="$(pwd)/fake.sendmail" \
566 $patches $patches $patches \
567 2>errors &&
568 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
569 test_cmp expect actual &&
570 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
571 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
572 test_cmp expect actual &&
573 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt2 >expect &&
574 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
575 test_cmp expect actual
578 test_expect_success $PREREQ 'setup fake editor' '
579 write_script fake-editor <<-\EOF
580 echo fake edit >>"$1"
584 test_set_editor "$(pwd)/fake-editor"
586 test_expect_success $PREREQ '--compose works' '
587 clean_fake_sendmail &&
588 git send-email \
589 --compose --subject foo \
590 --from="Example <nobody@example.com>" \
591 --to=nobody@example.com \
592 --smtp-server="$(pwd)/fake.sendmail" \
593 $patches \
594 2>errors
597 test_expect_success $PREREQ 'first message is compose text' '
598 grep "^fake edit" msgtxt1
601 test_expect_success $PREREQ 'second message is patch' '
602 grep "Subject:.*Second" msgtxt2
605 test_expect_success $PREREQ 'setup expect' "
606 cat >expected-suppress-sob <<\EOF
607 0001-Second.patch
608 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
609 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
610 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
611 Dry-OK. Log says:
612 Server: relay.example.com
613 MAIL FROM:<from@example.com>
614 RCPT TO:<to@example.com>
615 RCPT TO:<cc@example.com>
616 RCPT TO:<author@example.com>
617 RCPT TO:<one@example.com>
618 RCPT TO:<two@example.com>
619 From: Example <from@example.com>
620 To: to@example.com
621 Cc: cc@example.com,
622 A <author@example.com>,
623 One <one@example.com>,
624 two@example.com
625 Subject: [PATCH 1/1] Second.
626 Date: DATE-STRING
627 Message-Id: MESSAGE-ID-STRING
628 X-Mailer: X-MAILER-STRING
629 MIME-Version: 1.0
630 Content-Transfer-Encoding: 8bit
632 Result: OK
636 test_suppression () {
637 git send-email \
638 --dry-run \
639 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
640 --from="Example <from@example.com>" \
641 --to=to@example.com \
642 --smtp-server relay.example.com \
643 $patches | replace_variable_fields \
644 >actual-suppress-$1${2+"-$2"} &&
645 test_cmp expected-suppress-$1${2+"-$2"} actual-suppress-$1${2+"-$2"}
648 test_expect_success $PREREQ 'sendemail.cc set' '
649 git config sendemail.cc cc@example.com &&
650 test_suppression sob
653 test_expect_success $PREREQ 'setup expect' "
654 cat >expected-suppress-sob <<\EOF
655 0001-Second.patch
656 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
657 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
658 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
659 Dry-OK. Log says:
660 Server: relay.example.com
661 MAIL FROM:<from@example.com>
662 RCPT TO:<to@example.com>
663 RCPT TO:<author@example.com>
664 RCPT TO:<one@example.com>
665 RCPT TO:<two@example.com>
666 From: Example <from@example.com>
667 To: to@example.com
668 Cc: A <author@example.com>,
669 One <one@example.com>,
670 two@example.com
671 Subject: [PATCH 1/1] Second.
672 Date: DATE-STRING
673 Message-Id: MESSAGE-ID-STRING
674 X-Mailer: X-MAILER-STRING
675 MIME-Version: 1.0
676 Content-Transfer-Encoding: 8bit
678 Result: OK
682 test_expect_success $PREREQ 'sendemail.cc unset' '
683 git config --unset sendemail.cc &&
684 test_suppression sob
687 test_expect_success $PREREQ 'setup expect' "
688 cat >expected-suppress-cccmd <<\EOF
689 0001-Second.patch
690 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
691 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
692 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
693 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
694 Dry-OK. Log says:
695 Server: relay.example.com
696 MAIL FROM:<from@example.com>
697 RCPT TO:<to@example.com>
698 RCPT TO:<author@example.com>
699 RCPT TO:<one@example.com>
700 RCPT TO:<two@example.com>
701 RCPT TO:<committer@example.com>
702 From: Example <from@example.com>
703 To: to@example.com
704 Cc: A <author@example.com>,
705 One <one@example.com>,
706 two@example.com,
707 C O Mitter <committer@example.com>
708 Subject: [PATCH 1/1] Second.
709 Date: DATE-STRING
710 Message-Id: MESSAGE-ID-STRING
711 X-Mailer: X-MAILER-STRING
712 MIME-Version: 1.0
713 Content-Transfer-Encoding: 8bit
715 Result: OK
719 test_expect_success $PREREQ 'sendemail.cccmd' '
720 write_script cccmd <<-\EOF &&
721 echo cc-cmd@example.com
723 git config sendemail.cccmd ./cccmd &&
724 test_suppression cccmd
727 test_expect_success $PREREQ 'setup expect' '
728 cat >expected-suppress-all <<\EOF
729 0001-Second.patch
730 Dry-OK. Log says:
731 Server: relay.example.com
732 MAIL FROM:<from@example.com>
733 RCPT TO:<to@example.com>
734 From: Example <from@example.com>
735 To: to@example.com
736 Subject: [PATCH 1/1] Second.
737 Date: DATE-STRING
738 Message-Id: MESSAGE-ID-STRING
739 X-Mailer: X-MAILER-STRING
740 MIME-Version: 1.0
741 Content-Transfer-Encoding: 8bit
743 Result: OK
747 test_expect_success $PREREQ '--suppress-cc=all' '
748 test_suppression all
751 test_expect_success $PREREQ 'setup expect' "
752 cat >expected-suppress-body <<\EOF
753 0001-Second.patch
754 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
755 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
756 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
757 (cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
758 Dry-OK. Log says:
759 Server: relay.example.com
760 MAIL FROM:<from@example.com>
761 RCPT TO:<to@example.com>
762 RCPT TO:<author@example.com>
763 RCPT TO:<one@example.com>
764 RCPT TO:<two@example.com>
765 RCPT TO:<cc-cmd@example.com>
766 From: Example <from@example.com>
767 To: to@example.com
768 Cc: A <author@example.com>,
769 One <one@example.com>,
770 two@example.com,
771 cc-cmd@example.com
772 Subject: [PATCH 1/1] Second.
773 Date: DATE-STRING
774 Message-Id: MESSAGE-ID-STRING
775 X-Mailer: X-MAILER-STRING
776 MIME-Version: 1.0
777 Content-Transfer-Encoding: 8bit
779 Result: OK
783 test_expect_success $PREREQ '--suppress-cc=body' '
784 test_suppression body
787 test_expect_success $PREREQ 'setup expect' "
788 cat >expected-suppress-body-cccmd <<\EOF
789 0001-Second.patch
790 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
791 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
792 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
793 Dry-OK. Log says:
794 Server: relay.example.com
795 MAIL FROM:<from@example.com>
796 RCPT TO:<to@example.com>
797 RCPT TO:<author@example.com>
798 RCPT TO:<one@example.com>
799 RCPT TO:<two@example.com>
800 From: Example <from@example.com>
801 To: to@example.com
802 Cc: A <author@example.com>,
803 One <one@example.com>,
804 two@example.com
805 Subject: [PATCH 1/1] Second.
806 Date: DATE-STRING
807 Message-Id: MESSAGE-ID-STRING
808 X-Mailer: X-MAILER-STRING
809 MIME-Version: 1.0
810 Content-Transfer-Encoding: 8bit
812 Result: OK
816 test_expect_success $PREREQ '--suppress-cc=body --suppress-cc=cccmd' '
817 test_suppression body cccmd
820 test_expect_success $PREREQ 'setup expect' "
821 cat >expected-suppress-sob <<\EOF
822 0001-Second.patch
823 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
824 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
825 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
826 Dry-OK. Log says:
827 Server: relay.example.com
828 MAIL FROM:<from@example.com>
829 RCPT TO:<to@example.com>
830 RCPT TO:<author@example.com>
831 RCPT TO:<one@example.com>
832 RCPT TO:<two@example.com>
833 From: Example <from@example.com>
834 To: to@example.com
835 Cc: A <author@example.com>,
836 One <one@example.com>,
837 two@example.com
838 Subject: [PATCH 1/1] Second.
839 Date: DATE-STRING
840 Message-Id: MESSAGE-ID-STRING
841 X-Mailer: X-MAILER-STRING
842 MIME-Version: 1.0
843 Content-Transfer-Encoding: 8bit
845 Result: OK
849 test_expect_success $PREREQ '--suppress-cc=sob' '
850 test_might_fail git config --unset sendemail.cccmd &&
851 test_suppression sob
854 test_expect_success $PREREQ 'setup expect' "
855 cat >expected-suppress-bodycc <<\EOF
856 0001-Second.patch
857 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
858 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
859 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
860 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
861 Dry-OK. Log says:
862 Server: relay.example.com
863 MAIL FROM:<from@example.com>
864 RCPT TO:<to@example.com>
865 RCPT TO:<author@example.com>
866 RCPT TO:<one@example.com>
867 RCPT TO:<two@example.com>
868 RCPT TO:<committer@example.com>
869 From: Example <from@example.com>
870 To: to@example.com
871 Cc: A <author@example.com>,
872 One <one@example.com>,
873 two@example.com,
874 C O Mitter <committer@example.com>
875 Subject: [PATCH 1/1] Second.
876 Date: DATE-STRING
877 Message-Id: MESSAGE-ID-STRING
878 X-Mailer: X-MAILER-STRING
879 MIME-Version: 1.0
880 Content-Transfer-Encoding: 8bit
882 Result: OK
886 test_expect_success $PREREQ '--suppress-cc=bodycc' '
887 test_suppression bodycc
890 test_expect_success $PREREQ 'setup expect' "
891 cat >expected-suppress-cc <<\EOF
892 0001-Second.patch
893 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
894 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
895 Dry-OK. Log says:
896 Server: relay.example.com
897 MAIL FROM:<from@example.com>
898 RCPT TO:<to@example.com>
899 RCPT TO:<author@example.com>
900 RCPT TO:<committer@example.com>
901 From: Example <from@example.com>
902 To: to@example.com
903 Cc: A <author@example.com>,
904 C O Mitter <committer@example.com>
905 Subject: [PATCH 1/1] Second.
906 Date: DATE-STRING
907 Message-Id: MESSAGE-ID-STRING
908 X-Mailer: X-MAILER-STRING
909 MIME-Version: 1.0
910 Content-Transfer-Encoding: 8bit
912 Result: OK
916 test_expect_success $PREREQ '--suppress-cc=cc' '
917 test_suppression cc
920 test_confirm () {
921 echo y | \
922 GIT_SEND_EMAIL_NOTTY=1 \
923 git send-email \
924 --from="Example <nobody@example.com>" \
925 --to=nobody@example.com \
926 --smtp-server="$(pwd)/fake.sendmail" \
927 $@ $patches >stdout &&
928 grep "Send this email" stdout
931 test_expect_success $PREREQ '--confirm=always' '
932 test_confirm --confirm=always --suppress-cc=all
935 test_expect_success $PREREQ '--confirm=auto' '
936 test_confirm --confirm=auto
939 test_expect_success $PREREQ '--confirm=cc' '
940 test_confirm --confirm=cc
943 test_expect_success $PREREQ '--confirm=compose' '
944 test_confirm --confirm=compose --compose
947 test_expect_success $PREREQ 'confirm by default (due to cc)' '
948 test_when_finished git config sendemail.confirm never &&
949 git config --unset sendemail.confirm &&
950 test_confirm
953 test_expect_success $PREREQ 'confirm by default (due to --compose)' '
954 test_when_finished git config sendemail.confirm never &&
955 git config --unset sendemail.confirm &&
956 test_confirm --suppress-cc=all --compose
959 test_expect_success $PREREQ 'confirm detects EOF (inform assumes y)' '
960 test_when_finished git config sendemail.confirm never &&
961 git config --unset sendemail.confirm &&
962 rm -fr outdir &&
963 git format-patch -2 -o outdir &&
964 GIT_SEND_EMAIL_NOTTY=1 \
965 git send-email \
966 --from="Example <nobody@example.com>" \
967 --to=nobody@example.com \
968 --smtp-server="$(pwd)/fake.sendmail" \
969 outdir/*.patch </dev/null
972 test_expect_success $PREREQ 'confirm detects EOF (auto causes failure)' '
973 test_when_finished git config sendemail.confirm never &&
974 git config sendemail.confirm auto &&
975 GIT_SEND_EMAIL_NOTTY=1 &&
976 export GIT_SEND_EMAIL_NOTTY &&
977 test_must_fail git send-email \
978 --from="Example <nobody@example.com>" \
979 --to=nobody@example.com \
980 --smtp-server="$(pwd)/fake.sendmail" \
981 $patches </dev/null
984 test_expect_success $PREREQ 'confirm does not loop forever' '
985 test_when_finished git config sendemail.confirm never &&
986 git config sendemail.confirm auto &&
987 GIT_SEND_EMAIL_NOTTY=1 &&
988 export GIT_SEND_EMAIL_NOTTY &&
989 yes "bogus" | test_must_fail git send-email \
990 --from="Example <nobody@example.com>" \
991 --to=nobody@example.com \
992 --smtp-server="$(pwd)/fake.sendmail" \
993 $patches
996 test_expect_success $PREREQ 'utf8 Cc is rfc2047 encoded' '
997 clean_fake_sendmail &&
998 rm -fr outdir &&
999 git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
1000 git send-email \
1001 --from="Example <nobody@example.com>" \
1002 --to=nobody@example.com \
1003 --smtp-server="$(pwd)/fake.sendmail" \
1004 outdir/*.patch &&
1005 grep "^ " msgtxt1 |
1006 grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
1009 test_expect_success $PREREQ '--compose adds MIME for utf8 body' '
1010 clean_fake_sendmail &&
1011 write_script fake-editor-utf8 <<-\EOF &&
1012 echo "utf8 body: àéìöú" >>"$1"
1014 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1015 git send-email \
1016 --compose --subject foo \
1017 --from="Example <nobody@example.com>" \
1018 --to=nobody@example.com \
1019 --smtp-server="$(pwd)/fake.sendmail" \
1020 $patches &&
1021 grep "^utf8 body" msgtxt1 &&
1022 grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
1025 test_expect_success $PREREQ '--compose respects user mime type' '
1026 clean_fake_sendmail &&
1027 write_script fake-editor-utf8-mime <<-\EOF &&
1028 cat >"$1" <<-\EOM
1029 MIME-Version: 1.0
1030 Content-Type: text/plain; charset=iso-8859-1
1031 Content-Transfer-Encoding: 8bit
1032 Subject: foo
1034 utf8 body: àéìöú
1037 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
1038 git send-email \
1039 --compose --subject foo \
1040 --from="Example <nobody@example.com>" \
1041 --to=nobody@example.com \
1042 --smtp-server="$(pwd)/fake.sendmail" \
1043 $patches &&
1044 grep "^utf8 body" msgtxt1 &&
1045 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
1046 ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
1049 test_expect_success $PREREQ '--compose adds MIME for utf8 subject' '
1050 clean_fake_sendmail &&
1051 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
1052 git send-email \
1053 --compose --subject utf8-sübjëct \
1054 --from="Example <nobody@example.com>" \
1055 --to=nobody@example.com \
1056 --smtp-server="$(pwd)/fake.sendmail" \
1057 $patches &&
1058 grep "^fake edit" msgtxt1 &&
1059 grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
1062 test_expect_success $PREREQ 'utf8 author is correctly passed on' '
1063 clean_fake_sendmail &&
1064 test_commit weird_author &&
1065 test_when_finished "git reset --hard HEAD^" &&
1066 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
1067 git format-patch --stdout -1 >funny_name.patch &&
1068 git send-email --from="Example <nobody@example.com>" \
1069 --to=nobody@example.com \
1070 --smtp-server="$(pwd)/fake.sendmail" \
1071 funny_name.patch &&
1072 grep "^From: Füñný Nâmé <odd_?=mail@example.com>" msgtxt1
1075 test_expect_success $PREREQ 'utf8 sender is not duplicated' '
1076 clean_fake_sendmail &&
1077 test_commit weird_sender &&
1078 test_when_finished "git reset --hard HEAD^" &&
1079 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
1080 git format-patch --stdout -1 >funny_name.patch &&
1081 git send-email --from="Füñný Nâmé <odd_?=mail@example.com>" \
1082 --to=nobody@example.com \
1083 --smtp-server="$(pwd)/fake.sendmail" \
1084 funny_name.patch &&
1085 grep "^From: " msgtxt1 >msgfrom &&
1086 test_line_count = 1 msgfrom
1089 test_expect_success $PREREQ 'sendemail.composeencoding works' '
1090 clean_fake_sendmail &&
1091 git config sendemail.composeencoding iso-8859-1 &&
1092 write_script fake-editor-utf8 <<-\EOF &&
1093 echo "utf8 body: àéìöú" >>"$1"
1095 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1096 git send-email \
1097 --compose --subject foo \
1098 --from="Example <nobody@example.com>" \
1099 --to=nobody@example.com \
1100 --smtp-server="$(pwd)/fake.sendmail" \
1101 $patches &&
1102 grep "^utf8 body" msgtxt1 &&
1103 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1106 test_expect_success $PREREQ '--compose-encoding works' '
1107 clean_fake_sendmail &&
1108 write_script fake-editor-utf8 <<-\EOF &&
1109 echo "utf8 body: àéìöú" >>"$1"
1111 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1112 git send-email \
1113 --compose-encoding iso-8859-1 \
1114 --compose --subject foo \
1115 --from="Example <nobody@example.com>" \
1116 --to=nobody@example.com \
1117 --smtp-server="$(pwd)/fake.sendmail" \
1118 $patches &&
1119 grep "^utf8 body" msgtxt1 &&
1120 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1123 test_expect_success $PREREQ '--compose-encoding overrides sendemail.composeencoding' '
1124 clean_fake_sendmail &&
1125 git config sendemail.composeencoding iso-8859-1 &&
1126 write_script fake-editor-utf8 <<-\EOF &&
1127 echo "utf8 body: àéìöú" >>"$1"
1129 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1130 git send-email \
1131 --compose-encoding iso-8859-2 \
1132 --compose --subject foo \
1133 --from="Example <nobody@example.com>" \
1134 --to=nobody@example.com \
1135 --smtp-server="$(pwd)/fake.sendmail" \
1136 $patches &&
1137 grep "^utf8 body" msgtxt1 &&
1138 grep "^Content-Type: text/plain; charset=iso-8859-2" msgtxt1
1141 test_expect_success $PREREQ '--compose-encoding adds correct MIME for subject' '
1142 clean_fake_sendmail &&
1143 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
1144 git send-email \
1145 --compose-encoding iso-8859-2 \
1146 --compose --subject utf8-sübjëct \
1147 --from="Example <nobody@example.com>" \
1148 --to=nobody@example.com \
1149 --smtp-server="$(pwd)/fake.sendmail" \
1150 $patches &&
1151 grep "^fake edit" msgtxt1 &&
1152 grep "^Subject: =?iso-8859-2?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
1155 test_expect_success $PREREQ 'detects ambiguous reference/file conflict' '
1156 echo master >master &&
1157 git add master &&
1158 git commit -m"add master" &&
1159 test_must_fail git send-email --dry-run master 2>errors &&
1160 grep disambiguate errors
1163 test_expect_success $PREREQ 'feed two files' '
1164 rm -fr outdir &&
1165 git format-patch -2 -o outdir &&
1166 git send-email \
1167 --dry-run \
1168 --from="Example <nobody@example.com>" \
1169 --to=nobody@example.com \
1170 outdir/000?-*.patch 2>errors >out &&
1171 grep "^Subject: " out >subjects &&
1172 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
1173 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"
1176 test_expect_success $PREREQ 'in-reply-to but no threading' '
1177 git send-email \
1178 --dry-run \
1179 --from="Example <nobody@example.com>" \
1180 --to=nobody@example.com \
1181 --in-reply-to="<in-reply-id@example.com>" \
1182 --no-thread \
1183 $patches |
1184 grep "In-Reply-To: <in-reply-id@example.com>"
1187 test_expect_success $PREREQ 'no in-reply-to and no threading' '
1188 git send-email \
1189 --dry-run \
1190 --from="Example <nobody@example.com>" \
1191 --to=nobody@example.com \
1192 --no-thread \
1193 $patches $patches >stdout &&
1194 ! grep "In-Reply-To: " stdout
1197 test_expect_success $PREREQ 'threading but no chain-reply-to' '
1198 git send-email \
1199 --dry-run \
1200 --from="Example <nobody@example.com>" \
1201 --to=nobody@example.com \
1202 --thread \
1203 --no-chain-reply-to \
1204 $patches $patches >stdout &&
1205 grep "In-Reply-To: " stdout
1208 test_expect_success $PREREQ 'sendemail.to works' '
1209 git config --replace-all sendemail.to "Somebody <somebody@ex.com>" &&
1210 git send-email \
1211 --dry-run \
1212 --from="Example <nobody@example.com>" \
1213 $patches $patches >stdout &&
1214 grep "To: Somebody <somebody@ex.com>" stdout
1217 test_expect_success $PREREQ '--no-to overrides sendemail.to' '
1218 git send-email \
1219 --dry-run \
1220 --from="Example <nobody@example.com>" \
1221 --no-to \
1222 --to=nobody@example.com \
1223 $patches $patches >stdout &&
1224 grep "To: nobody@example.com" stdout &&
1225 ! grep "To: Somebody <somebody@ex.com>" stdout
1228 test_expect_success $PREREQ 'sendemail.cc works' '
1229 git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" &&
1230 git send-email \
1231 --dry-run \
1232 --from="Example <nobody@example.com>" \
1233 --to=nobody@example.com \
1234 $patches $patches >stdout &&
1235 grep "Cc: Somebody <somebody@ex.com>" stdout
1238 test_expect_success $PREREQ '--no-cc overrides sendemail.cc' '
1239 git send-email \
1240 --dry-run \
1241 --from="Example <nobody@example.com>" \
1242 --no-cc \
1243 --cc=bodies@example.com \
1244 --to=nobody@example.com \
1245 $patches $patches >stdout &&
1246 grep "Cc: bodies@example.com" stdout &&
1247 ! grep "Cc: Somebody <somebody@ex.com>" stdout
1250 test_expect_success $PREREQ 'sendemail.bcc works' '
1251 git config --replace-all sendemail.bcc "Other <other@ex.com>" &&
1252 git send-email \
1253 --dry-run \
1254 --from="Example <nobody@example.com>" \
1255 --to=nobody@example.com \
1256 --smtp-server relay.example.com \
1257 $patches $patches >stdout &&
1258 grep "RCPT TO:<other@ex.com>" stdout
1261 test_expect_success $PREREQ '--no-bcc overrides sendemail.bcc' '
1262 git send-email \
1263 --dry-run \
1264 --from="Example <nobody@example.com>" \
1265 --no-bcc \
1266 --bcc=bodies@example.com \
1267 --to=nobody@example.com \
1268 --smtp-server relay.example.com \
1269 $patches $patches >stdout &&
1270 grep "RCPT TO:<bodies@example.com>" stdout &&
1271 ! grep "RCPT TO:<other@ex.com>" stdout
1274 test_expect_success $PREREQ 'patches To headers are used by default' '
1275 patch=$(git format-patch -1 --to="bodies@example.com") &&
1276 test_when_finished "rm $patch" &&
1277 git send-email \
1278 --dry-run \
1279 --from="Example <nobody@example.com>" \
1280 --smtp-server relay.example.com \
1281 $patch >stdout &&
1282 grep "RCPT TO:<bodies@example.com>" stdout
1285 test_expect_success $PREREQ 'patches To headers are appended to' '
1286 patch=$(git format-patch -1 --to="bodies@example.com") &&
1287 test_when_finished "rm $patch" &&
1288 git send-email \
1289 --dry-run \
1290 --from="Example <nobody@example.com>" \
1291 --to=nobody@example.com \
1292 --smtp-server relay.example.com \
1293 $patch >stdout &&
1294 grep "RCPT TO:<bodies@example.com>" stdout &&
1295 grep "RCPT TO:<nobody@example.com>" stdout
1298 test_expect_success $PREREQ 'To headers from files reset each patch' '
1299 patch1=$(git format-patch -1 --to="bodies@example.com") &&
1300 patch2=$(git format-patch -1 --to="other@example.com" HEAD~) &&
1301 test_when_finished "rm $patch1 && rm $patch2" &&
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 $patch1 $patch2 >stdout &&
1308 test $(grep -c "RCPT TO:<bodies@example.com>" stdout) = 1 &&
1309 test $(grep -c "RCPT TO:<nobody@example.com>" stdout) = 2 &&
1310 test $(grep -c "RCPT TO:<other@example.com>" stdout) = 1
1313 test_expect_success $PREREQ 'setup expect' '
1314 cat >email-using-8bit <<\EOF
1315 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1316 Message-Id: <bogus-message-id@example.com>
1317 From: author@example.com
1318 Date: Sat, 12 Jun 2010 15:53:58 +0200
1319 Subject: subject goes here
1321 Dieser deutsche Text enthält einen Umlaut!
1325 test_expect_success $PREREQ 'setup expect' '
1326 echo "Subject: subject goes here" >expected
1329 test_expect_success $PREREQ 'ASCII subject is not RFC2047 quoted' '
1330 clean_fake_sendmail &&
1331 echo bogus |
1332 git send-email --from=author@example.com --to=nobody@example.com \
1333 --smtp-server="$(pwd)/fake.sendmail" \
1334 --8bit-encoding=UTF-8 \
1335 email-using-8bit >stdout &&
1336 grep "Subject" msgtxt1 >actual &&
1337 test_cmp expected actual
1340 test_expect_success $PREREQ 'setup expect' '
1341 cat >content-type-decl <<-\EOF
1342 MIME-Version: 1.0
1343 Content-Type: text/plain; charset=UTF-8
1344 Content-Transfer-Encoding: 8bit
1348 test_expect_success $PREREQ 'asks about and fixes 8bit encodings' '
1349 clean_fake_sendmail &&
1350 echo |
1351 git send-email --from=author@example.com --to=nobody@example.com \
1352 --smtp-server="$(pwd)/fake.sendmail" \
1353 email-using-8bit >stdout &&
1354 grep "do not declare a Content-Transfer-Encoding" stdout &&
1355 grep email-using-8bit stdout &&
1356 grep "Which 8bit encoding" stdout &&
1357 egrep "Content|MIME" msgtxt1 >actual &&
1358 test_cmp content-type-decl actual
1361 test_expect_success $PREREQ 'sendemail.8bitEncoding works' '
1362 clean_fake_sendmail &&
1363 git config sendemail.assume8bitEncoding UTF-8 &&
1364 echo bogus |
1365 git send-email --from=author@example.com --to=nobody@example.com \
1366 --smtp-server="$(pwd)/fake.sendmail" \
1367 email-using-8bit >stdout &&
1368 egrep "Content|MIME" msgtxt1 >actual &&
1369 test_cmp content-type-decl actual
1372 test_expect_success $PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
1373 clean_fake_sendmail &&
1374 git config sendemail.assume8bitEncoding "bogus too" &&
1375 echo bogus |
1376 git send-email --from=author@example.com --to=nobody@example.com \
1377 --smtp-server="$(pwd)/fake.sendmail" \
1378 --8bit-encoding=UTF-8 \
1379 email-using-8bit >stdout &&
1380 egrep "Content|MIME" msgtxt1 >actual &&
1381 test_cmp content-type-decl actual
1384 test_expect_success $PREREQ 'setup expect' '
1385 cat >email-using-8bit <<-\EOF
1386 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1387 Message-Id: <bogus-message-id@example.com>
1388 From: author@example.com
1389 Date: Sat, 12 Jun 2010 15:53:58 +0200
1390 Subject: Dieser Betreff enthält auch einen Umlaut!
1392 Nothing to see here.
1396 test_expect_success $PREREQ 'setup expect' '
1397 cat >expected <<-\EOF
1398 Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
1402 test_expect_success $PREREQ '--8bit-encoding also treats subject' '
1403 clean_fake_sendmail &&
1404 echo bogus |
1405 git send-email --from=author@example.com --to=nobody@example.com \
1406 --smtp-server="$(pwd)/fake.sendmail" \
1407 --8bit-encoding=UTF-8 \
1408 email-using-8bit >stdout &&
1409 grep "Subject" msgtxt1 >actual &&
1410 test_cmp expected actual
1413 test_expect_success $PREREQ 'setup expect' '
1414 cat >email-using-8bit <<-\EOF
1415 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1416 Message-Id: <bogus-message-id@example.com>
1417 From: A U Thor <author@example.com>
1418 Date: Sat, 12 Jun 2010 15:53:58 +0200
1419 Content-Type: text/plain; charset=UTF-8
1420 Subject: Nothing to see here.
1422 Dieser Betreff enthält auch einen Umlaut!
1426 test_expect_success $PREREQ 'sendemail.transferencoding=7bit fails on 8bit data' '
1427 clean_fake_sendmail &&
1428 git config sendemail.transferEncoding 7bit &&
1429 test_must_fail git send-email \
1430 --transfer-encoding=7bit \
1431 --smtp-server="$(pwd)/fake.sendmail" \
1432 email-using-8bit \
1433 2>errors >out &&
1434 grep "cannot send message as 7bit" errors &&
1435 test -z "$(ls msgtxt*)"
1438 test_expect_success $PREREQ '--transfer-encoding overrides sendemail.transferEncoding' '
1439 clean_fake_sendmail &&
1440 git config sendemail.transferEncoding 8bit &&
1441 test_must_fail git send-email \
1442 --transfer-encoding=7bit \
1443 --smtp-server="$(pwd)/fake.sendmail" \
1444 email-using-8bit \
1445 2>errors >out &&
1446 grep "cannot send message as 7bit" errors &&
1447 test -z "$(ls msgtxt*)"
1450 test_expect_success $PREREQ 'sendemail.transferencoding=8bit' '
1451 clean_fake_sendmail &&
1452 git send-email \
1453 --transfer-encoding=8bit \
1454 --smtp-server="$(pwd)/fake.sendmail" \
1455 email-using-8bit \
1456 2>errors >out &&
1457 sed '1,/^$/d' msgtxt1 >actual &&
1458 sed '1,/^$/d' email-using-8bit >expected &&
1459 test_cmp expected actual
1462 test_expect_success $PREREQ 'setup expect' '
1463 cat >expected <<-\EOF
1464 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1468 test_expect_success $PREREQ '8-bit and sendemail.transferencoding=quoted-printable' '
1469 clean_fake_sendmail &&
1470 git send-email \
1471 --transfer-encoding=quoted-printable \
1472 --smtp-server="$(pwd)/fake.sendmail" \
1473 email-using-8bit \
1474 2>errors >out &&
1475 sed '1,/^$/d' msgtxt1 >actual &&
1476 test_cmp expected actual
1479 test_expect_success $PREREQ 'setup expect' '
1480 cat >expected <<-\EOF
1481 RGllc2VyIEJldHJlZmYgZW50aMOkbHQgYXVjaCBlaW5lbiBVbWxhdXQhCg==
1485 test_expect_success $PREREQ '8-bit and sendemail.transferencoding=base64' '
1486 clean_fake_sendmail &&
1487 git send-email \
1488 --transfer-encoding=base64 \
1489 --smtp-server="$(pwd)/fake.sendmail" \
1490 email-using-8bit \
1491 2>errors >out &&
1492 sed '1,/^$/d' msgtxt1 >actual &&
1493 test_cmp expected actual
1496 test_expect_success $PREREQ 'setup expect' '
1497 cat >email-using-qp <<-\EOF
1498 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1499 Message-Id: <bogus-message-id@example.com>
1500 From: A U Thor <author@example.com>
1501 Date: Sat, 12 Jun 2010 15:53:58 +0200
1502 MIME-Version: 1.0
1503 Content-Transfer-Encoding: quoted-printable
1504 Content-Type: text/plain; charset=UTF-8
1505 Subject: Nothing to see here.
1507 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1511 test_expect_success $PREREQ 'convert from quoted-printable to base64' '
1512 clean_fake_sendmail &&
1513 git send-email \
1514 --transfer-encoding=base64 \
1515 --smtp-server="$(pwd)/fake.sendmail" \
1516 email-using-qp \
1517 2>errors >out &&
1518 sed '1,/^$/d' msgtxt1 >actual &&
1519 test_cmp expected actual
1522 test_expect_success $PREREQ 'setup expect' "
1523 tr -d '\\015' | tr '%' '\\015' >email-using-crlf <<EOF
1524 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1525 Message-Id: <bogus-message-id@example.com>
1526 From: A U Thor <author@example.com>
1527 Date: Sat, 12 Jun 2010 15:53:58 +0200
1528 Content-Type: text/plain; charset=UTF-8
1529 Subject: Nothing to see here.
1531 Look, I have a CRLF and an = sign!%
1535 test_expect_success $PREREQ 'setup expect' '
1536 cat >expected <<-\EOF
1537 Look, I have a CRLF and an =3D sign!=0D
1541 test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=quoted-printable' '
1542 clean_fake_sendmail &&
1543 git send-email \
1544 --transfer-encoding=quoted-printable \
1545 --smtp-server="$(pwd)/fake.sendmail" \
1546 email-using-crlf \
1547 2>errors >out &&
1548 sed '1,/^$/d' msgtxt1 >actual &&
1549 test_cmp expected actual
1552 test_expect_success $PREREQ 'setup expect' '
1553 cat >expected <<-\EOF
1554 TG9vaywgSSBoYXZlIGEgQ1JMRiBhbmQgYW4gPSBzaWduIQ0K
1558 test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=base64' '
1559 clean_fake_sendmail &&
1560 git send-email \
1561 --transfer-encoding=base64 \
1562 --smtp-server="$(pwd)/fake.sendmail" \
1563 email-using-crlf \
1564 2>errors >out &&
1565 sed '1,/^$/d' msgtxt1 >actual &&
1566 test_cmp expected actual
1570 # Note that the patches in this test are deliberately out of order; we
1571 # want to make sure it works even if the cover-letter is not in the
1572 # first mail.
1573 test_expect_success $PREREQ 'refusing to send cover letter template' '
1574 clean_fake_sendmail &&
1575 rm -fr outdir &&
1576 git format-patch --cover-letter -2 -o outdir &&
1577 test_must_fail git send-email \
1578 --from="Example <nobody@example.com>" \
1579 --to=nobody@example.com \
1580 --smtp-server="$(pwd)/fake.sendmail" \
1581 outdir/0002-*.patch \
1582 outdir/0000-*.patch \
1583 outdir/0001-*.patch \
1584 2>errors >out &&
1585 grep "SUBJECT HERE" errors &&
1586 test -z "$(ls msgtxt*)"
1589 test_expect_success $PREREQ '--force sends cover letter template anyway' '
1590 clean_fake_sendmail &&
1591 rm -fr outdir &&
1592 git format-patch --cover-letter -2 -o outdir &&
1593 git send-email \
1594 --force \
1595 --from="Example <nobody@example.com>" \
1596 --to=nobody@example.com \
1597 --smtp-server="$(pwd)/fake.sendmail" \
1598 outdir/0002-*.patch \
1599 outdir/0000-*.patch \
1600 outdir/0001-*.patch \
1601 2>errors >out &&
1602 ! grep "SUBJECT HERE" errors &&
1603 test -n "$(ls msgtxt*)"
1606 test_cover_addresses () {
1607 header="$1"
1608 shift
1609 clean_fake_sendmail &&
1610 rm -fr outdir &&
1611 git format-patch --cover-letter -2 -o outdir &&
1612 cover=$(echo outdir/0000-*.patch) &&
1613 mv $cover cover-to-edit.patch &&
1614 perl -pe "s/^From:/$header: extra\@address.com\nFrom:/" cover-to-edit.patch >"$cover" &&
1615 git send-email \
1616 --force \
1617 --from="Example <nobody@example.com>" \
1618 --no-to --no-cc \
1619 "$@" \
1620 --smtp-server="$(pwd)/fake.sendmail" \
1621 outdir/0000-*.patch \
1622 outdir/0001-*.patch \
1623 outdir/0002-*.patch \
1624 2>errors >out &&
1625 grep "^$header: extra@address.com" msgtxt1 >to1 &&
1626 grep "^$header: extra@address.com" msgtxt2 >to2 &&
1627 grep "^$header: extra@address.com" msgtxt3 >to3 &&
1628 test_line_count = 1 to1 &&
1629 test_line_count = 1 to2 &&
1630 test_line_count = 1 to3
1633 test_expect_success $PREREQ 'to-cover adds To to all mail' '
1634 test_cover_addresses "To" --to-cover
1637 test_expect_success $PREREQ 'cc-cover adds Cc to all mail' '
1638 test_cover_addresses "Cc" --cc-cover
1641 test_expect_success $PREREQ 'tocover adds To to all mail' '
1642 test_config sendemail.tocover true &&
1643 test_cover_addresses "To"
1646 test_expect_success $PREREQ 'cccover adds Cc to all mail' '
1647 test_config sendemail.cccover true &&
1648 test_cover_addresses "Cc"
1651 test_expect_success $PREREQ 'escaped quotes in sendemail.aliasfiletype=mutt' '
1652 clean_fake_sendmail &&
1653 echo "alias sbd \\\"Dot U. Sir\\\" <somebody@example.org>" >.mutt &&
1654 git config --replace-all sendemail.aliasesfile "$(pwd)/.mutt" &&
1655 git config sendemail.aliasfiletype mutt &&
1656 git send-email \
1657 --from="Example <nobody@example.com>" \
1658 --to=sbd \
1659 --smtp-server="$(pwd)/fake.sendmail" \
1660 outdir/0001-*.patch \
1661 2>errors >out &&
1662 grep "^!somebody@example\.org!$" commandline1 &&
1663 grep -F "To: \"Dot U. Sir\" <somebody@example.org>" out
1666 test_expect_success $PREREQ 'sendemail.aliasfiletype=mailrc' '
1667 clean_fake_sendmail &&
1668 echo "alias sbd somebody@example.org" >.mailrc &&
1669 git config --replace-all sendemail.aliasesfile "$(pwd)/.mailrc" &&
1670 git config sendemail.aliasfiletype mailrc &&
1671 git send-email \
1672 --from="Example <nobody@example.com>" \
1673 --to=sbd \
1674 --smtp-server="$(pwd)/fake.sendmail" \
1675 outdir/0001-*.patch \
1676 2>errors >out &&
1677 grep "^!somebody@example\.org!$" commandline1
1680 test_expect_success $PREREQ 'sendemail.aliasfile=~/.mailrc' '
1681 clean_fake_sendmail &&
1682 echo "alias sbd someone@example.org" >"$HOME/.mailrc" &&
1683 git config --replace-all sendemail.aliasesfile "~/.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 "^!someone@example\.org!$" commandline1
1694 test_dump_aliases () {
1695 msg="$1" && shift &&
1696 filetype="$1" && shift &&
1697 printf '%s\n' "$@" >expect &&
1698 cat >.tmp-email-aliases &&
1700 test_expect_success $PREREQ "$msg" '
1701 clean_fake_sendmail && rm -fr outdir &&
1702 git config --replace-all sendemail.aliasesfile \
1703 "$(pwd)/.tmp-email-aliases" &&
1704 git config sendemail.aliasfiletype "$filetype" &&
1705 git send-email --dump-aliases 2>errors >actual &&
1706 test_cmp expect actual
1710 test_dump_aliases '--dump-aliases sendmail format' \
1711 'sendmail' \
1712 'abgroup' \
1713 'alice' \
1714 'bcgrp' \
1715 'bob' \
1716 'chloe' <<-\EOF
1717 alice: Alice W Land <awol@example.com>
1718 bob: Robert Bobbyton <bob@example.com>
1719 chloe: chloe@example.com
1720 abgroup: alice, bob
1721 bcgrp: bob, chloe, Other <o@example.com>
1724 test_dump_aliases '--dump-aliases mutt format' \
1725 'mutt' \
1726 'alice' \
1727 'bob' \
1728 'chloe' \
1729 'donald' <<-\EOF
1730 alias alice Alice W Land <awol@example.com>
1731 alias donald Donald C Carlton <donc@example.com>
1732 alias bob Robert Bobbyton <bob@example.com>
1733 alias chloe chloe@example.com
1736 test_dump_aliases '--dump-aliases mailrc format' \
1737 'mailrc' \
1738 'alice' \
1739 'bob' \
1740 'chloe' \
1741 'eve' <<-\EOF
1742 alias alice Alice W Land <awol@example.com>
1743 alias eve Eve <eve@example.com>
1744 alias bob Robert Bobbyton <bob@example.com>
1745 alias chloe chloe@example.com
1748 test_dump_aliases '--dump-aliases pine format' \
1749 'pine' \
1750 'alice' \
1751 'bob' \
1752 'chloe' \
1753 'eve' <<-\EOF
1754 alice Alice W Land <awol@example.com>
1755 eve Eve <eve@example.com>
1756 bob Robert Bobbyton <bob@example.com>
1757 chloe chloe@example.com
1760 test_dump_aliases '--dump-aliases gnus format' \
1761 'gnus' \
1762 'alice' \
1763 'bob' \
1764 'chloe' \
1765 'eve' <<-\EOF
1766 (define-mail-alias "alice" "awol@example.com")
1767 (define-mail-alias "eve" "eve@example.com")
1768 (define-mail-alias "bob" "bob@example.com")
1769 (define-mail-alias "chloe" "chloe@example.com")
1772 test_expect_success '--dump-aliases must be used alone' '
1773 test_must_fail git send-email --dump-aliases --to=janice@example.com -1 refs/heads/accounting
1776 test_sendmail_aliases () {
1777 msg="$1" && shift &&
1778 expect="$@" &&
1779 cat >.tmp-email-aliases &&
1781 test_expect_success $PREREQ "$msg" '
1782 clean_fake_sendmail && rm -fr outdir &&
1783 git format-patch -1 -o outdir &&
1784 git config --replace-all sendemail.aliasesfile \
1785 "$(pwd)/.tmp-email-aliases" &&
1786 git config sendemail.aliasfiletype sendmail &&
1787 git send-email \
1788 --from="Example <nobody@example.com>" \
1789 --to=alice --to=bcgrp \
1790 --smtp-server="$(pwd)/fake.sendmail" \
1791 outdir/0001-*.patch \
1792 2>errors >out &&
1793 for i in $expect
1795 grep "^!$i!$" commandline1 || return 1
1796 done
1800 test_sendmail_aliases 'sendemail.aliasfiletype=sendmail' \
1801 'awol@example\.com' \
1802 'bob@example\.com' \
1803 'chloe@example\.com' \
1804 'o@example\.com' <<-\EOF
1805 alice: Alice W Land <awol@example.com>
1806 bob: Robert Bobbyton <bob@example.com>
1807 # this is a comment
1808 # this is also a comment
1809 chloe: chloe@example.com
1810 abgroup: alice, bob
1811 bcgrp: bob, chloe, Other <o@example.com>
1814 test_sendmail_aliases 'sendmail aliases line folding' \
1815 alice1 \
1816 bob1 bob2 \
1817 chuck1 chuck2 \
1818 darla1 darla2 darla3 \
1819 elton1 elton2 elton3 \
1820 fred1 fred2 \
1821 greg1 <<-\EOF
1822 alice: alice1
1823 bob: bob1,\
1824 bob2
1825 chuck: chuck1,
1826 chuck2
1827 darla: darla1,\
1828 darla2,
1829 darla3
1830 elton: elton1,
1831 elton2,\
1832 elton3
1833 fred: fred1,\
1834 fred2
1835 greg: greg1
1836 bcgrp: bob, chuck, darla, elton, fred, greg
1839 test_sendmail_aliases 'sendmail aliases tolerate bogus line folding' \
1840 alice1 bob1 <<-\EOF
1841 alice: alice1
1842 bcgrp: bob1\
1845 test_sendmail_aliases 'sendmail aliases empty' alice bcgrp <<-\EOF
1848 test_expect_success $PREREQ 'alias support in To header' '
1849 clean_fake_sendmail &&
1850 echo "alias sbd someone@example.org" >.mailrc &&
1851 test_config sendemail.aliasesfile ".mailrc" &&
1852 test_config sendemail.aliasfiletype mailrc &&
1853 git format-patch --stdout -1 --to=sbd >aliased.patch &&
1854 git send-email \
1855 --from="Example <nobody@example.com>" \
1856 --smtp-server="$(pwd)/fake.sendmail" \
1857 aliased.patch \
1858 2>errors >out &&
1859 grep "^!someone@example\.org!$" commandline1
1862 test_expect_success $PREREQ 'alias support in Cc 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 --cc=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 'tocmd works with aliases' '
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 >tocmd.patch &&
1882 echo tocmd--sbd >>tocmd.patch &&
1883 git send-email \
1884 --from="Example <nobody@example.com>" \
1885 --to-cmd=./tocmd-sed \
1886 --smtp-server="$(pwd)/fake.sendmail" \
1887 tocmd.patch \
1888 2>errors >out &&
1889 grep "^!someone@example\.org!$" commandline1
1892 test_expect_success $PREREQ 'cccmd works with aliases' '
1893 clean_fake_sendmail &&
1894 echo "alias sbd someone@example.org" >.mailrc &&
1895 test_config sendemail.aliasesfile ".mailrc" &&
1896 test_config sendemail.aliasfiletype mailrc &&
1897 git format-patch --stdout -1 >cccmd.patch &&
1898 echo cccmd--sbd >>cccmd.patch &&
1899 git send-email \
1900 --from="Example <nobody@example.com>" \
1901 --cc-cmd=./cccmd-sed \
1902 --smtp-server="$(pwd)/fake.sendmail" \
1903 cccmd.patch \
1904 2>errors >out &&
1905 grep "^!someone@example\.org!$" commandline1
1908 do_xmailer_test () {
1909 expected=$1 params=$2 &&
1910 git format-patch -1 &&
1911 git send-email \
1912 --from="Example <nobody@example.com>" \
1913 --to=someone@example.com \
1914 --smtp-server="$(pwd)/fake.sendmail" \
1915 $params \
1916 0001-*.patch \
1917 2>errors >out &&
1918 { grep '^X-Mailer:' out || :; } >mailer &&
1919 test_line_count = $expected mailer
1922 test_expect_success $PREREQ '--[no-]xmailer without any configuration' '
1923 do_xmailer_test 1 "--xmailer" &&
1924 do_xmailer_test 0 "--no-xmailer"
1927 test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=true' '
1928 test_config sendemail.xmailer true &&
1929 do_xmailer_test 1 "" &&
1930 do_xmailer_test 0 "--no-xmailer" &&
1931 do_xmailer_test 1 "--xmailer"
1934 test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=false' '
1935 test_config sendemail.xmailer false &&
1936 do_xmailer_test 0 "" &&
1937 do_xmailer_test 0 "--no-xmailer" &&
1938 do_xmailer_test 1 "--xmailer"
1941 test_expect_success $PREREQ 'setup expected-list' '
1942 git send-email \
1943 --dry-run \
1944 --from="Example <from@example.com>" \
1945 --to="To 1 <to1@example.com>" \
1946 --to="to2@example.com" \
1947 --to="to3@example.com" \
1948 --cc="Cc 1 <cc1@example.com>" \
1949 --cc="Cc2 <cc2@example.com>" \
1950 --bcc="bcc1@example.com" \
1951 --bcc="bcc2@example.com" \
1952 0001-add-master.patch | replace_variable_fields \
1953 >expected-list
1956 test_expect_success $PREREQ 'use email list in --cc --to and --bcc' '
1957 git send-email \
1958 --dry-run \
1959 --from="Example <from@example.com>" \
1960 --to="To 1 <to1@example.com>, to2@example.com" \
1961 --to="to3@example.com" \
1962 --cc="Cc 1 <cc1@example.com>, Cc2 <cc2@example.com>" \
1963 --bcc="bcc1@example.com, bcc2@example.com" \
1964 0001-add-master.patch | replace_variable_fields \
1965 >actual-list &&
1966 test_cmp expected-list actual-list
1969 test_expect_success $PREREQ 'aliases work with email list' '
1970 echo "alias to2 to2@example.com" >.mutt &&
1971 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt &&
1972 test_config sendemail.aliasesfile ".mutt" &&
1973 test_config sendemail.aliasfiletype mutt &&
1974 git send-email \
1975 --dry-run \
1976 --from="Example <from@example.com>" \
1977 --to="To 1 <to1@example.com>, to2, to3@example.com" \
1978 --cc="cc1, Cc2 <cc2@example.com>" \
1979 --bcc="bcc1@example.com, bcc2@example.com" \
1980 0001-add-master.patch | replace_variable_fields \
1981 >actual-list &&
1982 test_cmp expected-list actual-list
1985 test_expect_success $PREREQ 'leading and trailing whitespaces are removed' '
1986 echo "alias to2 to2@example.com" >.mutt &&
1987 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt &&
1988 test_config sendemail.aliasesfile ".mutt" &&
1989 test_config sendemail.aliasfiletype mutt &&
1990 TO1=$(echo "QTo 1 <to1@example.com>" | q_to_tab) &&
1991 TO2=$(echo "QZto2" | qz_to_tab_space) &&
1992 CC1=$(echo "cc1" | append_cr) &&
1993 BCC1=$(echo "Q bcc1@example.com Q" | q_to_nul) &&
1994 git send-email \
1995 --dry-run \
1996 --from=" Example <from@example.com>" \
1997 --to="$TO1" \
1998 --to="$TO2" \
1999 --to=" to3@example.com " \
2000 --cc="$CC1" \
2001 --cc="Cc2 <cc2@example.com>" \
2002 --bcc="$BCC1" \
2003 --bcc="bcc2@example.com" \
2004 0001-add-master.patch | replace_variable_fields \
2005 >actual-list &&
2006 test_cmp expected-list actual-list
2009 test_expect_success $PREREQ 'invoke hook' '
2010 mkdir -p .git/hooks &&
2012 write_script .git/hooks/sendemail-validate <<-\EOF &&
2013 # test that we have the correct environment variable, pwd, and
2014 # argument
2015 case "$GIT_DIR" in
2016 *.git)
2017 true
2020 false
2022 esac &&
2023 test -f 0001-add-master.patch &&
2024 grep "add master" "$1"
2027 mkdir subdir &&
2029 # Test that it works even if we are not at the root of the
2030 # working tree
2031 cd subdir &&
2032 git send-email \
2033 --from="Example <nobody@example.com>" \
2034 --to=nobody@example.com \
2035 --smtp-server="$(pwd)/../fake.sendmail" \
2036 ../0001-add-master.patch &&
2038 # Verify error message when a patch is rejected by the hook
2039 sed -e "s/add master/x/" ../0001-add-master.patch >../another.patch &&
2040 test_must_fail git send-email \
2041 --from="Example <nobody@example.com>" \
2042 --to=nobody@example.com \
2043 --smtp-server="$(pwd)/../fake.sendmail" \
2044 ../another.patch 2>err &&
2045 test_i18ngrep "rejected by sendemail-validate hook" err
2049 test_expect_success $PREREQ 'test that send-email works outside a repo' '
2050 nongit git send-email \
2051 --from="Example <nobody@example.com>" \
2052 --to=nobody@example.com \
2053 --smtp-server="$(pwd)/fake.sendmail" \
2054 "$(pwd)/0001-add-master.patch"
2057 test_done