Fourth batch
[git/raj.git] / t / t9001-send-email.sh
blobec261085ec68fdb8c9e9b54a9973be880a5c7db5
1 #!/bin/sh
3 test_description='git send-email'
4 . ./test-lib.sh
6 # May be altered later in the test
7 PREREQ="PERL"
9 replace_variable_fields () {
10 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
11 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
12 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/"
15 test_expect_success $PREREQ 'prepare reference tree' '
16 echo "1A quick brown fox jumps over the" >file &&
17 echo "lazy dog" >>file &&
18 git add file &&
19 GIT_AUTHOR_NAME="A" git commit -a -m "Initial."
22 test_expect_success $PREREQ 'Setup helper tool' '
23 write_script fake.sendmail <<-\EOF &&
24 shift
25 output=1
26 while test -f commandline$output
28 output=$(($output+1))
29 done
30 for a
32 echo "!$a!"
33 done >commandline$output
34 cat >"msgtxt$output"
35 EOF
36 git add fake.sendmail &&
37 GIT_AUTHOR_NAME="A" git commit -a -m "Second."
40 clean_fake_sendmail () {
41 rm -f commandline* msgtxt*
44 test_expect_success $PREREQ 'Extract patches' '
45 patches=$(git format-patch -s --cc="One <one@example.com>" --cc=two@example.com -n HEAD^1) &&
46 threaded_patches=$(git format-patch -o threaded -s --in-reply-to="format" HEAD^1)
49 # Test no confirm early to ensure remaining tests will not hang
50 test_no_confirm () {
51 rm -f no_confirm_okay
52 echo n | \
53 GIT_SEND_EMAIL_NOTTY=1 \
54 git send-email \
55 --from="Example <from@example.com>" \
56 --to=nobody@example.com \
57 --smtp-server="$(pwd)/fake.sendmail" \
58 $@ \
59 $patches >stdout &&
60 ! grep "Send this email" stdout &&
61 >no_confirm_okay
64 # Exit immediately to prevent hang if a no-confirm test fails
65 check_no_confirm () {
66 if ! test -f no_confirm_okay
67 then
68 say 'confirm test failed; skipping remaining tests to prevent hanging'
69 PREREQ="$PREREQ,CHECK_NO_CONFIRM"
71 return 0
74 test_expect_success $PREREQ 'No confirm with --suppress-cc' '
75 test_no_confirm --suppress-cc=sob &&
76 check_no_confirm
80 test_expect_success $PREREQ 'No confirm with --confirm=never' '
81 test_no_confirm --confirm=never &&
82 check_no_confirm
85 # leave sendemail.confirm set to never after this so that none of the
86 # remaining tests prompt unintentionally.
87 test_expect_success $PREREQ 'No confirm with sendemail.confirm=never' '
88 git config sendemail.confirm never &&
89 test_no_confirm --compose --subject=foo &&
90 check_no_confirm
93 test_expect_success $PREREQ 'Send patches' '
94 git send-email --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
97 test_expect_success $PREREQ 'setup expect' '
98 cat >expected <<-\EOF
99 !nobody@example.com!
100 !author@example.com!
101 !one@example.com!
102 !two@example.com!
106 test_expect_success $PREREQ 'Verify commandline' '
107 test_cmp expected commandline1
110 test_expect_success $PREREQ 'Send patches with --envelope-sender' '
111 clean_fake_sendmail &&
112 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
115 test_expect_success $PREREQ 'setup expect' '
116 cat >expected <<-\EOF
117 !patch@example.com!
118 !-i!
119 !nobody@example.com!
120 !author@example.com!
121 !one@example.com!
122 !two@example.com!
126 test_expect_success $PREREQ 'Verify commandline' '
127 test_cmp expected commandline1
130 test_expect_success $PREREQ 'Send patches with --envelope-sender=auto' '
131 clean_fake_sendmail &&
132 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
135 test_expect_success $PREREQ 'setup expect' '
136 cat >expected <<-\EOF
137 !nobody@example.com!
138 !-i!
139 !nobody@example.com!
140 !author@example.com!
141 !one@example.com!
142 !two@example.com!
146 test_expect_success $PREREQ 'Verify commandline' '
147 test_cmp expected commandline1
150 test_expect_success $PREREQ 'setup expect for cc trailer' "
151 cat >expected-cc <<\EOF
152 !recipient@example.com!
153 !author@example.com!
154 !one@example.com!
155 !two@example.com!
156 !three@example.com!
157 !four@example.com!
158 !five@example.com!
159 !six@example.com!
163 test_expect_success $PREREQ 'cc trailer with various syntax' '
164 test_commit cc-trailer &&
165 test_when_finished "git reset --hard HEAD^" &&
166 git commit --amend -F - <<-EOF &&
167 Test Cc: trailers.
169 Cc: one@example.com
170 Cc: <two@example.com> # trailing comments are ignored
171 Cc: <three@example.com>, <not.four@example.com> one address per line
172 Cc: "Some # Body" <four@example.com> [ <also.a.comment> ]
173 Cc: five@example.com # not.six@example.com
174 Cc: six@example.com, not.seven@example.com
176 clean_fake_sendmail &&
177 git send-email -1 --to=recipient@example.com \
178 --smtp-server="$(pwd)/fake.sendmail" &&
179 test_cmp expected-cc commandline1
182 test_expect_success $PREREQ 'setup fake get_maintainer.pl script for cc trailer' "
183 write_script expected-cc-script.sh <<-EOF
184 echo 'One Person <one@example.com> (supporter:THIS (FOO/bar))'
185 echo 'Two Person <two@example.com> (maintainer:THIS THING)'
186 echo 'Third List <three@example.com> (moderated list:THIS THING (FOO/bar))'
187 echo '<four@example.com> (moderated list:FOR THING)'
188 echo 'five@example.com (open list:FOR THING (FOO/bar))'
189 echo 'six@example.com (open list)'
193 test_expect_success $PREREQ 'cc trailer with get_maintainer.pl output' '
194 clean_fake_sendmail &&
195 git send-email -1 --to=recipient@example.com \
196 --cc-cmd=./expected-cc-script.sh \
197 --smtp-server="$(pwd)/fake.sendmail" &&
198 test_cmp expected-cc commandline1
201 test_expect_success $PREREQ 'setup expect' "
202 cat >expected-show-all-headers <<\EOF
203 0001-Second.patch
204 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
205 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
206 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
207 Dry-OK. Log says:
208 Server: relay.example.com
209 MAIL FROM:<from@example.com>
210 RCPT TO:<to@example.com>
211 RCPT TO:<cc@example.com>
212 RCPT TO:<author@example.com>
213 RCPT TO:<one@example.com>
214 RCPT TO:<two@example.com>
215 RCPT TO:<bcc@example.com>
216 From: Example <from@example.com>
217 To: to@example.com
218 Cc: cc@example.com,
219 A <author@example.com>,
220 One <one@example.com>,
221 two@example.com
222 Subject: [PATCH 1/1] Second.
223 Date: DATE-STRING
224 Message-Id: MESSAGE-ID-STRING
225 X-Mailer: X-MAILER-STRING
226 In-Reply-To: <unique-message-id@example.com>
227 References: <unique-message-id@example.com>
228 Reply-To: Reply <reply@example.com>
229 MIME-Version: 1.0
230 Content-Transfer-Encoding: 8bit
232 Result: OK
236 test_suppress_self () {
237 test_commit $3 &&
238 test_when_finished "git reset --hard HEAD^" &&
240 write_script cccmd-sed <<-EOF &&
241 sed -n -e s/^cccmd--//p "\$1"
244 git commit --amend --author="$1 <$2>" -F - &&
245 clean_fake_sendmail &&
246 git format-patch --stdout -1 >"suppress-self-$3.patch" &&
248 git send-email --from="$1 <$2>" \
249 --to=nobody@example.com \
250 --cc-cmd=./cccmd-sed \
251 --suppress-cc=self \
252 --smtp-server="$(pwd)/fake.sendmail" \
253 suppress-self-$3.patch &&
255 mv msgtxt1 msgtxt1-$3 &&
256 sed -e '/^$/q' msgtxt1-$3 >"msghdr1-$3" &&
258 (grep '^Cc:' msghdr1-$3 >"actual-no-cc-$3";
259 test_must_be_empty actual-no-cc-$3)
262 test_suppress_self_unquoted () {
263 test_suppress_self "$1" "$2" "unquoted-$3" <<-EOF
264 test suppress-cc.self unquoted-$3 with name $1 email $2
266 unquoted-$3
268 cccmd--$1 <$2>
270 Cc: $1 <$2>
271 Signed-off-by: $1 <$2>
275 test_suppress_self_quoted () {
276 test_suppress_self "$1" "$2" "quoted-$3" <<-EOF
277 test suppress-cc.self quoted-$3 with name $1 email $2
279 quoted-$3
281 cccmd--"$1" <$2>
283 Cc: $1 <$2>
284 Cc: "$1" <$2>
285 Signed-off-by: $1 <$2>
286 Signed-off-by: "$1" <$2>
290 test_expect_success $PREREQ 'self name is suppressed' "
291 test_suppress_self_unquoted 'A U Thor' 'author@example.com' \
292 'self_name_suppressed'
295 test_expect_success $PREREQ 'self name with dot is suppressed' "
296 test_suppress_self_quoted 'A U. Thor' 'author@example.com' \
297 'self_name_dot_suppressed'
300 test_expect_success $PREREQ 'non-ascii self name is suppressed' "
301 test_suppress_self_quoted 'Füñný Nâmé' 'odd_?=mail@example.com' \
302 'non_ascii_self_suppressed'
305 # This name is long enough to force format-patch to split it into multiple
306 # encoded-words, assuming it uses UTF-8 with the "Q" encoding.
307 test_expect_success $PREREQ 'long non-ascii self name is suppressed' "
308 test_suppress_self_quoted 'Ƒüñníęř €. Nâṁé' 'odd_?=mail@example.com' \
309 'long_non_ascii_self_suppressed'
312 test_expect_success $PREREQ 'sanitized self name is suppressed' "
313 test_suppress_self_unquoted '\"A U. Thor\"' 'author@example.com' \
314 'self_name_sanitized_suppressed'
317 test_expect_success $PREREQ 'Show all headers' '
318 git send-email \
319 --dry-run \
320 --suppress-cc=sob \
321 --from="Example <from@example.com>" \
322 --reply-to="Reply <reply@example.com>" \
323 --to=to@example.com \
324 --cc=cc@example.com \
325 --bcc=bcc@example.com \
326 --in-reply-to="<unique-message-id@example.com>" \
327 --smtp-server relay.example.com \
328 $patches | replace_variable_fields \
329 >actual-show-all-headers &&
330 test_cmp expected-show-all-headers actual-show-all-headers
333 test_expect_success $PREREQ 'Prompting works' '
334 clean_fake_sendmail &&
335 (echo "to@example.com" &&
336 echo ""
337 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
338 --smtp-server="$(pwd)/fake.sendmail" \
339 $patches \
340 2>errors &&
341 grep "^From: A U Thor <author@example.com>\$" msgtxt1 &&
342 grep "^To: to@example.com\$" msgtxt1
345 test_expect_success $PREREQ,AUTOIDENT 'implicit ident is allowed' '
346 clean_fake_sendmail &&
347 (sane_unset GIT_AUTHOR_NAME &&
348 sane_unset GIT_AUTHOR_EMAIL &&
349 sane_unset GIT_COMMITTER_NAME &&
350 sane_unset GIT_COMMITTER_EMAIL &&
351 GIT_SEND_EMAIL_NOTTY=1 git send-email \
352 --smtp-server="$(pwd)/fake.sendmail" \
353 --to=to@example.com \
354 $patches </dev/null 2>errors
358 test_expect_success $PREREQ,!AUTOIDENT 'broken implicit ident aborts send-email' '
359 clean_fake_sendmail &&
360 (sane_unset GIT_AUTHOR_NAME &&
361 sane_unset GIT_AUTHOR_EMAIL &&
362 sane_unset GIT_COMMITTER_NAME &&
363 sane_unset GIT_COMMITTER_EMAIL &&
364 GIT_SEND_EMAIL_NOTTY=1 && export GIT_SEND_EMAIL_NOTTY &&
365 test_must_fail git send-email \
366 --smtp-server="$(pwd)/fake.sendmail" \
367 --to=to@example.com \
368 $patches </dev/null 2>errors &&
369 test_i18ngrep "tell me who you are" errors
373 test_expect_success $PREREQ 'setup tocmd and cccmd scripts' '
374 write_script tocmd-sed <<-\EOF &&
375 sed -n -e "s/^tocmd--//p" "$1"
377 write_script cccmd-sed <<-\EOF
378 sed -n -e "s/^cccmd--//p" "$1"
382 test_expect_success $PREREQ 'tocmd works' '
383 clean_fake_sendmail &&
384 cp $patches tocmd.patch &&
385 echo tocmd--tocmd@example.com >>tocmd.patch &&
386 git send-email \
387 --from="Example <nobody@example.com>" \
388 --to-cmd=./tocmd-sed \
389 --smtp-server="$(pwd)/fake.sendmail" \
390 tocmd.patch \
392 grep "^To: tocmd@example.com" msgtxt1
395 test_expect_success $PREREQ 'cccmd works' '
396 clean_fake_sendmail &&
397 cp $patches cccmd.patch &&
398 echo "cccmd-- cccmd@example.com" >>cccmd.patch &&
399 git send-email \
400 --from="Example <nobody@example.com>" \
401 --to=nobody@example.com \
402 --cc-cmd=./cccmd-sed \
403 --smtp-server="$(pwd)/fake.sendmail" \
404 cccmd.patch \
406 grep "^ cccmd@example.com" msgtxt1
409 test_expect_success $PREREQ 'reject long lines' '
410 z8=zzzzzzzz &&
411 z64=$z8$z8$z8$z8$z8$z8$z8$z8 &&
412 z512=$z64$z64$z64$z64$z64$z64$z64$z64 &&
413 clean_fake_sendmail &&
414 cp $patches longline.patch &&
415 echo $z512$z512 >>longline.patch &&
416 test_must_fail git send-email \
417 --from="Example <nobody@example.com>" \
418 --to=nobody@example.com \
419 --smtp-server="$(pwd)/fake.sendmail" \
420 --transfer-encoding=8bit \
421 $patches longline.patch \
422 2>errors &&
423 grep longline.patch errors
426 test_expect_success $PREREQ 'no patch was sent' '
427 ! test -e commandline1
430 test_expect_success $PREREQ 'Author From: in message body' '
431 clean_fake_sendmail &&
432 git send-email \
433 --from="Example <nobody@example.com>" \
434 --to=nobody@example.com \
435 --smtp-server="$(pwd)/fake.sendmail" \
436 $patches &&
437 sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
438 grep "From: A <author@example.com>" msgbody1
441 test_expect_success $PREREQ 'Author From: not in message body' '
442 clean_fake_sendmail &&
443 git send-email \
444 --from="A <author@example.com>" \
445 --to=nobody@example.com \
446 --smtp-server="$(pwd)/fake.sendmail" \
447 $patches &&
448 sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
449 ! grep "From: A <author@example.com>" msgbody1
452 test_expect_success $PREREQ 'allow long lines with --no-validate' '
453 git send-email \
454 --from="Example <nobody@example.com>" \
455 --to=nobody@example.com \
456 --smtp-server="$(pwd)/fake.sendmail" \
457 --no-validate \
458 $patches longline.patch \
459 2>errors
462 test_expect_success $PREREQ 'short lines with auto encoding are 8bit' '
463 clean_fake_sendmail &&
464 git send-email \
465 --from="A <author@example.com>" \
466 --to=nobody@example.com \
467 --smtp-server="$(pwd)/fake.sendmail" \
468 --transfer-encoding=auto \
469 $patches &&
470 grep "Content-Transfer-Encoding: 8bit" msgtxt1
473 test_expect_success $PREREQ 'long lines with auto encoding are quoted-printable' '
474 clean_fake_sendmail &&
475 git send-email \
476 --from="Example <nobody@example.com>" \
477 --to=nobody@example.com \
478 --smtp-server="$(pwd)/fake.sendmail" \
479 --transfer-encoding=auto \
480 --no-validate \
481 longline.patch &&
482 grep "Content-Transfer-Encoding: quoted-printable" msgtxt1
485 test_expect_success $PREREQ 'carriage returns with auto encoding are quoted-printable' '
486 clean_fake_sendmail &&
487 cp $patches cr.patch &&
488 printf "this is a line\r\n" >>cr.patch &&
489 git send-email \
490 --from="Example <nobody@example.com>" \
491 --to=nobody@example.com \
492 --smtp-server="$(pwd)/fake.sendmail" \
493 --transfer-encoding=auto \
494 --no-validate \
495 cr.patch &&
496 grep "Content-Transfer-Encoding: quoted-printable" msgtxt1
499 for enc in auto quoted-printable base64
501 test_expect_success $PREREQ "--validate passes with encoding $enc" '
502 git send-email \
503 --from="Example <nobody@example.com>" \
504 --to=nobody@example.com \
505 --smtp-server="$(pwd)/fake.sendmail" \
506 --transfer-encoding=$enc \
507 --validate \
508 $patches longline.patch
511 done
513 for enc in 7bit 8bit quoted-printable base64
515 test_expect_success $PREREQ "--transfer-encoding=$enc produces correct header" '
516 clean_fake_sendmail &&
517 git send-email \
518 --from="Example <nobody@example.com>" \
519 --to=nobody@example.com \
520 --smtp-server="$(pwd)/fake.sendmail" \
521 --transfer-encoding=$enc \
522 $patches &&
523 grep "Content-Transfer-Encoding: $enc" msgtxt1
525 done
527 test_expect_success $PREREQ 'Invalid In-Reply-To' '
528 clean_fake_sendmail &&
529 git send-email \
530 --from="Example <nobody@example.com>" \
531 --to=nobody@example.com \
532 --in-reply-to=" " \
533 --smtp-server="$(pwd)/fake.sendmail" \
534 $patches \
535 2>errors &&
536 ! grep "^In-Reply-To: < *>" msgtxt1
539 test_expect_success $PREREQ 'Valid In-Reply-To when prompting' '
540 clean_fake_sendmail &&
541 (echo "From Example <from@example.com>" &&
542 echo "To Example <to@example.com>" &&
543 echo ""
544 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
545 --smtp-server="$(pwd)/fake.sendmail" \
546 $patches 2>errors &&
547 ! grep "^In-Reply-To: < *>" msgtxt1
550 test_expect_success $PREREQ 'In-Reply-To without --chain-reply-to' '
551 clean_fake_sendmail &&
552 echo "<unique-message-id@example.com>" >expect &&
553 git send-email \
554 --from="Example <nobody@example.com>" \
555 --to=nobody@example.com \
556 --no-chain-reply-to \
557 --in-reply-to="$(cat expect)" \
558 --smtp-server="$(pwd)/fake.sendmail" \
559 $patches $patches $patches \
560 2>errors &&
561 # The first message is a reply to --in-reply-to
562 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
563 test_cmp expect actual &&
564 # Second and subsequent messages are replies to the first one
565 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
566 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
567 test_cmp expect actual &&
568 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
569 test_cmp expect actual
572 test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' '
573 clean_fake_sendmail &&
574 echo "<unique-message-id@example.com>" >expect &&
575 git send-email \
576 --from="Example <nobody@example.com>" \
577 --to=nobody@example.com \
578 --chain-reply-to \
579 --in-reply-to="$(cat expect)" \
580 --smtp-server="$(pwd)/fake.sendmail" \
581 $patches $patches $patches \
582 2>errors &&
583 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
584 test_cmp expect actual &&
585 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
586 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
587 test_cmp expect actual &&
588 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt2 >expect &&
589 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
590 test_cmp expect actual
593 test_expect_success $PREREQ 'setup fake editor' '
594 write_script fake-editor <<-\EOF
595 echo fake edit >>"$1"
599 test_set_editor "$(pwd)/fake-editor"
601 test_expect_success $PREREQ '--compose works' '
602 clean_fake_sendmail &&
603 git send-email \
604 --compose --subject foo \
605 --from="Example <nobody@example.com>" \
606 --to=nobody@example.com \
607 --smtp-server="$(pwd)/fake.sendmail" \
608 $patches \
609 2>errors
612 test_expect_success $PREREQ 'first message is compose text' '
613 grep "^fake edit" msgtxt1
616 test_expect_success $PREREQ 'second message is patch' '
617 grep "Subject:.*Second" msgtxt2
620 test_expect_success $PREREQ 'setup expect' "
621 cat >expected-suppress-sob <<\EOF
622 0001-Second.patch
623 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
624 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
625 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
626 Dry-OK. Log says:
627 Server: relay.example.com
628 MAIL FROM:<from@example.com>
629 RCPT TO:<to@example.com>
630 RCPT TO:<cc@example.com>
631 RCPT TO:<author@example.com>
632 RCPT TO:<one@example.com>
633 RCPT TO:<two@example.com>
634 From: Example <from@example.com>
635 To: to@example.com
636 Cc: cc@example.com,
637 A <author@example.com>,
638 One <one@example.com>,
639 two@example.com
640 Subject: [PATCH 1/1] Second.
641 Date: DATE-STRING
642 Message-Id: MESSAGE-ID-STRING
643 X-Mailer: X-MAILER-STRING
644 MIME-Version: 1.0
645 Content-Transfer-Encoding: 8bit
647 Result: OK
651 test_suppression () {
652 git send-email \
653 --dry-run \
654 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
655 --from="Example <from@example.com>" \
656 --to=to@example.com \
657 --smtp-server relay.example.com \
658 $patches | replace_variable_fields \
659 >actual-suppress-$1${2+"-$2"} &&
660 test_cmp expected-suppress-$1${2+"-$2"} actual-suppress-$1${2+"-$2"}
663 test_expect_success $PREREQ 'sendemail.cc set' '
664 git config sendemail.cc cc@example.com &&
665 test_suppression sob
668 test_expect_success $PREREQ 'setup expect' "
669 cat >expected-suppress-sob <<\EOF
670 0001-Second.patch
671 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
672 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
673 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
674 Dry-OK. Log says:
675 Server: relay.example.com
676 MAIL FROM:<from@example.com>
677 RCPT TO:<to@example.com>
678 RCPT TO:<author@example.com>
679 RCPT TO:<one@example.com>
680 RCPT TO:<two@example.com>
681 From: Example <from@example.com>
682 To: to@example.com
683 Cc: A <author@example.com>,
684 One <one@example.com>,
685 two@example.com
686 Subject: [PATCH 1/1] Second.
687 Date: DATE-STRING
688 Message-Id: MESSAGE-ID-STRING
689 X-Mailer: X-MAILER-STRING
690 MIME-Version: 1.0
691 Content-Transfer-Encoding: 8bit
693 Result: OK
697 test_expect_success $PREREQ 'sendemail.cc unset' '
698 git config --unset sendemail.cc &&
699 test_suppression sob
702 test_expect_success $PREREQ 'setup expect' "
703 cat >expected-suppress-cccmd <<\EOF
704 0001-Second.patch
705 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
706 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
707 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
708 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
709 Dry-OK. Log says:
710 Server: relay.example.com
711 MAIL FROM:<from@example.com>
712 RCPT TO:<to@example.com>
713 RCPT TO:<author@example.com>
714 RCPT TO:<one@example.com>
715 RCPT TO:<two@example.com>
716 RCPT TO:<committer@example.com>
717 From: Example <from@example.com>
718 To: to@example.com
719 Cc: A <author@example.com>,
720 One <one@example.com>,
721 two@example.com,
722 C O Mitter <committer@example.com>
723 Subject: [PATCH 1/1] Second.
724 Date: DATE-STRING
725 Message-Id: MESSAGE-ID-STRING
726 X-Mailer: X-MAILER-STRING
727 MIME-Version: 1.0
728 Content-Transfer-Encoding: 8bit
730 Result: OK
734 test_expect_success $PREREQ 'sendemail.cccmd' '
735 write_script cccmd <<-\EOF &&
736 echo cc-cmd@example.com
738 git config sendemail.cccmd ./cccmd &&
739 test_suppression cccmd
742 test_expect_success $PREREQ 'setup expect' '
743 cat >expected-suppress-all <<\EOF
744 0001-Second.patch
745 Dry-OK. Log says:
746 Server: relay.example.com
747 MAIL FROM:<from@example.com>
748 RCPT TO:<to@example.com>
749 From: Example <from@example.com>
750 To: to@example.com
751 Subject: [PATCH 1/1] Second.
752 Date: DATE-STRING
753 Message-Id: MESSAGE-ID-STRING
754 X-Mailer: X-MAILER-STRING
755 MIME-Version: 1.0
756 Content-Transfer-Encoding: 8bit
758 Result: OK
762 test_expect_success $PREREQ '--suppress-cc=all' '
763 test_suppression all
766 test_expect_success $PREREQ 'setup expect' "
767 cat >expected-suppress-body <<\EOF
768 0001-Second.patch
769 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
770 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
771 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
772 (cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
773 Dry-OK. Log says:
774 Server: relay.example.com
775 MAIL FROM:<from@example.com>
776 RCPT TO:<to@example.com>
777 RCPT TO:<author@example.com>
778 RCPT TO:<one@example.com>
779 RCPT TO:<two@example.com>
780 RCPT TO:<cc-cmd@example.com>
781 From: Example <from@example.com>
782 To: to@example.com
783 Cc: A <author@example.com>,
784 One <one@example.com>,
785 two@example.com,
786 cc-cmd@example.com
787 Subject: [PATCH 1/1] Second.
788 Date: DATE-STRING
789 Message-Id: MESSAGE-ID-STRING
790 X-Mailer: X-MAILER-STRING
791 MIME-Version: 1.0
792 Content-Transfer-Encoding: 8bit
794 Result: OK
798 test_expect_success $PREREQ '--suppress-cc=body' '
799 test_suppression body
802 test_expect_success $PREREQ 'setup expect' "
803 cat >expected-suppress-body-cccmd <<\EOF
804 0001-Second.patch
805 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
806 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
807 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
808 Dry-OK. Log says:
809 Server: relay.example.com
810 MAIL FROM:<from@example.com>
811 RCPT TO:<to@example.com>
812 RCPT TO:<author@example.com>
813 RCPT TO:<one@example.com>
814 RCPT TO:<two@example.com>
815 From: Example <from@example.com>
816 To: to@example.com
817 Cc: A <author@example.com>,
818 One <one@example.com>,
819 two@example.com
820 Subject: [PATCH 1/1] Second.
821 Date: DATE-STRING
822 Message-Id: MESSAGE-ID-STRING
823 X-Mailer: X-MAILER-STRING
824 MIME-Version: 1.0
825 Content-Transfer-Encoding: 8bit
827 Result: OK
831 test_expect_success $PREREQ '--suppress-cc=body --suppress-cc=cccmd' '
832 test_suppression body cccmd
835 test_expect_success $PREREQ 'setup expect' "
836 cat >expected-suppress-sob <<\EOF
837 0001-Second.patch
838 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
839 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
840 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
841 Dry-OK. Log says:
842 Server: relay.example.com
843 MAIL FROM:<from@example.com>
844 RCPT TO:<to@example.com>
845 RCPT TO:<author@example.com>
846 RCPT TO:<one@example.com>
847 RCPT TO:<two@example.com>
848 From: Example <from@example.com>
849 To: to@example.com
850 Cc: A <author@example.com>,
851 One <one@example.com>,
852 two@example.com
853 Subject: [PATCH 1/1] Second.
854 Date: DATE-STRING
855 Message-Id: MESSAGE-ID-STRING
856 X-Mailer: X-MAILER-STRING
857 MIME-Version: 1.0
858 Content-Transfer-Encoding: 8bit
860 Result: OK
864 test_expect_success $PREREQ '--suppress-cc=sob' '
865 test_might_fail git config --unset sendemail.cccmd &&
866 test_suppression sob
869 test_expect_success $PREREQ 'setup expect' "
870 cat >expected-suppress-bodycc <<\EOF
871 0001-Second.patch
872 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
873 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
874 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
875 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
876 Dry-OK. Log says:
877 Server: relay.example.com
878 MAIL FROM:<from@example.com>
879 RCPT TO:<to@example.com>
880 RCPT TO:<author@example.com>
881 RCPT TO:<one@example.com>
882 RCPT TO:<two@example.com>
883 RCPT TO:<committer@example.com>
884 From: Example <from@example.com>
885 To: to@example.com
886 Cc: A <author@example.com>,
887 One <one@example.com>,
888 two@example.com,
889 C O Mitter <committer@example.com>
890 Subject: [PATCH 1/1] Second.
891 Date: DATE-STRING
892 Message-Id: MESSAGE-ID-STRING
893 X-Mailer: X-MAILER-STRING
894 MIME-Version: 1.0
895 Content-Transfer-Encoding: 8bit
897 Result: OK
901 test_expect_success $PREREQ '--suppress-cc=bodycc' '
902 test_suppression bodycc
905 test_expect_success $PREREQ 'setup expect' "
906 cat >expected-suppress-cc <<\EOF
907 0001-Second.patch
908 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
909 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
910 Dry-OK. Log says:
911 Server: relay.example.com
912 MAIL FROM:<from@example.com>
913 RCPT TO:<to@example.com>
914 RCPT TO:<author@example.com>
915 RCPT TO:<committer@example.com>
916 From: Example <from@example.com>
917 To: to@example.com
918 Cc: A <author@example.com>,
919 C O Mitter <committer@example.com>
920 Subject: [PATCH 1/1] Second.
921 Date: DATE-STRING
922 Message-Id: MESSAGE-ID-STRING
923 X-Mailer: X-MAILER-STRING
924 MIME-Version: 1.0
925 Content-Transfer-Encoding: 8bit
927 Result: OK
931 test_expect_success $PREREQ '--suppress-cc=cc' '
932 test_suppression cc
935 test_confirm () {
936 echo y | \
937 GIT_SEND_EMAIL_NOTTY=1 \
938 git send-email \
939 --from="Example <nobody@example.com>" \
940 --to=nobody@example.com \
941 --smtp-server="$(pwd)/fake.sendmail" \
942 $@ $patches >stdout &&
943 grep "Send this email" stdout
946 test_expect_success $PREREQ '--confirm=always' '
947 test_confirm --confirm=always --suppress-cc=all
950 test_expect_success $PREREQ '--confirm=auto' '
951 test_confirm --confirm=auto
954 test_expect_success $PREREQ '--confirm=cc' '
955 test_confirm --confirm=cc
958 test_expect_success $PREREQ '--confirm=compose' '
959 test_confirm --confirm=compose --compose
962 test_expect_success $PREREQ 'confirm by default (due to cc)' '
963 test_when_finished git config sendemail.confirm never &&
964 git config --unset sendemail.confirm &&
965 test_confirm
968 test_expect_success $PREREQ 'confirm by default (due to --compose)' '
969 test_when_finished git config sendemail.confirm never &&
970 git config --unset sendemail.confirm &&
971 test_confirm --suppress-cc=all --compose
974 test_expect_success $PREREQ 'confirm detects EOF (inform assumes y)' '
975 test_when_finished git config sendemail.confirm never &&
976 git config --unset sendemail.confirm &&
977 rm -fr outdir &&
978 git format-patch -2 -o outdir &&
979 GIT_SEND_EMAIL_NOTTY=1 \
980 git send-email \
981 --from="Example <nobody@example.com>" \
982 --to=nobody@example.com \
983 --smtp-server="$(pwd)/fake.sendmail" \
984 outdir/*.patch </dev/null
987 test_expect_success $PREREQ 'confirm detects EOF (auto causes failure)' '
988 test_when_finished git config sendemail.confirm never &&
989 git config sendemail.confirm auto &&
990 GIT_SEND_EMAIL_NOTTY=1 &&
991 export GIT_SEND_EMAIL_NOTTY &&
992 test_must_fail git send-email \
993 --from="Example <nobody@example.com>" \
994 --to=nobody@example.com \
995 --smtp-server="$(pwd)/fake.sendmail" \
996 $patches </dev/null
999 test_expect_success $PREREQ 'confirm does not loop forever' '
1000 test_when_finished git config sendemail.confirm never &&
1001 git config sendemail.confirm auto &&
1002 GIT_SEND_EMAIL_NOTTY=1 &&
1003 export GIT_SEND_EMAIL_NOTTY &&
1004 yes "bogus" | test_must_fail git send-email \
1005 --from="Example <nobody@example.com>" \
1006 --to=nobody@example.com \
1007 --smtp-server="$(pwd)/fake.sendmail" \
1008 $patches
1011 test_expect_success $PREREQ 'utf8 Cc is rfc2047 encoded' '
1012 clean_fake_sendmail &&
1013 rm -fr outdir &&
1014 git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
1015 git send-email \
1016 --from="Example <nobody@example.com>" \
1017 --to=nobody@example.com \
1018 --smtp-server="$(pwd)/fake.sendmail" \
1019 outdir/*.patch &&
1020 grep "^ " msgtxt1 |
1021 grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
1024 test_expect_success $PREREQ '--compose adds MIME for utf8 body' '
1025 clean_fake_sendmail &&
1026 write_script fake-editor-utf8 <<-\EOF &&
1027 echo "utf8 body: àéìöú" >>"$1"
1029 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1030 git send-email \
1031 --compose --subject foo \
1032 --from="Example <nobody@example.com>" \
1033 --to=nobody@example.com \
1034 --smtp-server="$(pwd)/fake.sendmail" \
1035 $patches &&
1036 grep "^utf8 body" msgtxt1 &&
1037 grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
1040 test_expect_success $PREREQ '--compose respects user mime type' '
1041 clean_fake_sendmail &&
1042 write_script fake-editor-utf8-mime <<-\EOF &&
1043 cat >"$1" <<-\EOM
1044 MIME-Version: 1.0
1045 Content-Type: text/plain; charset=iso-8859-1
1046 Content-Transfer-Encoding: 8bit
1047 Subject: foo
1049 utf8 body: àéìöú
1052 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
1053 git send-email \
1054 --compose --subject foo \
1055 --from="Example <nobody@example.com>" \
1056 --to=nobody@example.com \
1057 --smtp-server="$(pwd)/fake.sendmail" \
1058 $patches &&
1059 grep "^utf8 body" msgtxt1 &&
1060 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
1061 ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
1064 test_expect_success $PREREQ '--compose adds MIME for utf8 subject' '
1065 clean_fake_sendmail &&
1066 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
1067 git send-email \
1068 --compose --subject utf8-sübjëct \
1069 --from="Example <nobody@example.com>" \
1070 --to=nobody@example.com \
1071 --smtp-server="$(pwd)/fake.sendmail" \
1072 $patches &&
1073 grep "^fake edit" msgtxt1 &&
1074 grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
1077 test_expect_success $PREREQ 'utf8 author is correctly passed on' '
1078 clean_fake_sendmail &&
1079 test_commit weird_author &&
1080 test_when_finished "git reset --hard HEAD^" &&
1081 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
1082 git format-patch --stdout -1 >funny_name.patch &&
1083 git send-email --from="Example <nobody@example.com>" \
1084 --to=nobody@example.com \
1085 --smtp-server="$(pwd)/fake.sendmail" \
1086 funny_name.patch &&
1087 grep "^From: Füñný Nâmé <odd_?=mail@example.com>" msgtxt1
1090 test_expect_success $PREREQ 'utf8 sender is not duplicated' '
1091 clean_fake_sendmail &&
1092 test_commit weird_sender &&
1093 test_when_finished "git reset --hard HEAD^" &&
1094 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
1095 git format-patch --stdout -1 >funny_name.patch &&
1096 git send-email --from="Füñný Nâmé <odd_?=mail@example.com>" \
1097 --to=nobody@example.com \
1098 --smtp-server="$(pwd)/fake.sendmail" \
1099 funny_name.patch &&
1100 grep "^From: " msgtxt1 >msgfrom &&
1101 test_line_count = 1 msgfrom
1104 test_expect_success $PREREQ 'sendemail.composeencoding works' '
1105 clean_fake_sendmail &&
1106 git config sendemail.composeencoding iso-8859-1 &&
1107 write_script fake-editor-utf8 <<-\EOF &&
1108 echo "utf8 body: àéìöú" >>"$1"
1110 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1111 git send-email \
1112 --compose --subject foo \
1113 --from="Example <nobody@example.com>" \
1114 --to=nobody@example.com \
1115 --smtp-server="$(pwd)/fake.sendmail" \
1116 $patches &&
1117 grep "^utf8 body" msgtxt1 &&
1118 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1121 test_expect_success $PREREQ '--compose-encoding works' '
1122 clean_fake_sendmail &&
1123 write_script fake-editor-utf8 <<-\EOF &&
1124 echo "utf8 body: àéìöú" >>"$1"
1126 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1127 git send-email \
1128 --compose-encoding iso-8859-1 \
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
1138 test_expect_success $PREREQ '--compose-encoding overrides sendemail.composeencoding' '
1139 clean_fake_sendmail &&
1140 git config sendemail.composeencoding iso-8859-1 &&
1141 write_script fake-editor-utf8 <<-\EOF &&
1142 echo "utf8 body: àéìöú" >>"$1"
1144 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1145 git send-email \
1146 --compose-encoding iso-8859-2 \
1147 --compose --subject foo \
1148 --from="Example <nobody@example.com>" \
1149 --to=nobody@example.com \
1150 --smtp-server="$(pwd)/fake.sendmail" \
1151 $patches &&
1152 grep "^utf8 body" msgtxt1 &&
1153 grep "^Content-Type: text/plain; charset=iso-8859-2" msgtxt1
1156 test_expect_success $PREREQ '--compose-encoding adds correct MIME for subject' '
1157 clean_fake_sendmail &&
1158 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
1159 git send-email \
1160 --compose-encoding iso-8859-2 \
1161 --compose --subject utf8-sübjëct \
1162 --from="Example <nobody@example.com>" \
1163 --to=nobody@example.com \
1164 --smtp-server="$(pwd)/fake.sendmail" \
1165 $patches &&
1166 grep "^fake edit" msgtxt1 &&
1167 grep "^Subject: =?iso-8859-2?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
1170 test_expect_success $PREREQ 'detects ambiguous reference/file conflict' '
1171 echo master >master &&
1172 git add master &&
1173 git commit -m"add master" &&
1174 test_must_fail git send-email --dry-run master 2>errors &&
1175 grep disambiguate errors
1178 test_expect_success $PREREQ 'feed two files' '
1179 rm -fr outdir &&
1180 git format-patch -2 -o outdir &&
1181 git send-email \
1182 --dry-run \
1183 --from="Example <nobody@example.com>" \
1184 --to=nobody@example.com \
1185 outdir/000?-*.patch 2>errors >out &&
1186 grep "^Subject: " out >subjects &&
1187 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
1188 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"
1191 test_expect_success $PREREQ 'in-reply-to but no threading' '
1192 git send-email \
1193 --dry-run \
1194 --from="Example <nobody@example.com>" \
1195 --to=nobody@example.com \
1196 --in-reply-to="<in-reply-id@example.com>" \
1197 --no-thread \
1198 $patches >out &&
1199 grep "In-Reply-To: <in-reply-id@example.com>" out
1202 test_expect_success $PREREQ 'no in-reply-to and no threading' '
1203 git send-email \
1204 --dry-run \
1205 --from="Example <nobody@example.com>" \
1206 --to=nobody@example.com \
1207 --no-thread \
1208 $patches >stdout &&
1209 ! grep "In-Reply-To: " stdout
1212 test_expect_success $PREREQ 'threading but no chain-reply-to' '
1213 git send-email \
1214 --dry-run \
1215 --from="Example <nobody@example.com>" \
1216 --to=nobody@example.com \
1217 --thread \
1218 --no-chain-reply-to \
1219 $patches $patches >stdout &&
1220 grep "In-Reply-To: " stdout
1223 test_expect_success $PREREQ 'override in-reply-to if no threading' '
1224 git send-email \
1225 --dry-run \
1226 --from="Example <nobody@example.com>" \
1227 --to=nobody@example.com \
1228 --no-thread \
1229 --in-reply-to="override" \
1230 $threaded_patches >stdout &&
1231 grep "In-Reply-To: <override>" stdout
1234 test_expect_success $PREREQ 'sendemail.to works' '
1235 git config --replace-all sendemail.to "Somebody <somebody@ex.com>" &&
1236 git send-email \
1237 --dry-run \
1238 --from="Example <nobody@example.com>" \
1239 $patches >stdout &&
1240 grep "To: Somebody <somebody@ex.com>" stdout
1243 test_expect_success $PREREQ 'setup sendemail.identity' '
1244 git config --replace-all sendemail.to "default@example.com" &&
1245 git config --replace-all sendemail.isp.to "isp@example.com" &&
1246 git config --replace-all sendemail.cloud.to "cloud@example.com"
1249 test_expect_success $PREREQ 'sendemail.identity: reads the correct identity config' '
1250 git -c sendemail.identity=cloud send-email \
1251 --dry-run \
1252 --from="nobody@example.com" \
1253 $patches >stdout &&
1254 grep "To: cloud@example.com" stdout
1257 test_expect_success $PREREQ 'sendemail.identity: identity overrides sendemail.identity' '
1258 git -c sendemail.identity=cloud send-email \
1259 --identity=isp \
1260 --dry-run \
1261 --from="nobody@example.com" \
1262 $patches >stdout &&
1263 grep "To: isp@example.com" stdout
1266 test_expect_success $PREREQ 'sendemail.identity: --no-identity clears previous identity' '
1267 git -c sendemail.identity=cloud send-email \
1268 --no-identity \
1269 --dry-run \
1270 --from="nobody@example.com" \
1271 $patches >stdout &&
1272 grep "To: default@example.com" stdout
1275 test_expect_success $PREREQ 'sendemail.identity: bool identity variable existence overrides' '
1276 git -c sendemail.identity=cloud \
1277 -c sendemail.xmailer=true \
1278 -c sendemail.cloud.xmailer=false \
1279 send-email \
1280 --dry-run \
1281 --from="nobody@example.com" \
1282 $patches >stdout &&
1283 grep "To: cloud@example.com" stdout &&
1284 ! grep "X-Mailer" stdout
1287 test_expect_success $PREREQ 'sendemail.identity: bool variable fallback' '
1288 git -c sendemail.identity=cloud \
1289 -c sendemail.xmailer=false \
1290 send-email \
1291 --dry-run \
1292 --from="nobody@example.com" \
1293 $patches >stdout &&
1294 grep "To: cloud@example.com" stdout &&
1295 ! grep "X-Mailer" stdout
1298 test_expect_success $PREREQ '--no-to overrides sendemail.to' '
1299 git send-email \
1300 --dry-run \
1301 --from="Example <nobody@example.com>" \
1302 --no-to \
1303 --to=nobody@example.com \
1304 $patches >stdout &&
1305 grep "To: nobody@example.com" stdout &&
1306 ! grep "To: Somebody <somebody@ex.com>" stdout
1309 test_expect_success $PREREQ 'sendemail.cc works' '
1310 git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" &&
1311 git send-email \
1312 --dry-run \
1313 --from="Example <nobody@example.com>" \
1314 --to=nobody@example.com \
1315 $patches >stdout &&
1316 grep "Cc: Somebody <somebody@ex.com>" stdout
1319 test_expect_success $PREREQ '--no-cc overrides sendemail.cc' '
1320 git send-email \
1321 --dry-run \
1322 --from="Example <nobody@example.com>" \
1323 --no-cc \
1324 --cc=bodies@example.com \
1325 --to=nobody@example.com \
1326 $patches >stdout &&
1327 grep "Cc: bodies@example.com" stdout &&
1328 ! grep "Cc: Somebody <somebody@ex.com>" stdout
1331 test_expect_success $PREREQ 'sendemail.bcc works' '
1332 git config --replace-all sendemail.bcc "Other <other@ex.com>" &&
1333 git send-email \
1334 --dry-run \
1335 --from="Example <nobody@example.com>" \
1336 --to=nobody@example.com \
1337 --smtp-server relay.example.com \
1338 $patches >stdout &&
1339 grep "RCPT TO:<other@ex.com>" stdout
1342 test_expect_success $PREREQ '--no-bcc overrides sendemail.bcc' '
1343 git send-email \
1344 --dry-run \
1345 --from="Example <nobody@example.com>" \
1346 --no-bcc \
1347 --bcc=bodies@example.com \
1348 --to=nobody@example.com \
1349 --smtp-server relay.example.com \
1350 $patches >stdout &&
1351 grep "RCPT TO:<bodies@example.com>" stdout &&
1352 ! grep "RCPT TO:<other@ex.com>" stdout
1355 test_expect_success $PREREQ 'patches To headers are used by default' '
1356 patch=$(git format-patch -1 --to="bodies@example.com") &&
1357 test_when_finished "rm $patch" &&
1358 git send-email \
1359 --dry-run \
1360 --from="Example <nobody@example.com>" \
1361 --smtp-server relay.example.com \
1362 $patch >stdout &&
1363 grep "RCPT TO:<bodies@example.com>" stdout
1366 test_expect_success $PREREQ 'patches To headers are appended to' '
1367 patch=$(git format-patch -1 --to="bodies@example.com") &&
1368 test_when_finished "rm $patch" &&
1369 git send-email \
1370 --dry-run \
1371 --from="Example <nobody@example.com>" \
1372 --to=nobody@example.com \
1373 --smtp-server relay.example.com \
1374 $patch >stdout &&
1375 grep "RCPT TO:<bodies@example.com>" stdout &&
1376 grep "RCPT TO:<nobody@example.com>" stdout
1379 test_expect_success $PREREQ 'To headers from files reset each patch' '
1380 patch1=$(git format-patch -1 --to="bodies@example.com") &&
1381 patch2=$(git format-patch -1 --to="other@example.com" HEAD~) &&
1382 test_when_finished "rm $patch1 && rm $patch2" &&
1383 git send-email \
1384 --dry-run \
1385 --from="Example <nobody@example.com>" \
1386 --to="nobody@example.com" \
1387 --smtp-server relay.example.com \
1388 $patch1 $patch2 >stdout &&
1389 test $(grep -c "RCPT TO:<bodies@example.com>" stdout) = 1 &&
1390 test $(grep -c "RCPT TO:<nobody@example.com>" stdout) = 2 &&
1391 test $(grep -c "RCPT TO:<other@example.com>" stdout) = 1
1394 test_expect_success $PREREQ 'setup expect' '
1395 cat >email-using-8bit <<\EOF
1396 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1397 Message-Id: <bogus-message-id@example.com>
1398 From: author@example.com
1399 Date: Sat, 12 Jun 2010 15:53:58 +0200
1400 Subject: subject goes here
1402 Dieser deutsche Text enthält einen Umlaut!
1406 test_expect_success $PREREQ 'setup expect' '
1407 echo "Subject: subject goes here" >expected
1410 test_expect_success $PREREQ 'ASCII subject is not RFC2047 quoted' '
1411 clean_fake_sendmail &&
1412 echo bogus |
1413 git send-email --from=author@example.com --to=nobody@example.com \
1414 --smtp-server="$(pwd)/fake.sendmail" \
1415 --8bit-encoding=UTF-8 \
1416 email-using-8bit >stdout &&
1417 grep "Subject" msgtxt1 >actual &&
1418 test_cmp expected actual
1421 test_expect_success $PREREQ 'setup expect' '
1422 cat >content-type-decl <<-\EOF
1423 MIME-Version: 1.0
1424 Content-Type: text/plain; charset=UTF-8
1425 Content-Transfer-Encoding: 8bit
1429 test_expect_success $PREREQ 'asks about and fixes 8bit encodings' '
1430 clean_fake_sendmail &&
1431 echo |
1432 git send-email --from=author@example.com --to=nobody@example.com \
1433 --smtp-server="$(pwd)/fake.sendmail" \
1434 email-using-8bit >stdout &&
1435 grep "do not declare a Content-Transfer-Encoding" stdout &&
1436 grep email-using-8bit stdout &&
1437 grep "Which 8bit encoding" stdout &&
1438 egrep "Content|MIME" msgtxt1 >actual &&
1439 test_cmp content-type-decl actual
1442 test_expect_success $PREREQ 'sendemail.8bitEncoding works' '
1443 clean_fake_sendmail &&
1444 git config sendemail.assume8bitEncoding UTF-8 &&
1445 echo bogus |
1446 git send-email --from=author@example.com --to=nobody@example.com \
1447 --smtp-server="$(pwd)/fake.sendmail" \
1448 email-using-8bit >stdout &&
1449 egrep "Content|MIME" msgtxt1 >actual &&
1450 test_cmp content-type-decl actual
1453 test_expect_success $PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
1454 clean_fake_sendmail &&
1455 git config sendemail.assume8bitEncoding "bogus too" &&
1456 echo bogus |
1457 git send-email --from=author@example.com --to=nobody@example.com \
1458 --smtp-server="$(pwd)/fake.sendmail" \
1459 --8bit-encoding=UTF-8 \
1460 email-using-8bit >stdout &&
1461 egrep "Content|MIME" msgtxt1 >actual &&
1462 test_cmp content-type-decl actual
1465 test_expect_success $PREREQ 'setup expect' '
1466 cat >email-using-8bit <<-\EOF
1467 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1468 Message-Id: <bogus-message-id@example.com>
1469 From: author@example.com
1470 Date: Sat, 12 Jun 2010 15:53:58 +0200
1471 Subject: Dieser Betreff enthält auch einen Umlaut!
1473 Nothing to see here.
1477 test_expect_success $PREREQ 'setup expect' '
1478 cat >expected <<-\EOF
1479 Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
1483 test_expect_success $PREREQ '--8bit-encoding also treats subject' '
1484 clean_fake_sendmail &&
1485 echo bogus |
1486 git send-email --from=author@example.com --to=nobody@example.com \
1487 --smtp-server="$(pwd)/fake.sendmail" \
1488 --8bit-encoding=UTF-8 \
1489 email-using-8bit >stdout &&
1490 grep "Subject" msgtxt1 >actual &&
1491 test_cmp expected actual
1494 test_expect_success $PREREQ 'setup expect' '
1495 cat >email-using-8bit <<-\EOF
1496 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1497 Message-Id: <bogus-message-id@example.com>
1498 From: A U Thor <author@example.com>
1499 Date: Sat, 12 Jun 2010 15:53:58 +0200
1500 Content-Type: text/plain; charset=UTF-8
1501 Subject: Nothing to see here.
1503 Dieser Betreff enthält auch einen Umlaut!
1507 test_expect_success $PREREQ '--transfer-encoding overrides sendemail.transferEncoding' '
1508 clean_fake_sendmail &&
1509 test_must_fail git -c sendemail.transferEncoding=8bit \
1510 send-email \
1511 --transfer-encoding=7bit \
1512 --smtp-server="$(pwd)/fake.sendmail" \
1513 email-using-8bit \
1514 2>errors >out &&
1515 grep "cannot send message as 7bit" errors &&
1516 test -z "$(ls msgtxt*)"
1519 test_expect_success $PREREQ 'sendemail.transferEncoding via config' '
1520 clean_fake_sendmail &&
1521 test_must_fail git -c sendemail.transferEncoding=7bit \
1522 send-email \
1523 --smtp-server="$(pwd)/fake.sendmail" \
1524 email-using-8bit \
1525 2>errors >out &&
1526 grep "cannot send message as 7bit" errors &&
1527 test -z "$(ls msgtxt*)"
1530 test_expect_success $PREREQ 'sendemail.transferEncoding via cli' '
1531 clean_fake_sendmail &&
1532 test_must_fail git send-email \
1533 --transfer-encoding=7bit \
1534 --smtp-server="$(pwd)/fake.sendmail" \
1535 email-using-8bit \
1536 2>errors >out &&
1537 grep "cannot send message as 7bit" errors &&
1538 test -z "$(ls msgtxt*)"
1541 test_expect_success $PREREQ 'setup expect' '
1542 cat >expected <<-\EOF
1543 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1547 test_expect_success $PREREQ '8-bit and sendemail.transferencoding=quoted-printable' '
1548 clean_fake_sendmail &&
1549 git send-email \
1550 --transfer-encoding=quoted-printable \
1551 --smtp-server="$(pwd)/fake.sendmail" \
1552 email-using-8bit \
1553 2>errors >out &&
1554 sed '1,/^$/d' msgtxt1 >actual &&
1555 test_cmp expected actual
1558 test_expect_success $PREREQ 'setup expect' '
1559 cat >expected <<-\EOF
1560 RGllc2VyIEJldHJlZmYgZW50aMOkbHQgYXVjaCBlaW5lbiBVbWxhdXQhCg==
1564 test_expect_success $PREREQ '8-bit and sendemail.transferencoding=base64' '
1565 clean_fake_sendmail &&
1566 git send-email \
1567 --transfer-encoding=base64 \
1568 --smtp-server="$(pwd)/fake.sendmail" \
1569 email-using-8bit \
1570 2>errors >out &&
1571 sed '1,/^$/d' msgtxt1 >actual &&
1572 test_cmp expected actual
1575 test_expect_success $PREREQ 'setup expect' '
1576 cat >email-using-qp <<-\EOF
1577 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1578 Message-Id: <bogus-message-id@example.com>
1579 From: A U Thor <author@example.com>
1580 Date: Sat, 12 Jun 2010 15:53:58 +0200
1581 MIME-Version: 1.0
1582 Content-Transfer-Encoding: quoted-printable
1583 Content-Type: text/plain; charset=UTF-8
1584 Subject: Nothing to see here.
1586 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1590 test_expect_success $PREREQ 'convert from quoted-printable to base64' '
1591 clean_fake_sendmail &&
1592 git send-email \
1593 --transfer-encoding=base64 \
1594 --smtp-server="$(pwd)/fake.sendmail" \
1595 email-using-qp \
1596 2>errors >out &&
1597 sed '1,/^$/d' msgtxt1 >actual &&
1598 test_cmp expected actual
1601 test_expect_success $PREREQ 'setup expect' "
1602 tr -d '\\015' | tr '%' '\\015' >email-using-crlf <<EOF
1603 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1604 Message-Id: <bogus-message-id@example.com>
1605 From: A U Thor <author@example.com>
1606 Date: Sat, 12 Jun 2010 15:53:58 +0200
1607 Content-Type: text/plain; charset=UTF-8
1608 Subject: Nothing to see here.
1610 Look, I have a CRLF and an = sign!%
1614 test_expect_success $PREREQ 'setup expect' '
1615 cat >expected <<-\EOF
1616 Look, I have a CRLF and an =3D sign!=0D
1620 test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=quoted-printable' '
1621 clean_fake_sendmail &&
1622 git send-email \
1623 --transfer-encoding=quoted-printable \
1624 --smtp-server="$(pwd)/fake.sendmail" \
1625 email-using-crlf \
1626 2>errors >out &&
1627 sed '1,/^$/d' msgtxt1 >actual &&
1628 test_cmp expected actual
1631 test_expect_success $PREREQ 'setup expect' '
1632 cat >expected <<-\EOF
1633 TG9vaywgSSBoYXZlIGEgQ1JMRiBhbmQgYW4gPSBzaWduIQ0K
1637 test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=base64' '
1638 clean_fake_sendmail &&
1639 git send-email \
1640 --transfer-encoding=base64 \
1641 --smtp-server="$(pwd)/fake.sendmail" \
1642 email-using-crlf \
1643 2>errors >out &&
1644 sed '1,/^$/d' msgtxt1 >actual &&
1645 test_cmp expected actual
1649 # Note that the patches in this test are deliberately out of order; we
1650 # want to make sure it works even if the cover-letter is not in the
1651 # first mail.
1652 test_expect_success $PREREQ 'refusing to send cover letter template' '
1653 clean_fake_sendmail &&
1654 rm -fr outdir &&
1655 git format-patch --cover-letter -2 -o outdir &&
1656 test_must_fail git send-email \
1657 --from="Example <nobody@example.com>" \
1658 --to=nobody@example.com \
1659 --smtp-server="$(pwd)/fake.sendmail" \
1660 outdir/0002-*.patch \
1661 outdir/0000-*.patch \
1662 outdir/0001-*.patch \
1663 2>errors >out &&
1664 grep "SUBJECT HERE" errors &&
1665 test -z "$(ls msgtxt*)"
1668 test_expect_success $PREREQ '--force sends cover letter template anyway' '
1669 clean_fake_sendmail &&
1670 rm -fr outdir &&
1671 git format-patch --cover-letter -2 -o outdir &&
1672 git send-email \
1673 --force \
1674 --from="Example <nobody@example.com>" \
1675 --to=nobody@example.com \
1676 --smtp-server="$(pwd)/fake.sendmail" \
1677 outdir/0002-*.patch \
1678 outdir/0000-*.patch \
1679 outdir/0001-*.patch \
1680 2>errors >out &&
1681 ! grep "SUBJECT HERE" errors &&
1682 test -n "$(ls msgtxt*)"
1685 test_cover_addresses () {
1686 header="$1"
1687 shift
1688 clean_fake_sendmail &&
1689 rm -fr outdir &&
1690 git format-patch --cover-letter -2 -o outdir &&
1691 cover=$(echo outdir/0000-*.patch) &&
1692 mv $cover cover-to-edit.patch &&
1693 perl -pe "s/^From:/$header: extra\@address.com\nFrom:/" cover-to-edit.patch >"$cover" &&
1694 git send-email \
1695 --force \
1696 --from="Example <nobody@example.com>" \
1697 --no-to --no-cc \
1698 "$@" \
1699 --smtp-server="$(pwd)/fake.sendmail" \
1700 outdir/0000-*.patch \
1701 outdir/0001-*.patch \
1702 outdir/0002-*.patch \
1703 2>errors >out &&
1704 grep "^$header: extra@address.com" msgtxt1 >to1 &&
1705 grep "^$header: extra@address.com" msgtxt2 >to2 &&
1706 grep "^$header: extra@address.com" msgtxt3 >to3 &&
1707 test_line_count = 1 to1 &&
1708 test_line_count = 1 to2 &&
1709 test_line_count = 1 to3
1712 test_expect_success $PREREQ 'to-cover adds To to all mail' '
1713 test_cover_addresses "To" --to-cover
1716 test_expect_success $PREREQ 'cc-cover adds Cc to all mail' '
1717 test_cover_addresses "Cc" --cc-cover
1720 test_expect_success $PREREQ 'tocover adds To to all mail' '
1721 test_config sendemail.tocover true &&
1722 test_cover_addresses "To"
1725 test_expect_success $PREREQ 'cccover adds Cc to all mail' '
1726 test_config sendemail.cccover true &&
1727 test_cover_addresses "Cc"
1730 test_expect_success $PREREQ 'escaped quotes in sendemail.aliasfiletype=mutt' '
1731 clean_fake_sendmail &&
1732 echo "alias sbd \\\"Dot U. Sir\\\" <somebody@example.org>" >.mutt &&
1733 git config --replace-all sendemail.aliasesfile "$(pwd)/.mutt" &&
1734 git config sendemail.aliasfiletype mutt &&
1735 git send-email \
1736 --from="Example <nobody@example.com>" \
1737 --to=sbd \
1738 --smtp-server="$(pwd)/fake.sendmail" \
1739 outdir/0001-*.patch \
1740 2>errors >out &&
1741 grep "^!somebody@example\.org!$" commandline1 &&
1742 grep -F "To: \"Dot U. Sir\" <somebody@example.org>" out
1745 test_expect_success $PREREQ 'sendemail.aliasfiletype=mailrc' '
1746 clean_fake_sendmail &&
1747 echo "alias sbd somebody@example.org" >.mailrc &&
1748 git config --replace-all sendemail.aliasesfile "$(pwd)/.mailrc" &&
1749 git config sendemail.aliasfiletype mailrc &&
1750 git send-email \
1751 --from="Example <nobody@example.com>" \
1752 --to=sbd \
1753 --smtp-server="$(pwd)/fake.sendmail" \
1754 outdir/0001-*.patch \
1755 2>errors >out &&
1756 grep "^!somebody@example\.org!$" commandline1
1759 test_expect_success $PREREQ 'sendemail.aliasfile=~/.mailrc' '
1760 clean_fake_sendmail &&
1761 echo "alias sbd someone@example.org" >"$HOME/.mailrc" &&
1762 git config --replace-all sendemail.aliasesfile "~/.mailrc" &&
1763 git config sendemail.aliasfiletype mailrc &&
1764 git send-email \
1765 --from="Example <nobody@example.com>" \
1766 --to=sbd \
1767 --smtp-server="$(pwd)/fake.sendmail" \
1768 outdir/0001-*.patch \
1769 2>errors >out &&
1770 grep "^!someone@example\.org!$" commandline1
1773 test_dump_aliases () {
1774 msg="$1" && shift &&
1775 filetype="$1" && shift &&
1776 printf '%s\n' "$@" >expect &&
1777 cat >.tmp-email-aliases &&
1779 test_expect_success $PREREQ "$msg" '
1780 clean_fake_sendmail && rm -fr outdir &&
1781 git config --replace-all sendemail.aliasesfile \
1782 "$(pwd)/.tmp-email-aliases" &&
1783 git config sendemail.aliasfiletype "$filetype" &&
1784 git send-email --dump-aliases 2>errors >actual &&
1785 test_cmp expect actual
1789 test_dump_aliases '--dump-aliases sendmail format' \
1790 'sendmail' \
1791 'abgroup' \
1792 'alice' \
1793 'bcgrp' \
1794 'bob' \
1795 'chloe' <<-\EOF
1796 alice: Alice W Land <awol@example.com>
1797 bob: Robert Bobbyton <bob@example.com>
1798 chloe: chloe@example.com
1799 abgroup: alice, bob
1800 bcgrp: bob, chloe, Other <o@example.com>
1803 test_dump_aliases '--dump-aliases mutt format' \
1804 'mutt' \
1805 'alice' \
1806 'bob' \
1807 'chloe' \
1808 'donald' <<-\EOF
1809 alias alice Alice W Land <awol@example.com>
1810 alias donald Donald C Carlton <donc@example.com>
1811 alias bob Robert Bobbyton <bob@example.com>
1812 alias chloe chloe@example.com
1815 test_dump_aliases '--dump-aliases mailrc format' \
1816 'mailrc' \
1817 'alice' \
1818 'bob' \
1819 'chloe' \
1820 'eve' <<-\EOF
1821 alias alice Alice W Land <awol@example.com>
1822 alias eve Eve <eve@example.com>
1823 alias bob Robert Bobbyton <bob@example.com>
1824 alias chloe chloe@example.com
1827 test_dump_aliases '--dump-aliases pine format' \
1828 'pine' \
1829 'alice' \
1830 'bob' \
1831 'chloe' \
1832 'eve' <<-\EOF
1833 alice Alice W Land <awol@example.com>
1834 eve Eve <eve@example.com>
1835 bob Robert Bobbyton <bob@example.com>
1836 chloe chloe@example.com
1839 test_dump_aliases '--dump-aliases gnus format' \
1840 'gnus' \
1841 'alice' \
1842 'bob' \
1843 'chloe' \
1844 'eve' <<-\EOF
1845 (define-mail-alias "alice" "awol@example.com")
1846 (define-mail-alias "eve" "eve@example.com")
1847 (define-mail-alias "bob" "bob@example.com")
1848 (define-mail-alias "chloe" "chloe@example.com")
1851 test_expect_success '--dump-aliases must be used alone' '
1852 test_must_fail git send-email --dump-aliases --to=janice@example.com -1 refs/heads/accounting
1855 test_expect_success $PREREQ 'aliases and sendemail.identity' '
1856 test_must_fail git \
1857 -c sendemail.identity=cloud \
1858 -c sendemail.aliasesfile=default-aliases \
1859 -c sendemail.cloud.aliasesfile=cloud-aliases \
1860 send-email -1 2>stderr &&
1861 test_i18ngrep "cloud-aliases" stderr
1864 test_sendmail_aliases () {
1865 msg="$1" && shift &&
1866 expect="$@" &&
1867 cat >.tmp-email-aliases &&
1869 test_expect_success $PREREQ "$msg" '
1870 clean_fake_sendmail && rm -fr outdir &&
1871 git format-patch -1 -o outdir &&
1872 git config --replace-all sendemail.aliasesfile \
1873 "$(pwd)/.tmp-email-aliases" &&
1874 git config sendemail.aliasfiletype sendmail &&
1875 git send-email \
1876 --from="Example <nobody@example.com>" \
1877 --to=alice --to=bcgrp \
1878 --smtp-server="$(pwd)/fake.sendmail" \
1879 outdir/0001-*.patch \
1880 2>errors >out &&
1881 for i in $expect
1883 grep "^!$i!$" commandline1 || return 1
1884 done
1888 test_sendmail_aliases 'sendemail.aliasfiletype=sendmail' \
1889 'awol@example\.com' \
1890 'bob@example\.com' \
1891 'chloe@example\.com' \
1892 'o@example\.com' <<-\EOF
1893 alice: Alice W Land <awol@example.com>
1894 bob: Robert Bobbyton <bob@example.com>
1895 # this is a comment
1896 # this is also a comment
1897 chloe: chloe@example.com
1898 abgroup: alice, bob
1899 bcgrp: bob, chloe, Other <o@example.com>
1902 test_sendmail_aliases 'sendmail aliases line folding' \
1903 alice1 \
1904 bob1 bob2 \
1905 chuck1 chuck2 \
1906 darla1 darla2 darla3 \
1907 elton1 elton2 elton3 \
1908 fred1 fred2 \
1909 greg1 <<-\EOF
1910 alice: alice1
1911 bob: bob1,\
1912 bob2
1913 chuck: chuck1,
1914 chuck2
1915 darla: darla1,\
1916 darla2,
1917 darla3
1918 elton: elton1,
1919 elton2,\
1920 elton3
1921 fred: fred1,\
1922 fred2
1923 greg: greg1
1924 bcgrp: bob, chuck, darla, elton, fred, greg
1927 test_sendmail_aliases 'sendmail aliases tolerate bogus line folding' \
1928 alice1 bob1 <<-\EOF
1929 alice: alice1
1930 bcgrp: bob1\
1933 test_sendmail_aliases 'sendmail aliases empty' alice bcgrp <<-\EOF
1936 test_expect_success $PREREQ 'alias support in To header' '
1937 clean_fake_sendmail &&
1938 echo "alias sbd someone@example.org" >.mailrc &&
1939 test_config sendemail.aliasesfile ".mailrc" &&
1940 test_config sendemail.aliasfiletype mailrc &&
1941 git format-patch --stdout -1 --to=sbd >aliased.patch &&
1942 git send-email \
1943 --from="Example <nobody@example.com>" \
1944 --smtp-server="$(pwd)/fake.sendmail" \
1945 aliased.patch \
1946 2>errors >out &&
1947 grep "^!someone@example\.org!$" commandline1
1950 test_expect_success $PREREQ 'alias support in Cc header' '
1951 clean_fake_sendmail &&
1952 echo "alias sbd someone@example.org" >.mailrc &&
1953 test_config sendemail.aliasesfile ".mailrc" &&
1954 test_config sendemail.aliasfiletype mailrc &&
1955 git format-patch --stdout -1 --cc=sbd >aliased.patch &&
1956 git send-email \
1957 --from="Example <nobody@example.com>" \
1958 --smtp-server="$(pwd)/fake.sendmail" \
1959 aliased.patch \
1960 2>errors >out &&
1961 grep "^!someone@example\.org!$" commandline1
1964 test_expect_success $PREREQ 'tocmd works with aliases' '
1965 clean_fake_sendmail &&
1966 echo "alias sbd someone@example.org" >.mailrc &&
1967 test_config sendemail.aliasesfile ".mailrc" &&
1968 test_config sendemail.aliasfiletype mailrc &&
1969 git format-patch --stdout -1 >tocmd.patch &&
1970 echo tocmd--sbd >>tocmd.patch &&
1971 git send-email \
1972 --from="Example <nobody@example.com>" \
1973 --to-cmd=./tocmd-sed \
1974 --smtp-server="$(pwd)/fake.sendmail" \
1975 tocmd.patch \
1976 2>errors >out &&
1977 grep "^!someone@example\.org!$" commandline1
1980 test_expect_success $PREREQ 'cccmd works with aliases' '
1981 clean_fake_sendmail &&
1982 echo "alias sbd someone@example.org" >.mailrc &&
1983 test_config sendemail.aliasesfile ".mailrc" &&
1984 test_config sendemail.aliasfiletype mailrc &&
1985 git format-patch --stdout -1 >cccmd.patch &&
1986 echo cccmd--sbd >>cccmd.patch &&
1987 git send-email \
1988 --from="Example <nobody@example.com>" \
1989 --cc-cmd=./cccmd-sed \
1990 --smtp-server="$(pwd)/fake.sendmail" \
1991 cccmd.patch \
1992 2>errors >out &&
1993 grep "^!someone@example\.org!$" commandline1
1996 do_xmailer_test () {
1997 expected=$1 params=$2 &&
1998 git format-patch -1 &&
1999 git send-email \
2000 --from="Example <nobody@example.com>" \
2001 --to=someone@example.com \
2002 --smtp-server="$(pwd)/fake.sendmail" \
2003 $params \
2004 0001-*.patch \
2005 2>errors >out &&
2006 { grep '^X-Mailer:' out || :; } >mailer &&
2007 test_line_count = $expected mailer
2010 test_expect_success $PREREQ '--[no-]xmailer without any configuration' '
2011 do_xmailer_test 1 "--xmailer" &&
2012 do_xmailer_test 0 "--no-xmailer"
2015 test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=true' '
2016 test_config sendemail.xmailer true &&
2017 do_xmailer_test 1 "" &&
2018 do_xmailer_test 0 "--no-xmailer" &&
2019 do_xmailer_test 1 "--xmailer"
2022 test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=false' '
2023 test_config sendemail.xmailer false &&
2024 do_xmailer_test 0 "" &&
2025 do_xmailer_test 0 "--no-xmailer" &&
2026 do_xmailer_test 1 "--xmailer"
2029 test_expect_success $PREREQ 'setup expected-list' '
2030 git send-email \
2031 --dry-run \
2032 --from="Example <from@example.com>" \
2033 --to="To 1 <to1@example.com>" \
2034 --to="to2@example.com" \
2035 --to="to3@example.com" \
2036 --cc="Cc 1 <cc1@example.com>" \
2037 --cc="Cc2 <cc2@example.com>" \
2038 --bcc="bcc1@example.com" \
2039 --bcc="bcc2@example.com" \
2040 0001-add-master.patch | replace_variable_fields \
2041 >expected-list
2044 test_expect_success $PREREQ 'use email list in --cc --to and --bcc' '
2045 git send-email \
2046 --dry-run \
2047 --from="Example <from@example.com>" \
2048 --to="To 1 <to1@example.com>, to2@example.com" \
2049 --to="to3@example.com" \
2050 --cc="Cc 1 <cc1@example.com>, Cc2 <cc2@example.com>" \
2051 --bcc="bcc1@example.com, bcc2@example.com" \
2052 0001-add-master.patch | replace_variable_fields \
2053 >actual-list &&
2054 test_cmp expected-list actual-list
2057 test_expect_success $PREREQ 'aliases work with email list' '
2058 echo "alias to2 to2@example.com" >.mutt &&
2059 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt &&
2060 test_config sendemail.aliasesfile ".mutt" &&
2061 test_config sendemail.aliasfiletype mutt &&
2062 git send-email \
2063 --dry-run \
2064 --from="Example <from@example.com>" \
2065 --to="To 1 <to1@example.com>, to2, to3@example.com" \
2066 --cc="cc1, Cc2 <cc2@example.com>" \
2067 --bcc="bcc1@example.com, bcc2@example.com" \
2068 0001-add-master.patch | replace_variable_fields \
2069 >actual-list &&
2070 test_cmp expected-list actual-list
2073 test_expect_success $PREREQ 'leading and trailing whitespaces are removed' '
2074 echo "alias to2 to2@example.com" >.mutt &&
2075 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt &&
2076 test_config sendemail.aliasesfile ".mutt" &&
2077 test_config sendemail.aliasfiletype mutt &&
2078 TO1=$(echo "QTo 1 <to1@example.com>" | q_to_tab) &&
2079 TO2=$(echo "QZto2" | qz_to_tab_space) &&
2080 CC1=$(echo "cc1" | append_cr) &&
2081 BCC1=$(echo " bcc1@example.com Q" | q_to_nul) &&
2082 git send-email \
2083 --dry-run \
2084 --from=" Example <from@example.com>" \
2085 --to="$TO1" \
2086 --to="$TO2" \
2087 --to=" to3@example.com " \
2088 --cc="$CC1" \
2089 --cc="Cc2 <cc2@example.com>" \
2090 --bcc="$BCC1" \
2091 --bcc="bcc2@example.com" \
2092 0001-add-master.patch | replace_variable_fields \
2093 >actual-list &&
2094 test_cmp expected-list actual-list
2097 test_expect_success $PREREQ 'invoke hook' '
2098 mkdir -p .git/hooks &&
2100 write_script .git/hooks/sendemail-validate <<-\EOF &&
2101 # test that we have the correct environment variable, pwd, and
2102 # argument
2103 case "$GIT_DIR" in
2104 *.git)
2105 true
2108 false
2110 esac &&
2111 test -f 0001-add-master.patch &&
2112 grep "add master" "$1"
2115 mkdir subdir &&
2117 # Test that it works even if we are not at the root of the
2118 # working tree
2119 cd subdir &&
2120 git send-email \
2121 --from="Example <nobody@example.com>" \
2122 --to=nobody@example.com \
2123 --smtp-server="$(pwd)/../fake.sendmail" \
2124 ../0001-add-master.patch &&
2126 # Verify error message when a patch is rejected by the hook
2127 sed -e "s/add master/x/" ../0001-add-master.patch >../another.patch &&
2128 test_must_fail git send-email \
2129 --from="Example <nobody@example.com>" \
2130 --to=nobody@example.com \
2131 --smtp-server="$(pwd)/../fake.sendmail" \
2132 ../another.patch 2>err &&
2133 test_i18ngrep "rejected by sendemail-validate hook" err
2137 test_expect_success $PREREQ 'test that send-email works outside a repo' '
2138 nongit git send-email \
2139 --from="Example <nobody@example.com>" \
2140 --to=nobody@example.com \
2141 --smtp-server="$(pwd)/fake.sendmail" \
2142 "$(pwd)/0001-add-master.patch"
2145 test_done