send-email: clear the $message_id after validation
[alt-git.git] / t / t9001-send-email.sh
blob8d49eff91a384e0df883e242ffdfd0edac6c3c60
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 --thread=shallow -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 ""
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
349 test_expect_success $PREREQ,AUTOIDENT 'implicit ident is allowed' '
350 clean_fake_sendmail &&
351 (sane_unset GIT_AUTHOR_NAME &&
352 sane_unset GIT_AUTHOR_EMAIL &&
353 sane_unset GIT_COMMITTER_NAME &&
354 sane_unset GIT_COMMITTER_EMAIL &&
355 GIT_SEND_EMAIL_NOTTY=1 git send-email \
356 --smtp-server="$(pwd)/fake.sendmail" \
357 --to=to@example.com \
358 $patches </dev/null 2>errors
362 test_expect_success $PREREQ,!AUTOIDENT 'broken implicit ident aborts send-email' '
363 clean_fake_sendmail &&
364 (sane_unset GIT_AUTHOR_NAME &&
365 sane_unset GIT_AUTHOR_EMAIL &&
366 sane_unset GIT_COMMITTER_NAME &&
367 sane_unset GIT_COMMITTER_EMAIL &&
368 GIT_SEND_EMAIL_NOTTY=1 && export GIT_SEND_EMAIL_NOTTY &&
369 test_must_fail git send-email \
370 --smtp-server="$(pwd)/fake.sendmail" \
371 --to=to@example.com \
372 $patches </dev/null 2>errors &&
373 test_i18ngrep "tell me who you are" errors
377 test_expect_success $PREREQ 'setup tocmd and cccmd scripts' '
378 write_script tocmd-sed <<-\EOF &&
379 sed -n -e "s/^tocmd--//p" "$1"
381 write_script cccmd-sed <<-\EOF
382 sed -n -e "s/^cccmd--//p" "$1"
386 test_expect_success $PREREQ 'tocmd works' '
387 clean_fake_sendmail &&
388 cp $patches tocmd.patch &&
389 echo tocmd--tocmd@example.com >>tocmd.patch &&
390 git send-email \
391 --from="Example <nobody@example.com>" \
392 --to-cmd=./tocmd-sed \
393 --smtp-server="$(pwd)/fake.sendmail" \
394 tocmd.patch \
396 grep "^To: tocmd@example.com" msgtxt1
399 test_expect_success $PREREQ 'cccmd works' '
400 clean_fake_sendmail &&
401 cp $patches cccmd.patch &&
402 echo "cccmd-- cccmd@example.com" >>cccmd.patch &&
403 git send-email \
404 --from="Example <nobody@example.com>" \
405 --to=nobody@example.com \
406 --cc-cmd=./cccmd-sed \
407 --smtp-server="$(pwd)/fake.sendmail" \
408 cccmd.patch \
410 grep "^ cccmd@example.com" msgtxt1
413 test_expect_success $PREREQ 'reject long lines' '
414 z8=zzzzzzzz &&
415 z64=$z8$z8$z8$z8$z8$z8$z8$z8 &&
416 z512=$z64$z64$z64$z64$z64$z64$z64$z64 &&
417 clean_fake_sendmail &&
418 cp $patches longline.patch &&
419 cat >>longline.patch <<-EOF &&
420 $z512$z512
421 not a long line
422 $z512$z512
424 test_must_fail git send-email \
425 --from="Example <nobody@example.com>" \
426 --to=nobody@example.com \
427 --smtp-server="$(pwd)/fake.sendmail" \
428 --transfer-encoding=8bit \
429 $patches longline.patch \
430 2>actual &&
431 cat >expect <<-\EOF &&
432 fatal: longline.patch:35 is longer than 998 characters
433 warning: no patches were sent
435 test_cmp expect actual
438 test_expect_success $PREREQ 'no patch was sent' '
439 ! test -e commandline1
442 test_expect_success $PREREQ 'Author From: in message body' '
443 clean_fake_sendmail &&
444 git send-email \
445 --from="Example <nobody@example.com>" \
446 --to=nobody@example.com \
447 --smtp-server="$(pwd)/fake.sendmail" \
448 $patches &&
449 sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
450 grep "From: A <author@example.com>" msgbody1
453 test_expect_success $PREREQ 'Author From: not in message body' '
454 clean_fake_sendmail &&
455 git send-email \
456 --from="A <author@example.com>" \
457 --to=nobody@example.com \
458 --smtp-server="$(pwd)/fake.sendmail" \
459 $patches &&
460 sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
461 ! grep "From: A <author@example.com>" msgbody1
464 test_expect_success $PREREQ 'allow long lines with --no-validate' '
465 git send-email \
466 --from="Example <nobody@example.com>" \
467 --to=nobody@example.com \
468 --smtp-server="$(pwd)/fake.sendmail" \
469 --no-validate \
470 $patches longline.patch \
471 2>errors
474 test_expect_success $PREREQ 'short lines with auto encoding are 8bit' '
475 clean_fake_sendmail &&
476 git send-email \
477 --from="A <author@example.com>" \
478 --to=nobody@example.com \
479 --smtp-server="$(pwd)/fake.sendmail" \
480 --transfer-encoding=auto \
481 $patches &&
482 grep "Content-Transfer-Encoding: 8bit" msgtxt1
485 test_expect_success $PREREQ 'long lines with auto encoding are quoted-printable' '
486 clean_fake_sendmail &&
487 git send-email \
488 --from="Example <nobody@example.com>" \
489 --to=nobody@example.com \
490 --smtp-server="$(pwd)/fake.sendmail" \
491 --transfer-encoding=auto \
492 --no-validate \
493 longline.patch &&
494 grep "Content-Transfer-Encoding: quoted-printable" msgtxt1
497 test_expect_success $PREREQ 'carriage returns with auto encoding are quoted-printable' '
498 clean_fake_sendmail &&
499 cp $patches cr.patch &&
500 printf "this is a line\r\n" >>cr.patch &&
501 git send-email \
502 --from="Example <nobody@example.com>" \
503 --to=nobody@example.com \
504 --smtp-server="$(pwd)/fake.sendmail" \
505 --transfer-encoding=auto \
506 --no-validate \
507 cr.patch &&
508 grep "Content-Transfer-Encoding: quoted-printable" msgtxt1
511 for enc in auto quoted-printable base64
513 test_expect_success $PREREQ "--validate passes with encoding $enc" '
514 git send-email \
515 --from="Example <nobody@example.com>" \
516 --to=nobody@example.com \
517 --smtp-server="$(pwd)/fake.sendmail" \
518 --transfer-encoding=$enc \
519 --validate \
520 $patches longline.patch
523 done
525 test_expect_success $PREREQ "--validate respects relative core.hooksPath path" '
526 clean_fake_sendmail &&
527 mkdir my-hooks &&
528 test_when_finished "rm my-hooks.ran" &&
529 write_script my-hooks/sendemail-validate <<-\EOF &&
530 >my-hooks.ran
531 exit 1
533 test_config core.hooksPath "my-hooks" &&
534 test_must_fail git send-email \
535 --from="Example <nobody@example.com>" \
536 --to=nobody@example.com \
537 --smtp-server="$(pwd)/fake.sendmail" \
538 --validate \
539 longline.patch 2>actual &&
540 test_path_is_file my-hooks.ran &&
541 cat >expect <<-EOF &&
542 fatal: longline.patch: rejected by sendemail-validate hook
543 fatal: command '"'"'git hook run --ignore-missing sendemail-validate -- <patch> <header>'"'"' died with exit code 1
544 warning: no patches were sent
546 test_cmp expect actual
549 test_expect_success $PREREQ "--validate respects absolute core.hooksPath path" '
550 hooks_path="$(pwd)/my-hooks" &&
551 test_config core.hooksPath "$hooks_path" &&
552 test_when_finished "rm my-hooks.ran" &&
553 test_must_fail git send-email \
554 --from="Example <nobody@example.com>" \
555 --to=nobody@example.com \
556 --smtp-server="$(pwd)/fake.sendmail" \
557 --validate \
558 longline.patch 2>actual &&
559 test_path_is_file my-hooks.ran &&
560 cat >expect <<-EOF &&
561 fatal: longline.patch: rejected by sendemail-validate hook
562 fatal: command '"'"'git hook run --ignore-missing sendemail-validate -- <patch> <header>'"'"' died with exit code 1
563 warning: no patches were sent
565 test_cmp expect actual
568 test_expect_success $PREREQ "--validate hook supports header argument" '
569 write_script my-hooks/sendemail-validate <<-\EOF &&
570 if test "$#" -ge 2
571 then
572 grep "X-test-header: v1.0" "$2"
573 else
574 echo "No header arg passed"
575 exit 1
578 test_config core.hooksPath "my-hooks" &&
579 rm -fr outdir &&
580 git format-patch \
581 --add-header="X-test-header: v1.0" \
582 -n HEAD^1 -o outdir &&
583 git send-email \
584 --dry-run \
585 --to=nobody@example.com \
586 --smtp-server="$(pwd)/fake.sendmail" \
587 --validate \
588 outdir/000?-*.patch
591 test_expect_success $PREREQ 'clear message-id before parsing a new message' '
592 clean_fake_sendmail &&
593 echo true | write_script my-hooks/sendemail-validate &&
594 test_config core.hooksPath my-hooks &&
595 GIT_SEND_EMAIL_NOTTY=1 \
596 git send-email --validate --to=recipient@example.com \
597 --smtp-server="$(pwd)/fake.sendmail" \
598 $patches $threaded_patches &&
599 id0=$(grep "^Message-ID: " $threaded_patches) &&
600 id1=$(grep "^Message-ID: " msgtxt1) &&
601 id2=$(grep "^Message-ID: " msgtxt2) &&
602 test "z$id0" = "z$id2" &&
603 test "z$id1" != "z$id2"
606 for enc in 7bit 8bit quoted-printable base64
608 test_expect_success $PREREQ "--transfer-encoding=$enc produces correct header" '
609 clean_fake_sendmail &&
610 git send-email \
611 --from="Example <nobody@example.com>" \
612 --to=nobody@example.com \
613 --smtp-server="$(pwd)/fake.sendmail" \
614 --transfer-encoding=$enc \
615 $patches &&
616 grep "Content-Transfer-Encoding: $enc" msgtxt1
618 done
620 test_expect_success $PREREQ 'Invalid In-Reply-To' '
621 clean_fake_sendmail &&
622 git send-email \
623 --from="Example <nobody@example.com>" \
624 --to=nobody@example.com \
625 --in-reply-to=" " \
626 --smtp-server="$(pwd)/fake.sendmail" \
627 $patches \
628 2>errors &&
629 ! grep "^In-Reply-To: < *>" msgtxt1
632 test_expect_success $PREREQ 'Valid In-Reply-To when prompting' '
633 clean_fake_sendmail &&
634 (echo "From Example <from@example.com>" &&
635 echo "To Example <to@example.com>" &&
636 echo ""
637 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
638 --smtp-server="$(pwd)/fake.sendmail" \
639 $patches 2>errors &&
640 ! grep "^In-Reply-To: < *>" msgtxt1
643 test_expect_success $PREREQ 'In-Reply-To without --chain-reply-to' '
644 clean_fake_sendmail &&
645 echo "<unique-message-id@example.com>" >expect &&
646 git send-email \
647 --from="Example <nobody@example.com>" \
648 --to=nobody@example.com \
649 --no-chain-reply-to \
650 --in-reply-to="$(cat expect)" \
651 --smtp-server="$(pwd)/fake.sendmail" \
652 $patches $patches $patches \
653 2>errors &&
654 # The first message is a reply to --in-reply-to
655 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
656 test_cmp expect actual &&
657 # Second and subsequent messages are replies to the first one
658 sed -n -e "s/^Message-ID: *\(.*\)/\1/p" msgtxt1 >expect &&
659 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
660 test_cmp expect actual &&
661 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
662 test_cmp expect actual
665 test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' '
666 clean_fake_sendmail &&
667 echo "<unique-message-id@example.com>" >expect &&
668 git send-email \
669 --from="Example <nobody@example.com>" \
670 --to=nobody@example.com \
671 --chain-reply-to \
672 --in-reply-to="$(cat expect)" \
673 --smtp-server="$(pwd)/fake.sendmail" \
674 $patches $patches $patches \
675 2>errors &&
676 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
677 test_cmp expect actual &&
678 sed -n -e "s/^Message-ID: *\(.*\)/\1/p" msgtxt1 >expect &&
679 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
680 test_cmp expect actual &&
681 sed -n -e "s/^Message-ID: *\(.*\)/\1/p" msgtxt2 >expect &&
682 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
683 test_cmp expect actual
686 test_set_editor "$(pwd)/fake-editor"
688 test_expect_success $PREREQ 'setup erroring fake editor' '
689 write_script fake-editor <<-\EOF
690 echo >&2 "I am about to error"
691 exit 1
695 test_expect_success $PREREQ 'fake editor dies with error' '
696 clean_fake_sendmail &&
697 test_must_fail git send-email \
698 --compose --subject foo \
699 --from="Example <nobody@example.com>" \
700 --to=nobody@example.com \
701 --smtp-server="$(pwd)/fake.sendmail" \
702 $patches 2>err &&
703 grep "I am about to error" err &&
704 grep "the editor exited uncleanly, aborting everything" err
707 test_expect_success $PREREQ 'setup fake editor' '
708 write_script fake-editor <<-\EOF
709 echo fake edit >>"$1"
713 test_expect_success $PREREQ '--compose works' '
714 clean_fake_sendmail &&
715 git send-email \
716 --compose --subject foo \
717 --from="Example <nobody@example.com>" \
718 --to=nobody@example.com \
719 --smtp-server="$(pwd)/fake.sendmail" \
720 $patches \
721 2>errors
724 test_expect_success $PREREQ 'first message is compose text' '
725 grep "^fake edit" msgtxt1
728 test_expect_success $PREREQ 'second message is patch' '
729 grep "Subject:.*Second" msgtxt2
732 test_expect_success $PREREQ 'setup expect' "
733 cat >expected-suppress-sob <<\EOF
734 0001-Second.patch
735 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
736 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
737 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
738 Dry-OK. Log says:
739 Server: relay.example.com
740 MAIL FROM:<from@example.com>
741 RCPT TO:<to@example.com>
742 RCPT TO:<cc@example.com>
743 RCPT TO:<author@example.com>
744 RCPT TO:<one@example.com>
745 RCPT TO:<two@example.com>
746 From: Example <from@example.com>
747 To: to@example.com
748 Cc: cc@example.com,
749 A <author@example.com>,
750 One <one@example.com>,
751 two@example.com
752 Subject: [PATCH 1/1] Second.
753 Date: DATE-STRING
754 Message-ID: MESSAGE-ID-STRING
755 X-Mailer: X-MAILER-STRING
756 MIME-Version: 1.0
757 Content-Transfer-Encoding: 8bit
759 Result: OK
763 test_suppression () {
764 git send-email \
765 --dry-run \
766 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
767 --from="Example <from@example.com>" \
768 --to=to@example.com \
769 --smtp-server relay.example.com \
770 $patches | replace_variable_fields \
771 >actual-suppress-$1${2+"-$2"} &&
772 test_cmp expected-suppress-$1${2+"-$2"} actual-suppress-$1${2+"-$2"}
775 test_expect_success $PREREQ 'sendemail.cc set' '
776 git config sendemail.cc cc@example.com &&
777 test_suppression sob
780 test_expect_success $PREREQ 'setup expect' "
781 cat >expected-suppress-sob <<\EOF
782 0001-Second.patch
783 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
784 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
785 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
786 Dry-OK. Log says:
787 Server: relay.example.com
788 MAIL FROM:<from@example.com>
789 RCPT TO:<to@example.com>
790 RCPT TO:<author@example.com>
791 RCPT TO:<one@example.com>
792 RCPT TO:<two@example.com>
793 From: Example <from@example.com>
794 To: to@example.com
795 Cc: A <author@example.com>,
796 One <one@example.com>,
797 two@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.cc unset' '
810 git config --unset sendemail.cc &&
811 test_suppression sob
814 test_expect_success $PREREQ 'setup expect' "
815 cat >expected-suppress-cccmd <<\EOF
816 0001-Second.patch
817 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
818 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
819 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
820 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
821 Dry-OK. Log says:
822 Server: relay.example.com
823 MAIL FROM:<from@example.com>
824 RCPT TO:<to@example.com>
825 RCPT TO:<author@example.com>
826 RCPT TO:<one@example.com>
827 RCPT TO:<two@example.com>
828 RCPT TO:<committer@example.com>
829 From: Example <from@example.com>
830 To: to@example.com
831 Cc: A <author@example.com>,
832 One <one@example.com>,
833 two@example.com,
834 C O Mitter <committer@example.com>
835 Subject: [PATCH 1/1] Second.
836 Date: DATE-STRING
837 Message-ID: MESSAGE-ID-STRING
838 X-Mailer: X-MAILER-STRING
839 MIME-Version: 1.0
840 Content-Transfer-Encoding: 8bit
842 Result: OK
846 test_expect_success $PREREQ 'sendemail.cccmd' '
847 write_script cccmd <<-\EOF &&
848 echo cc-cmd@example.com
850 git config sendemail.cccmd ./cccmd &&
851 test_suppression cccmd
854 test_expect_success $PREREQ 'setup expect' '
855 cat >expected-suppress-all <<\EOF
856 0001-Second.patch
857 Dry-OK. Log says:
858 Server: relay.example.com
859 MAIL FROM:<from@example.com>
860 RCPT TO:<to@example.com>
861 From: Example <from@example.com>
862 To: to@example.com
863 Subject: [PATCH 1/1] Second.
864 Date: DATE-STRING
865 Message-ID: MESSAGE-ID-STRING
866 X-Mailer: X-MAILER-STRING
867 MIME-Version: 1.0
868 Content-Transfer-Encoding: 8bit
870 Result: OK
874 test_expect_success $PREREQ '--suppress-cc=all' '
875 test_suppression all
878 test_expect_success $PREREQ 'setup expect' "
879 cat >expected-suppress-body <<\EOF
880 0001-Second.patch
881 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
882 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
883 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
884 (cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
885 Dry-OK. Log says:
886 Server: relay.example.com
887 MAIL FROM:<from@example.com>
888 RCPT TO:<to@example.com>
889 RCPT TO:<author@example.com>
890 RCPT TO:<one@example.com>
891 RCPT TO:<two@example.com>
892 RCPT TO:<cc-cmd@example.com>
893 From: Example <from@example.com>
894 To: to@example.com
895 Cc: A <author@example.com>,
896 One <one@example.com>,
897 two@example.com,
898 cc-cmd@example.com
899 Subject: [PATCH 1/1] Second.
900 Date: DATE-STRING
901 Message-ID: MESSAGE-ID-STRING
902 X-Mailer: X-MAILER-STRING
903 MIME-Version: 1.0
904 Content-Transfer-Encoding: 8bit
906 Result: OK
910 test_expect_success $PREREQ '--suppress-cc=body' '
911 test_suppression body
914 test_expect_success $PREREQ 'setup expect' "
915 cat >expected-suppress-body-cccmd <<\EOF
916 0001-Second.patch
917 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
918 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
919 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
920 Dry-OK. Log says:
921 Server: relay.example.com
922 MAIL FROM:<from@example.com>
923 RCPT TO:<to@example.com>
924 RCPT TO:<author@example.com>
925 RCPT TO:<one@example.com>
926 RCPT TO:<two@example.com>
927 From: Example <from@example.com>
928 To: to@example.com
929 Cc: A <author@example.com>,
930 One <one@example.com>,
931 two@example.com
932 Subject: [PATCH 1/1] Second.
933 Date: DATE-STRING
934 Message-ID: MESSAGE-ID-STRING
935 X-Mailer: X-MAILER-STRING
936 MIME-Version: 1.0
937 Content-Transfer-Encoding: 8bit
939 Result: OK
943 test_expect_success $PREREQ '--suppress-cc=body --suppress-cc=cccmd' '
944 test_suppression body cccmd
947 test_expect_success $PREREQ 'setup expect' "
948 cat >expected-suppress-sob <<\EOF
949 0001-Second.patch
950 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
951 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
952 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
953 Dry-OK. Log says:
954 Server: relay.example.com
955 MAIL FROM:<from@example.com>
956 RCPT TO:<to@example.com>
957 RCPT TO:<author@example.com>
958 RCPT TO:<one@example.com>
959 RCPT TO:<two@example.com>
960 From: Example <from@example.com>
961 To: to@example.com
962 Cc: A <author@example.com>,
963 One <one@example.com>,
964 two@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=sob' '
977 test_might_fail git config --unset sendemail.cccmd &&
978 test_suppression sob
981 test_expect_success $PREREQ 'setup expect' "
982 cat >expected-suppress-bodycc <<\EOF
983 0001-Second.patch
984 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
985 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
986 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
987 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
988 Dry-OK. Log says:
989 Server: relay.example.com
990 MAIL FROM:<from@example.com>
991 RCPT TO:<to@example.com>
992 RCPT TO:<author@example.com>
993 RCPT TO:<one@example.com>
994 RCPT TO:<two@example.com>
995 RCPT TO:<committer@example.com>
996 From: Example <from@example.com>
997 To: to@example.com
998 Cc: A <author@example.com>,
999 One <one@example.com>,
1000 two@example.com,
1001 C O Mitter <committer@example.com>
1002 Subject: [PATCH 1/1] Second.
1003 Date: DATE-STRING
1004 Message-ID: MESSAGE-ID-STRING
1005 X-Mailer: X-MAILER-STRING
1006 MIME-Version: 1.0
1007 Content-Transfer-Encoding: 8bit
1009 Result: OK
1013 test_expect_success $PREREQ '--suppress-cc=bodycc' '
1014 test_suppression bodycc
1017 test_expect_success $PREREQ 'setup expect' "
1018 cat >expected-suppress-cc <<\EOF
1019 0001-Second.patch
1020 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
1021 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
1022 Dry-OK. Log says:
1023 Server: relay.example.com
1024 MAIL FROM:<from@example.com>
1025 RCPT TO:<to@example.com>
1026 RCPT TO:<author@example.com>
1027 RCPT TO:<committer@example.com>
1028 From: Example <from@example.com>
1029 To: to@example.com
1030 Cc: A <author@example.com>,
1031 C O Mitter <committer@example.com>
1032 Subject: [PATCH 1/1] Second.
1033 Date: DATE-STRING
1034 Message-ID: MESSAGE-ID-STRING
1035 X-Mailer: X-MAILER-STRING
1036 MIME-Version: 1.0
1037 Content-Transfer-Encoding: 8bit
1039 Result: OK
1043 test_expect_success $PREREQ '--suppress-cc=cc' '
1044 test_suppression cc
1047 test_confirm () {
1048 echo y | \
1049 GIT_SEND_EMAIL_NOTTY=1 \
1050 git send-email \
1051 --from="Example <nobody@example.com>" \
1052 --to=nobody@example.com \
1053 --smtp-server="$(pwd)/fake.sendmail" \
1054 $@ $patches >stdout &&
1055 grep "Send this email" stdout
1058 test_expect_success $PREREQ '--confirm=always' '
1059 test_confirm --confirm=always --suppress-cc=all
1062 test_expect_success $PREREQ '--confirm=auto' '
1063 test_confirm --confirm=auto
1066 test_expect_success $PREREQ '--confirm=cc' '
1067 test_confirm --confirm=cc
1070 test_expect_success $PREREQ '--confirm=compose' '
1071 test_confirm --confirm=compose --compose
1074 test_expect_success $PREREQ 'confirm by default (due to cc)' '
1075 test_when_finished git config sendemail.confirm never &&
1076 git config --unset sendemail.confirm &&
1077 test_confirm
1080 test_expect_success $PREREQ 'confirm by default (due to --compose)' '
1081 test_when_finished git config sendemail.confirm never &&
1082 git config --unset sendemail.confirm &&
1083 test_confirm --suppress-cc=all --compose
1086 test_expect_success $PREREQ 'confirm detects EOF (inform assumes y)' '
1087 test_when_finished git config sendemail.confirm never &&
1088 git config --unset sendemail.confirm &&
1089 rm -fr outdir &&
1090 git format-patch -2 -o outdir &&
1091 GIT_SEND_EMAIL_NOTTY=1 \
1092 git send-email \
1093 --from="Example <nobody@example.com>" \
1094 --to=nobody@example.com \
1095 --smtp-server="$(pwd)/fake.sendmail" \
1096 outdir/*.patch </dev/null
1099 test_expect_success $PREREQ 'confirm detects EOF (auto causes failure)' '
1100 test_when_finished git config sendemail.confirm never &&
1101 git config sendemail.confirm auto &&
1102 GIT_SEND_EMAIL_NOTTY=1 &&
1103 export GIT_SEND_EMAIL_NOTTY &&
1104 test_must_fail git send-email \
1105 --from="Example <nobody@example.com>" \
1106 --to=nobody@example.com \
1107 --smtp-server="$(pwd)/fake.sendmail" \
1108 $patches </dev/null
1111 test_expect_success $PREREQ 'confirm does not loop forever' '
1112 test_when_finished git config sendemail.confirm never &&
1113 git config sendemail.confirm auto &&
1114 GIT_SEND_EMAIL_NOTTY=1 &&
1115 export GIT_SEND_EMAIL_NOTTY &&
1116 yes "bogus" | test_must_fail git send-email \
1117 --from="Example <nobody@example.com>" \
1118 --to=nobody@example.com \
1119 --smtp-server="$(pwd)/fake.sendmail" \
1120 $patches
1123 test_expect_success $PREREQ 'utf8 Cc is rfc2047 encoded' '
1124 clean_fake_sendmail &&
1125 rm -fr outdir &&
1126 git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
1127 git send-email \
1128 --from="Example <nobody@example.com>" \
1129 --to=nobody@example.com \
1130 --smtp-server="$(pwd)/fake.sendmail" \
1131 outdir/*.patch &&
1132 grep "^ " msgtxt1 |
1133 grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
1136 test_expect_success $PREREQ '--compose adds MIME for utf8 body' '
1137 clean_fake_sendmail &&
1138 write_script fake-editor-utf8 <<-\EOF &&
1139 echo "utf8 body: àéìöú" >>"$1"
1141 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1142 git send-email \
1143 --compose --subject foo \
1144 --from="Example <nobody@example.com>" \
1145 --to=nobody@example.com \
1146 --smtp-server="$(pwd)/fake.sendmail" \
1147 $patches &&
1148 grep "^utf8 body" msgtxt1 &&
1149 grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
1152 test_expect_success $PREREQ '--compose respects user mime type' '
1153 clean_fake_sendmail &&
1154 write_script fake-editor-utf8-mime <<-\EOF &&
1155 cat >"$1" <<-\EOM
1156 MIME-Version: 1.0
1157 Content-Type: text/plain; charset=iso-8859-1
1158 Content-Transfer-Encoding: 8bit
1159 Subject: foo
1161 utf8 body: àéìöú
1164 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
1165 git send-email \
1166 --compose --subject foo \
1167 --from="Example <nobody@example.com>" \
1168 --to=nobody@example.com \
1169 --smtp-server="$(pwd)/fake.sendmail" \
1170 $patches &&
1171 grep "^utf8 body" msgtxt1 &&
1172 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
1173 ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
1176 test_expect_success $PREREQ '--compose adds MIME for utf8 subject' '
1177 clean_fake_sendmail &&
1178 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
1179 git send-email \
1180 --compose --subject utf8-sübjëct \
1181 --from="Example <nobody@example.com>" \
1182 --to=nobody@example.com \
1183 --smtp-server="$(pwd)/fake.sendmail" \
1184 $patches &&
1185 grep "^fake edit" msgtxt1 &&
1186 grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
1189 test_expect_success $PREREQ 'utf8 author is correctly passed on' '
1190 clean_fake_sendmail &&
1191 test_commit weird_author &&
1192 test_when_finished "git reset --hard HEAD^" &&
1193 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
1194 git format-patch --stdout -1 >funny_name.patch &&
1195 git send-email --from="Example <nobody@example.com>" \
1196 --to=nobody@example.com \
1197 --smtp-server="$(pwd)/fake.sendmail" \
1198 funny_name.patch &&
1199 grep "^From: Füñný Nâmé <odd_?=mail@example.com>" msgtxt1
1202 test_expect_success $PREREQ 'utf8 sender is not duplicated' '
1203 clean_fake_sendmail &&
1204 test_commit weird_sender &&
1205 test_when_finished "git reset --hard HEAD^" &&
1206 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
1207 git format-patch --stdout -1 >funny_name.patch &&
1208 git send-email --from="Füñný Nâmé <odd_?=mail@example.com>" \
1209 --to=nobody@example.com \
1210 --smtp-server="$(pwd)/fake.sendmail" \
1211 funny_name.patch &&
1212 grep "^From: " msgtxt1 >msgfrom &&
1213 test_line_count = 1 msgfrom
1216 test_expect_success $PREREQ 'sendemail.composeencoding works' '
1217 clean_fake_sendmail &&
1218 git config sendemail.composeencoding iso-8859-1 &&
1219 write_script fake-editor-utf8 <<-\EOF &&
1220 echo "utf8 body: àéìöú" >>"$1"
1222 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1223 git send-email \
1224 --compose --subject foo \
1225 --from="Example <nobody@example.com>" \
1226 --to=nobody@example.com \
1227 --smtp-server="$(pwd)/fake.sendmail" \
1228 $patches &&
1229 grep "^utf8 body" msgtxt1 &&
1230 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1233 test_expect_success $PREREQ '--compose-encoding works' '
1234 clean_fake_sendmail &&
1235 write_script fake-editor-utf8 <<-\EOF &&
1236 echo "utf8 body: àéìöú" >>"$1"
1238 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1239 git send-email \
1240 --compose-encoding iso-8859-1 \
1241 --compose --subject foo \
1242 --from="Example <nobody@example.com>" \
1243 --to=nobody@example.com \
1244 --smtp-server="$(pwd)/fake.sendmail" \
1245 $patches &&
1246 grep "^utf8 body" msgtxt1 &&
1247 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1250 test_expect_success $PREREQ '--compose-encoding overrides sendemail.composeencoding' '
1251 clean_fake_sendmail &&
1252 git config sendemail.composeencoding iso-8859-1 &&
1253 write_script fake-editor-utf8 <<-\EOF &&
1254 echo "utf8 body: àéìöú" >>"$1"
1256 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1257 git send-email \
1258 --compose-encoding iso-8859-2 \
1259 --compose --subject foo \
1260 --from="Example <nobody@example.com>" \
1261 --to=nobody@example.com \
1262 --smtp-server="$(pwd)/fake.sendmail" \
1263 $patches &&
1264 grep "^utf8 body" msgtxt1 &&
1265 grep "^Content-Type: text/plain; charset=iso-8859-2" msgtxt1
1268 test_expect_success $PREREQ '--compose-encoding adds correct MIME for subject' '
1269 clean_fake_sendmail &&
1270 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
1271 git send-email \
1272 --compose-encoding iso-8859-2 \
1273 --compose --subject utf8-sübjëct \
1274 --from="Example <nobody@example.com>" \
1275 --to=nobody@example.com \
1276 --smtp-server="$(pwd)/fake.sendmail" \
1277 $patches &&
1278 grep "^fake edit" msgtxt1 &&
1279 grep "^Subject: =?iso-8859-2?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
1282 test_expect_success $PREREQ 'detects ambiguous reference/file conflict' '
1283 echo main >main &&
1284 git add main &&
1285 git commit -m"add main" &&
1286 test_must_fail git send-email --dry-run main 2>errors &&
1287 grep disambiguate errors
1290 test_expect_success $PREREQ 'feed two files' '
1291 rm -fr outdir &&
1292 git format-patch -2 -o outdir &&
1293 git send-email \
1294 --dry-run \
1295 --from="Example <nobody@example.com>" \
1296 --to=nobody@example.com \
1297 outdir/000?-*.patch 2>errors >out &&
1298 grep "^Subject: " out >subjects &&
1299 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
1300 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add main"
1303 test_expect_success $PREREQ 'in-reply-to but no threading' '
1304 git send-email \
1305 --dry-run \
1306 --from="Example <nobody@example.com>" \
1307 --to=nobody@example.com \
1308 --in-reply-to="<in-reply-id@example.com>" \
1309 --no-thread \
1310 $patches >out &&
1311 grep "In-Reply-To: <in-reply-id@example.com>" out
1314 test_expect_success $PREREQ 'no in-reply-to and no threading' '
1315 git send-email \
1316 --dry-run \
1317 --from="Example <nobody@example.com>" \
1318 --to=nobody@example.com \
1319 --no-thread \
1320 $patches >stdout &&
1321 ! grep "In-Reply-To: " stdout
1324 test_expect_success $PREREQ 'threading but no chain-reply-to' '
1325 git send-email \
1326 --dry-run \
1327 --from="Example <nobody@example.com>" \
1328 --to=nobody@example.com \
1329 --thread \
1330 --no-chain-reply-to \
1331 $patches $patches >stdout &&
1332 grep "In-Reply-To: " stdout
1335 test_expect_success $PREREQ 'override in-reply-to if no threading' '
1336 git send-email \
1337 --dry-run \
1338 --from="Example <nobody@example.com>" \
1339 --to=nobody@example.com \
1340 --no-thread \
1341 --in-reply-to="override" \
1342 $threaded_patches >stdout &&
1343 grep "In-Reply-To: <override>" stdout
1346 test_expect_success $PREREQ 'sendemail.to works' '
1347 git config --replace-all sendemail.to "Somebody <somebody@ex.com>" &&
1348 git send-email \
1349 --dry-run \
1350 --from="Example <nobody@example.com>" \
1351 $patches >stdout &&
1352 grep "To: Somebody <somebody@ex.com>" stdout
1355 test_expect_success $PREREQ 'setup sendemail.identity' '
1356 git config --replace-all sendemail.to "default@example.com" &&
1357 git config --replace-all sendemail.isp.to "isp@example.com" &&
1358 git config --replace-all sendemail.cloud.to "cloud@example.com"
1361 test_expect_success $PREREQ 'sendemail.identity: reads the correct identity config' '
1362 git -c sendemail.identity=cloud send-email \
1363 --dry-run \
1364 --from="nobody@example.com" \
1365 $patches >stdout &&
1366 grep "To: cloud@example.com" stdout
1369 test_expect_success $PREREQ 'sendemail.identity: identity overrides sendemail.identity' '
1370 git -c sendemail.identity=cloud send-email \
1371 --identity=isp \
1372 --dry-run \
1373 --from="nobody@example.com" \
1374 $patches >stdout &&
1375 grep "To: isp@example.com" stdout
1378 test_expect_success $PREREQ 'sendemail.identity: --no-identity clears previous identity' '
1379 git -c sendemail.identity=cloud send-email \
1380 --no-identity \
1381 --dry-run \
1382 --from="nobody@example.com" \
1383 $patches >stdout &&
1384 grep "To: default@example.com" stdout
1387 test_expect_success $PREREQ 'sendemail.identity: bool identity variable existence overrides' '
1388 git -c sendemail.identity=cloud \
1389 -c sendemail.xmailer=true \
1390 -c sendemail.cloud.xmailer=false \
1391 send-email \
1392 --dry-run \
1393 --from="nobody@example.com" \
1394 $patches >stdout &&
1395 grep "To: cloud@example.com" stdout &&
1396 ! grep "X-Mailer" stdout
1399 test_expect_success $PREREQ 'sendemail.identity: bool variable fallback' '
1400 git -c sendemail.identity=cloud \
1401 -c sendemail.xmailer=false \
1402 send-email \
1403 --dry-run \
1404 --from="nobody@example.com" \
1405 $patches >stdout &&
1406 grep "To: cloud@example.com" stdout &&
1407 ! grep "X-Mailer" stdout
1410 test_expect_success $PREREQ 'sendemail.identity: bool variable without a value' '
1411 git -c sendemail.xmailer \
1412 send-email \
1413 --dry-run \
1414 --from="nobody@example.com" \
1415 $patches >stdout &&
1416 grep "To: default@example.com" stdout &&
1417 grep "X-Mailer" stdout
1420 test_expect_success $PREREQ '--no-to overrides sendemail.to' '
1421 git send-email \
1422 --dry-run \
1423 --from="Example <nobody@example.com>" \
1424 --no-to \
1425 --to=nobody@example.com \
1426 $patches >stdout &&
1427 grep "To: nobody@example.com" stdout &&
1428 ! grep "To: Somebody <somebody@ex.com>" stdout
1431 test_expect_success $PREREQ 'sendemail.cc works' '
1432 git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" &&
1433 git send-email \
1434 --dry-run \
1435 --from="Example <nobody@example.com>" \
1436 --to=nobody@example.com \
1437 $patches >stdout &&
1438 grep "Cc: Somebody <somebody@ex.com>" stdout
1441 test_expect_success $PREREQ '--no-cc overrides sendemail.cc' '
1442 git send-email \
1443 --dry-run \
1444 --from="Example <nobody@example.com>" \
1445 --no-cc \
1446 --cc=bodies@example.com \
1447 --to=nobody@example.com \
1448 $patches >stdout &&
1449 grep "Cc: bodies@example.com" stdout &&
1450 ! grep "Cc: Somebody <somebody@ex.com>" stdout
1453 test_expect_success $PREREQ 'sendemail.bcc works' '
1454 git config --replace-all sendemail.bcc "Other <other@ex.com>" &&
1455 git send-email \
1456 --dry-run \
1457 --from="Example <nobody@example.com>" \
1458 --to=nobody@example.com \
1459 --smtp-server relay.example.com \
1460 $patches >stdout &&
1461 grep "RCPT TO:<other@ex.com>" stdout
1464 test_expect_success $PREREQ '--no-bcc overrides sendemail.bcc' '
1465 git send-email \
1466 --dry-run \
1467 --from="Example <nobody@example.com>" \
1468 --no-bcc \
1469 --bcc=bodies@example.com \
1470 --to=nobody@example.com \
1471 --smtp-server relay.example.com \
1472 $patches >stdout &&
1473 grep "RCPT TO:<bodies@example.com>" stdout &&
1474 ! grep "RCPT TO:<other@ex.com>" stdout
1477 test_expect_success $PREREQ 'patches To headers are used by default' '
1478 patch=$(git format-patch -1 --to="bodies@example.com") &&
1479 test_when_finished "rm $patch" &&
1480 git send-email \
1481 --dry-run \
1482 --from="Example <nobody@example.com>" \
1483 --smtp-server relay.example.com \
1484 $patch >stdout &&
1485 grep "RCPT TO:<bodies@example.com>" stdout
1488 test_expect_success $PREREQ 'patches To headers are appended to' '
1489 patch=$(git format-patch -1 --to="bodies@example.com") &&
1490 test_when_finished "rm $patch" &&
1491 git send-email \
1492 --dry-run \
1493 --from="Example <nobody@example.com>" \
1494 --to=nobody@example.com \
1495 --smtp-server relay.example.com \
1496 $patch >stdout &&
1497 grep "RCPT TO:<bodies@example.com>" stdout &&
1498 grep "RCPT TO:<nobody@example.com>" stdout
1501 test_expect_success $PREREQ 'To headers from files reset each patch' '
1502 patch1=$(git format-patch -1 --to="bodies@example.com") &&
1503 patch2=$(git format-patch -1 --to="other@example.com" HEAD~) &&
1504 test_when_finished "rm $patch1 && rm $patch2" &&
1505 git send-email \
1506 --dry-run \
1507 --from="Example <nobody@example.com>" \
1508 --to="nobody@example.com" \
1509 --smtp-server relay.example.com \
1510 $patch1 $patch2 >stdout &&
1511 test $(grep -c "RCPT TO:<bodies@example.com>" stdout) = 1 &&
1512 test $(grep -c "RCPT TO:<nobody@example.com>" stdout) = 2 &&
1513 test $(grep -c "RCPT TO:<other@example.com>" stdout) = 1
1516 test_expect_success $PREREQ 'setup expect' '
1517 cat >email-using-8bit <<\EOF
1518 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1519 Message-ID: <bogus-message-id@example.com>
1520 From: author@example.com
1521 Date: Sat, 12 Jun 2010 15:53:58 +0200
1522 Subject: subject goes here
1524 Dieser deutsche Text enthält einen Umlaut!
1528 test_expect_success $PREREQ 'setup expect' '
1529 echo "Subject: subject goes here" >expected
1532 test_expect_success $PREREQ 'ASCII subject is not RFC2047 quoted' '
1533 clean_fake_sendmail &&
1534 echo bogus |
1535 git send-email --from=author@example.com --to=nobody@example.com \
1536 --smtp-server="$(pwd)/fake.sendmail" \
1537 --8bit-encoding=UTF-8 \
1538 email-using-8bit >stdout &&
1539 grep "Subject" msgtxt1 >actual &&
1540 test_cmp expected actual
1543 test_expect_success $PREREQ 'setup expect' '
1544 cat >content-type-decl <<-\EOF
1545 MIME-Version: 1.0
1546 Content-Type: text/plain; charset=UTF-8
1547 Content-Transfer-Encoding: 8bit
1551 test_expect_success $PREREQ 'asks about and fixes 8bit encodings' '
1552 clean_fake_sendmail &&
1553 echo |
1554 git send-email --from=author@example.com --to=nobody@example.com \
1555 --smtp-server="$(pwd)/fake.sendmail" \
1556 email-using-8bit >stdout &&
1557 grep "do not declare a Content-Transfer-Encoding" stdout &&
1558 grep email-using-8bit stdout &&
1559 grep "Which 8bit encoding" stdout &&
1560 grep -E "Content|MIME" msgtxt1 >actual &&
1561 test_cmp content-type-decl actual
1564 test_expect_success $PREREQ 'sendemail.8bitEncoding works' '
1565 clean_fake_sendmail &&
1566 git config sendemail.assume8bitEncoding UTF-8 &&
1567 echo bogus |
1568 git send-email --from=author@example.com --to=nobody@example.com \
1569 --smtp-server="$(pwd)/fake.sendmail" \
1570 email-using-8bit >stdout &&
1571 grep -E "Content|MIME" msgtxt1 >actual &&
1572 test_cmp content-type-decl actual
1575 test_expect_success $PREREQ 'sendemail.8bitEncoding in .git/config overrides --global .gitconfig' '
1576 clean_fake_sendmail &&
1577 git config sendemail.assume8bitEncoding UTF-8 &&
1578 test_when_finished "rm -rf home" &&
1579 mkdir home &&
1580 git config -f home/.gitconfig sendemail.assume8bitEncoding "bogus too" &&
1581 echo bogus |
1582 env HOME="$(pwd)/home" DEBUG=1 \
1583 git send-email --from=author@example.com --to=nobody@example.com \
1584 --smtp-server="$(pwd)/fake.sendmail" \
1585 email-using-8bit >stdout &&
1586 grep -E "Content|MIME" msgtxt1 >actual &&
1587 test_cmp content-type-decl actual
1590 test_expect_success $PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
1591 clean_fake_sendmail &&
1592 git config sendemail.assume8bitEncoding "bogus too" &&
1593 echo bogus |
1594 git send-email --from=author@example.com --to=nobody@example.com \
1595 --smtp-server="$(pwd)/fake.sendmail" \
1596 --8bit-encoding=UTF-8 \
1597 email-using-8bit >stdout &&
1598 grep -E "Content|MIME" msgtxt1 >actual &&
1599 test_cmp content-type-decl actual
1602 test_expect_success $PREREQ 'setup expect' '
1603 cat >email-using-8bit <<-\EOF
1604 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1605 Message-ID: <bogus-message-id@example.com>
1606 From: author@example.com
1607 Date: Sat, 12 Jun 2010 15:53:58 +0200
1608 Subject: Dieser Betreff enthält auch einen Umlaut!
1610 Nothing to see here.
1614 test_expect_success $PREREQ 'setup expect' '
1615 cat >expected <<-\EOF
1616 Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
1620 test_expect_success $PREREQ '--8bit-encoding also treats subject' '
1621 clean_fake_sendmail &&
1622 echo bogus |
1623 git send-email --from=author@example.com --to=nobody@example.com \
1624 --smtp-server="$(pwd)/fake.sendmail" \
1625 --8bit-encoding=UTF-8 \
1626 email-using-8bit >stdout &&
1627 grep "Subject" msgtxt1 >actual &&
1628 test_cmp expected actual
1631 test_expect_success $PREREQ 'setup expect' '
1632 cat >email-using-8bit <<-\EOF
1633 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1634 Message-ID: <bogus-message-id@example.com>
1635 From: A U Thor <author@example.com>
1636 Date: Sat, 12 Jun 2010 15:53:58 +0200
1637 Content-Type: text/plain; charset=UTF-8
1638 Subject: Nothing to see here.
1640 Dieser Betreff enthält auch einen Umlaut!
1644 test_expect_success $PREREQ '--transfer-encoding overrides sendemail.transferEncoding' '
1645 clean_fake_sendmail &&
1646 test_must_fail git -c sendemail.transferEncoding=8bit \
1647 send-email \
1648 --transfer-encoding=7bit \
1649 --smtp-server="$(pwd)/fake.sendmail" \
1650 email-using-8bit \
1651 2>errors >out &&
1652 grep "cannot send message as 7bit" errors &&
1653 test -z "$(ls msgtxt*)"
1656 test_expect_success $PREREQ 'sendemail.transferEncoding via config' '
1657 clean_fake_sendmail &&
1658 test_must_fail git -c sendemail.transferEncoding=7bit \
1659 send-email \
1660 --smtp-server="$(pwd)/fake.sendmail" \
1661 email-using-8bit \
1662 2>errors >out &&
1663 grep "cannot send message as 7bit" errors &&
1664 test -z "$(ls msgtxt*)"
1667 test_expect_success $PREREQ 'sendemail.transferEncoding via cli' '
1668 clean_fake_sendmail &&
1669 test_must_fail git send-email \
1670 --transfer-encoding=7bit \
1671 --smtp-server="$(pwd)/fake.sendmail" \
1672 email-using-8bit \
1673 2>errors >out &&
1674 grep "cannot send message as 7bit" errors &&
1675 test -z "$(ls msgtxt*)"
1678 test_expect_success $PREREQ 'setup expect' '
1679 cat >expected <<-\EOF
1680 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1684 test_expect_success $PREREQ '8-bit and sendemail.transferencoding=quoted-printable' '
1685 clean_fake_sendmail &&
1686 git send-email \
1687 --transfer-encoding=quoted-printable \
1688 --smtp-server="$(pwd)/fake.sendmail" \
1689 email-using-8bit \
1690 2>errors >out &&
1691 sed "1,/^$/d" msgtxt1 >actual &&
1692 test_cmp expected actual
1695 test_expect_success $PREREQ 'setup expect' '
1696 cat >expected <<-\EOF
1697 RGllc2VyIEJldHJlZmYgZW50aMOkbHQgYXVjaCBlaW5lbiBVbWxhdXQhCg==
1701 test_expect_success $PREREQ '8-bit and sendemail.transferencoding=base64' '
1702 clean_fake_sendmail &&
1703 git send-email \
1704 --transfer-encoding=base64 \
1705 --smtp-server="$(pwd)/fake.sendmail" \
1706 email-using-8bit \
1707 2>errors >out &&
1708 sed "1,/^$/d" msgtxt1 >actual &&
1709 test_cmp expected actual
1712 test_expect_success $PREREQ 'setup expect' '
1713 cat >email-using-qp <<-\EOF
1714 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1715 Message-ID: <bogus-message-id@example.com>
1716 From: A U Thor <author@example.com>
1717 Date: Sat, 12 Jun 2010 15:53:58 +0200
1718 MIME-Version: 1.0
1719 Content-Transfer-Encoding: quoted-printable
1720 Content-Type: text/plain; charset=UTF-8
1721 Subject: Nothing to see here.
1723 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1727 test_expect_success $PREREQ 'convert from quoted-printable to base64' '
1728 clean_fake_sendmail &&
1729 git send-email \
1730 --transfer-encoding=base64 \
1731 --smtp-server="$(pwd)/fake.sendmail" \
1732 email-using-qp \
1733 2>errors >out &&
1734 sed "1,/^$/d" msgtxt1 >actual &&
1735 test_cmp expected actual
1738 test_expect_success $PREREQ 'setup expect' "
1739 tr -d '\\015' | tr '%' '\\015' >email-using-crlf <<EOF
1740 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1741 Message-ID: <bogus-message-id@example.com>
1742 From: A U Thor <author@example.com>
1743 Date: Sat, 12 Jun 2010 15:53:58 +0200
1744 Content-Type: text/plain; charset=UTF-8
1745 Subject: Nothing to see here.
1747 Look, I have a CRLF and an = sign!%
1751 test_expect_success $PREREQ 'setup expect' '
1752 cat >expected <<-\EOF
1753 Look, I have a CRLF and an =3D sign!=0D
1757 test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=quoted-printable' '
1758 clean_fake_sendmail &&
1759 git send-email \
1760 --transfer-encoding=quoted-printable \
1761 --smtp-server="$(pwd)/fake.sendmail" \
1762 email-using-crlf \
1763 2>errors >out &&
1764 sed "1,/^$/d" msgtxt1 >actual &&
1765 test_cmp expected actual
1768 test_expect_success $PREREQ 'setup expect' '
1769 cat >expected <<-\EOF
1770 TG9vaywgSSBoYXZlIGEgQ1JMRiBhbmQgYW4gPSBzaWduIQ0K
1774 test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=base64' '
1775 clean_fake_sendmail &&
1776 git send-email \
1777 --transfer-encoding=base64 \
1778 --smtp-server="$(pwd)/fake.sendmail" \
1779 email-using-crlf \
1780 2>errors >out &&
1781 sed "1,/^$/d" msgtxt1 >actual &&
1782 test_cmp expected actual
1786 # Note that the patches in this test are deliberately out of order; we
1787 # want to make sure it works even if the cover-letter is not in the
1788 # first mail.
1789 test_expect_success $PREREQ 'refusing to send cover letter template' '
1790 clean_fake_sendmail &&
1791 rm -fr outdir &&
1792 git format-patch --cover-letter -2 -o outdir &&
1793 test_must_fail git send-email \
1794 --from="Example <nobody@example.com>" \
1795 --to=nobody@example.com \
1796 --smtp-server="$(pwd)/fake.sendmail" \
1797 outdir/0002-*.patch \
1798 outdir/0000-*.patch \
1799 outdir/0001-*.patch \
1800 2>errors >out &&
1801 grep "SUBJECT HERE" errors &&
1802 test -z "$(ls msgtxt*)"
1805 test_expect_success $PREREQ '--force sends cover letter template anyway' '
1806 clean_fake_sendmail &&
1807 rm -fr outdir &&
1808 git format-patch --cover-letter -2 -o outdir &&
1809 git send-email \
1810 --force \
1811 --from="Example <nobody@example.com>" \
1812 --to=nobody@example.com \
1813 --smtp-server="$(pwd)/fake.sendmail" \
1814 outdir/0002-*.patch \
1815 outdir/0000-*.patch \
1816 outdir/0001-*.patch \
1817 2>errors >out &&
1818 ! grep "SUBJECT HERE" errors &&
1819 test -n "$(ls msgtxt*)"
1822 test_cover_addresses () {
1823 header="$1"
1824 shift
1825 clean_fake_sendmail &&
1826 rm -fr outdir &&
1827 git format-patch --cover-letter -2 -o outdir &&
1828 cover=$(echo outdir/0000-*.patch) &&
1829 mv $cover cover-to-edit.patch &&
1830 perl -pe "s/^From:/$header: extra\@address.com\nFrom:/" cover-to-edit.patch >"$cover" &&
1831 git send-email \
1832 --force \
1833 --from="Example <nobody@example.com>" \
1834 --no-to --no-cc \
1835 "$@" \
1836 --smtp-server="$(pwd)/fake.sendmail" \
1837 outdir/0000-*.patch \
1838 outdir/0001-*.patch \
1839 outdir/0002-*.patch \
1840 2>errors >out &&
1841 grep "^$header: extra@address.com" msgtxt1 >to1 &&
1842 grep "^$header: extra@address.com" msgtxt2 >to2 &&
1843 grep "^$header: extra@address.com" msgtxt3 >to3 &&
1844 test_line_count = 1 to1 &&
1845 test_line_count = 1 to2 &&
1846 test_line_count = 1 to3
1849 test_expect_success $PREREQ 'to-cover adds To to all mail' '
1850 test_cover_addresses "To" --to-cover
1853 test_expect_success $PREREQ 'cc-cover adds Cc to all mail' '
1854 test_cover_addresses "Cc" --cc-cover
1857 test_expect_success $PREREQ 'tocover adds To to all mail' '
1858 test_config sendemail.tocover true &&
1859 test_cover_addresses "To"
1862 test_expect_success $PREREQ 'cccover adds Cc to all mail' '
1863 test_config sendemail.cccover true &&
1864 test_cover_addresses "Cc"
1867 test_expect_success $PREREQ 'escaped quotes in sendemail.aliasfiletype=mutt' '
1868 clean_fake_sendmail &&
1869 echo "alias sbd \\\"Dot U. Sir\\\" <somebody@example.org>" >.mutt &&
1870 git config --replace-all sendemail.aliasesfile "$(pwd)/.mutt" &&
1871 git config sendemail.aliasfiletype mutt &&
1872 git send-email \
1873 --from="Example <nobody@example.com>" \
1874 --to=sbd \
1875 --smtp-server="$(pwd)/fake.sendmail" \
1876 outdir/0001-*.patch \
1877 2>errors >out &&
1878 grep "^!somebody@example\.org!$" commandline1 &&
1879 grep -F "To: \"Dot U. Sir\" <somebody@example.org>" out
1882 test_expect_success $PREREQ 'sendemail.aliasfiletype=mailrc' '
1883 clean_fake_sendmail &&
1884 echo "alias sbd somebody@example.org" >.mailrc &&
1885 git config --replace-all sendemail.aliasesfile "$(pwd)/.mailrc" &&
1886 git config sendemail.aliasfiletype mailrc &&
1887 git send-email \
1888 --from="Example <nobody@example.com>" \
1889 --to=sbd \
1890 --smtp-server="$(pwd)/fake.sendmail" \
1891 outdir/0001-*.patch \
1892 2>errors >out &&
1893 grep "^!somebody@example\.org!$" commandline1
1896 test_expect_success $PREREQ 'sendemail.aliasesfile=~/.mailrc' '
1897 clean_fake_sendmail &&
1898 echo "alias sbd someone@example.org" >"$HOME/.mailrc" &&
1899 git config --replace-all sendemail.aliasesfile "~/.mailrc" &&
1900 git config sendemail.aliasfiletype mailrc &&
1901 git send-email \
1902 --from="Example <nobody@example.com>" \
1903 --to=sbd \
1904 --smtp-server="$(pwd)/fake.sendmail" \
1905 outdir/0001-*.patch \
1906 2>errors >out &&
1907 grep "^!someone@example\.org!$" commandline1
1910 test_dump_aliases () {
1911 msg="$1" && shift &&
1912 filetype="$1" && shift &&
1913 printf '%s\n' "$@" >expect &&
1914 cat >.tmp-email-aliases &&
1916 test_expect_success $PREREQ "$msg" '
1917 clean_fake_sendmail && rm -fr outdir &&
1918 git config --replace-all sendemail.aliasesfile \
1919 "$(pwd)/.tmp-email-aliases" &&
1920 git config sendemail.aliasfiletype "$filetype" &&
1921 git send-email --dump-aliases 2>errors >actual &&
1922 test_cmp expect actual
1926 test_dump_aliases '--dump-aliases sendmail format' \
1927 'sendmail' \
1928 'abgroup' \
1929 'alice' \
1930 'bcgrp' \
1931 'bob' \
1932 'chloe' <<-\EOF
1933 alice: Alice W Land <awol@example.com>
1934 bob: Robert Bobbyton <bob@example.com>
1935 chloe: chloe@example.com
1936 abgroup: alice, bob
1937 bcgrp: bob, chloe, Other <o@example.com>
1940 test_dump_aliases '--dump-aliases mutt format' \
1941 'mutt' \
1942 'alice' \
1943 'bob' \
1944 'chloe' \
1945 'donald' <<-\EOF
1946 alias alice Alice W Land <awol@example.com>
1947 alias donald Donald C Carlton <donc@example.com>
1948 alias bob Robert Bobbyton <bob@example.com>
1949 alias chloe chloe@example.com
1952 test_dump_aliases '--dump-aliases mailrc format' \
1953 'mailrc' \
1954 'alice' \
1955 'bob' \
1956 'chloe' \
1957 'eve' <<-\EOF
1958 alias alice Alice W Land <awol@example.com>
1959 alias eve Eve <eve@example.com>
1960 alias bob Robert Bobbyton <bob@example.com>
1961 alias chloe chloe@example.com
1964 test_dump_aliases '--dump-aliases pine format' \
1965 'pine' \
1966 'alice' \
1967 'bob' \
1968 'chloe' \
1969 'eve' <<-\EOF
1970 alice Alice W Land <awol@example.com>
1971 eve Eve <eve@example.com>
1972 bob Robert Bobbyton <bob@example.com>
1973 chloe chloe@example.com
1976 test_dump_aliases '--dump-aliases gnus format' \
1977 'gnus' \
1978 'alice' \
1979 'bob' \
1980 'chloe' \
1981 'eve' <<-\EOF
1982 (define-mail-alias "alice" "awol@example.com")
1983 (define-mail-alias "eve" "eve@example.com")
1984 (define-mail-alias "bob" "bob@example.com")
1985 (define-mail-alias "chloe" "chloe@example.com")
1988 test_expect_success '--dump-aliases must be used alone' '
1989 test_must_fail git send-email --dump-aliases --to=janice@example.com -1 refs/heads/accounting
1992 test_expect_success $PREREQ 'aliases and sendemail.identity' '
1993 test_must_fail git \
1994 -c sendemail.identity=cloud \
1995 -c sendemail.aliasesfile=default-aliases \
1996 -c sendemail.cloud.aliasesfile=cloud-aliases \
1997 send-email -1 2>stderr &&
1998 test_i18ngrep "cloud-aliases" stderr
2001 test_sendmail_aliases () {
2002 msg="$1" && shift &&
2003 expect="$@" &&
2004 cat >.tmp-email-aliases &&
2006 test_expect_success $PREREQ "$msg" '
2007 clean_fake_sendmail && rm -fr outdir &&
2008 git format-patch -1 -o outdir &&
2009 git config --replace-all sendemail.aliasesfile \
2010 "$(pwd)/.tmp-email-aliases" &&
2011 git config sendemail.aliasfiletype sendmail &&
2012 git send-email \
2013 --from="Example <nobody@example.com>" \
2014 --to=alice --to=bcgrp \
2015 --smtp-server="$(pwd)/fake.sendmail" \
2016 outdir/0001-*.patch \
2017 2>errors >out &&
2018 for i in $expect
2020 grep "^!$i!$" commandline1 || return 1
2021 done
2025 test_sendmail_aliases 'sendemail.aliasfiletype=sendmail' \
2026 'awol@example\.com' \
2027 'bob@example\.com' \
2028 'chloe@example\.com' \
2029 'o@example\.com' <<-\EOF
2030 alice: Alice W Land <awol@example.com>
2031 bob: Robert Bobbyton <bob@example.com>
2032 # this is a comment
2033 # this is also a comment
2034 chloe: chloe@example.com
2035 abgroup: alice, bob
2036 bcgrp: bob, chloe, Other <o@example.com>
2039 test_sendmail_aliases 'sendmail aliases line folding' \
2040 alice1 \
2041 bob1 bob2 \
2042 chuck1 chuck2 \
2043 darla1 darla2 darla3 \
2044 elton1 elton2 elton3 \
2045 fred1 fred2 \
2046 greg1 <<-\EOF
2047 alice: alice1
2048 bob: bob1,\
2049 bob2
2050 chuck: chuck1,
2051 chuck2
2052 darla: darla1,\
2053 darla2,
2054 darla3
2055 elton: elton1,
2056 elton2,\
2057 elton3
2058 fred: fred1,\
2059 fred2
2060 greg: greg1
2061 bcgrp: bob, chuck, darla, elton, fred, greg
2064 test_sendmail_aliases 'sendmail aliases tolerate bogus line folding' \
2065 alice1 bob1 <<-\EOF
2066 alice: alice1
2067 bcgrp: bob1\
2070 test_sendmail_aliases 'sendmail aliases empty' alice bcgrp <<-\EOF
2073 test_expect_success $PREREQ 'alias support in To header' '
2074 clean_fake_sendmail &&
2075 echo "alias sbd someone@example.org" >.mailrc &&
2076 test_config sendemail.aliasesfile ".mailrc" &&
2077 test_config sendemail.aliasfiletype mailrc &&
2078 git format-patch --stdout -1 --to=sbd >aliased.patch &&
2079 git send-email \
2080 --from="Example <nobody@example.com>" \
2081 --smtp-server="$(pwd)/fake.sendmail" \
2082 aliased.patch \
2083 2>errors >out &&
2084 grep "^!someone@example\.org!$" commandline1
2087 test_expect_success $PREREQ 'alias support in Cc header' '
2088 clean_fake_sendmail &&
2089 echo "alias sbd someone@example.org" >.mailrc &&
2090 test_config sendemail.aliasesfile ".mailrc" &&
2091 test_config sendemail.aliasfiletype mailrc &&
2092 git format-patch --stdout -1 --cc=sbd >aliased.patch &&
2093 git send-email \
2094 --from="Example <nobody@example.com>" \
2095 --smtp-server="$(pwd)/fake.sendmail" \
2096 aliased.patch \
2097 2>errors >out &&
2098 grep "^!someone@example\.org!$" commandline1
2101 test_expect_success $PREREQ 'tocmd works with aliases' '
2102 clean_fake_sendmail &&
2103 echo "alias sbd someone@example.org" >.mailrc &&
2104 test_config sendemail.aliasesfile ".mailrc" &&
2105 test_config sendemail.aliasfiletype mailrc &&
2106 git format-patch --stdout -1 >tocmd.patch &&
2107 echo tocmd--sbd >>tocmd.patch &&
2108 git send-email \
2109 --from="Example <nobody@example.com>" \
2110 --to-cmd=./tocmd-sed \
2111 --smtp-server="$(pwd)/fake.sendmail" \
2112 tocmd.patch \
2113 2>errors >out &&
2114 grep "^!someone@example\.org!$" commandline1
2117 test_expect_success $PREREQ 'cccmd works with aliases' '
2118 clean_fake_sendmail &&
2119 echo "alias sbd someone@example.org" >.mailrc &&
2120 test_config sendemail.aliasesfile ".mailrc" &&
2121 test_config sendemail.aliasfiletype mailrc &&
2122 git format-patch --stdout -1 >cccmd.patch &&
2123 echo cccmd--sbd >>cccmd.patch &&
2124 git send-email \
2125 --from="Example <nobody@example.com>" \
2126 --cc-cmd=./cccmd-sed \
2127 --smtp-server="$(pwd)/fake.sendmail" \
2128 cccmd.patch \
2129 2>errors >out &&
2130 grep "^!someone@example\.org!$" commandline1
2133 do_xmailer_test () {
2134 expected=$1 params=$2 &&
2135 git format-patch -1 &&
2136 git send-email \
2137 --from="Example <nobody@example.com>" \
2138 --to=someone@example.com \
2139 --smtp-server="$(pwd)/fake.sendmail" \
2140 $params \
2141 0001-*.patch \
2142 2>errors >out &&
2143 { grep '^X-Mailer:' out || :; } >mailer &&
2144 test_line_count = $expected mailer
2147 test_expect_success $PREREQ '--[no-]xmailer without any configuration' '
2148 do_xmailer_test 1 "--xmailer" &&
2149 do_xmailer_test 0 "--no-xmailer"
2152 test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=true' '
2153 test_config sendemail.xmailer true &&
2154 do_xmailer_test 1 "" &&
2155 do_xmailer_test 0 "--no-xmailer" &&
2156 do_xmailer_test 1 "--xmailer"
2159 test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer' '
2160 test_when_finished "test_unconfig sendemail.xmailer" &&
2161 cat >>.git/config <<-\EOF &&
2162 [sendemail]
2163 xmailer
2165 test_config sendemail.xmailer true &&
2166 do_xmailer_test 1 "" &&
2167 do_xmailer_test 0 "--no-xmailer" &&
2168 do_xmailer_test 1 "--xmailer"
2171 test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=false' '
2172 test_config sendemail.xmailer false &&
2173 do_xmailer_test 0 "" &&
2174 do_xmailer_test 0 "--no-xmailer" &&
2175 do_xmailer_test 1 "--xmailer"
2178 test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=' '
2179 test_config sendemail.xmailer "" &&
2180 do_xmailer_test 0 "" &&
2181 do_xmailer_test 0 "--no-xmailer" &&
2182 do_xmailer_test 1 "--xmailer"
2185 test_expect_success $PREREQ 'setup expected-list' '
2186 git send-email \
2187 --dry-run \
2188 --from="Example <from@example.com>" \
2189 --to="To 1 <to1@example.com>" \
2190 --to="to2@example.com" \
2191 --to="to3@example.com" \
2192 --cc="Cc 1 <cc1@example.com>" \
2193 --cc="Cc2 <cc2@example.com>" \
2194 --bcc="bcc1@example.com" \
2195 --bcc="bcc2@example.com" \
2196 0001-add-main.patch | replace_variable_fields \
2197 >expected-list
2200 test_expect_success $PREREQ 'use email list in --cc --to and --bcc' '
2201 git send-email \
2202 --dry-run \
2203 --from="Example <from@example.com>" \
2204 --to="To 1 <to1@example.com>, to2@example.com" \
2205 --to="to3@example.com" \
2206 --cc="Cc 1 <cc1@example.com>, Cc2 <cc2@example.com>" \
2207 --bcc="bcc1@example.com, bcc2@example.com" \
2208 0001-add-main.patch | replace_variable_fields \
2209 >actual-list &&
2210 test_cmp expected-list actual-list
2213 test_expect_success $PREREQ 'aliases work with email list' '
2214 echo "alias to2 to2@example.com" >.mutt &&
2215 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt &&
2216 test_config sendemail.aliasesfile ".mutt" &&
2217 test_config sendemail.aliasfiletype mutt &&
2218 git send-email \
2219 --dry-run \
2220 --from="Example <from@example.com>" \
2221 --to="To 1 <to1@example.com>, to2, to3@example.com" \
2222 --cc="cc1, Cc2 <cc2@example.com>" \
2223 --bcc="bcc1@example.com, bcc2@example.com" \
2224 0001-add-main.patch | replace_variable_fields \
2225 >actual-list &&
2226 test_cmp expected-list actual-list
2229 test_expect_success $PREREQ 'leading and trailing whitespaces are removed' '
2230 echo "alias to2 to2@example.com" >.mutt &&
2231 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt &&
2232 test_config sendemail.aliasesfile ".mutt" &&
2233 test_config sendemail.aliasfiletype mutt &&
2234 TO1=$(echo "QTo 1 <to1@example.com>" | q_to_tab) &&
2235 TO2=$(echo "QZto2" | qz_to_tab_space) &&
2236 CC1=$(echo "cc1" | append_cr) &&
2237 BCC1=$(echo " bcc1@example.com Q" | q_to_nul) &&
2238 git send-email \
2239 --dry-run \
2240 --from=" Example <from@example.com>" \
2241 --to="$TO1" \
2242 --to="$TO2" \
2243 --to=" to3@example.com " \
2244 --cc="$CC1" \
2245 --cc="Cc2 <cc2@example.com>" \
2246 --bcc="$BCC1" \
2247 --bcc="bcc2@example.com" \
2248 0001-add-main.patch | replace_variable_fields \
2249 >actual-list &&
2250 test_cmp expected-list actual-list
2253 test_expect_success $PREREQ 'test using command name with --sendmail-cmd' '
2254 clean_fake_sendmail &&
2255 PATH="$PWD:$PATH" \
2256 git send-email \
2257 --from="Example <nobody@example.com>" \
2258 --to=nobody@example.com \
2259 --sendmail-cmd="fake.sendmail" \
2260 HEAD^ &&
2261 test_path_is_file commandline1
2264 test_expect_success $PREREQ 'test using arguments with --sendmail-cmd' '
2265 clean_fake_sendmail &&
2266 git send-email \
2267 --from="Example <nobody@example.com>" \
2268 --to=nobody@example.com \
2269 --sendmail-cmd='\''"$(pwd)/fake.sendmail" -f nobody@example.com'\'' \
2270 HEAD^ &&
2271 test_path_is_file commandline1
2274 test_expect_success $PREREQ 'test shell expression with --sendmail-cmd' '
2275 clean_fake_sendmail &&
2276 git send-email \
2277 --from="Example <nobody@example.com>" \
2278 --to=nobody@example.com \
2279 --sendmail-cmd='\''f() { "$(pwd)/fake.sendmail" "$@"; };f'\'' \
2280 HEAD^ &&
2281 test_path_is_file commandline1
2284 test_expect_success $PREREQ 'set up in-reply-to/references patches' '
2285 cat >has-reply.patch <<-\EOF &&
2286 From: A U Thor <author@example.com>
2287 Subject: patch with in-reply-to
2288 Message-ID: <patch.with.in.reply.to@example.com>
2289 In-Reply-To: <replied.to@example.com>
2290 References: <replied.to@example.com>
2292 This is the body.
2294 cat >no-reply.patch <<-\EOF
2295 From: A U Thor <author@example.com>
2296 Subject: patch without in-reply-to
2297 Message-ID: <patch.without.in.reply.to@example.com>
2299 This is the body.
2303 test_expect_success $PREREQ 'patch reply headers correct with --no-thread' '
2304 clean_fake_sendmail &&
2305 git send-email \
2306 --no-thread \
2307 --to=nobody@example.com \
2308 --smtp-server="$(pwd)/fake.sendmail" \
2309 has-reply.patch no-reply.patch &&
2310 grep "In-Reply-To: <replied.to@example.com>" msgtxt1 &&
2311 grep "References: <replied.to@example.com>" msgtxt1 &&
2312 ! grep replied.to@example.com msgtxt2
2315 test_expect_success $PREREQ 'cmdline in-reply-to used with --no-thread' '
2316 clean_fake_sendmail &&
2317 git send-email \
2318 --no-thread \
2319 --in-reply-to="<cmdline.reply@example.com>" \
2320 --to=nobody@example.com \
2321 --smtp-server="$(pwd)/fake.sendmail" \
2322 has-reply.patch no-reply.patch &&
2323 grep "In-Reply-To: <cmdline.reply@example.com>" msgtxt1 &&
2324 grep "References: <cmdline.reply@example.com>" msgtxt1 &&
2325 grep "In-Reply-To: <cmdline.reply@example.com>" msgtxt2 &&
2326 grep "References: <cmdline.reply@example.com>" msgtxt2
2329 test_expect_success $PREREQ 'invoke hook' '
2330 test_hook sendemail-validate <<-\EOF &&
2331 # test that we have the correct environment variable, pwd, and
2332 # argument
2333 case "$GIT_DIR" in
2334 *.git)
2335 true
2338 false
2340 esac &&
2341 test -f 0001-add-main.patch &&
2342 grep "add main" "$1"
2345 mkdir subdir &&
2347 # Test that it works even if we are not at the root of the
2348 # working tree
2349 cd subdir &&
2350 git send-email \
2351 --from="Example <nobody@example.com>" \
2352 --to=nobody@example.com \
2353 --smtp-server="$(pwd)/../fake.sendmail" \
2354 ../0001-add-main.patch &&
2356 # Verify error message when a patch is rejected by the hook
2357 sed -e "s/add main/x/" ../0001-add-main.patch >../another.patch &&
2358 test_must_fail git send-email \
2359 --from="Example <nobody@example.com>" \
2360 --to=nobody@example.com \
2361 --smtp-server="$(pwd)/../fake.sendmail" \
2362 ../another.patch 2>err &&
2363 test_i18ngrep "rejected by sendemail-validate hook" err
2367 test_expect_success $PREREQ 'test that send-email works outside a repo' '
2368 nongit git send-email \
2369 --from="Example <nobody@example.com>" \
2370 --to=nobody@example.com \
2371 --smtp-server="$(pwd)/fake.sendmail" \
2372 "$(pwd)/0001-add-main.patch"
2375 test_expect_success $PREREQ 'send-email relays -v 3 to format-patch' '
2376 test_when_finished "rm -f out" &&
2377 git send-email --dry-run -v 3 -1 >out &&
2378 grep "PATCH v3" out
2381 test_expect_success $PREREQ 'test that sendmail config is rejected' '
2382 test_config sendmail.program sendmail &&
2383 test_must_fail git send-email \
2384 --from="Example <nobody@example.com>" \
2385 --to=nobody@example.com \
2386 --smtp-server="$(pwd)/fake.sendmail" \
2387 HEAD^ 2>err &&
2388 test_i18ngrep "found configuration options for '"'"sendmail"'"'" err
2391 test_expect_success $PREREQ 'test that sendmail config rejection is specific' '
2392 test_config resendmail.program sendmail &&
2393 git send-email \
2394 --from="Example <nobody@example.com>" \
2395 --to=nobody@example.com \
2396 --smtp-server="$(pwd)/fake.sendmail" \
2397 HEAD^
2400 test_expect_success $PREREQ 'test forbidSendmailVariables behavior override' '
2401 test_config sendmail.program sendmail &&
2402 test_config sendemail.forbidSendmailVariables false &&
2403 git send-email \
2404 --from="Example <nobody@example.com>" \
2405 --to=nobody@example.com \
2406 --smtp-server="$(pwd)/fake.sendmail" \
2407 HEAD^
2410 test_done