Revert "Add a helper function to compare file contents"
[alt-git.git] / t / t9001-send-email.sh
blob0f08a9542b3cd3af6bafe90eea0f2a86e3546fb0
1 #!/bin/sh
3 test_description='git send-email'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7 TEST_PASSES_SANITIZE_LEAK=true
8 . ./test-lib.sh
10 # May be altered later in the test
11 PREREQ="PERL"
13 replace_variable_fields () {
14 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
15 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
16 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/"
19 test_expect_success $PREREQ 'prepare reference tree' '
20 echo "1A quick brown fox jumps over the" >file &&
21 echo "lazy dog" >>file &&
22 git add file &&
23 GIT_AUTHOR_NAME="A" git commit -a -m "Initial."
26 test_expect_success $PREREQ 'Setup helper tool' '
27 write_script fake.sendmail <<-\EOF &&
28 shift
29 output=1
30 while test -f commandline$output
32 output=$(($output+1))
33 done
34 for a
36 echo "!$a!"
37 done >commandline$output
38 cat >"msgtxt$output"
39 EOF
40 git add fake.sendmail &&
41 GIT_AUTHOR_NAME="A" git commit -a -m "Second."
44 clean_fake_sendmail () {
45 rm -f commandline* msgtxt*
48 test_expect_success $PREREQ 'Extract patches' '
49 patches=$(git format-patch -s --cc="One <one@example.com>" --cc=two@example.com -n HEAD^1) &&
50 threaded_patches=$(git format-patch -o threaded -s --in-reply-to="format" HEAD^1)
53 # Test no confirm early to ensure remaining tests will not hang
54 test_no_confirm () {
55 rm -f no_confirm_okay
56 echo n | \
57 GIT_SEND_EMAIL_NOTTY=1 \
58 git send-email \
59 --from="Example <from@example.com>" \
60 --to=nobody@example.com \
61 --smtp-server="$(pwd)/fake.sendmail" \
62 $@ \
63 $patches >stdout &&
64 ! grep "Send this email" stdout &&
65 >no_confirm_okay
68 # Exit immediately to prevent hang if a no-confirm test fails
69 check_no_confirm () {
70 if ! test -f no_confirm_okay
71 then
72 say 'confirm test failed; skipping remaining tests to prevent hanging'
73 PREREQ="$PREREQ,CHECK_NO_CONFIRM"
75 return 0
78 test_expect_success $PREREQ 'No confirm with --suppress-cc' '
79 test_no_confirm --suppress-cc=sob &&
80 check_no_confirm
84 test_expect_success $PREREQ 'No confirm with --confirm=never' '
85 test_no_confirm --confirm=never &&
86 check_no_confirm
89 # leave sendemail.confirm set to never after this so that none of the
90 # remaining tests prompt unintentionally.
91 test_expect_success $PREREQ 'No confirm with sendemail.confirm=never' '
92 git config sendemail.confirm never &&
93 test_no_confirm --compose --subject=foo &&
94 check_no_confirm
97 test_expect_success $PREREQ 'Send patches' '
98 git send-email --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
101 test_expect_success $PREREQ 'setup expect' '
102 cat >expected <<-\EOF
103 !nobody@example.com!
104 !author@example.com!
105 !one@example.com!
106 !two@example.com!
110 test_expect_success $PREREQ 'Verify commandline' '
111 test_cmp expected commandline1
114 test_expect_success $PREREQ 'Send patches with --envelope-sender' '
115 clean_fake_sendmail &&
116 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
119 test_expect_success $PREREQ 'setup expect' '
120 cat >expected <<-\EOF
121 !patch@example.com!
122 !-i!
123 !nobody@example.com!
124 !author@example.com!
125 !one@example.com!
126 !two@example.com!
130 test_expect_success $PREREQ 'Verify commandline' '
131 test_cmp expected commandline1
134 test_expect_success $PREREQ 'Send patches with --envelope-sender=auto' '
135 clean_fake_sendmail &&
136 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
139 test_expect_success $PREREQ 'setup expect' '
140 cat >expected <<-\EOF
141 !nobody@example.com!
142 !-i!
143 !nobody@example.com!
144 !author@example.com!
145 !one@example.com!
146 !two@example.com!
150 test_expect_success $PREREQ 'Verify commandline' '
151 test_cmp expected commandline1
154 test_expect_success $PREREQ 'setup expect for cc trailer' "
155 cat >expected-cc <<\EOF
156 !recipient@example.com!
157 !author@example.com!
158 !one@example.com!
159 !two@example.com!
160 !three@example.com!
161 !four@example.com!
162 !five@example.com!
163 !six@example.com!
167 test_expect_success $PREREQ 'cc trailer with various syntax' '
168 test_commit cc-trailer &&
169 test_when_finished "git reset --hard HEAD^" &&
170 git commit --amend -F - <<-EOF &&
171 Test Cc: trailers.
173 Cc: one@example.com
174 Cc: <two@example.com> # trailing comments are ignored
175 Cc: <three@example.com>, <not.four@example.com> one address per line
176 Cc: "Some # Body" <four@example.com> [ <also.a.comment> ]
177 Cc: five@example.com # not.six@example.com
178 Cc: six@example.com, not.seven@example.com
180 clean_fake_sendmail &&
181 git send-email -1 --to=recipient@example.com \
182 --smtp-server="$(pwd)/fake.sendmail" &&
183 test_cmp expected-cc commandline1
186 test_expect_success $PREREQ 'setup fake get_maintainer.pl script for cc trailer' "
187 write_script expected-cc-script.sh <<-EOF
188 echo 'One Person <one@example.com> (supporter:THIS (FOO/bar))'
189 echo 'Two Person <two@example.com> (maintainer:THIS THING)'
190 echo 'Third List <three@example.com> (moderated list:THIS THING (FOO/bar))'
191 echo '<four@example.com> (moderated list:FOR THING)'
192 echo 'five@example.com (open list:FOR THING (FOO/bar))'
193 echo 'six@example.com (open list)'
197 test_expect_success $PREREQ 'cc trailer with get_maintainer.pl output' '
198 clean_fake_sendmail &&
199 git send-email -1 --to=recipient@example.com \
200 --cc-cmd=./expected-cc-script.sh \
201 --smtp-server="$(pwd)/fake.sendmail" &&
202 test_cmp expected-cc commandline1
205 test_expect_success $PREREQ 'setup expect' "
206 cat >expected-show-all-headers <<\EOF
207 0001-Second.patch
208 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
209 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
210 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
211 Dry-OK. Log says:
212 Server: relay.example.com
213 MAIL FROM:<from@example.com>
214 RCPT TO:<to@example.com>
215 RCPT TO:<cc@example.com>
216 RCPT TO:<author@example.com>
217 RCPT TO:<one@example.com>
218 RCPT TO:<two@example.com>
219 RCPT TO:<bcc@example.com>
220 From: Example <from@example.com>
221 To: to@example.com
222 Cc: cc@example.com,
223 A <author@example.com>,
224 One <one@example.com>,
225 two@example.com
226 Subject: [PATCH 1/1] Second.
227 Date: DATE-STRING
228 Message-Id: MESSAGE-ID-STRING
229 X-Mailer: X-MAILER-STRING
230 In-Reply-To: <unique-message-id@example.com>
231 References: <unique-message-id@example.com>
232 Reply-To: Reply <reply@example.com>
233 MIME-Version: 1.0
234 Content-Transfer-Encoding: 8bit
236 Result: OK
240 test_suppress_self () {
241 test_commit $3 &&
242 test_when_finished "git reset --hard HEAD^" &&
244 write_script cccmd-sed <<-EOF &&
245 sed -n -e s/^cccmd--//p "\$1"
248 git commit --amend --author="$1 <$2>" -F - &&
249 clean_fake_sendmail &&
250 git format-patch --stdout -1 >"suppress-self-$3.patch" &&
252 git send-email --from="$1 <$2>" \
253 --to=nobody@example.com \
254 --cc-cmd=./cccmd-sed \
255 --suppress-cc=self \
256 --smtp-server="$(pwd)/fake.sendmail" \
257 suppress-self-$3.patch &&
259 mv msgtxt1 msgtxt1-$3 &&
260 sed -e '/^$/q' msgtxt1-$3 >"msghdr1-$3" &&
262 (grep '^Cc:' msghdr1-$3 >"actual-no-cc-$3";
263 test_must_be_empty actual-no-cc-$3)
266 test_suppress_self_unquoted () {
267 test_suppress_self "$1" "$2" "unquoted-$3" <<-EOF
268 test suppress-cc.self unquoted-$3 with name $1 email $2
270 unquoted-$3
272 cccmd--$1 <$2>
274 Cc: $1 <$2>
275 Signed-off-by: $1 <$2>
279 test_suppress_self_quoted () {
280 test_suppress_self "$1" "$2" "quoted-$3" <<-EOF
281 test suppress-cc.self quoted-$3 with name $1 email $2
283 quoted-$3
285 cccmd--"$1" <$2>
287 Cc: $1 <$2>
288 Cc: "$1" <$2>
289 Signed-off-by: $1 <$2>
290 Signed-off-by: "$1" <$2>
294 test_expect_success $PREREQ 'self name is suppressed' "
295 test_suppress_self_unquoted 'A U Thor' 'author@example.com' \
296 'self_name_suppressed'
299 test_expect_success $PREREQ 'self name with dot is suppressed' "
300 test_suppress_self_quoted 'A U. Thor' 'author@example.com' \
301 'self_name_dot_suppressed'
304 test_expect_success $PREREQ 'non-ascii self name is suppressed' "
305 test_suppress_self_quoted 'Füñný Nâmé' 'odd_?=mail@example.com' \
306 'non_ascii_self_suppressed'
309 # This name is long enough to force format-patch to split it into multiple
310 # encoded-words, assuming it uses UTF-8 with the "Q" encoding.
311 test_expect_success $PREREQ 'long non-ascii self name is suppressed' "
312 test_suppress_self_quoted 'Ƒüñníęř €. Nâṁé' 'odd_?=mail@example.com' \
313 'long_non_ascii_self_suppressed'
316 test_expect_success $PREREQ 'sanitized self name is suppressed' "
317 test_suppress_self_unquoted '\"A U. Thor\"' 'author@example.com' \
318 'self_name_sanitized_suppressed'
321 test_expect_success $PREREQ 'Show all headers' '
322 git send-email \
323 --dry-run \
324 --suppress-cc=sob \
325 --from="Example <from@example.com>" \
326 --reply-to="Reply <reply@example.com>" \
327 --to=to@example.com \
328 --cc=cc@example.com \
329 --bcc=bcc@example.com \
330 --in-reply-to="<unique-message-id@example.com>" \
331 --smtp-server relay.example.com \
332 $patches | replace_variable_fields \
333 >actual-show-all-headers &&
334 test_cmp expected-show-all-headers actual-show-all-headers
337 test_expect_success $PREREQ 'Prompting works' '
338 clean_fake_sendmail &&
339 (echo "to@example.com" &&
340 echo "my-message-id@example.com"
341 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
342 --smtp-server="$(pwd)/fake.sendmail" \
343 $patches \
344 2>errors &&
345 grep "^From: A U Thor <author@example.com>\$" msgtxt1 &&
346 grep "^To: to@example.com\$" msgtxt1 &&
347 grep "^In-Reply-To: <my-message-id@example.com>" msgtxt1
350 test_expect_success $PREREQ,AUTOIDENT 'implicit ident is allowed' '
351 clean_fake_sendmail &&
352 (sane_unset GIT_AUTHOR_NAME &&
353 sane_unset GIT_AUTHOR_EMAIL &&
354 sane_unset GIT_COMMITTER_NAME &&
355 sane_unset GIT_COMMITTER_EMAIL &&
356 GIT_SEND_EMAIL_NOTTY=1 git send-email \
357 --smtp-server="$(pwd)/fake.sendmail" \
358 --to=to@example.com \
359 $patches </dev/null 2>errors
363 test_expect_success $PREREQ,!AUTOIDENT 'broken implicit ident aborts send-email' '
364 clean_fake_sendmail &&
365 (sane_unset GIT_AUTHOR_NAME &&
366 sane_unset GIT_AUTHOR_EMAIL &&
367 sane_unset GIT_COMMITTER_NAME &&
368 sane_unset GIT_COMMITTER_EMAIL &&
369 GIT_SEND_EMAIL_NOTTY=1 && export GIT_SEND_EMAIL_NOTTY &&
370 test_must_fail git send-email \
371 --smtp-server="$(pwd)/fake.sendmail" \
372 --to=to@example.com \
373 $patches </dev/null 2>errors &&
374 test_i18ngrep "tell me who you are" errors
378 test_expect_success $PREREQ 'setup tocmd and cccmd scripts' '
379 write_script tocmd-sed <<-\EOF &&
380 sed -n -e "s/^tocmd--//p" "$1"
382 write_script cccmd-sed <<-\EOF
383 sed -n -e "s/^cccmd--//p" "$1"
387 test_expect_success $PREREQ 'tocmd works' '
388 clean_fake_sendmail &&
389 cp $patches tocmd.patch &&
390 echo tocmd--tocmd@example.com >>tocmd.patch &&
391 git send-email \
392 --from="Example <nobody@example.com>" \
393 --to-cmd=./tocmd-sed \
394 --smtp-server="$(pwd)/fake.sendmail" \
395 tocmd.patch \
397 grep "^To: tocmd@example.com" msgtxt1
400 test_expect_success $PREREQ 'cccmd works' '
401 clean_fake_sendmail &&
402 cp $patches cccmd.patch &&
403 echo "cccmd-- cccmd@example.com" >>cccmd.patch &&
404 git send-email \
405 --from="Example <nobody@example.com>" \
406 --to=nobody@example.com \
407 --cc-cmd=./cccmd-sed \
408 --smtp-server="$(pwd)/fake.sendmail" \
409 cccmd.patch \
411 grep "^ cccmd@example.com" msgtxt1
414 test_expect_success $PREREQ 'reject long lines' '
415 z8=zzzzzzzz &&
416 z64=$z8$z8$z8$z8$z8$z8$z8$z8 &&
417 z512=$z64$z64$z64$z64$z64$z64$z64$z64 &&
418 clean_fake_sendmail &&
419 cp $patches longline.patch &&
420 cat >>longline.patch <<-EOF &&
421 $z512$z512
422 not a long line
423 $z512$z512
425 test_must_fail git send-email \
426 --from="Example <nobody@example.com>" \
427 --to=nobody@example.com \
428 --smtp-server="$(pwd)/fake.sendmail" \
429 --transfer-encoding=8bit \
430 $patches longline.patch \
431 2>actual &&
432 cat >expect <<-\EOF &&
433 fatal: longline.patch:35 is longer than 998 characters
434 warning: no patches were sent
436 test_cmp expect actual
439 test_expect_success $PREREQ 'no patch was sent' '
440 ! test -e commandline1
443 test_expect_success $PREREQ 'Author From: in message body' '
444 clean_fake_sendmail &&
445 git send-email \
446 --from="Example <nobody@example.com>" \
447 --to=nobody@example.com \
448 --smtp-server="$(pwd)/fake.sendmail" \
449 $patches &&
450 sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
451 grep "From: A <author@example.com>" msgbody1
454 test_expect_success $PREREQ 'Author From: not in message body' '
455 clean_fake_sendmail &&
456 git send-email \
457 --from="A <author@example.com>" \
458 --to=nobody@example.com \
459 --smtp-server="$(pwd)/fake.sendmail" \
460 $patches &&
461 sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
462 ! grep "From: A <author@example.com>" msgbody1
465 test_expect_success $PREREQ 'allow long lines with --no-validate' '
466 git send-email \
467 --from="Example <nobody@example.com>" \
468 --to=nobody@example.com \
469 --smtp-server="$(pwd)/fake.sendmail" \
470 --no-validate \
471 $patches longline.patch \
472 2>errors
475 test_expect_success $PREREQ 'short lines with auto encoding are 8bit' '
476 clean_fake_sendmail &&
477 git send-email \
478 --from="A <author@example.com>" \
479 --to=nobody@example.com \
480 --smtp-server="$(pwd)/fake.sendmail" \
481 --transfer-encoding=auto \
482 $patches &&
483 grep "Content-Transfer-Encoding: 8bit" msgtxt1
486 test_expect_success $PREREQ 'long lines with auto encoding are quoted-printable' '
487 clean_fake_sendmail &&
488 git send-email \
489 --from="Example <nobody@example.com>" \
490 --to=nobody@example.com \
491 --smtp-server="$(pwd)/fake.sendmail" \
492 --transfer-encoding=auto \
493 --no-validate \
494 longline.patch &&
495 grep "Content-Transfer-Encoding: quoted-printable" msgtxt1
498 test_expect_success $PREREQ 'carriage returns with auto encoding are quoted-printable' '
499 clean_fake_sendmail &&
500 cp $patches cr.patch &&
501 printf "this is a line\r\n" >>cr.patch &&
502 git send-email \
503 --from="Example <nobody@example.com>" \
504 --to=nobody@example.com \
505 --smtp-server="$(pwd)/fake.sendmail" \
506 --transfer-encoding=auto \
507 --no-validate \
508 cr.patch &&
509 grep "Content-Transfer-Encoding: quoted-printable" msgtxt1
512 for enc in auto quoted-printable base64
514 test_expect_success $PREREQ "--validate passes with encoding $enc" '
515 git send-email \
516 --from="Example <nobody@example.com>" \
517 --to=nobody@example.com \
518 --smtp-server="$(pwd)/fake.sendmail" \
519 --transfer-encoding=$enc \
520 --validate \
521 $patches longline.patch
524 done
526 test_expect_success $PREREQ "--validate respects relative core.hooksPath path" '
527 clean_fake_sendmail &&
528 mkdir my-hooks &&
529 test_when_finished "rm my-hooks.ran" &&
530 write_script my-hooks/sendemail-validate <<-\EOF &&
531 >my-hooks.ran
532 exit 1
534 test_config core.hooksPath "my-hooks" &&
535 test_must_fail git send-email \
536 --from="Example <nobody@example.com>" \
537 --to=nobody@example.com \
538 --smtp-server="$(pwd)/fake.sendmail" \
539 --validate \
540 longline.patch 2>actual &&
541 test_path_is_file my-hooks.ran &&
542 cat >expect <<-EOF &&
543 fatal: longline.patch: rejected by sendemail-validate hook
544 fatal: command '"'"'git hook run --ignore-missing sendemail-validate -- <patch>'"'"' died with exit code 1
545 warning: no patches were sent
547 test_cmp expect actual
550 test_expect_success $PREREQ "--validate respects absolute core.hooksPath path" '
551 hooks_path="$(pwd)/my-hooks" &&
552 test_config core.hooksPath "$hooks_path" &&
553 test_when_finished "rm my-hooks.ran" &&
554 test_must_fail git send-email \
555 --from="Example <nobody@example.com>" \
556 --to=nobody@example.com \
557 --smtp-server="$(pwd)/fake.sendmail" \
558 --validate \
559 longline.patch 2>actual &&
560 test_path_is_file my-hooks.ran &&
561 cat >expect <<-EOF &&
562 fatal: longline.patch: rejected by sendemail-validate hook
563 fatal: command '"'"'git hook run --ignore-missing sendemail-validate -- <patch>'"'"' died with exit code 1
564 warning: no patches were sent
566 test_cmp expect actual
569 for enc in 7bit 8bit quoted-printable base64
571 test_expect_success $PREREQ "--transfer-encoding=$enc produces correct header" '
572 clean_fake_sendmail &&
573 git send-email \
574 --from="Example <nobody@example.com>" \
575 --to=nobody@example.com \
576 --smtp-server="$(pwd)/fake.sendmail" \
577 --transfer-encoding=$enc \
578 $patches &&
579 grep "Content-Transfer-Encoding: $enc" msgtxt1
581 done
583 test_expect_success $PREREQ 'Invalid In-Reply-To' '
584 clean_fake_sendmail &&
585 git send-email \
586 --from="Example <nobody@example.com>" \
587 --to=nobody@example.com \
588 --in-reply-to=" " \
589 --smtp-server="$(pwd)/fake.sendmail" \
590 $patches \
591 2>errors &&
592 ! grep "^In-Reply-To: < *>" msgtxt1
595 test_expect_success $PREREQ 'Valid In-Reply-To when prompting' '
596 clean_fake_sendmail &&
597 (echo "From Example <from@example.com>" &&
598 echo "To Example <to@example.com>" &&
599 echo ""
600 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
601 --smtp-server="$(pwd)/fake.sendmail" \
602 $patches 2>errors &&
603 ! grep "^In-Reply-To: < *>" msgtxt1
606 test_expect_success $PREREQ 'In-Reply-To without --chain-reply-to' '
607 clean_fake_sendmail &&
608 echo "<unique-message-id@example.com>" >expect &&
609 git send-email \
610 --from="Example <nobody@example.com>" \
611 --to=nobody@example.com \
612 --no-chain-reply-to \
613 --in-reply-to="$(cat expect)" \
614 --smtp-server="$(pwd)/fake.sendmail" \
615 $patches $patches $patches \
616 2>errors &&
617 # The first message is a reply to --in-reply-to
618 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
619 test_cmp expect actual &&
620 # Second and subsequent messages are replies to the first one
621 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
622 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
623 test_cmp expect actual &&
624 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
625 test_cmp expect actual
628 test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' '
629 clean_fake_sendmail &&
630 echo "<unique-message-id@example.com>" >expect &&
631 git send-email \
632 --from="Example <nobody@example.com>" \
633 --to=nobody@example.com \
634 --chain-reply-to \
635 --in-reply-to="$(cat expect)" \
636 --smtp-server="$(pwd)/fake.sendmail" \
637 $patches $patches $patches \
638 2>errors &&
639 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
640 test_cmp expect actual &&
641 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
642 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
643 test_cmp expect actual &&
644 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt2 >expect &&
645 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
646 test_cmp expect actual
649 test_set_editor "$(pwd)/fake-editor"
651 test_expect_success $PREREQ 'setup erroring fake editor' '
652 write_script fake-editor <<-\EOF
653 echo >&2 "I am about to error"
654 exit 1
658 test_expect_success $PREREQ 'fake editor dies with error' '
659 clean_fake_sendmail &&
660 test_must_fail git send-email \
661 --compose --subject foo \
662 --from="Example <nobody@example.com>" \
663 --to=nobody@example.com \
664 --smtp-server="$(pwd)/fake.sendmail" \
665 $patches 2>err &&
666 grep "I am about to error" err &&
667 grep "the editor exited uncleanly, aborting everything" err
670 test_expect_success $PREREQ 'setup fake editor' '
671 write_script fake-editor <<-\EOF
672 echo fake edit >>"$1"
676 test_expect_success $PREREQ '--compose works' '
677 clean_fake_sendmail &&
678 git send-email \
679 --compose --subject foo \
680 --from="Example <nobody@example.com>" \
681 --to=nobody@example.com \
682 --smtp-server="$(pwd)/fake.sendmail" \
683 $patches \
684 2>errors
687 test_expect_success $PREREQ 'first message is compose text' '
688 grep "^fake edit" msgtxt1
691 test_expect_success $PREREQ 'second message is patch' '
692 grep "Subject:.*Second" msgtxt2
695 test_expect_success $PREREQ 'setup expect' "
696 cat >expected-suppress-sob <<\EOF
697 0001-Second.patch
698 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
699 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
700 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
701 Dry-OK. Log says:
702 Server: relay.example.com
703 MAIL FROM:<from@example.com>
704 RCPT TO:<to@example.com>
705 RCPT TO:<cc@example.com>
706 RCPT TO:<author@example.com>
707 RCPT TO:<one@example.com>
708 RCPT TO:<two@example.com>
709 From: Example <from@example.com>
710 To: to@example.com
711 Cc: cc@example.com,
712 A <author@example.com>,
713 One <one@example.com>,
714 two@example.com
715 Subject: [PATCH 1/1] Second.
716 Date: DATE-STRING
717 Message-Id: MESSAGE-ID-STRING
718 X-Mailer: X-MAILER-STRING
719 MIME-Version: 1.0
720 Content-Transfer-Encoding: 8bit
722 Result: OK
726 test_suppression () {
727 git send-email \
728 --dry-run \
729 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
730 --from="Example <from@example.com>" \
731 --to=to@example.com \
732 --smtp-server relay.example.com \
733 $patches | replace_variable_fields \
734 >actual-suppress-$1${2+"-$2"} &&
735 test_cmp expected-suppress-$1${2+"-$2"} actual-suppress-$1${2+"-$2"}
738 test_expect_success $PREREQ 'sendemail.cc set' '
739 git config sendemail.cc cc@example.com &&
740 test_suppression sob
743 test_expect_success $PREREQ 'setup expect' "
744 cat >expected-suppress-sob <<\EOF
745 0001-Second.patch
746 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
747 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
748 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
749 Dry-OK. Log says:
750 Server: relay.example.com
751 MAIL FROM:<from@example.com>
752 RCPT TO:<to@example.com>
753 RCPT TO:<author@example.com>
754 RCPT TO:<one@example.com>
755 RCPT TO:<two@example.com>
756 From: Example <from@example.com>
757 To: to@example.com
758 Cc: A <author@example.com>,
759 One <one@example.com>,
760 two@example.com
761 Subject: [PATCH 1/1] Second.
762 Date: DATE-STRING
763 Message-Id: MESSAGE-ID-STRING
764 X-Mailer: X-MAILER-STRING
765 MIME-Version: 1.0
766 Content-Transfer-Encoding: 8bit
768 Result: OK
772 test_expect_success $PREREQ 'sendemail.cc unset' '
773 git config --unset sendemail.cc &&
774 test_suppression sob
777 test_expect_success $PREREQ 'setup expect' "
778 cat >expected-suppress-cccmd <<\EOF
779 0001-Second.patch
780 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
781 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
782 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
783 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
784 Dry-OK. Log says:
785 Server: relay.example.com
786 MAIL FROM:<from@example.com>
787 RCPT TO:<to@example.com>
788 RCPT TO:<author@example.com>
789 RCPT TO:<one@example.com>
790 RCPT TO:<two@example.com>
791 RCPT TO:<committer@example.com>
792 From: Example <from@example.com>
793 To: to@example.com
794 Cc: A <author@example.com>,
795 One <one@example.com>,
796 two@example.com,
797 C O Mitter <committer@example.com>
798 Subject: [PATCH 1/1] Second.
799 Date: DATE-STRING
800 Message-Id: MESSAGE-ID-STRING
801 X-Mailer: X-MAILER-STRING
802 MIME-Version: 1.0
803 Content-Transfer-Encoding: 8bit
805 Result: OK
809 test_expect_success $PREREQ 'sendemail.cccmd' '
810 write_script cccmd <<-\EOF &&
811 echo cc-cmd@example.com
813 git config sendemail.cccmd ./cccmd &&
814 test_suppression cccmd
817 test_expect_success $PREREQ 'setup expect' '
818 cat >expected-suppress-all <<\EOF
819 0001-Second.patch
820 Dry-OK. Log says:
821 Server: relay.example.com
822 MAIL FROM:<from@example.com>
823 RCPT TO:<to@example.com>
824 From: Example <from@example.com>
825 To: to@example.com
826 Subject: [PATCH 1/1] Second.
827 Date: DATE-STRING
828 Message-Id: MESSAGE-ID-STRING
829 X-Mailer: X-MAILER-STRING
830 MIME-Version: 1.0
831 Content-Transfer-Encoding: 8bit
833 Result: OK
837 test_expect_success $PREREQ '--suppress-cc=all' '
838 test_suppression all
841 test_expect_success $PREREQ 'setup expect' "
842 cat >expected-suppress-body <<\EOF
843 0001-Second.patch
844 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
845 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
846 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
847 (cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
848 Dry-OK. Log says:
849 Server: relay.example.com
850 MAIL FROM:<from@example.com>
851 RCPT TO:<to@example.com>
852 RCPT TO:<author@example.com>
853 RCPT TO:<one@example.com>
854 RCPT TO:<two@example.com>
855 RCPT TO:<cc-cmd@example.com>
856 From: Example <from@example.com>
857 To: to@example.com
858 Cc: A <author@example.com>,
859 One <one@example.com>,
860 two@example.com,
861 cc-cmd@example.com
862 Subject: [PATCH 1/1] Second.
863 Date: DATE-STRING
864 Message-Id: MESSAGE-ID-STRING
865 X-Mailer: X-MAILER-STRING
866 MIME-Version: 1.0
867 Content-Transfer-Encoding: 8bit
869 Result: OK
873 test_expect_success $PREREQ '--suppress-cc=body' '
874 test_suppression body
877 test_expect_success $PREREQ 'setup expect' "
878 cat >expected-suppress-body-cccmd <<\EOF
879 0001-Second.patch
880 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
881 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
882 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
883 Dry-OK. Log says:
884 Server: relay.example.com
885 MAIL FROM:<from@example.com>
886 RCPT TO:<to@example.com>
887 RCPT TO:<author@example.com>
888 RCPT TO:<one@example.com>
889 RCPT TO:<two@example.com>
890 From: Example <from@example.com>
891 To: to@example.com
892 Cc: A <author@example.com>,
893 One <one@example.com>,
894 two@example.com
895 Subject: [PATCH 1/1] Second.
896 Date: DATE-STRING
897 Message-Id: MESSAGE-ID-STRING
898 X-Mailer: X-MAILER-STRING
899 MIME-Version: 1.0
900 Content-Transfer-Encoding: 8bit
902 Result: OK
906 test_expect_success $PREREQ '--suppress-cc=body --suppress-cc=cccmd' '
907 test_suppression body cccmd
910 test_expect_success $PREREQ 'setup expect' "
911 cat >expected-suppress-sob <<\EOF
912 0001-Second.patch
913 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
914 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
915 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
916 Dry-OK. Log says:
917 Server: relay.example.com
918 MAIL FROM:<from@example.com>
919 RCPT TO:<to@example.com>
920 RCPT TO:<author@example.com>
921 RCPT TO:<one@example.com>
922 RCPT TO:<two@example.com>
923 From: Example <from@example.com>
924 To: to@example.com
925 Cc: A <author@example.com>,
926 One <one@example.com>,
927 two@example.com
928 Subject: [PATCH 1/1] Second.
929 Date: DATE-STRING
930 Message-Id: MESSAGE-ID-STRING
931 X-Mailer: X-MAILER-STRING
932 MIME-Version: 1.0
933 Content-Transfer-Encoding: 8bit
935 Result: OK
939 test_expect_success $PREREQ '--suppress-cc=sob' '
940 test_might_fail git config --unset sendemail.cccmd &&
941 test_suppression sob
944 test_expect_success $PREREQ 'setup expect' "
945 cat >expected-suppress-bodycc <<\EOF
946 0001-Second.patch
947 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
948 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
949 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
950 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
951 Dry-OK. Log says:
952 Server: relay.example.com
953 MAIL FROM:<from@example.com>
954 RCPT TO:<to@example.com>
955 RCPT TO:<author@example.com>
956 RCPT TO:<one@example.com>
957 RCPT TO:<two@example.com>
958 RCPT TO:<committer@example.com>
959 From: Example <from@example.com>
960 To: to@example.com
961 Cc: A <author@example.com>,
962 One <one@example.com>,
963 two@example.com,
964 C O Mitter <committer@example.com>
965 Subject: [PATCH 1/1] Second.
966 Date: DATE-STRING
967 Message-Id: MESSAGE-ID-STRING
968 X-Mailer: X-MAILER-STRING
969 MIME-Version: 1.0
970 Content-Transfer-Encoding: 8bit
972 Result: OK
976 test_expect_success $PREREQ '--suppress-cc=bodycc' '
977 test_suppression bodycc
980 test_expect_success $PREREQ 'setup expect' "
981 cat >expected-suppress-cc <<\EOF
982 0001-Second.patch
983 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
984 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
985 Dry-OK. Log says:
986 Server: relay.example.com
987 MAIL FROM:<from@example.com>
988 RCPT TO:<to@example.com>
989 RCPT TO:<author@example.com>
990 RCPT TO:<committer@example.com>
991 From: Example <from@example.com>
992 To: to@example.com
993 Cc: A <author@example.com>,
994 C O Mitter <committer@example.com>
995 Subject: [PATCH 1/1] Second.
996 Date: DATE-STRING
997 Message-Id: MESSAGE-ID-STRING
998 X-Mailer: X-MAILER-STRING
999 MIME-Version: 1.0
1000 Content-Transfer-Encoding: 8bit
1002 Result: OK
1006 test_expect_success $PREREQ '--suppress-cc=cc' '
1007 test_suppression cc
1010 test_confirm () {
1011 echo y | \
1012 GIT_SEND_EMAIL_NOTTY=1 \
1013 git send-email \
1014 --from="Example <nobody@example.com>" \
1015 --to=nobody@example.com \
1016 --smtp-server="$(pwd)/fake.sendmail" \
1017 $@ $patches >stdout &&
1018 grep "Send this email" stdout
1021 test_expect_success $PREREQ '--confirm=always' '
1022 test_confirm --confirm=always --suppress-cc=all
1025 test_expect_success $PREREQ '--confirm=auto' '
1026 test_confirm --confirm=auto
1029 test_expect_success $PREREQ '--confirm=cc' '
1030 test_confirm --confirm=cc
1033 test_expect_success $PREREQ '--confirm=compose' '
1034 test_confirm --confirm=compose --compose
1037 test_expect_success $PREREQ 'confirm by default (due to cc)' '
1038 test_when_finished git config sendemail.confirm never &&
1039 git config --unset sendemail.confirm &&
1040 test_confirm
1043 test_expect_success $PREREQ 'confirm by default (due to --compose)' '
1044 test_when_finished git config sendemail.confirm never &&
1045 git config --unset sendemail.confirm &&
1046 test_confirm --suppress-cc=all --compose
1049 test_expect_success $PREREQ 'confirm detects EOF (inform assumes y)' '
1050 test_when_finished git config sendemail.confirm never &&
1051 git config --unset sendemail.confirm &&
1052 rm -fr outdir &&
1053 git format-patch -2 -o outdir &&
1054 GIT_SEND_EMAIL_NOTTY=1 \
1055 git send-email \
1056 --from="Example <nobody@example.com>" \
1057 --to=nobody@example.com \
1058 --smtp-server="$(pwd)/fake.sendmail" \
1059 outdir/*.patch </dev/null
1062 test_expect_success $PREREQ 'confirm detects EOF (auto causes failure)' '
1063 test_when_finished git config sendemail.confirm never &&
1064 git config sendemail.confirm auto &&
1065 GIT_SEND_EMAIL_NOTTY=1 &&
1066 export GIT_SEND_EMAIL_NOTTY &&
1067 test_must_fail git send-email \
1068 --from="Example <nobody@example.com>" \
1069 --to=nobody@example.com \
1070 --smtp-server="$(pwd)/fake.sendmail" \
1071 $patches </dev/null
1074 test_expect_success $PREREQ 'confirm does not loop forever' '
1075 test_when_finished git config sendemail.confirm never &&
1076 git config sendemail.confirm auto &&
1077 GIT_SEND_EMAIL_NOTTY=1 &&
1078 export GIT_SEND_EMAIL_NOTTY &&
1079 yes "bogus" | test_must_fail git send-email \
1080 --from="Example <nobody@example.com>" \
1081 --to=nobody@example.com \
1082 --smtp-server="$(pwd)/fake.sendmail" \
1083 $patches
1086 test_expect_success $PREREQ 'utf8 Cc is rfc2047 encoded' '
1087 clean_fake_sendmail &&
1088 rm -fr outdir &&
1089 git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
1090 git send-email \
1091 --from="Example <nobody@example.com>" \
1092 --to=nobody@example.com \
1093 --smtp-server="$(pwd)/fake.sendmail" \
1094 outdir/*.patch &&
1095 grep "^ " msgtxt1 |
1096 grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
1099 test_expect_success $PREREQ '--compose adds MIME for utf8 body' '
1100 clean_fake_sendmail &&
1101 write_script fake-editor-utf8 <<-\EOF &&
1102 echo "utf8 body: àéìöú" >>"$1"
1104 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1105 git send-email \
1106 --compose --subject foo \
1107 --from="Example <nobody@example.com>" \
1108 --to=nobody@example.com \
1109 --smtp-server="$(pwd)/fake.sendmail" \
1110 $patches &&
1111 grep "^utf8 body" msgtxt1 &&
1112 grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
1115 test_expect_success $PREREQ '--compose respects user mime type' '
1116 clean_fake_sendmail &&
1117 write_script fake-editor-utf8-mime <<-\EOF &&
1118 cat >"$1" <<-\EOM
1119 MIME-Version: 1.0
1120 Content-Type: text/plain; charset=iso-8859-1
1121 Content-Transfer-Encoding: 8bit
1122 Subject: foo
1124 utf8 body: àéìöú
1127 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
1128 git send-email \
1129 --compose --subject foo \
1130 --from="Example <nobody@example.com>" \
1131 --to=nobody@example.com \
1132 --smtp-server="$(pwd)/fake.sendmail" \
1133 $patches &&
1134 grep "^utf8 body" msgtxt1 &&
1135 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
1136 ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
1139 test_expect_success $PREREQ '--compose adds MIME for utf8 subject' '
1140 clean_fake_sendmail &&
1141 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
1142 git send-email \
1143 --compose --subject utf8-sübjëct \
1144 --from="Example <nobody@example.com>" \
1145 --to=nobody@example.com \
1146 --smtp-server="$(pwd)/fake.sendmail" \
1147 $patches &&
1148 grep "^fake edit" msgtxt1 &&
1149 grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
1152 test_expect_success $PREREQ 'utf8 author is correctly passed on' '
1153 clean_fake_sendmail &&
1154 test_commit weird_author &&
1155 test_when_finished "git reset --hard HEAD^" &&
1156 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
1157 git format-patch --stdout -1 >funny_name.patch &&
1158 git send-email --from="Example <nobody@example.com>" \
1159 --to=nobody@example.com \
1160 --smtp-server="$(pwd)/fake.sendmail" \
1161 funny_name.patch &&
1162 grep "^From: Füñný Nâmé <odd_?=mail@example.com>" msgtxt1
1165 test_expect_success $PREREQ 'utf8 sender is not duplicated' '
1166 clean_fake_sendmail &&
1167 test_commit weird_sender &&
1168 test_when_finished "git reset --hard HEAD^" &&
1169 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
1170 git format-patch --stdout -1 >funny_name.patch &&
1171 git send-email --from="Füñný Nâmé <odd_?=mail@example.com>" \
1172 --to=nobody@example.com \
1173 --smtp-server="$(pwd)/fake.sendmail" \
1174 funny_name.patch &&
1175 grep "^From: " msgtxt1 >msgfrom &&
1176 test_line_count = 1 msgfrom
1179 test_expect_success $PREREQ 'sendemail.composeencoding works' '
1180 clean_fake_sendmail &&
1181 git config sendemail.composeencoding iso-8859-1 &&
1182 write_script fake-editor-utf8 <<-\EOF &&
1183 echo "utf8 body: àéìöú" >>"$1"
1185 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1186 git send-email \
1187 --compose --subject foo \
1188 --from="Example <nobody@example.com>" \
1189 --to=nobody@example.com \
1190 --smtp-server="$(pwd)/fake.sendmail" \
1191 $patches &&
1192 grep "^utf8 body" msgtxt1 &&
1193 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1196 test_expect_success $PREREQ '--compose-encoding works' '
1197 clean_fake_sendmail &&
1198 write_script fake-editor-utf8 <<-\EOF &&
1199 echo "utf8 body: àéìöú" >>"$1"
1201 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1202 git send-email \
1203 --compose-encoding iso-8859-1 \
1204 --compose --subject foo \
1205 --from="Example <nobody@example.com>" \
1206 --to=nobody@example.com \
1207 --smtp-server="$(pwd)/fake.sendmail" \
1208 $patches &&
1209 grep "^utf8 body" msgtxt1 &&
1210 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1213 test_expect_success $PREREQ '--compose-encoding overrides sendemail.composeencoding' '
1214 clean_fake_sendmail &&
1215 git config sendemail.composeencoding iso-8859-1 &&
1216 write_script fake-editor-utf8 <<-\EOF &&
1217 echo "utf8 body: àéìöú" >>"$1"
1219 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1220 git send-email \
1221 --compose-encoding iso-8859-2 \
1222 --compose --subject foo \
1223 --from="Example <nobody@example.com>" \
1224 --to=nobody@example.com \
1225 --smtp-server="$(pwd)/fake.sendmail" \
1226 $patches &&
1227 grep "^utf8 body" msgtxt1 &&
1228 grep "^Content-Type: text/plain; charset=iso-8859-2" msgtxt1
1231 test_expect_success $PREREQ '--compose-encoding adds correct MIME for subject' '
1232 clean_fake_sendmail &&
1233 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
1234 git send-email \
1235 --compose-encoding iso-8859-2 \
1236 --compose --subject utf8-sübjëct \
1237 --from="Example <nobody@example.com>" \
1238 --to=nobody@example.com \
1239 --smtp-server="$(pwd)/fake.sendmail" \
1240 $patches &&
1241 grep "^fake edit" msgtxt1 &&
1242 grep "^Subject: =?iso-8859-2?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
1245 test_expect_success $PREREQ 'detects ambiguous reference/file conflict' '
1246 echo main >main &&
1247 git add main &&
1248 git commit -m"add main" &&
1249 test_must_fail git send-email --dry-run main 2>errors &&
1250 grep disambiguate errors
1253 test_expect_success $PREREQ 'feed two files' '
1254 rm -fr outdir &&
1255 git format-patch -2 -o outdir &&
1256 git send-email \
1257 --dry-run \
1258 --from="Example <nobody@example.com>" \
1259 --to=nobody@example.com \
1260 outdir/000?-*.patch 2>errors >out &&
1261 grep "^Subject: " out >subjects &&
1262 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
1263 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add main"
1266 test_expect_success $PREREQ 'in-reply-to but no threading' '
1267 git send-email \
1268 --dry-run \
1269 --from="Example <nobody@example.com>" \
1270 --to=nobody@example.com \
1271 --in-reply-to="<in-reply-id@example.com>" \
1272 --no-thread \
1273 $patches >out &&
1274 grep "In-Reply-To: <in-reply-id@example.com>" out
1277 test_expect_success $PREREQ 'no in-reply-to and no threading' '
1278 git send-email \
1279 --dry-run \
1280 --from="Example <nobody@example.com>" \
1281 --to=nobody@example.com \
1282 --no-thread \
1283 $patches >stdout &&
1284 ! grep "In-Reply-To: " stdout
1287 test_expect_success $PREREQ 'threading but no chain-reply-to' '
1288 git send-email \
1289 --dry-run \
1290 --from="Example <nobody@example.com>" \
1291 --to=nobody@example.com \
1292 --thread \
1293 --no-chain-reply-to \
1294 $patches $patches >stdout &&
1295 grep "In-Reply-To: " stdout
1298 test_expect_success $PREREQ 'override in-reply-to if no threading' '
1299 git send-email \
1300 --dry-run \
1301 --from="Example <nobody@example.com>" \
1302 --to=nobody@example.com \
1303 --no-thread \
1304 --in-reply-to="override" \
1305 $threaded_patches >stdout &&
1306 grep "In-Reply-To: <override>" stdout
1309 test_expect_success $PREREQ 'sendemail.to works' '
1310 git config --replace-all sendemail.to "Somebody <somebody@ex.com>" &&
1311 git send-email \
1312 --dry-run \
1313 --from="Example <nobody@example.com>" \
1314 $patches >stdout &&
1315 grep "To: Somebody <somebody@ex.com>" stdout
1318 test_expect_success $PREREQ 'setup sendemail.identity' '
1319 git config --replace-all sendemail.to "default@example.com" &&
1320 git config --replace-all sendemail.isp.to "isp@example.com" &&
1321 git config --replace-all sendemail.cloud.to "cloud@example.com"
1324 test_expect_success $PREREQ 'sendemail.identity: reads the correct identity config' '
1325 git -c sendemail.identity=cloud send-email \
1326 --dry-run \
1327 --from="nobody@example.com" \
1328 $patches >stdout &&
1329 grep "To: cloud@example.com" stdout
1332 test_expect_success $PREREQ 'sendemail.identity: identity overrides sendemail.identity' '
1333 git -c sendemail.identity=cloud send-email \
1334 --identity=isp \
1335 --dry-run \
1336 --from="nobody@example.com" \
1337 $patches >stdout &&
1338 grep "To: isp@example.com" stdout
1341 test_expect_success $PREREQ 'sendemail.identity: --no-identity clears previous identity' '
1342 git -c sendemail.identity=cloud send-email \
1343 --no-identity \
1344 --dry-run \
1345 --from="nobody@example.com" \
1346 $patches >stdout &&
1347 grep "To: default@example.com" stdout
1350 test_expect_success $PREREQ 'sendemail.identity: bool identity variable existence overrides' '
1351 git -c sendemail.identity=cloud \
1352 -c sendemail.xmailer=true \
1353 -c sendemail.cloud.xmailer=false \
1354 send-email \
1355 --dry-run \
1356 --from="nobody@example.com" \
1357 $patches >stdout &&
1358 grep "To: cloud@example.com" stdout &&
1359 ! grep "X-Mailer" stdout
1362 test_expect_success $PREREQ 'sendemail.identity: bool variable fallback' '
1363 git -c sendemail.identity=cloud \
1364 -c sendemail.xmailer=false \
1365 send-email \
1366 --dry-run \
1367 --from="nobody@example.com" \
1368 $patches >stdout &&
1369 grep "To: cloud@example.com" stdout &&
1370 ! grep "X-Mailer" stdout
1373 test_expect_success $PREREQ 'sendemail.identity: bool variable without a value' '
1374 git -c sendemail.xmailer \
1375 send-email \
1376 --dry-run \
1377 --from="nobody@example.com" \
1378 $patches >stdout &&
1379 grep "To: default@example.com" stdout &&
1380 grep "X-Mailer" stdout
1383 test_expect_success $PREREQ '--no-to overrides sendemail.to' '
1384 git send-email \
1385 --dry-run \
1386 --from="Example <nobody@example.com>" \
1387 --no-to \
1388 --to=nobody@example.com \
1389 $patches >stdout &&
1390 grep "To: nobody@example.com" stdout &&
1391 ! grep "To: Somebody <somebody@ex.com>" stdout
1394 test_expect_success $PREREQ 'sendemail.cc works' '
1395 git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" &&
1396 git send-email \
1397 --dry-run \
1398 --from="Example <nobody@example.com>" \
1399 --to=nobody@example.com \
1400 $patches >stdout &&
1401 grep "Cc: Somebody <somebody@ex.com>" stdout
1404 test_expect_success $PREREQ '--no-cc overrides sendemail.cc' '
1405 git send-email \
1406 --dry-run \
1407 --from="Example <nobody@example.com>" \
1408 --no-cc \
1409 --cc=bodies@example.com \
1410 --to=nobody@example.com \
1411 $patches >stdout &&
1412 grep "Cc: bodies@example.com" stdout &&
1413 ! grep "Cc: Somebody <somebody@ex.com>" stdout
1416 test_expect_success $PREREQ 'sendemail.bcc works' '
1417 git config --replace-all sendemail.bcc "Other <other@ex.com>" &&
1418 git send-email \
1419 --dry-run \
1420 --from="Example <nobody@example.com>" \
1421 --to=nobody@example.com \
1422 --smtp-server relay.example.com \
1423 $patches >stdout &&
1424 grep "RCPT TO:<other@ex.com>" stdout
1427 test_expect_success $PREREQ '--no-bcc overrides sendemail.bcc' '
1428 git send-email \
1429 --dry-run \
1430 --from="Example <nobody@example.com>" \
1431 --no-bcc \
1432 --bcc=bodies@example.com \
1433 --to=nobody@example.com \
1434 --smtp-server relay.example.com \
1435 $patches >stdout &&
1436 grep "RCPT TO:<bodies@example.com>" stdout &&
1437 ! grep "RCPT TO:<other@ex.com>" stdout
1440 test_expect_success $PREREQ 'patches To headers are used by default' '
1441 patch=$(git format-patch -1 --to="bodies@example.com") &&
1442 test_when_finished "rm $patch" &&
1443 git send-email \
1444 --dry-run \
1445 --from="Example <nobody@example.com>" \
1446 --smtp-server relay.example.com \
1447 $patch >stdout &&
1448 grep "RCPT TO:<bodies@example.com>" stdout
1451 test_expect_success $PREREQ 'patches To headers are appended to' '
1452 patch=$(git format-patch -1 --to="bodies@example.com") &&
1453 test_when_finished "rm $patch" &&
1454 git send-email \
1455 --dry-run \
1456 --from="Example <nobody@example.com>" \
1457 --to=nobody@example.com \
1458 --smtp-server relay.example.com \
1459 $patch >stdout &&
1460 grep "RCPT TO:<bodies@example.com>" stdout &&
1461 grep "RCPT TO:<nobody@example.com>" stdout
1464 test_expect_success $PREREQ 'To headers from files reset each patch' '
1465 patch1=$(git format-patch -1 --to="bodies@example.com") &&
1466 patch2=$(git format-patch -1 --to="other@example.com" HEAD~) &&
1467 test_when_finished "rm $patch1 && rm $patch2" &&
1468 git send-email \
1469 --dry-run \
1470 --from="Example <nobody@example.com>" \
1471 --to="nobody@example.com" \
1472 --smtp-server relay.example.com \
1473 $patch1 $patch2 >stdout &&
1474 test $(grep -c "RCPT TO:<bodies@example.com>" stdout) = 1 &&
1475 test $(grep -c "RCPT TO:<nobody@example.com>" stdout) = 2 &&
1476 test $(grep -c "RCPT TO:<other@example.com>" stdout) = 1
1479 test_expect_success $PREREQ 'setup expect' '
1480 cat >email-using-8bit <<\EOF
1481 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1482 Message-Id: <bogus-message-id@example.com>
1483 From: author@example.com
1484 Date: Sat, 12 Jun 2010 15:53:58 +0200
1485 Subject: subject goes here
1487 Dieser deutsche Text enthält einen Umlaut!
1491 test_expect_success $PREREQ 'setup expect' '
1492 echo "Subject: subject goes here" >expected
1495 test_expect_success $PREREQ 'ASCII subject is not RFC2047 quoted' '
1496 clean_fake_sendmail &&
1497 echo bogus |
1498 git send-email --from=author@example.com --to=nobody@example.com \
1499 --smtp-server="$(pwd)/fake.sendmail" \
1500 --8bit-encoding=UTF-8 \
1501 email-using-8bit >stdout &&
1502 grep "Subject" msgtxt1 >actual &&
1503 test_cmp expected actual
1506 test_expect_success $PREREQ 'setup expect' '
1507 cat >content-type-decl <<-\EOF
1508 MIME-Version: 1.0
1509 Content-Type: text/plain; charset=UTF-8
1510 Content-Transfer-Encoding: 8bit
1514 test_expect_success $PREREQ 'asks about and fixes 8bit encodings' '
1515 clean_fake_sendmail &&
1516 echo |
1517 git send-email --from=author@example.com --to=nobody@example.com \
1518 --smtp-server="$(pwd)/fake.sendmail" \
1519 email-using-8bit >stdout &&
1520 grep "do not declare a Content-Transfer-Encoding" stdout &&
1521 grep email-using-8bit stdout &&
1522 grep "Which 8bit encoding" stdout &&
1523 grep -E "Content|MIME" msgtxt1 >actual &&
1524 test_cmp content-type-decl actual
1527 test_expect_success $PREREQ 'sendemail.8bitEncoding works' '
1528 clean_fake_sendmail &&
1529 git config sendemail.assume8bitEncoding UTF-8 &&
1530 echo bogus |
1531 git send-email --from=author@example.com --to=nobody@example.com \
1532 --smtp-server="$(pwd)/fake.sendmail" \
1533 email-using-8bit >stdout &&
1534 grep -E "Content|MIME" msgtxt1 >actual &&
1535 test_cmp content-type-decl actual
1538 test_expect_success $PREREQ 'sendemail.8bitEncoding in .git/config overrides --global .gitconfig' '
1539 clean_fake_sendmail &&
1540 git config sendemail.assume8bitEncoding UTF-8 &&
1541 test_when_finished "rm -rf home" &&
1542 mkdir home &&
1543 git config -f home/.gitconfig sendemail.assume8bitEncoding "bogus too" &&
1544 echo bogus |
1545 env HOME="$(pwd)/home" DEBUG=1 \
1546 git send-email --from=author@example.com --to=nobody@example.com \
1547 --smtp-server="$(pwd)/fake.sendmail" \
1548 email-using-8bit >stdout &&
1549 grep -E "Content|MIME" msgtxt1 >actual &&
1550 test_cmp content-type-decl actual
1553 test_expect_success $PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
1554 clean_fake_sendmail &&
1555 git config sendemail.assume8bitEncoding "bogus too" &&
1556 echo bogus |
1557 git send-email --from=author@example.com --to=nobody@example.com \
1558 --smtp-server="$(pwd)/fake.sendmail" \
1559 --8bit-encoding=UTF-8 \
1560 email-using-8bit >stdout &&
1561 grep -E "Content|MIME" msgtxt1 >actual &&
1562 test_cmp content-type-decl actual
1565 test_expect_success $PREREQ 'setup expect' '
1566 cat >email-using-8bit <<-\EOF
1567 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1568 Message-Id: <bogus-message-id@example.com>
1569 From: author@example.com
1570 Date: Sat, 12 Jun 2010 15:53:58 +0200
1571 Subject: Dieser Betreff enthält auch einen Umlaut!
1573 Nothing to see here.
1577 test_expect_success $PREREQ 'setup expect' '
1578 cat >expected <<-\EOF
1579 Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
1583 test_expect_success $PREREQ '--8bit-encoding also treats subject' '
1584 clean_fake_sendmail &&
1585 echo bogus |
1586 git send-email --from=author@example.com --to=nobody@example.com \
1587 --smtp-server="$(pwd)/fake.sendmail" \
1588 --8bit-encoding=UTF-8 \
1589 email-using-8bit >stdout &&
1590 grep "Subject" msgtxt1 >actual &&
1591 test_cmp expected actual
1594 test_expect_success $PREREQ 'setup expect' '
1595 cat >email-using-8bit <<-\EOF
1596 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1597 Message-Id: <bogus-message-id@example.com>
1598 From: A U Thor <author@example.com>
1599 Date: Sat, 12 Jun 2010 15:53:58 +0200
1600 Content-Type: text/plain; charset=UTF-8
1601 Subject: Nothing to see here.
1603 Dieser Betreff enthält auch einen Umlaut!
1607 test_expect_success $PREREQ '--transfer-encoding overrides sendemail.transferEncoding' '
1608 clean_fake_sendmail &&
1609 test_must_fail git -c sendemail.transferEncoding=8bit \
1610 send-email \
1611 --transfer-encoding=7bit \
1612 --smtp-server="$(pwd)/fake.sendmail" \
1613 email-using-8bit \
1614 2>errors >out &&
1615 grep "cannot send message as 7bit" errors &&
1616 test -z "$(ls msgtxt*)"
1619 test_expect_success $PREREQ 'sendemail.transferEncoding via config' '
1620 clean_fake_sendmail &&
1621 test_must_fail git -c sendemail.transferEncoding=7bit \
1622 send-email \
1623 --smtp-server="$(pwd)/fake.sendmail" \
1624 email-using-8bit \
1625 2>errors >out &&
1626 grep "cannot send message as 7bit" errors &&
1627 test -z "$(ls msgtxt*)"
1630 test_expect_success $PREREQ 'sendemail.transferEncoding via cli' '
1631 clean_fake_sendmail &&
1632 test_must_fail git send-email \
1633 --transfer-encoding=7bit \
1634 --smtp-server="$(pwd)/fake.sendmail" \
1635 email-using-8bit \
1636 2>errors >out &&
1637 grep "cannot send message as 7bit" errors &&
1638 test -z "$(ls msgtxt*)"
1641 test_expect_success $PREREQ 'setup expect' '
1642 cat >expected <<-\EOF
1643 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1647 test_expect_success $PREREQ '8-bit and sendemail.transferencoding=quoted-printable' '
1648 clean_fake_sendmail &&
1649 git send-email \
1650 --transfer-encoding=quoted-printable \
1651 --smtp-server="$(pwd)/fake.sendmail" \
1652 email-using-8bit \
1653 2>errors >out &&
1654 sed "1,/^$/d" msgtxt1 >actual &&
1655 test_cmp expected actual
1658 test_expect_success $PREREQ 'setup expect' '
1659 cat >expected <<-\EOF
1660 RGllc2VyIEJldHJlZmYgZW50aMOkbHQgYXVjaCBlaW5lbiBVbWxhdXQhCg==
1664 test_expect_success $PREREQ '8-bit and sendemail.transferencoding=base64' '
1665 clean_fake_sendmail &&
1666 git send-email \
1667 --transfer-encoding=base64 \
1668 --smtp-server="$(pwd)/fake.sendmail" \
1669 email-using-8bit \
1670 2>errors >out &&
1671 sed "1,/^$/d" msgtxt1 >actual &&
1672 test_cmp expected actual
1675 test_expect_success $PREREQ 'setup expect' '
1676 cat >email-using-qp <<-\EOF
1677 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1678 Message-Id: <bogus-message-id@example.com>
1679 From: A U Thor <author@example.com>
1680 Date: Sat, 12 Jun 2010 15:53:58 +0200
1681 MIME-Version: 1.0
1682 Content-Transfer-Encoding: quoted-printable
1683 Content-Type: text/plain; charset=UTF-8
1684 Subject: Nothing to see here.
1686 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1690 test_expect_success $PREREQ 'convert from quoted-printable to base64' '
1691 clean_fake_sendmail &&
1692 git send-email \
1693 --transfer-encoding=base64 \
1694 --smtp-server="$(pwd)/fake.sendmail" \
1695 email-using-qp \
1696 2>errors >out &&
1697 sed "1,/^$/d" msgtxt1 >actual &&
1698 test_cmp expected actual
1701 test_expect_success $PREREQ 'setup expect' "
1702 tr -d '\\015' | tr '%' '\\015' >email-using-crlf <<EOF
1703 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1704 Message-Id: <bogus-message-id@example.com>
1705 From: A U Thor <author@example.com>
1706 Date: Sat, 12 Jun 2010 15:53:58 +0200
1707 Content-Type: text/plain; charset=UTF-8
1708 Subject: Nothing to see here.
1710 Look, I have a CRLF and an = sign!%
1714 test_expect_success $PREREQ 'setup expect' '
1715 cat >expected <<-\EOF
1716 Look, I have a CRLF and an =3D sign!=0D
1720 test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=quoted-printable' '
1721 clean_fake_sendmail &&
1722 git send-email \
1723 --transfer-encoding=quoted-printable \
1724 --smtp-server="$(pwd)/fake.sendmail" \
1725 email-using-crlf \
1726 2>errors >out &&
1727 sed "1,/^$/d" msgtxt1 >actual &&
1728 test_cmp expected actual
1731 test_expect_success $PREREQ 'setup expect' '
1732 cat >expected <<-\EOF
1733 TG9vaywgSSBoYXZlIGEgQ1JMRiBhbmQgYW4gPSBzaWduIQ0K
1737 test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=base64' '
1738 clean_fake_sendmail &&
1739 git send-email \
1740 --transfer-encoding=base64 \
1741 --smtp-server="$(pwd)/fake.sendmail" \
1742 email-using-crlf \
1743 2>errors >out &&
1744 sed "1,/^$/d" msgtxt1 >actual &&
1745 test_cmp expected actual
1749 # Note that the patches in this test are deliberately out of order; we
1750 # want to make sure it works even if the cover-letter is not in the
1751 # first mail.
1752 test_expect_success $PREREQ 'refusing to send cover letter template' '
1753 clean_fake_sendmail &&
1754 rm -fr outdir &&
1755 git format-patch --cover-letter -2 -o outdir &&
1756 test_must_fail git send-email \
1757 --from="Example <nobody@example.com>" \
1758 --to=nobody@example.com \
1759 --smtp-server="$(pwd)/fake.sendmail" \
1760 outdir/0002-*.patch \
1761 outdir/0000-*.patch \
1762 outdir/0001-*.patch \
1763 2>errors >out &&
1764 grep "SUBJECT HERE" errors &&
1765 test -z "$(ls msgtxt*)"
1768 test_expect_success $PREREQ '--force sends cover letter template anyway' '
1769 clean_fake_sendmail &&
1770 rm -fr outdir &&
1771 git format-patch --cover-letter -2 -o outdir &&
1772 git send-email \
1773 --force \
1774 --from="Example <nobody@example.com>" \
1775 --to=nobody@example.com \
1776 --smtp-server="$(pwd)/fake.sendmail" \
1777 outdir/0002-*.patch \
1778 outdir/0000-*.patch \
1779 outdir/0001-*.patch \
1780 2>errors >out &&
1781 ! grep "SUBJECT HERE" errors &&
1782 test -n "$(ls msgtxt*)"
1785 test_cover_addresses () {
1786 header="$1"
1787 shift
1788 clean_fake_sendmail &&
1789 rm -fr outdir &&
1790 git format-patch --cover-letter -2 -o outdir &&
1791 cover=$(echo outdir/0000-*.patch) &&
1792 mv $cover cover-to-edit.patch &&
1793 perl -pe "s/^From:/$header: extra\@address.com\nFrom:/" cover-to-edit.patch >"$cover" &&
1794 git send-email \
1795 --force \
1796 --from="Example <nobody@example.com>" \
1797 --no-to --no-cc \
1798 "$@" \
1799 --smtp-server="$(pwd)/fake.sendmail" \
1800 outdir/0000-*.patch \
1801 outdir/0001-*.patch \
1802 outdir/0002-*.patch \
1803 2>errors >out &&
1804 grep "^$header: extra@address.com" msgtxt1 >to1 &&
1805 grep "^$header: extra@address.com" msgtxt2 >to2 &&
1806 grep "^$header: extra@address.com" msgtxt3 >to3 &&
1807 test_line_count = 1 to1 &&
1808 test_line_count = 1 to2 &&
1809 test_line_count = 1 to3
1812 test_expect_success $PREREQ 'to-cover adds To to all mail' '
1813 test_cover_addresses "To" --to-cover
1816 test_expect_success $PREREQ 'cc-cover adds Cc to all mail' '
1817 test_cover_addresses "Cc" --cc-cover
1820 test_expect_success $PREREQ 'tocover adds To to all mail' '
1821 test_config sendemail.tocover true &&
1822 test_cover_addresses "To"
1825 test_expect_success $PREREQ 'cccover adds Cc to all mail' '
1826 test_config sendemail.cccover true &&
1827 test_cover_addresses "Cc"
1830 test_expect_success $PREREQ 'escaped quotes in sendemail.aliasfiletype=mutt' '
1831 clean_fake_sendmail &&
1832 echo "alias sbd \\\"Dot U. Sir\\\" <somebody@example.org>" >.mutt &&
1833 git config --replace-all sendemail.aliasesfile "$(pwd)/.mutt" &&
1834 git config sendemail.aliasfiletype mutt &&
1835 git send-email \
1836 --from="Example <nobody@example.com>" \
1837 --to=sbd \
1838 --smtp-server="$(pwd)/fake.sendmail" \
1839 outdir/0001-*.patch \
1840 2>errors >out &&
1841 grep "^!somebody@example\.org!$" commandline1 &&
1842 grep -F "To: \"Dot U. Sir\" <somebody@example.org>" out
1845 test_expect_success $PREREQ 'sendemail.aliasfiletype=mailrc' '
1846 clean_fake_sendmail &&
1847 echo "alias sbd somebody@example.org" >.mailrc &&
1848 git config --replace-all sendemail.aliasesfile "$(pwd)/.mailrc" &&
1849 git config sendemail.aliasfiletype mailrc &&
1850 git send-email \
1851 --from="Example <nobody@example.com>" \
1852 --to=sbd \
1853 --smtp-server="$(pwd)/fake.sendmail" \
1854 outdir/0001-*.patch \
1855 2>errors >out &&
1856 grep "^!somebody@example\.org!$" commandline1
1859 test_expect_success $PREREQ 'sendemail.aliasesfile=~/.mailrc' '
1860 clean_fake_sendmail &&
1861 echo "alias sbd someone@example.org" >"$HOME/.mailrc" &&
1862 git config --replace-all sendemail.aliasesfile "~/.mailrc" &&
1863 git config sendemail.aliasfiletype mailrc &&
1864 git send-email \
1865 --from="Example <nobody@example.com>" \
1866 --to=sbd \
1867 --smtp-server="$(pwd)/fake.sendmail" \
1868 outdir/0001-*.patch \
1869 2>errors >out &&
1870 grep "^!someone@example\.org!$" commandline1
1873 test_dump_aliases () {
1874 msg="$1" && shift &&
1875 filetype="$1" && shift &&
1876 printf '%s\n' "$@" >expect &&
1877 cat >.tmp-email-aliases &&
1879 test_expect_success $PREREQ "$msg" '
1880 clean_fake_sendmail && rm -fr outdir &&
1881 git config --replace-all sendemail.aliasesfile \
1882 "$(pwd)/.tmp-email-aliases" &&
1883 git config sendemail.aliasfiletype "$filetype" &&
1884 git send-email --dump-aliases 2>errors >actual &&
1885 test_cmp expect actual
1889 test_dump_aliases '--dump-aliases sendmail format' \
1890 'sendmail' \
1891 'abgroup' \
1892 'alice' \
1893 'bcgrp' \
1894 'bob' \
1895 'chloe' <<-\EOF
1896 alice: Alice W Land <awol@example.com>
1897 bob: Robert Bobbyton <bob@example.com>
1898 chloe: chloe@example.com
1899 abgroup: alice, bob
1900 bcgrp: bob, chloe, Other <o@example.com>
1903 test_dump_aliases '--dump-aliases mutt format' \
1904 'mutt' \
1905 'alice' \
1906 'bob' \
1907 'chloe' \
1908 'donald' <<-\EOF
1909 alias alice Alice W Land <awol@example.com>
1910 alias donald Donald C Carlton <donc@example.com>
1911 alias bob Robert Bobbyton <bob@example.com>
1912 alias chloe chloe@example.com
1915 test_dump_aliases '--dump-aliases mailrc format' \
1916 'mailrc' \
1917 'alice' \
1918 'bob' \
1919 'chloe' \
1920 'eve' <<-\EOF
1921 alias alice Alice W Land <awol@example.com>
1922 alias eve Eve <eve@example.com>
1923 alias bob Robert Bobbyton <bob@example.com>
1924 alias chloe chloe@example.com
1927 test_dump_aliases '--dump-aliases pine format' \
1928 'pine' \
1929 'alice' \
1930 'bob' \
1931 'chloe' \
1932 'eve' <<-\EOF
1933 alice Alice W Land <awol@example.com>
1934 eve Eve <eve@example.com>
1935 bob Robert Bobbyton <bob@example.com>
1936 chloe chloe@example.com
1939 test_dump_aliases '--dump-aliases gnus format' \
1940 'gnus' \
1941 'alice' \
1942 'bob' \
1943 'chloe' \
1944 'eve' <<-\EOF
1945 (define-mail-alias "alice" "awol@example.com")
1946 (define-mail-alias "eve" "eve@example.com")
1947 (define-mail-alias "bob" "bob@example.com")
1948 (define-mail-alias "chloe" "chloe@example.com")
1951 test_expect_success '--dump-aliases must be used alone' '
1952 test_must_fail git send-email --dump-aliases --to=janice@example.com -1 refs/heads/accounting
1955 test_expect_success $PREREQ 'aliases and sendemail.identity' '
1956 test_must_fail git \
1957 -c sendemail.identity=cloud \
1958 -c sendemail.aliasesfile=default-aliases \
1959 -c sendemail.cloud.aliasesfile=cloud-aliases \
1960 send-email -1 2>stderr &&
1961 test_i18ngrep "cloud-aliases" stderr
1964 test_sendmail_aliases () {
1965 msg="$1" && shift &&
1966 expect="$@" &&
1967 cat >.tmp-email-aliases &&
1969 test_expect_success $PREREQ "$msg" '
1970 clean_fake_sendmail && rm -fr outdir &&
1971 git format-patch -1 -o outdir &&
1972 git config --replace-all sendemail.aliasesfile \
1973 "$(pwd)/.tmp-email-aliases" &&
1974 git config sendemail.aliasfiletype sendmail &&
1975 git send-email \
1976 --from="Example <nobody@example.com>" \
1977 --to=alice --to=bcgrp \
1978 --smtp-server="$(pwd)/fake.sendmail" \
1979 outdir/0001-*.patch \
1980 2>errors >out &&
1981 for i in $expect
1983 grep "^!$i!$" commandline1 || return 1
1984 done
1988 test_sendmail_aliases 'sendemail.aliasfiletype=sendmail' \
1989 'awol@example\.com' \
1990 'bob@example\.com' \
1991 'chloe@example\.com' \
1992 'o@example\.com' <<-\EOF
1993 alice: Alice W Land <awol@example.com>
1994 bob: Robert Bobbyton <bob@example.com>
1995 # this is a comment
1996 # this is also a comment
1997 chloe: chloe@example.com
1998 abgroup: alice, bob
1999 bcgrp: bob, chloe, Other <o@example.com>
2002 test_sendmail_aliases 'sendmail aliases line folding' \
2003 alice1 \
2004 bob1 bob2 \
2005 chuck1 chuck2 \
2006 darla1 darla2 darla3 \
2007 elton1 elton2 elton3 \
2008 fred1 fred2 \
2009 greg1 <<-\EOF
2010 alice: alice1
2011 bob: bob1,\
2012 bob2
2013 chuck: chuck1,
2014 chuck2
2015 darla: darla1,\
2016 darla2,
2017 darla3
2018 elton: elton1,
2019 elton2,\
2020 elton3
2021 fred: fred1,\
2022 fred2
2023 greg: greg1
2024 bcgrp: bob, chuck, darla, elton, fred, greg
2027 test_sendmail_aliases 'sendmail aliases tolerate bogus line folding' \
2028 alice1 bob1 <<-\EOF
2029 alice: alice1
2030 bcgrp: bob1\
2033 test_sendmail_aliases 'sendmail aliases empty' alice bcgrp <<-\EOF
2036 test_expect_success $PREREQ 'alias support in To header' '
2037 clean_fake_sendmail &&
2038 echo "alias sbd someone@example.org" >.mailrc &&
2039 test_config sendemail.aliasesfile ".mailrc" &&
2040 test_config sendemail.aliasfiletype mailrc &&
2041 git format-patch --stdout -1 --to=sbd >aliased.patch &&
2042 git send-email \
2043 --from="Example <nobody@example.com>" \
2044 --smtp-server="$(pwd)/fake.sendmail" \
2045 aliased.patch \
2046 2>errors >out &&
2047 grep "^!someone@example\.org!$" commandline1
2050 test_expect_success $PREREQ 'alias support in Cc header' '
2051 clean_fake_sendmail &&
2052 echo "alias sbd someone@example.org" >.mailrc &&
2053 test_config sendemail.aliasesfile ".mailrc" &&
2054 test_config sendemail.aliasfiletype mailrc &&
2055 git format-patch --stdout -1 --cc=sbd >aliased.patch &&
2056 git send-email \
2057 --from="Example <nobody@example.com>" \
2058 --smtp-server="$(pwd)/fake.sendmail" \
2059 aliased.patch \
2060 2>errors >out &&
2061 grep "^!someone@example\.org!$" commandline1
2064 test_expect_success $PREREQ 'tocmd works with aliases' '
2065 clean_fake_sendmail &&
2066 echo "alias sbd someone@example.org" >.mailrc &&
2067 test_config sendemail.aliasesfile ".mailrc" &&
2068 test_config sendemail.aliasfiletype mailrc &&
2069 git format-patch --stdout -1 >tocmd.patch &&
2070 echo tocmd--sbd >>tocmd.patch &&
2071 git send-email \
2072 --from="Example <nobody@example.com>" \
2073 --to-cmd=./tocmd-sed \
2074 --smtp-server="$(pwd)/fake.sendmail" \
2075 tocmd.patch \
2076 2>errors >out &&
2077 grep "^!someone@example\.org!$" commandline1
2080 test_expect_success $PREREQ 'cccmd works with aliases' '
2081 clean_fake_sendmail &&
2082 echo "alias sbd someone@example.org" >.mailrc &&
2083 test_config sendemail.aliasesfile ".mailrc" &&
2084 test_config sendemail.aliasfiletype mailrc &&
2085 git format-patch --stdout -1 >cccmd.patch &&
2086 echo cccmd--sbd >>cccmd.patch &&
2087 git send-email \
2088 --from="Example <nobody@example.com>" \
2089 --cc-cmd=./cccmd-sed \
2090 --smtp-server="$(pwd)/fake.sendmail" \
2091 cccmd.patch \
2092 2>errors >out &&
2093 grep "^!someone@example\.org!$" commandline1
2096 do_xmailer_test () {
2097 expected=$1 params=$2 &&
2098 git format-patch -1 &&
2099 git send-email \
2100 --from="Example <nobody@example.com>" \
2101 --to=someone@example.com \
2102 --smtp-server="$(pwd)/fake.sendmail" \
2103 $params \
2104 0001-*.patch \
2105 2>errors >out &&
2106 { grep '^X-Mailer:' out || :; } >mailer &&
2107 test_line_count = $expected mailer
2110 test_expect_success $PREREQ '--[no-]xmailer without any configuration' '
2111 do_xmailer_test 1 "--xmailer" &&
2112 do_xmailer_test 0 "--no-xmailer"
2115 test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=true' '
2116 test_config sendemail.xmailer true &&
2117 do_xmailer_test 1 "" &&
2118 do_xmailer_test 0 "--no-xmailer" &&
2119 do_xmailer_test 1 "--xmailer"
2122 test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer' '
2123 test_when_finished "test_unconfig sendemail.xmailer" &&
2124 cat >>.git/config <<-\EOF &&
2125 [sendemail]
2126 xmailer
2128 test_config sendemail.xmailer true &&
2129 do_xmailer_test 1 "" &&
2130 do_xmailer_test 0 "--no-xmailer" &&
2131 do_xmailer_test 1 "--xmailer"
2134 test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=false' '
2135 test_config sendemail.xmailer false &&
2136 do_xmailer_test 0 "" &&
2137 do_xmailer_test 0 "--no-xmailer" &&
2138 do_xmailer_test 1 "--xmailer"
2141 test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=' '
2142 test_config sendemail.xmailer "" &&
2143 do_xmailer_test 0 "" &&
2144 do_xmailer_test 0 "--no-xmailer" &&
2145 do_xmailer_test 1 "--xmailer"
2148 test_expect_success $PREREQ 'setup expected-list' '
2149 git send-email \
2150 --dry-run \
2151 --from="Example <from@example.com>" \
2152 --to="To 1 <to1@example.com>" \
2153 --to="to2@example.com" \
2154 --to="to3@example.com" \
2155 --cc="Cc 1 <cc1@example.com>" \
2156 --cc="Cc2 <cc2@example.com>" \
2157 --bcc="bcc1@example.com" \
2158 --bcc="bcc2@example.com" \
2159 0001-add-main.patch | replace_variable_fields \
2160 >expected-list
2163 test_expect_success $PREREQ 'use email list in --cc --to and --bcc' '
2164 git send-email \
2165 --dry-run \
2166 --from="Example <from@example.com>" \
2167 --to="To 1 <to1@example.com>, to2@example.com" \
2168 --to="to3@example.com" \
2169 --cc="Cc 1 <cc1@example.com>, Cc2 <cc2@example.com>" \
2170 --bcc="bcc1@example.com, bcc2@example.com" \
2171 0001-add-main.patch | replace_variable_fields \
2172 >actual-list &&
2173 test_cmp expected-list actual-list
2176 test_expect_success $PREREQ 'aliases work with email list' '
2177 echo "alias to2 to2@example.com" >.mutt &&
2178 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt &&
2179 test_config sendemail.aliasesfile ".mutt" &&
2180 test_config sendemail.aliasfiletype mutt &&
2181 git send-email \
2182 --dry-run \
2183 --from="Example <from@example.com>" \
2184 --to="To 1 <to1@example.com>, to2, to3@example.com" \
2185 --cc="cc1, Cc2 <cc2@example.com>" \
2186 --bcc="bcc1@example.com, bcc2@example.com" \
2187 0001-add-main.patch | replace_variable_fields \
2188 >actual-list &&
2189 test_cmp expected-list actual-list
2192 test_expect_success $PREREQ 'leading and trailing whitespaces are removed' '
2193 echo "alias to2 to2@example.com" >.mutt &&
2194 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt &&
2195 test_config sendemail.aliasesfile ".mutt" &&
2196 test_config sendemail.aliasfiletype mutt &&
2197 TO1=$(echo "QTo 1 <to1@example.com>" | q_to_tab) &&
2198 TO2=$(echo "QZto2" | qz_to_tab_space) &&
2199 CC1=$(echo "cc1" | append_cr) &&
2200 BCC1=$(echo " bcc1@example.com Q" | q_to_nul) &&
2201 git send-email \
2202 --dry-run \
2203 --from=" Example <from@example.com>" \
2204 --to="$TO1" \
2205 --to="$TO2" \
2206 --to=" to3@example.com " \
2207 --cc="$CC1" \
2208 --cc="Cc2 <cc2@example.com>" \
2209 --bcc="$BCC1" \
2210 --bcc="bcc2@example.com" \
2211 0001-add-main.patch | replace_variable_fields \
2212 >actual-list &&
2213 test_cmp expected-list actual-list
2216 test_expect_success $PREREQ 'test using command name with --sendmail-cmd' '
2217 clean_fake_sendmail &&
2218 PATH="$PWD:$PATH" \
2219 git send-email \
2220 --from="Example <nobody@example.com>" \
2221 --to=nobody@example.com \
2222 --sendmail-cmd="fake.sendmail" \
2223 HEAD^ &&
2224 test_path_is_file commandline1
2227 test_expect_success $PREREQ 'test using arguments with --sendmail-cmd' '
2228 clean_fake_sendmail &&
2229 git send-email \
2230 --from="Example <nobody@example.com>" \
2231 --to=nobody@example.com \
2232 --sendmail-cmd='\''"$(pwd)/fake.sendmail" -f nobody@example.com'\'' \
2233 HEAD^ &&
2234 test_path_is_file commandline1
2237 test_expect_success $PREREQ 'test shell expression with --sendmail-cmd' '
2238 clean_fake_sendmail &&
2239 git send-email \
2240 --from="Example <nobody@example.com>" \
2241 --to=nobody@example.com \
2242 --sendmail-cmd='\''f() { "$(pwd)/fake.sendmail" "$@"; };f'\'' \
2243 HEAD^ &&
2244 test_path_is_file commandline1
2247 test_expect_success $PREREQ 'set up in-reply-to/references patches' '
2248 cat >has-reply.patch <<-\EOF &&
2249 From: A U Thor <author@example.com>
2250 Subject: patch with in-reply-to
2251 Message-ID: <patch.with.in.reply.to@example.com>
2252 In-Reply-To: <replied.to@example.com>
2253 References: <replied.to@example.com>
2255 This is the body.
2257 cat >no-reply.patch <<-\EOF
2258 From: A U Thor <author@example.com>
2259 Subject: patch without in-reply-to
2260 Message-ID: <patch.without.in.reply.to@example.com>
2262 This is the body.
2266 test_expect_success $PREREQ 'patch reply headers correct with --no-thread' '
2267 clean_fake_sendmail &&
2268 git send-email \
2269 --no-thread \
2270 --to=nobody@example.com \
2271 --smtp-server="$(pwd)/fake.sendmail" \
2272 has-reply.patch no-reply.patch &&
2273 grep "In-Reply-To: <replied.to@example.com>" msgtxt1 &&
2274 grep "References: <replied.to@example.com>" msgtxt1 &&
2275 ! grep replied.to@example.com msgtxt2
2278 test_expect_success $PREREQ 'cmdline in-reply-to used with --no-thread' '
2279 clean_fake_sendmail &&
2280 git send-email \
2281 --no-thread \
2282 --in-reply-to="<cmdline.reply@example.com>" \
2283 --to=nobody@example.com \
2284 --smtp-server="$(pwd)/fake.sendmail" \
2285 has-reply.patch no-reply.patch &&
2286 grep "In-Reply-To: <cmdline.reply@example.com>" msgtxt1 &&
2287 grep "References: <cmdline.reply@example.com>" msgtxt1 &&
2288 grep "In-Reply-To: <cmdline.reply@example.com>" msgtxt2 &&
2289 grep "References: <cmdline.reply@example.com>" msgtxt2
2292 test_expect_success $PREREQ 'invoke hook' '
2293 test_hook sendemail-validate <<-\EOF &&
2294 # test that we have the correct environment variable, pwd, and
2295 # argument
2296 case "$GIT_DIR" in
2297 *.git)
2298 true
2301 false
2303 esac &&
2304 test -f 0001-add-main.patch &&
2305 grep "add main" "$1"
2308 mkdir subdir &&
2310 # Test that it works even if we are not at the root of the
2311 # working tree
2312 cd subdir &&
2313 git send-email \
2314 --from="Example <nobody@example.com>" \
2315 --to=nobody@example.com \
2316 --smtp-server="$(pwd)/../fake.sendmail" \
2317 ../0001-add-main.patch &&
2319 # Verify error message when a patch is rejected by the hook
2320 sed -e "s/add main/x/" ../0001-add-main.patch >../another.patch &&
2321 test_must_fail git send-email \
2322 --from="Example <nobody@example.com>" \
2323 --to=nobody@example.com \
2324 --smtp-server="$(pwd)/../fake.sendmail" \
2325 ../another.patch 2>err &&
2326 test_i18ngrep "rejected by sendemail-validate hook" err
2330 test_expect_success $PREREQ 'test that send-email works outside a repo' '
2331 nongit git send-email \
2332 --from="Example <nobody@example.com>" \
2333 --to=nobody@example.com \
2334 --smtp-server="$(pwd)/fake.sendmail" \
2335 "$(pwd)/0001-add-main.patch"
2338 test_expect_success $PREREQ 'test that sendmail config is rejected' '
2339 test_config sendmail.program sendmail &&
2340 test_must_fail git send-email \
2341 --from="Example <nobody@example.com>" \
2342 --to=nobody@example.com \
2343 --smtp-server="$(pwd)/fake.sendmail" \
2344 HEAD^ 2>err &&
2345 test_i18ngrep "found configuration options for '"'"sendmail"'"'" err
2348 test_expect_success $PREREQ 'test that sendmail config rejection is specific' '
2349 test_config resendmail.program sendmail &&
2350 git send-email \
2351 --from="Example <nobody@example.com>" \
2352 --to=nobody@example.com \
2353 --smtp-server="$(pwd)/fake.sendmail" \
2354 HEAD^
2357 test_expect_success $PREREQ 'test forbidSendmailVariables behavior override' '
2358 test_config sendmail.program sendmail &&
2359 test_config sendemail.forbidSendmailVariables false &&
2360 git send-email \
2361 --from="Example <nobody@example.com>" \
2362 --to=nobody@example.com \
2363 --smtp-server="$(pwd)/fake.sendmail" \
2364 HEAD^
2367 test_done