Seventh batch for 2.20
[git/debian.git] / t / t9001-send-email.sh
blob1ef1a19003db5c9be94197e9d6cb25110591705b
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
495 done
497 test_expect_success $PREREQ 'Invalid In-Reply-To' '
498 clean_fake_sendmail &&
499 git send-email \
500 --from="Example <nobody@example.com>" \
501 --to=nobody@example.com \
502 --in-reply-to=" " \
503 --smtp-server="$(pwd)/fake.sendmail" \
504 $patches \
505 2>errors &&
506 ! grep "^In-Reply-To: < *>" msgtxt1
509 test_expect_success $PREREQ 'Valid In-Reply-To when prompting' '
510 clean_fake_sendmail &&
511 (echo "From Example <from@example.com>" &&
512 echo "To Example <to@example.com>" &&
513 echo ""
514 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
515 --smtp-server="$(pwd)/fake.sendmail" \
516 $patches 2>errors &&
517 ! grep "^In-Reply-To: < *>" msgtxt1
520 test_expect_success $PREREQ 'In-Reply-To without --chain-reply-to' '
521 clean_fake_sendmail &&
522 echo "<unique-message-id@example.com>" >expect &&
523 git send-email \
524 --from="Example <nobody@example.com>" \
525 --to=nobody@example.com \
526 --no-chain-reply-to \
527 --in-reply-to="$(cat expect)" \
528 --smtp-server="$(pwd)/fake.sendmail" \
529 $patches $patches $patches \
530 2>errors &&
531 # The first message is a reply to --in-reply-to
532 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
533 test_cmp expect actual &&
534 # Second and subsequent messages are replies to the first one
535 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
536 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
537 test_cmp expect actual &&
538 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
539 test_cmp expect actual
542 test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' '
543 clean_fake_sendmail &&
544 echo "<unique-message-id@example.com>" >expect &&
545 git send-email \
546 --from="Example <nobody@example.com>" \
547 --to=nobody@example.com \
548 --chain-reply-to \
549 --in-reply-to="$(cat expect)" \
550 --smtp-server="$(pwd)/fake.sendmail" \
551 $patches $patches $patches \
552 2>errors &&
553 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
554 test_cmp expect actual &&
555 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
556 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
557 test_cmp expect actual &&
558 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt2 >expect &&
559 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
560 test_cmp expect actual
563 test_expect_success $PREREQ 'setup fake editor' '
564 write_script fake-editor <<-\EOF
565 echo fake edit >>"$1"
569 test_set_editor "$(pwd)/fake-editor"
571 test_expect_success $PREREQ '--compose works' '
572 clean_fake_sendmail &&
573 git send-email \
574 --compose --subject foo \
575 --from="Example <nobody@example.com>" \
576 --to=nobody@example.com \
577 --smtp-server="$(pwd)/fake.sendmail" \
578 $patches \
579 2>errors
582 test_expect_success $PREREQ 'first message is compose text' '
583 grep "^fake edit" msgtxt1
586 test_expect_success $PREREQ 'second message is patch' '
587 grep "Subject:.*Second" msgtxt2
590 test_expect_success $PREREQ 'setup expect' "
591 cat >expected-suppress-sob <<\EOF
592 0001-Second.patch
593 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
594 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
595 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
596 Dry-OK. Log says:
597 Server: relay.example.com
598 MAIL FROM:<from@example.com>
599 RCPT TO:<to@example.com>
600 RCPT TO:<cc@example.com>
601 RCPT TO:<author@example.com>
602 RCPT TO:<one@example.com>
603 RCPT TO:<two@example.com>
604 From: Example <from@example.com>
605 To: to@example.com
606 Cc: cc@example.com,
607 A <author@example.com>,
608 One <one@example.com>,
609 two@example.com
610 Subject: [PATCH 1/1] Second.
611 Date: DATE-STRING
612 Message-Id: MESSAGE-ID-STRING
613 X-Mailer: X-MAILER-STRING
614 MIME-Version: 1.0
615 Content-Transfer-Encoding: 8bit
617 Result: OK
621 test_suppression () {
622 git send-email \
623 --dry-run \
624 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
625 --from="Example <from@example.com>" \
626 --to=to@example.com \
627 --smtp-server relay.example.com \
628 $patches | replace_variable_fields \
629 >actual-suppress-$1${2+"-$2"} &&
630 test_cmp expected-suppress-$1${2+"-$2"} actual-suppress-$1${2+"-$2"}
633 test_expect_success $PREREQ 'sendemail.cc set' '
634 git config sendemail.cc cc@example.com &&
635 test_suppression sob
638 test_expect_success $PREREQ 'setup expect' "
639 cat >expected-suppress-sob <<\EOF
640 0001-Second.patch
641 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
642 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
643 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
644 Dry-OK. Log says:
645 Server: relay.example.com
646 MAIL FROM:<from@example.com>
647 RCPT TO:<to@example.com>
648 RCPT TO:<author@example.com>
649 RCPT TO:<one@example.com>
650 RCPT TO:<two@example.com>
651 From: Example <from@example.com>
652 To: to@example.com
653 Cc: A <author@example.com>,
654 One <one@example.com>,
655 two@example.com
656 Subject: [PATCH 1/1] Second.
657 Date: DATE-STRING
658 Message-Id: MESSAGE-ID-STRING
659 X-Mailer: X-MAILER-STRING
660 MIME-Version: 1.0
661 Content-Transfer-Encoding: 8bit
663 Result: OK
667 test_expect_success $PREREQ 'sendemail.cc unset' '
668 git config --unset sendemail.cc &&
669 test_suppression sob
672 test_expect_success $PREREQ 'setup expect' "
673 cat >expected-suppress-cccmd <<\EOF
674 0001-Second.patch
675 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
676 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
677 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
678 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
679 Dry-OK. Log says:
680 Server: relay.example.com
681 MAIL FROM:<from@example.com>
682 RCPT TO:<to@example.com>
683 RCPT TO:<author@example.com>
684 RCPT TO:<one@example.com>
685 RCPT TO:<two@example.com>
686 RCPT TO:<committer@example.com>
687 From: Example <from@example.com>
688 To: to@example.com
689 Cc: A <author@example.com>,
690 One <one@example.com>,
691 two@example.com,
692 C O Mitter <committer@example.com>
693 Subject: [PATCH 1/1] Second.
694 Date: DATE-STRING
695 Message-Id: MESSAGE-ID-STRING
696 X-Mailer: X-MAILER-STRING
697 MIME-Version: 1.0
698 Content-Transfer-Encoding: 8bit
700 Result: OK
704 test_expect_success $PREREQ 'sendemail.cccmd' '
705 write_script cccmd <<-\EOF &&
706 echo cc-cmd@example.com
708 git config sendemail.cccmd ./cccmd &&
709 test_suppression cccmd
712 test_expect_success $PREREQ 'setup expect' '
713 cat >expected-suppress-all <<\EOF
714 0001-Second.patch
715 Dry-OK. Log says:
716 Server: relay.example.com
717 MAIL FROM:<from@example.com>
718 RCPT TO:<to@example.com>
719 From: Example <from@example.com>
720 To: to@example.com
721 Subject: [PATCH 1/1] Second.
722 Date: DATE-STRING
723 Message-Id: MESSAGE-ID-STRING
724 X-Mailer: X-MAILER-STRING
725 MIME-Version: 1.0
726 Content-Transfer-Encoding: 8bit
728 Result: OK
732 test_expect_success $PREREQ '--suppress-cc=all' '
733 test_suppression all
736 test_expect_success $PREREQ 'setup expect' "
737 cat >expected-suppress-body <<\EOF
738 0001-Second.patch
739 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
740 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
741 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
742 (cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
743 Dry-OK. Log says:
744 Server: relay.example.com
745 MAIL FROM:<from@example.com>
746 RCPT TO:<to@example.com>
747 RCPT TO:<author@example.com>
748 RCPT TO:<one@example.com>
749 RCPT TO:<two@example.com>
750 RCPT TO:<cc-cmd@example.com>
751 From: Example <from@example.com>
752 To: to@example.com
753 Cc: A <author@example.com>,
754 One <one@example.com>,
755 two@example.com,
756 cc-cmd@example.com
757 Subject: [PATCH 1/1] Second.
758 Date: DATE-STRING
759 Message-Id: MESSAGE-ID-STRING
760 X-Mailer: X-MAILER-STRING
761 MIME-Version: 1.0
762 Content-Transfer-Encoding: 8bit
764 Result: OK
768 test_expect_success $PREREQ '--suppress-cc=body' '
769 test_suppression body
772 test_expect_success $PREREQ 'setup expect' "
773 cat >expected-suppress-body-cccmd <<\EOF
774 0001-Second.patch
775 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
776 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
777 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
778 Dry-OK. Log says:
779 Server: relay.example.com
780 MAIL FROM:<from@example.com>
781 RCPT TO:<to@example.com>
782 RCPT TO:<author@example.com>
783 RCPT TO:<one@example.com>
784 RCPT TO:<two@example.com>
785 From: Example <from@example.com>
786 To: to@example.com
787 Cc: A <author@example.com>,
788 One <one@example.com>,
789 two@example.com
790 Subject: [PATCH 1/1] Second.
791 Date: DATE-STRING
792 Message-Id: MESSAGE-ID-STRING
793 X-Mailer: X-MAILER-STRING
794 MIME-Version: 1.0
795 Content-Transfer-Encoding: 8bit
797 Result: OK
801 test_expect_success $PREREQ '--suppress-cc=body --suppress-cc=cccmd' '
802 test_suppression body cccmd
805 test_expect_success $PREREQ 'setup expect' "
806 cat >expected-suppress-sob <<\EOF
807 0001-Second.patch
808 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
809 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
810 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
811 Dry-OK. Log says:
812 Server: relay.example.com
813 MAIL FROM:<from@example.com>
814 RCPT TO:<to@example.com>
815 RCPT TO:<author@example.com>
816 RCPT TO:<one@example.com>
817 RCPT TO:<two@example.com>
818 From: Example <from@example.com>
819 To: to@example.com
820 Cc: A <author@example.com>,
821 One <one@example.com>,
822 two@example.com
823 Subject: [PATCH 1/1] Second.
824 Date: DATE-STRING
825 Message-Id: MESSAGE-ID-STRING
826 X-Mailer: X-MAILER-STRING
827 MIME-Version: 1.0
828 Content-Transfer-Encoding: 8bit
830 Result: OK
834 test_expect_success $PREREQ '--suppress-cc=sob' '
835 test_might_fail git config --unset sendemail.cccmd &&
836 test_suppression sob
839 test_expect_success $PREREQ 'setup expect' "
840 cat >expected-suppress-bodycc <<\EOF
841 0001-Second.patch
842 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
843 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
844 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
845 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
846 Dry-OK. Log says:
847 Server: relay.example.com
848 MAIL FROM:<from@example.com>
849 RCPT TO:<to@example.com>
850 RCPT TO:<author@example.com>
851 RCPT TO:<one@example.com>
852 RCPT TO:<two@example.com>
853 RCPT TO:<committer@example.com>
854 From: Example <from@example.com>
855 To: to@example.com
856 Cc: A <author@example.com>,
857 One <one@example.com>,
858 two@example.com,
859 C O Mitter <committer@example.com>
860 Subject: [PATCH 1/1] Second.
861 Date: DATE-STRING
862 Message-Id: MESSAGE-ID-STRING
863 X-Mailer: X-MAILER-STRING
864 MIME-Version: 1.0
865 Content-Transfer-Encoding: 8bit
867 Result: OK
871 test_expect_success $PREREQ '--suppress-cc=bodycc' '
872 test_suppression bodycc
875 test_expect_success $PREREQ 'setup expect' "
876 cat >expected-suppress-cc <<\EOF
877 0001-Second.patch
878 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
879 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
880 Dry-OK. Log says:
881 Server: relay.example.com
882 MAIL FROM:<from@example.com>
883 RCPT TO:<to@example.com>
884 RCPT TO:<author@example.com>
885 RCPT TO:<committer@example.com>
886 From: Example <from@example.com>
887 To: to@example.com
888 Cc: A <author@example.com>,
889 C O Mitter <committer@example.com>
890 Subject: [PATCH 1/1] Second.
891 Date: DATE-STRING
892 Message-Id: MESSAGE-ID-STRING
893 X-Mailer: X-MAILER-STRING
894 MIME-Version: 1.0
895 Content-Transfer-Encoding: 8bit
897 Result: OK
901 test_expect_success $PREREQ '--suppress-cc=cc' '
902 test_suppression cc
905 test_confirm () {
906 echo y | \
907 GIT_SEND_EMAIL_NOTTY=1 \
908 git send-email \
909 --from="Example <nobody@example.com>" \
910 --to=nobody@example.com \
911 --smtp-server="$(pwd)/fake.sendmail" \
912 $@ $patches >stdout &&
913 grep "Send this email" stdout
916 test_expect_success $PREREQ '--confirm=always' '
917 test_confirm --confirm=always --suppress-cc=all
920 test_expect_success $PREREQ '--confirm=auto' '
921 test_confirm --confirm=auto
924 test_expect_success $PREREQ '--confirm=cc' '
925 test_confirm --confirm=cc
928 test_expect_success $PREREQ '--confirm=compose' '
929 test_confirm --confirm=compose --compose
932 test_expect_success $PREREQ 'confirm by default (due to cc)' '
933 test_when_finished git config sendemail.confirm never &&
934 git config --unset sendemail.confirm &&
935 test_confirm
938 test_expect_success $PREREQ 'confirm by default (due to --compose)' '
939 test_when_finished git config sendemail.confirm never &&
940 git config --unset sendemail.confirm &&
941 test_confirm --suppress-cc=all --compose
944 test_expect_success $PREREQ 'confirm detects EOF (inform assumes y)' '
945 test_when_finished git config sendemail.confirm never &&
946 git config --unset sendemail.confirm &&
947 rm -fr outdir &&
948 git format-patch -2 -o outdir &&
949 GIT_SEND_EMAIL_NOTTY=1 \
950 git send-email \
951 --from="Example <nobody@example.com>" \
952 --to=nobody@example.com \
953 --smtp-server="$(pwd)/fake.sendmail" \
954 outdir/*.patch </dev/null
957 test_expect_success $PREREQ 'confirm detects EOF (auto causes failure)' '
958 test_when_finished git config sendemail.confirm never &&
959 git config sendemail.confirm auto &&
960 GIT_SEND_EMAIL_NOTTY=1 &&
961 export GIT_SEND_EMAIL_NOTTY &&
962 test_must_fail git send-email \
963 --from="Example <nobody@example.com>" \
964 --to=nobody@example.com \
965 --smtp-server="$(pwd)/fake.sendmail" \
966 $patches </dev/null
969 test_expect_success $PREREQ 'confirm does not loop forever' '
970 test_when_finished git config sendemail.confirm never &&
971 git config sendemail.confirm auto &&
972 GIT_SEND_EMAIL_NOTTY=1 &&
973 export GIT_SEND_EMAIL_NOTTY &&
974 yes "bogus" | test_must_fail git send-email \
975 --from="Example <nobody@example.com>" \
976 --to=nobody@example.com \
977 --smtp-server="$(pwd)/fake.sendmail" \
978 $patches
981 test_expect_success $PREREQ 'utf8 Cc is rfc2047 encoded' '
982 clean_fake_sendmail &&
983 rm -fr outdir &&
984 git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
985 git send-email \
986 --from="Example <nobody@example.com>" \
987 --to=nobody@example.com \
988 --smtp-server="$(pwd)/fake.sendmail" \
989 outdir/*.patch &&
990 grep "^ " msgtxt1 |
991 grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
994 test_expect_success $PREREQ '--compose adds MIME for utf8 body' '
995 clean_fake_sendmail &&
996 write_script fake-editor-utf8 <<-\EOF &&
997 echo "utf8 body: àéìöú" >>"$1"
999 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1000 git send-email \
1001 --compose --subject foo \
1002 --from="Example <nobody@example.com>" \
1003 --to=nobody@example.com \
1004 --smtp-server="$(pwd)/fake.sendmail" \
1005 $patches &&
1006 grep "^utf8 body" msgtxt1 &&
1007 grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
1010 test_expect_success $PREREQ '--compose respects user mime type' '
1011 clean_fake_sendmail &&
1012 write_script fake-editor-utf8-mime <<-\EOF &&
1013 cat >"$1" <<-\EOM
1014 MIME-Version: 1.0
1015 Content-Type: text/plain; charset=iso-8859-1
1016 Content-Transfer-Encoding: 8bit
1017 Subject: foo
1019 utf8 body: àéìöú
1022 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
1023 git send-email \
1024 --compose --subject foo \
1025 --from="Example <nobody@example.com>" \
1026 --to=nobody@example.com \
1027 --smtp-server="$(pwd)/fake.sendmail" \
1028 $patches &&
1029 grep "^utf8 body" msgtxt1 &&
1030 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
1031 ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
1034 test_expect_success $PREREQ '--compose adds MIME for utf8 subject' '
1035 clean_fake_sendmail &&
1036 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
1037 git send-email \
1038 --compose --subject utf8-sübjëct \
1039 --from="Example <nobody@example.com>" \
1040 --to=nobody@example.com \
1041 --smtp-server="$(pwd)/fake.sendmail" \
1042 $patches &&
1043 grep "^fake edit" msgtxt1 &&
1044 grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
1047 test_expect_success $PREREQ 'utf8 author is correctly passed on' '
1048 clean_fake_sendmail &&
1049 test_commit weird_author &&
1050 test_when_finished "git reset --hard HEAD^" &&
1051 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
1052 git format-patch --stdout -1 >funny_name.patch &&
1053 git send-email --from="Example <nobody@example.com>" \
1054 --to=nobody@example.com \
1055 --smtp-server="$(pwd)/fake.sendmail" \
1056 funny_name.patch &&
1057 grep "^From: Füñný Nâmé <odd_?=mail@example.com>" msgtxt1
1060 test_expect_success $PREREQ 'utf8 sender is not duplicated' '
1061 clean_fake_sendmail &&
1062 test_commit weird_sender &&
1063 test_when_finished "git reset --hard HEAD^" &&
1064 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
1065 git format-patch --stdout -1 >funny_name.patch &&
1066 git send-email --from="Füñný Nâmé <odd_?=mail@example.com>" \
1067 --to=nobody@example.com \
1068 --smtp-server="$(pwd)/fake.sendmail" \
1069 funny_name.patch &&
1070 grep "^From: " msgtxt1 >msgfrom &&
1071 test_line_count = 1 msgfrom
1074 test_expect_success $PREREQ 'sendemail.composeencoding works' '
1075 clean_fake_sendmail &&
1076 git config sendemail.composeencoding iso-8859-1 &&
1077 write_script fake-editor-utf8 <<-\EOF &&
1078 echo "utf8 body: àéìöú" >>"$1"
1080 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1081 git send-email \
1082 --compose --subject foo \
1083 --from="Example <nobody@example.com>" \
1084 --to=nobody@example.com \
1085 --smtp-server="$(pwd)/fake.sendmail" \
1086 $patches &&
1087 grep "^utf8 body" msgtxt1 &&
1088 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1091 test_expect_success $PREREQ '--compose-encoding works' '
1092 clean_fake_sendmail &&
1093 write_script fake-editor-utf8 <<-\EOF &&
1094 echo "utf8 body: àéìöú" >>"$1"
1096 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1097 git send-email \
1098 --compose-encoding iso-8859-1 \
1099 --compose --subject foo \
1100 --from="Example <nobody@example.com>" \
1101 --to=nobody@example.com \
1102 --smtp-server="$(pwd)/fake.sendmail" \
1103 $patches &&
1104 grep "^utf8 body" msgtxt1 &&
1105 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1108 test_expect_success $PREREQ '--compose-encoding overrides sendemail.composeencoding' '
1109 clean_fake_sendmail &&
1110 git config sendemail.composeencoding iso-8859-1 &&
1111 write_script fake-editor-utf8 <<-\EOF &&
1112 echo "utf8 body: àéìöú" >>"$1"
1114 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1115 git send-email \
1116 --compose-encoding iso-8859-2 \
1117 --compose --subject foo \
1118 --from="Example <nobody@example.com>" \
1119 --to=nobody@example.com \
1120 --smtp-server="$(pwd)/fake.sendmail" \
1121 $patches &&
1122 grep "^utf8 body" msgtxt1 &&
1123 grep "^Content-Type: text/plain; charset=iso-8859-2" msgtxt1
1126 test_expect_success $PREREQ '--compose-encoding adds correct MIME for subject' '
1127 clean_fake_sendmail &&
1128 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
1129 git send-email \
1130 --compose-encoding iso-8859-2 \
1131 --compose --subject utf8-sübjëct \
1132 --from="Example <nobody@example.com>" \
1133 --to=nobody@example.com \
1134 --smtp-server="$(pwd)/fake.sendmail" \
1135 $patches &&
1136 grep "^fake edit" msgtxt1 &&
1137 grep "^Subject: =?iso-8859-2?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
1140 test_expect_success $PREREQ 'detects ambiguous reference/file conflict' '
1141 echo master >master &&
1142 git add master &&
1143 git commit -m"add master" &&
1144 test_must_fail git send-email --dry-run master 2>errors &&
1145 grep disambiguate errors
1148 test_expect_success $PREREQ 'feed two files' '
1149 rm -fr outdir &&
1150 git format-patch -2 -o outdir &&
1151 git send-email \
1152 --dry-run \
1153 --from="Example <nobody@example.com>" \
1154 --to=nobody@example.com \
1155 outdir/000?-*.patch 2>errors >out &&
1156 grep "^Subject: " out >subjects &&
1157 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
1158 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"
1161 test_expect_success $PREREQ 'in-reply-to but no threading' '
1162 git send-email \
1163 --dry-run \
1164 --from="Example <nobody@example.com>" \
1165 --to=nobody@example.com \
1166 --in-reply-to="<in-reply-id@example.com>" \
1167 --no-thread \
1168 $patches |
1169 grep "In-Reply-To: <in-reply-id@example.com>"
1172 test_expect_success $PREREQ 'no in-reply-to and no threading' '
1173 git send-email \
1174 --dry-run \
1175 --from="Example <nobody@example.com>" \
1176 --to=nobody@example.com \
1177 --no-thread \
1178 $patches $patches >stdout &&
1179 ! grep "In-Reply-To: " stdout
1182 test_expect_success $PREREQ 'threading but no chain-reply-to' '
1183 git send-email \
1184 --dry-run \
1185 --from="Example <nobody@example.com>" \
1186 --to=nobody@example.com \
1187 --thread \
1188 --no-chain-reply-to \
1189 $patches $patches >stdout &&
1190 grep "In-Reply-To: " stdout
1193 test_expect_success $PREREQ 'sendemail.to works' '
1194 git config --replace-all sendemail.to "Somebody <somebody@ex.com>" &&
1195 git send-email \
1196 --dry-run \
1197 --from="Example <nobody@example.com>" \
1198 $patches $patches >stdout &&
1199 grep "To: Somebody <somebody@ex.com>" stdout
1202 test_expect_success $PREREQ '--no-to overrides sendemail.to' '
1203 git send-email \
1204 --dry-run \
1205 --from="Example <nobody@example.com>" \
1206 --no-to \
1207 --to=nobody@example.com \
1208 $patches $patches >stdout &&
1209 grep "To: nobody@example.com" stdout &&
1210 ! grep "To: Somebody <somebody@ex.com>" stdout
1213 test_expect_success $PREREQ 'sendemail.cc works' '
1214 git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" &&
1215 git send-email \
1216 --dry-run \
1217 --from="Example <nobody@example.com>" \
1218 --to=nobody@example.com \
1219 $patches $patches >stdout &&
1220 grep "Cc: Somebody <somebody@ex.com>" stdout
1223 test_expect_success $PREREQ '--no-cc overrides sendemail.cc' '
1224 git send-email \
1225 --dry-run \
1226 --from="Example <nobody@example.com>" \
1227 --no-cc \
1228 --cc=bodies@example.com \
1229 --to=nobody@example.com \
1230 $patches $patches >stdout &&
1231 grep "Cc: bodies@example.com" stdout &&
1232 ! grep "Cc: Somebody <somebody@ex.com>" stdout
1235 test_expect_success $PREREQ 'sendemail.bcc works' '
1236 git config --replace-all sendemail.bcc "Other <other@ex.com>" &&
1237 git send-email \
1238 --dry-run \
1239 --from="Example <nobody@example.com>" \
1240 --to=nobody@example.com \
1241 --smtp-server relay.example.com \
1242 $patches $patches >stdout &&
1243 grep "RCPT TO:<other@ex.com>" stdout
1246 test_expect_success $PREREQ '--no-bcc overrides sendemail.bcc' '
1247 git send-email \
1248 --dry-run \
1249 --from="Example <nobody@example.com>" \
1250 --no-bcc \
1251 --bcc=bodies@example.com \
1252 --to=nobody@example.com \
1253 --smtp-server relay.example.com \
1254 $patches $patches >stdout &&
1255 grep "RCPT TO:<bodies@example.com>" stdout &&
1256 ! grep "RCPT TO:<other@ex.com>" stdout
1259 test_expect_success $PREREQ 'patches To headers are used by default' '
1260 patch=$(git format-patch -1 --to="bodies@example.com") &&
1261 test_when_finished "rm $patch" &&
1262 git send-email \
1263 --dry-run \
1264 --from="Example <nobody@example.com>" \
1265 --smtp-server relay.example.com \
1266 $patch >stdout &&
1267 grep "RCPT TO:<bodies@example.com>" stdout
1270 test_expect_success $PREREQ 'patches To headers are appended to' '
1271 patch=$(git format-patch -1 --to="bodies@example.com") &&
1272 test_when_finished "rm $patch" &&
1273 git send-email \
1274 --dry-run \
1275 --from="Example <nobody@example.com>" \
1276 --to=nobody@example.com \
1277 --smtp-server relay.example.com \
1278 $patch >stdout &&
1279 grep "RCPT TO:<bodies@example.com>" stdout &&
1280 grep "RCPT TO:<nobody@example.com>" stdout
1283 test_expect_success $PREREQ 'To headers from files reset each patch' '
1284 patch1=$(git format-patch -1 --to="bodies@example.com") &&
1285 patch2=$(git format-patch -1 --to="other@example.com" HEAD~) &&
1286 test_when_finished "rm $patch1 && rm $patch2" &&
1287 git send-email \
1288 --dry-run \
1289 --from="Example <nobody@example.com>" \
1290 --to="nobody@example.com" \
1291 --smtp-server relay.example.com \
1292 $patch1 $patch2 >stdout &&
1293 test $(grep -c "RCPT TO:<bodies@example.com>" stdout) = 1 &&
1294 test $(grep -c "RCPT TO:<nobody@example.com>" stdout) = 2 &&
1295 test $(grep -c "RCPT TO:<other@example.com>" stdout) = 1
1298 test_expect_success $PREREQ 'setup expect' '
1299 cat >email-using-8bit <<\EOF
1300 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1301 Message-Id: <bogus-message-id@example.com>
1302 From: author@example.com
1303 Date: Sat, 12 Jun 2010 15:53:58 +0200
1304 Subject: subject goes here
1306 Dieser deutsche Text enthält einen Umlaut!
1310 test_expect_success $PREREQ 'setup expect' '
1311 echo "Subject: subject goes here" >expected
1314 test_expect_success $PREREQ 'ASCII subject is not RFC2047 quoted' '
1315 clean_fake_sendmail &&
1316 echo bogus |
1317 git send-email --from=author@example.com --to=nobody@example.com \
1318 --smtp-server="$(pwd)/fake.sendmail" \
1319 --8bit-encoding=UTF-8 \
1320 email-using-8bit >stdout &&
1321 grep "Subject" msgtxt1 >actual &&
1322 test_cmp expected actual
1325 test_expect_success $PREREQ 'setup expect' '
1326 cat >content-type-decl <<-\EOF
1327 MIME-Version: 1.0
1328 Content-Type: text/plain; charset=UTF-8
1329 Content-Transfer-Encoding: 8bit
1333 test_expect_success $PREREQ 'asks about and fixes 8bit encodings' '
1334 clean_fake_sendmail &&
1335 echo |
1336 git send-email --from=author@example.com --to=nobody@example.com \
1337 --smtp-server="$(pwd)/fake.sendmail" \
1338 email-using-8bit >stdout &&
1339 grep "do not declare a Content-Transfer-Encoding" stdout &&
1340 grep email-using-8bit stdout &&
1341 grep "Which 8bit encoding" stdout &&
1342 egrep "Content|MIME" msgtxt1 >actual &&
1343 test_cmp content-type-decl actual
1346 test_expect_success $PREREQ 'sendemail.8bitEncoding works' '
1347 clean_fake_sendmail &&
1348 git config sendemail.assume8bitEncoding UTF-8 &&
1349 echo bogus |
1350 git send-email --from=author@example.com --to=nobody@example.com \
1351 --smtp-server="$(pwd)/fake.sendmail" \
1352 email-using-8bit >stdout &&
1353 egrep "Content|MIME" msgtxt1 >actual &&
1354 test_cmp content-type-decl actual
1357 test_expect_success $PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
1358 clean_fake_sendmail &&
1359 git config sendemail.assume8bitEncoding "bogus too" &&
1360 echo bogus |
1361 git send-email --from=author@example.com --to=nobody@example.com \
1362 --smtp-server="$(pwd)/fake.sendmail" \
1363 --8bit-encoding=UTF-8 \
1364 email-using-8bit >stdout &&
1365 egrep "Content|MIME" msgtxt1 >actual &&
1366 test_cmp content-type-decl actual
1369 test_expect_success $PREREQ 'setup expect' '
1370 cat >email-using-8bit <<-\EOF
1371 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1372 Message-Id: <bogus-message-id@example.com>
1373 From: author@example.com
1374 Date: Sat, 12 Jun 2010 15:53:58 +0200
1375 Subject: Dieser Betreff enthält auch einen Umlaut!
1377 Nothing to see here.
1381 test_expect_success $PREREQ 'setup expect' '
1382 cat >expected <<-\EOF
1383 Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
1387 test_expect_success $PREREQ '--8bit-encoding also treats subject' '
1388 clean_fake_sendmail &&
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 grep "Subject" msgtxt1 >actual &&
1395 test_cmp expected 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: A U Thor <author@example.com>
1403 Date: Sat, 12 Jun 2010 15:53:58 +0200
1404 Content-Type: text/plain; charset=UTF-8
1405 Subject: Nothing to see here.
1407 Dieser Betreff enthält auch einen Umlaut!
1411 test_expect_success $PREREQ 'sendemail.transferencoding=7bit fails on 8bit data' '
1412 clean_fake_sendmail &&
1413 git config sendemail.transferEncoding 7bit &&
1414 test_must_fail git send-email \
1415 --transfer-encoding=7bit \
1416 --smtp-server="$(pwd)/fake.sendmail" \
1417 email-using-8bit \
1418 2>errors >out &&
1419 grep "cannot send message as 7bit" errors &&
1420 test -z "$(ls msgtxt*)"
1423 test_expect_success $PREREQ '--transfer-encoding overrides sendemail.transferEncoding' '
1424 clean_fake_sendmail &&
1425 git config sendemail.transferEncoding 8bit &&
1426 test_must_fail git send-email \
1427 --transfer-encoding=7bit \
1428 --smtp-server="$(pwd)/fake.sendmail" \
1429 email-using-8bit \
1430 2>errors >out &&
1431 grep "cannot send message as 7bit" errors &&
1432 test -z "$(ls msgtxt*)"
1435 test_expect_success $PREREQ 'sendemail.transferencoding=8bit' '
1436 clean_fake_sendmail &&
1437 git send-email \
1438 --transfer-encoding=8bit \
1439 --smtp-server="$(pwd)/fake.sendmail" \
1440 email-using-8bit \
1441 2>errors >out &&
1442 sed '1,/^$/d' msgtxt1 >actual &&
1443 sed '1,/^$/d' email-using-8bit >expected &&
1444 test_cmp expected actual
1447 test_expect_success $PREREQ 'setup expect' '
1448 cat >expected <<-\EOF
1449 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1453 test_expect_success $PREREQ '8-bit and sendemail.transferencoding=quoted-printable' '
1454 clean_fake_sendmail &&
1455 git send-email \
1456 --transfer-encoding=quoted-printable \
1457 --smtp-server="$(pwd)/fake.sendmail" \
1458 email-using-8bit \
1459 2>errors >out &&
1460 sed '1,/^$/d' msgtxt1 >actual &&
1461 test_cmp expected actual
1464 test_expect_success $PREREQ 'setup expect' '
1465 cat >expected <<-\EOF
1466 RGllc2VyIEJldHJlZmYgZW50aMOkbHQgYXVjaCBlaW5lbiBVbWxhdXQhCg==
1470 test_expect_success $PREREQ '8-bit and sendemail.transferencoding=base64' '
1471 clean_fake_sendmail &&
1472 git send-email \
1473 --transfer-encoding=base64 \
1474 --smtp-server="$(pwd)/fake.sendmail" \
1475 email-using-8bit \
1476 2>errors >out &&
1477 sed '1,/^$/d' msgtxt1 >actual &&
1478 test_cmp expected actual
1481 test_expect_success $PREREQ 'setup expect' '
1482 cat >email-using-qp <<-\EOF
1483 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1484 Message-Id: <bogus-message-id@example.com>
1485 From: A U Thor <author@example.com>
1486 Date: Sat, 12 Jun 2010 15:53:58 +0200
1487 MIME-Version: 1.0
1488 Content-Transfer-Encoding: quoted-printable
1489 Content-Type: text/plain; charset=UTF-8
1490 Subject: Nothing to see here.
1492 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1496 test_expect_success $PREREQ 'convert from quoted-printable to base64' '
1497 clean_fake_sendmail &&
1498 git send-email \
1499 --transfer-encoding=base64 \
1500 --smtp-server="$(pwd)/fake.sendmail" \
1501 email-using-qp \
1502 2>errors >out &&
1503 sed '1,/^$/d' msgtxt1 >actual &&
1504 test_cmp expected actual
1507 test_expect_success $PREREQ 'setup expect' "
1508 tr -d '\\015' | tr '%' '\\015' >email-using-crlf <<EOF
1509 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1510 Message-Id: <bogus-message-id@example.com>
1511 From: A U Thor <author@example.com>
1512 Date: Sat, 12 Jun 2010 15:53:58 +0200
1513 Content-Type: text/plain; charset=UTF-8
1514 Subject: Nothing to see here.
1516 Look, I have a CRLF and an = sign!%
1520 test_expect_success $PREREQ 'setup expect' '
1521 cat >expected <<-\EOF
1522 Look, I have a CRLF and an =3D sign!=0D
1526 test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=quoted-printable' '
1527 clean_fake_sendmail &&
1528 git send-email \
1529 --transfer-encoding=quoted-printable \
1530 --smtp-server="$(pwd)/fake.sendmail" \
1531 email-using-crlf \
1532 2>errors >out &&
1533 sed '1,/^$/d' msgtxt1 >actual &&
1534 test_cmp expected actual
1537 test_expect_success $PREREQ 'setup expect' '
1538 cat >expected <<-\EOF
1539 TG9vaywgSSBoYXZlIGEgQ1JMRiBhbmQgYW4gPSBzaWduIQ0K
1543 test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=base64' '
1544 clean_fake_sendmail &&
1545 git send-email \
1546 --transfer-encoding=base64 \
1547 --smtp-server="$(pwd)/fake.sendmail" \
1548 email-using-crlf \
1549 2>errors >out &&
1550 sed '1,/^$/d' msgtxt1 >actual &&
1551 test_cmp expected actual
1555 # Note that the patches in this test are deliberately out of order; we
1556 # want to make sure it works even if the cover-letter is not in the
1557 # first mail.
1558 test_expect_success $PREREQ 'refusing to send cover letter template' '
1559 clean_fake_sendmail &&
1560 rm -fr outdir &&
1561 git format-patch --cover-letter -2 -o outdir &&
1562 test_must_fail git send-email \
1563 --from="Example <nobody@example.com>" \
1564 --to=nobody@example.com \
1565 --smtp-server="$(pwd)/fake.sendmail" \
1566 outdir/0002-*.patch \
1567 outdir/0000-*.patch \
1568 outdir/0001-*.patch \
1569 2>errors >out &&
1570 grep "SUBJECT HERE" errors &&
1571 test -z "$(ls msgtxt*)"
1574 test_expect_success $PREREQ '--force sends cover letter template anyway' '
1575 clean_fake_sendmail &&
1576 rm -fr outdir &&
1577 git format-patch --cover-letter -2 -o outdir &&
1578 git send-email \
1579 --force \
1580 --from="Example <nobody@example.com>" \
1581 --to=nobody@example.com \
1582 --smtp-server="$(pwd)/fake.sendmail" \
1583 outdir/0002-*.patch \
1584 outdir/0000-*.patch \
1585 outdir/0001-*.patch \
1586 2>errors >out &&
1587 ! grep "SUBJECT HERE" errors &&
1588 test -n "$(ls msgtxt*)"
1591 test_cover_addresses () {
1592 header="$1"
1593 shift
1594 clean_fake_sendmail &&
1595 rm -fr outdir &&
1596 git format-patch --cover-letter -2 -o outdir &&
1597 cover=$(echo outdir/0000-*.patch) &&
1598 mv $cover cover-to-edit.patch &&
1599 perl -pe "s/^From:/$header: extra\@address.com\nFrom:/" cover-to-edit.patch >"$cover" &&
1600 git send-email \
1601 --force \
1602 --from="Example <nobody@example.com>" \
1603 --no-to --no-cc \
1604 "$@" \
1605 --smtp-server="$(pwd)/fake.sendmail" \
1606 outdir/0000-*.patch \
1607 outdir/0001-*.patch \
1608 outdir/0002-*.patch \
1609 2>errors >out &&
1610 grep "^$header: extra@address.com" msgtxt1 >to1 &&
1611 grep "^$header: extra@address.com" msgtxt2 >to2 &&
1612 grep "^$header: extra@address.com" msgtxt3 >to3 &&
1613 test_line_count = 1 to1 &&
1614 test_line_count = 1 to2 &&
1615 test_line_count = 1 to3
1618 test_expect_success $PREREQ 'to-cover adds To to all mail' '
1619 test_cover_addresses "To" --to-cover
1622 test_expect_success $PREREQ 'cc-cover adds Cc to all mail' '
1623 test_cover_addresses "Cc" --cc-cover
1626 test_expect_success $PREREQ 'tocover adds To to all mail' '
1627 test_config sendemail.tocover true &&
1628 test_cover_addresses "To"
1631 test_expect_success $PREREQ 'cccover adds Cc to all mail' '
1632 test_config sendemail.cccover true &&
1633 test_cover_addresses "Cc"
1636 test_expect_success $PREREQ 'escaped quotes in sendemail.aliasfiletype=mutt' '
1637 clean_fake_sendmail &&
1638 echo "alias sbd \\\"Dot U. Sir\\\" <somebody@example.org>" >.mutt &&
1639 git config --replace-all sendemail.aliasesfile "$(pwd)/.mutt" &&
1640 git config sendemail.aliasfiletype mutt &&
1641 git send-email \
1642 --from="Example <nobody@example.com>" \
1643 --to=sbd \
1644 --smtp-server="$(pwd)/fake.sendmail" \
1645 outdir/0001-*.patch \
1646 2>errors >out &&
1647 grep "^!somebody@example\.org!$" commandline1 &&
1648 grep -F "To: \"Dot U. Sir\" <somebody@example.org>" out
1651 test_expect_success $PREREQ 'sendemail.aliasfiletype=mailrc' '
1652 clean_fake_sendmail &&
1653 echo "alias sbd somebody@example.org" >.mailrc &&
1654 git config --replace-all sendemail.aliasesfile "$(pwd)/.mailrc" &&
1655 git config sendemail.aliasfiletype mailrc &&
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
1665 test_expect_success $PREREQ 'sendemail.aliasfile=~/.mailrc' '
1666 clean_fake_sendmail &&
1667 echo "alias sbd someone@example.org" >"$HOME/.mailrc" &&
1668 git config --replace-all sendemail.aliasesfile "~/.mailrc" &&
1669 git config sendemail.aliasfiletype mailrc &&
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 "^!someone@example\.org!$" commandline1
1679 test_dump_aliases () {
1680 msg="$1" && shift &&
1681 filetype="$1" && shift &&
1682 printf '%s\n' "$@" >expect &&
1683 cat >.tmp-email-aliases &&
1685 test_expect_success $PREREQ "$msg" '
1686 clean_fake_sendmail && rm -fr outdir &&
1687 git config --replace-all sendemail.aliasesfile \
1688 "$(pwd)/.tmp-email-aliases" &&
1689 git config sendemail.aliasfiletype "$filetype" &&
1690 git send-email --dump-aliases 2>errors >actual &&
1691 test_cmp expect actual
1695 test_dump_aliases '--dump-aliases sendmail format' \
1696 'sendmail' \
1697 'abgroup' \
1698 'alice' \
1699 'bcgrp' \
1700 'bob' \
1701 'chloe' <<-\EOF
1702 alice: Alice W Land <awol@example.com>
1703 bob: Robert Bobbyton <bob@example.com>
1704 chloe: chloe@example.com
1705 abgroup: alice, bob
1706 bcgrp: bob, chloe, Other <o@example.com>
1709 test_dump_aliases '--dump-aliases mutt format' \
1710 'mutt' \
1711 'alice' \
1712 'bob' \
1713 'chloe' \
1714 'donald' <<-\EOF
1715 alias alice Alice W Land <awol@example.com>
1716 alias donald Donald C Carlton <donc@example.com>
1717 alias bob Robert Bobbyton <bob@example.com>
1718 alias chloe chloe@example.com
1721 test_dump_aliases '--dump-aliases mailrc format' \
1722 'mailrc' \
1723 'alice' \
1724 'bob' \
1725 'chloe' \
1726 'eve' <<-\EOF
1727 alias alice Alice W Land <awol@example.com>
1728 alias eve Eve <eve@example.com>
1729 alias bob Robert Bobbyton <bob@example.com>
1730 alias chloe chloe@example.com
1733 test_dump_aliases '--dump-aliases pine format' \
1734 'pine' \
1735 'alice' \
1736 'bob' \
1737 'chloe' \
1738 'eve' <<-\EOF
1739 alice Alice W Land <awol@example.com>
1740 eve Eve <eve@example.com>
1741 bob Robert Bobbyton <bob@example.com>
1742 chloe chloe@example.com
1745 test_dump_aliases '--dump-aliases gnus format' \
1746 'gnus' \
1747 'alice' \
1748 'bob' \
1749 'chloe' \
1750 'eve' <<-\EOF
1751 (define-mail-alias "alice" "awol@example.com")
1752 (define-mail-alias "eve" "eve@example.com")
1753 (define-mail-alias "bob" "bob@example.com")
1754 (define-mail-alias "chloe" "chloe@example.com")
1757 test_expect_success '--dump-aliases must be used alone' '
1758 test_must_fail git send-email --dump-aliases --to=janice@example.com -1 refs/heads/accounting
1761 test_sendmail_aliases () {
1762 msg="$1" && shift &&
1763 expect="$@" &&
1764 cat >.tmp-email-aliases &&
1766 test_expect_success $PREREQ "$msg" '
1767 clean_fake_sendmail && rm -fr outdir &&
1768 git format-patch -1 -o outdir &&
1769 git config --replace-all sendemail.aliasesfile \
1770 "$(pwd)/.tmp-email-aliases" &&
1771 git config sendemail.aliasfiletype sendmail &&
1772 git send-email \
1773 --from="Example <nobody@example.com>" \
1774 --to=alice --to=bcgrp \
1775 --smtp-server="$(pwd)/fake.sendmail" \
1776 outdir/0001-*.patch \
1777 2>errors >out &&
1778 for i in $expect
1780 grep "^!$i!$" commandline1 || return 1
1781 done
1785 test_sendmail_aliases 'sendemail.aliasfiletype=sendmail' \
1786 'awol@example\.com' \
1787 'bob@example\.com' \
1788 'chloe@example\.com' \
1789 'o@example\.com' <<-\EOF
1790 alice: Alice W Land <awol@example.com>
1791 bob: Robert Bobbyton <bob@example.com>
1792 # this is a comment
1793 # this is also a comment
1794 chloe: chloe@example.com
1795 abgroup: alice, bob
1796 bcgrp: bob, chloe, Other <o@example.com>
1799 test_sendmail_aliases 'sendmail aliases line folding' \
1800 alice1 \
1801 bob1 bob2 \
1802 chuck1 chuck2 \
1803 darla1 darla2 darla3 \
1804 elton1 elton2 elton3 \
1805 fred1 fred2 \
1806 greg1 <<-\EOF
1807 alice: alice1
1808 bob: bob1,\
1809 bob2
1810 chuck: chuck1,
1811 chuck2
1812 darla: darla1,\
1813 darla2,
1814 darla3
1815 elton: elton1,
1816 elton2,\
1817 elton3
1818 fred: fred1,\
1819 fred2
1820 greg: greg1
1821 bcgrp: bob, chuck, darla, elton, fred, greg
1824 test_sendmail_aliases 'sendmail aliases tolerate bogus line folding' \
1825 alice1 bob1 <<-\EOF
1826 alice: alice1
1827 bcgrp: bob1\
1830 test_sendmail_aliases 'sendmail aliases empty' alice bcgrp <<-\EOF
1833 test_expect_success $PREREQ 'alias support in To header' '
1834 clean_fake_sendmail &&
1835 echo "alias sbd someone@example.org" >.mailrc &&
1836 test_config sendemail.aliasesfile ".mailrc" &&
1837 test_config sendemail.aliasfiletype mailrc &&
1838 git format-patch --stdout -1 --to=sbd >aliased.patch &&
1839 git send-email \
1840 --from="Example <nobody@example.com>" \
1841 --smtp-server="$(pwd)/fake.sendmail" \
1842 aliased.patch \
1843 2>errors >out &&
1844 grep "^!someone@example\.org!$" commandline1
1847 test_expect_success $PREREQ 'alias support in Cc header' '
1848 clean_fake_sendmail &&
1849 echo "alias sbd someone@example.org" >.mailrc &&
1850 test_config sendemail.aliasesfile ".mailrc" &&
1851 test_config sendemail.aliasfiletype mailrc &&
1852 git format-patch --stdout -1 --cc=sbd >aliased.patch &&
1853 git send-email \
1854 --from="Example <nobody@example.com>" \
1855 --smtp-server="$(pwd)/fake.sendmail" \
1856 aliased.patch \
1857 2>errors >out &&
1858 grep "^!someone@example\.org!$" commandline1
1861 test_expect_success $PREREQ 'tocmd works with aliases' '
1862 clean_fake_sendmail &&
1863 echo "alias sbd someone@example.org" >.mailrc &&
1864 test_config sendemail.aliasesfile ".mailrc" &&
1865 test_config sendemail.aliasfiletype mailrc &&
1866 git format-patch --stdout -1 >tocmd.patch &&
1867 echo tocmd--sbd >>tocmd.patch &&
1868 git send-email \
1869 --from="Example <nobody@example.com>" \
1870 --to-cmd=./tocmd-sed \
1871 --smtp-server="$(pwd)/fake.sendmail" \
1872 tocmd.patch \
1873 2>errors >out &&
1874 grep "^!someone@example\.org!$" commandline1
1877 test_expect_success $PREREQ 'cccmd works with aliases' '
1878 clean_fake_sendmail &&
1879 echo "alias sbd someone@example.org" >.mailrc &&
1880 test_config sendemail.aliasesfile ".mailrc" &&
1881 test_config sendemail.aliasfiletype mailrc &&
1882 git format-patch --stdout -1 >cccmd.patch &&
1883 echo cccmd--sbd >>cccmd.patch &&
1884 git send-email \
1885 --from="Example <nobody@example.com>" \
1886 --cc-cmd=./cccmd-sed \
1887 --smtp-server="$(pwd)/fake.sendmail" \
1888 cccmd.patch \
1889 2>errors >out &&
1890 grep "^!someone@example\.org!$" commandline1
1893 do_xmailer_test () {
1894 expected=$1 params=$2 &&
1895 git format-patch -1 &&
1896 git send-email \
1897 --from="Example <nobody@example.com>" \
1898 --to=someone@example.com \
1899 --smtp-server="$(pwd)/fake.sendmail" \
1900 $params \
1901 0001-*.patch \
1902 2>errors >out &&
1903 { grep '^X-Mailer:' out || :; } >mailer &&
1904 test_line_count = $expected mailer
1907 test_expect_success $PREREQ '--[no-]xmailer without any configuration' '
1908 do_xmailer_test 1 "--xmailer" &&
1909 do_xmailer_test 0 "--no-xmailer"
1912 test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=true' '
1913 test_config sendemail.xmailer true &&
1914 do_xmailer_test 1 "" &&
1915 do_xmailer_test 0 "--no-xmailer" &&
1916 do_xmailer_test 1 "--xmailer"
1919 test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=false' '
1920 test_config sendemail.xmailer false &&
1921 do_xmailer_test 0 "" &&
1922 do_xmailer_test 0 "--no-xmailer" &&
1923 do_xmailer_test 1 "--xmailer"
1926 test_expect_success $PREREQ 'setup expected-list' '
1927 git send-email \
1928 --dry-run \
1929 --from="Example <from@example.com>" \
1930 --to="To 1 <to1@example.com>" \
1931 --to="to2@example.com" \
1932 --to="to3@example.com" \
1933 --cc="Cc 1 <cc1@example.com>" \
1934 --cc="Cc2 <cc2@example.com>" \
1935 --bcc="bcc1@example.com" \
1936 --bcc="bcc2@example.com" \
1937 0001-add-master.patch | replace_variable_fields \
1938 >expected-list
1941 test_expect_success $PREREQ 'use email list in --cc --to and --bcc' '
1942 git send-email \
1943 --dry-run \
1944 --from="Example <from@example.com>" \
1945 --to="To 1 <to1@example.com>, to2@example.com" \
1946 --to="to3@example.com" \
1947 --cc="Cc 1 <cc1@example.com>, Cc2 <cc2@example.com>" \
1948 --bcc="bcc1@example.com, bcc2@example.com" \
1949 0001-add-master.patch | replace_variable_fields \
1950 >actual-list &&
1951 test_cmp expected-list actual-list
1954 test_expect_success $PREREQ 'aliases work with email list' '
1955 echo "alias to2 to2@example.com" >.mutt &&
1956 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt &&
1957 test_config sendemail.aliasesfile ".mutt" &&
1958 test_config sendemail.aliasfiletype mutt &&
1959 git send-email \
1960 --dry-run \
1961 --from="Example <from@example.com>" \
1962 --to="To 1 <to1@example.com>, to2, to3@example.com" \
1963 --cc="cc1, Cc2 <cc2@example.com>" \
1964 --bcc="bcc1@example.com, bcc2@example.com" \
1965 0001-add-master.patch | replace_variable_fields \
1966 >actual-list &&
1967 test_cmp expected-list actual-list
1970 test_expect_success $PREREQ 'leading and trailing whitespaces are removed' '
1971 echo "alias to2 to2@example.com" >.mutt &&
1972 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt &&
1973 test_config sendemail.aliasesfile ".mutt" &&
1974 test_config sendemail.aliasfiletype mutt &&
1975 TO1=$(echo "QTo 1 <to1@example.com>" | q_to_tab) &&
1976 TO2=$(echo "QZto2" | qz_to_tab_space) &&
1977 CC1=$(echo "cc1" | append_cr) &&
1978 BCC1=$(echo "Q bcc1@example.com Q" | q_to_nul) &&
1979 git send-email \
1980 --dry-run \
1981 --from=" Example <from@example.com>" \
1982 --to="$TO1" \
1983 --to="$TO2" \
1984 --to=" to3@example.com " \
1985 --cc="$CC1" \
1986 --cc="Cc2 <cc2@example.com>" \
1987 --bcc="$BCC1" \
1988 --bcc="bcc2@example.com" \
1989 0001-add-master.patch | replace_variable_fields \
1990 >actual-list &&
1991 test_cmp expected-list actual-list
1994 test_expect_success $PREREQ 'invoke hook' '
1995 mkdir -p .git/hooks &&
1997 write_script .git/hooks/sendemail-validate <<-\EOF &&
1998 # test that we have the correct environment variable, pwd, and
1999 # argument
2000 case "$GIT_DIR" in
2001 *.git)
2002 true
2005 false
2007 esac &&
2008 test -f 0001-add-master.patch &&
2009 grep "add master" "$1"
2012 mkdir subdir &&
2014 # Test that it works even if we are not at the root of the
2015 # working tree
2016 cd subdir &&
2017 git send-email \
2018 --from="Example <nobody@example.com>" \
2019 --to=nobody@example.com \
2020 --smtp-server="$(pwd)/../fake.sendmail" \
2021 ../0001-add-master.patch &&
2023 # Verify error message when a patch is rejected by the hook
2024 sed -e "s/add master/x/" ../0001-add-master.patch >../another.patch &&
2025 test_must_fail git send-email \
2026 --from="Example <nobody@example.com>" \
2027 --to=nobody@example.com \
2028 --smtp-server="$(pwd)/../fake.sendmail" \
2029 ../another.patch 2>err &&
2030 test_i18ngrep "rejected by sendemail-validate hook" err
2034 test_expect_success $PREREQ 'test that send-email works outside a repo' '
2035 nongit git send-email \
2036 --from="Example <nobody@example.com>" \
2037 --to=nobody@example.com \
2038 --smtp-server="$(pwd)/fake.sendmail" \
2039 "$(pwd)/0001-add-master.patch"
2042 test_done