interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / t / t9001-send-email.sh

2866 lines · 83675 bytes Raw Blame History
1#!/bin/sh
2
3test_description='git send-email'
4GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
5export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
6
7. ./test-lib.sh
8
9# May be altered later in the test
10PREREQ="PERL"
11
12replace_variable_fields () {
13 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
14 -e "s/^\(Message-ID:\).*/\1 MESSAGE-ID-STRING/" \
15 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/"
16}
17
18test_expect_success $PREREQ 'prepare reference tree' '
19 echo "1A quick brown fox jumps over the" >file &&
20 echo "lazy dog" >>file &&
21 git add file &&
22 GIT_AUTHOR_NAME="A" git commit -a -m "Initial."
23'
24
25test_expect_success $PREREQ 'Setup helper tool' '
26 write_script fake.sendmail <<-\EOF &&
27 shift
28 output=1
29 while test -f commandline$output
30 do
31 output=$(($output+1))
32 done
33 for a
34 do
35 echo "!$a!"
36 done >commandline$output
37 cat >"msgtxt$output"
38 EOF
39 git add fake.sendmail &&
40 GIT_AUTHOR_NAME="A" git commit -a -m "Second."
41'
42
43clean_fake_sendmail () {
44 rm -f commandline* msgtxt*
45}
46
47test_expect_success $PREREQ 'Extract patches' '
48 patches=$(git format-patch -s --cc="One <one@example.com>" --cc=two@example.com -n HEAD^1) &&
49 threaded_patches=$(git format-patch -o threaded --thread=shallow -s --in-reply-to="format" HEAD^1)
50'
51
52# Test no confirm early to ensure remaining tests will not hang
53test_no_confirm () {
54 rm -f no_confirm_okay
55 echo n | \
56 GIT_SEND_EMAIL_NOTTY=1 \
57 git send-email \
58 --from="Example <from@example.com>" \
59 --to=nobody@example.com \
60 --smtp-server="$(pwd)/fake.sendmail" \
61 $@ \
62 $patches >stdout &&
63 ! grep "Send this email" stdout &&
64 >no_confirm_okay
65}
66
67# Exit immediately to prevent hang if a no-confirm test fails
68check_no_confirm () {
69 if ! test -f no_confirm_okay
70 then
71 say 'confirm test failed; skipping remaining tests to prevent hanging'
72 PREREQ="$PREREQ,CHECK_NO_CONFIRM"
73 fi
74 return 0
75}
76
77test_expect_success $PREREQ 'No confirm with --suppress-cc' '
78 test_no_confirm --suppress-cc=sob &&
79 check_no_confirm
80'
81
82
83test_expect_success $PREREQ 'No confirm with --confirm=never' '
84 test_no_confirm --confirm=never &&
85 check_no_confirm
86'
87
88# leave sendemail.confirm set to never after this so that none of the
89# remaining tests prompt unintentionally.
90test_expect_success $PREREQ 'No confirm with sendemail.confirm=never' '
91 git config sendemail.confirm never &&
92 test_no_confirm --compose --subject=foo &&
93 check_no_confirm
94'
95
96test_expect_success $PREREQ 'Send patches' '
97 git send-email --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
98'
99
100test_expect_success $PREREQ 'setup expect' '
101 cat >expected <<-\EOF
102 !nobody@example.com!
103 !author@example.com!
104 !one@example.com!
105 !two@example.com!
106 EOF
107'
108
109test_expect_success $PREREQ 'Verify commandline' '
110 test_cmp expected commandline1
111'
112
113test_expect_success $PREREQ 'Send patches with --envelope-sender' '
114 clean_fake_sendmail &&
115 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
116'
117
118test_expect_success $PREREQ 'setup expect' '
119 cat >expected <<-\EOF
120 !patch@example.com!
121 !-i!
122 !nobody@example.com!
123 !author@example.com!
124 !one@example.com!
125 !two@example.com!
126 EOF
127'
128
129test_expect_success $PREREQ 'Verify commandline' '
130 test_cmp expected commandline1
131'
132
133test_expect_success $PREREQ 'Send patches with --envelope-sender=auto' '
134 clean_fake_sendmail &&
135 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
136'
137
138test_expect_success $PREREQ 'setup expect' '
139 cat >expected <<-\EOF
140 !nobody@example.com!
141 !-i!
142 !nobody@example.com!
143 !author@example.com!
144 !one@example.com!
145 !two@example.com!
146 EOF
147'
148
149test_expect_success $PREREQ 'Verify commandline' '
150 test_cmp expected commandline1
151'
152
153test_expect_success $PREREQ 'setup expect for cc trailer' "
154cat >expected-cc <<\EOF
155!recipient@example.com!
156!author@example.com!
157!one@example.com!
158!two@example.com!
159!three@example.com!
160!four@example.com!
161!five@example.com!
162!six@example.com!
163EOF
164"
165
166test_expect_success $PREREQ 'cc trailer with various syntax' '
167 test_commit cc-trailer &&
168 test_when_finished "git reset --hard HEAD^" &&
169 git commit --amend -F - <<-EOF &&
170 Test Cc: trailers.
171
172 Cc: one@example.com
173 Cc: <two@example.com> # trailing comments are ignored
174 Cc: <three@example.com>, <not.four@example.com> one address per line
175 Cc: "Some # Body" <four@example.com> [ <also.a.comment> ]
176 Cc: five@example.com # not.six@example.com
177 Cc: six@example.com, not.seven@example.com
178 EOF
179 clean_fake_sendmail &&
180 git send-email -1 --to=recipient@example.com \
181 --smtp-server="$(pwd)/fake.sendmail" &&
182 test_cmp expected-cc commandline1
183'
184
185test_expect_success $PREREQ 'setup fake get_maintainer.pl script for cc trailer' "
186 write_script expected-cc-script.sh <<-EOF
187 echo 'One Person <one@example.com> (supporter:THIS (FOO/bar))'
188 echo 'Two Person <two@example.com> (maintainer:THIS THING)'
189 echo 'Third List <three@example.com> (moderated list:THIS THING (FOO/bar))'
190 echo '<four@example.com> (moderated list:FOR THING)'
191 echo 'five@example.com (open list:FOR THING (FOO/bar))'
192 echo 'six@example.com (open list)'
193 EOF
194"
195
196test_expect_success $PREREQ 'cc trailer with get_maintainer.pl output' '
197 clean_fake_sendmail &&
198 git send-email -1 --to=recipient@example.com \
199 --cc-cmd=./expected-cc-script.sh \
200 --smtp-server="$(pwd)/fake.sendmail" &&
201 test_cmp expected-cc commandline1
202'
203
204test_expect_failure $PREREQ 'invalid smtp server port value' '
205 clean_fake_sendmail &&
206 git send-email -1 --to=recipient@example.com \
207 --smtp-server-port=bogus-symbolic-name \
208 --smtp-server="$(pwd)/fake.sendmail"
209'
210
211test_expect_success $PREREQ 'setup expect' "
212cat >expected-show-all-headers <<\EOF
2130001-Second.patch
214(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
215(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
216(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
217Dry-OK. Log says:
218Server: relay.example.com
219MAIL FROM:<from@example.com>
220RCPT TO:<to@example.com>
221RCPT TO:<cc@example.com>
222RCPT TO:<author@example.com>
223RCPT TO:<one@example.com>
224RCPT TO:<two@example.com>
225RCPT TO:<bcc@example.com>
226From: Example <from@example.com>
227To: to@example.com
228Cc: cc@example.com,
229 A <author@example.com>,
230 One <one@example.com>,
231 two@example.com
232Subject: [PATCH 1/1] Second.
233Date: DATE-STRING
234Message-ID: MESSAGE-ID-STRING
235X-Mailer: X-MAILER-STRING
236In-Reply-To: <unique-message-id@example.com>
237References: <unique-message-id@example.com>
238Reply-To: Reply <reply@example.com>
239MIME-Version: 1.0
240Content-Transfer-Encoding: 8bit
241
242Result: OK
243EOF
244"
245
246test_suppress_self () {
247 test_commit $3 &&
248 test_when_finished "git reset --hard HEAD^" &&
249
250 write_script cccmd-sed <<-EOF &&
251 sed -n -e s/^cccmd--//p "\$1"
252 EOF
253
254 git commit --amend --author="$1 <$2>" -F - &&
255 clean_fake_sendmail &&
256 git format-patch --stdout -1 >"suppress-self-$3.patch" &&
257
258 git send-email --from="$1 <$2>" \
259 --to=nobody@example.com \
260 --cc-cmd=./cccmd-sed \
261 --suppress-cc=self \
262 --smtp-server="$(pwd)/fake.sendmail" \
263 suppress-self-$3.patch &&
264
265 mv msgtxt1 msgtxt1-$3 &&
266 sed -e '/^$/q' msgtxt1-$3 >"msghdr1-$3" &&
267
268 (grep '^Cc:' msghdr1-$3 >"actual-no-cc-$3";
269 test_must_be_empty actual-no-cc-$3)
270}
271
272test_suppress_self_unquoted () {
273 test_suppress_self "$1" "$2" "unquoted-$3" <<-EOF
274 test suppress-cc.self unquoted-$3 with name $1 email $2
275
276 unquoted-$3
277
278 cccmd--$1 <$2>
279
280 Cc: $1 <$2>
281 Signed-off-by: $1 <$2>
282 EOF
283}
284
285test_suppress_self_quoted () {
286 test_suppress_self "$1" "$2" "quoted-$3" <<-EOF
287 test suppress-cc.self quoted-$3 with name $1 email $2
288
289 quoted-$3
290
291 cccmd--"$1" <$2>
292
293 Cc: $1 <$2>
294 Cc: "$1" <$2>
295 Signed-off-by: $1 <$2>
296 Signed-off-by: "$1" <$2>
297 EOF
298}
299
300test_expect_success $PREREQ 'self name is suppressed' "
301 test_suppress_self_unquoted 'A U Thor' 'author@example.com' \
302 'self_name_suppressed'
303"
304
305test_expect_success $PREREQ 'self name with dot is suppressed' "
306 test_suppress_self_quoted 'A U. Thor' 'author@example.com' \
307 'self_name_dot_suppressed'
308"
309
310test_expect_success $PREREQ 'non-ascii self name is suppressed' "
311 test_suppress_self_quoted 'Füñný Nâmé' 'odd_?=mail@example.com' \
312 'non_ascii_self_suppressed'
313"
314
315# This name is long enough to force format-patch to split it into multiple
316# encoded-words, assuming it uses UTF-8 with the "Q" encoding.
317test_expect_success $PREREQ 'long non-ascii self name is suppressed' "
318 test_suppress_self_quoted 'Ƒüñníęř €. Nâṁé' 'odd_?=mail@example.com' \
319 'long_non_ascii_self_suppressed'
320"
321
322test_expect_success $PREREQ 'sanitized self name is suppressed' "
323 test_suppress_self_unquoted '\"A U. Thor\"' 'author@example.com' \
324 'self_name_sanitized_suppressed'
325"
326
327test_expect_success $PREREQ 'Show all headers' '
328 git send-email \
329 --dry-run \
330 --suppress-cc=sob \
331 --from="Example <from@example.com>" \
332 --reply-to="Reply <reply@example.com>" \
333 --to=to@example.com \
334 --cc=cc@example.com \
335 --bcc=bcc@example.com \
336 --in-reply-to="<unique-message-id@example.com>" \
337 --smtp-server relay.example.com \
338 $patches | replace_variable_fields \
339 >actual-show-all-headers &&
340 test_cmp expected-show-all-headers actual-show-all-headers
341'
342
343test_expect_success $PREREQ 'Prompting works' '
344 clean_fake_sendmail &&
345 (echo "to@example.com" &&
346 echo "my-message-id@example.com"
347 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
348 --smtp-server="$(pwd)/fake.sendmail" \
349 $patches \
350 2>errors &&
351 test_grep "^From: A U Thor <author@example.com>\$" msgtxt1 &&
352 test_grep "^To: to@example.com\$" msgtxt1 &&
353 test_grep "^In-Reply-To: <my-message-id@example.com>" msgtxt1
354'
355
356test_expect_success $PREREQ,AUTOIDENT 'implicit ident is allowed' '
357 clean_fake_sendmail &&
358 (sane_unset GIT_AUTHOR_NAME &&
359 sane_unset GIT_AUTHOR_EMAIL &&
360 sane_unset GIT_COMMITTER_NAME &&
361 sane_unset GIT_COMMITTER_EMAIL &&
362 GIT_SEND_EMAIL_NOTTY=1 git send-email \
363 --smtp-server="$(pwd)/fake.sendmail" \
364 --to=to@example.com \
365 $patches </dev/null 2>errors
366 )
367'
368
369test_expect_success $PREREQ,!AUTOIDENT 'broken implicit ident aborts send-email' '
370 clean_fake_sendmail &&
371 (sane_unset GIT_AUTHOR_NAME &&
372 sane_unset GIT_AUTHOR_EMAIL &&
373 sane_unset GIT_COMMITTER_NAME &&
374 sane_unset GIT_COMMITTER_EMAIL &&
375 GIT_SEND_EMAIL_NOTTY=1 && export GIT_SEND_EMAIL_NOTTY &&
376 test_must_fail git send-email \
377 --smtp-server="$(pwd)/fake.sendmail" \
378 --to=to@example.com \
379 $patches </dev/null 2>errors &&
380 test_grep "tell me who you are" errors
381 )
382'
383
384test_expect_success $PREREQ 'setup cmd scripts' '
385 write_script tocmd-sed <<-\EOF &&
386 sed -n -e "s/^tocmd--//p" "$1"
387 EOF
388 write_script cccmd-sed <<-\EOF &&
389 sed -n -e "s/^cccmd--//p" "$1"
390 EOF
391 write_script headercmd-sed <<-\EOF
392 sed -n -e "s/^headercmd--//p" "$1"
393 EOF
394'
395
396test_expect_success $PREREQ 'tocmd works' '
397 clean_fake_sendmail &&
398 cp $patches tocmd.patch &&
399 echo tocmd--tocmd@example.com >>tocmd.patch &&
400 git send-email \
401 --from="Example <nobody@example.com>" \
402 --to-cmd=./tocmd-sed \
403 --smtp-server="$(pwd)/fake.sendmail" \
404 tocmd.patch \
405 &&
406 test_grep "^To: tocmd@example.com" msgtxt1
407'
408
409test_expect_success $PREREQ 'cccmd works' '
410 clean_fake_sendmail &&
411 cp $patches cccmd.patch &&
412 echo "cccmd-- cccmd@example.com" >>cccmd.patch &&
413 git send-email \
414 --from="Example <nobody@example.com>" \
415 --to=nobody@example.com \
416 --cc-cmd=./cccmd-sed \
417 --smtp-server="$(pwd)/fake.sendmail" \
418 cccmd.patch \
419 &&
420 test_grep "^ cccmd@example.com" msgtxt1
421'
422
423test_expect_success $PREREQ 'headercmd works' '
424 clean_fake_sendmail &&
425 cp $patches headercmd.patch &&
426 echo "headercmd--X-Debbugs-CC: dummy@example.com" >>headercmd.patch &&
427 git send-email \
428 --from="Example <nobody@example.com>" \
429 --to=nobody@example.com \
430 --header-cmd=./headercmd-sed \
431 --smtp-server="$(pwd)/fake.sendmail" \
432 headercmd.patch \
433 &&
434 test_grep "^X-Debbugs-CC: dummy@example.com" msgtxt1
435'
436
437test_expect_success $PREREQ '--no-header-cmd works' '
438 clean_fake_sendmail &&
439 cp $patches headercmd.patch &&
440 echo "headercmd--X-Debbugs-CC: dummy@example.com" >>headercmd.patch &&
441 git send-email \
442 --from="Example <nobody@example.com>" \
443 --to=nobody@example.com \
444 --header-cmd=./headercmd-sed \
445 --no-header-cmd \
446 --smtp-server="$(pwd)/fake.sendmail" \
447 headercmd.patch \
448 &&
449 test_grep ! "^X-Debbugs-CC: dummy@example.com" msgtxt1
450'
451
452test_expect_success $PREREQ 'multiline fields are correctly unfolded' '
453 clean_fake_sendmail &&
454 cp $patches headercmd.patch &&
455 write_script headercmd-multiline <<-\EOF &&
456 echo "X-Debbugs-CC: someone@example.com
457FoldedField: This is a tale
458 best told using
459 multiple lines."
460 EOF
461 git send-email \
462 --from="Example <nobody@example.com>" \
463 --to=nobody@example.com \
464 --header-cmd=./headercmd-multiline \
465 --smtp-server="$(pwd)/fake.sendmail" \
466 headercmd.patch &&
467 test_grep "^FoldedField: This is a tale best told using multiple lines.$" msgtxt1
468'
469
470# Blank lines in the middle of the output of a command are invalid.
471test_expect_success $PREREQ 'malform output reported on blank lines in command output' '
472 clean_fake_sendmail &&
473 cp $patches headercmd.patch &&
474 write_script headercmd-malformed-output <<-\EOF &&
475 echo "X-Debbugs-CC: someone@example.com
476
477SomeOtherField: someone-else@example.com"
478 EOF
479 ! git send-email \
480 --from="Example <nobody@example.com>" \
481 --to=nobody@example.com \
482 --header-cmd=./headercmd-malformed-output \
483 --smtp-server="$(pwd)/fake.sendmail" \
484 headercmd.patch
485'
486
487test_expect_success $PREREQ 'reject long lines' '
488 z8=zzzzzzzz &&
489 z64=$z8$z8$z8$z8$z8$z8$z8$z8 &&
490 z512=$z64$z64$z64$z64$z64$z64$z64$z64 &&
491 clean_fake_sendmail &&
492 cp $patches longline.patch &&
493 cat >>longline.patch <<-EOF &&
494 $z512$z512
495 not a long line
496 $z512$z512
497 EOF
498 test_must_fail git send-email \
499 --from="Example <nobody@example.com>" \
500 --to=nobody@example.com \
501 --smtp-server="$(pwd)/fake.sendmail" \
502 --transfer-encoding=8bit \
503 $patches longline.patch \
504 2>actual &&
505 cat >expect <<-\EOF &&
506 fatal: longline.patch:35 is longer than 998 characters
507 warning: no patches were sent
508 EOF
509 test_cmp expect actual
510'
511
512test_expect_success $PREREQ 'no patch was sent' '
513 ! test -e commandline1
514'
515
516test_expect_success $PREREQ 'Author From: in message body' '
517 clean_fake_sendmail &&
518 git send-email \
519 --from="Example <nobody@example.com>" \
520 --to=nobody@example.com \
521 --smtp-server="$(pwd)/fake.sendmail" \
522 $patches &&
523 sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
524 test_grep "From: A <author@example.com>" msgbody1
525'
526
527test_expect_success $PREREQ 'Author From: not in message body' '
528 clean_fake_sendmail &&
529 git send-email \
530 --from="A <author@example.com>" \
531 --to=nobody@example.com \
532 --smtp-server="$(pwd)/fake.sendmail" \
533 $patches &&
534 sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
535 test_grep ! "From: A <author@example.com>" msgbody1
536'
537
538test_expect_success $PREREQ 'allow long lines with --no-validate' '
539 git send-email \
540 --from="Example <nobody@example.com>" \
541 --to=nobody@example.com \
542 --smtp-server="$(pwd)/fake.sendmail" \
543 --no-validate \
544 $patches longline.patch \
545 2>errors
546'
547
548test_expect_success $PREREQ 'short lines with auto encoding are 8bit' '
549 clean_fake_sendmail &&
550 git send-email \
551 --from="A <author@example.com>" \
552 --to=nobody@example.com \
553 --smtp-server="$(pwd)/fake.sendmail" \
554 --transfer-encoding=auto \
555 $patches &&
556 test_grep "Content-Transfer-Encoding: 8bit" msgtxt1
557'
558
559test_expect_success $PREREQ 'long lines with auto encoding are quoted-printable' '
560 clean_fake_sendmail &&
561 git send-email \
562 --from="Example <nobody@example.com>" \
563 --to=nobody@example.com \
564 --smtp-server="$(pwd)/fake.sendmail" \
565 --transfer-encoding=auto \
566 --no-validate \
567 longline.patch &&
568 test_grep "Content-Transfer-Encoding: quoted-printable" msgtxt1
569'
570
571test_expect_success $PREREQ 'carriage returns with auto encoding are quoted-printable' '
572 clean_fake_sendmail &&
573 cp $patches cr.patch &&
574 printf "this is a line\r\n" >>cr.patch &&
575 git send-email \
576 --from="Example <nobody@example.com>" \
577 --to=nobody@example.com \
578 --smtp-server="$(pwd)/fake.sendmail" \
579 --transfer-encoding=auto \
580 --no-validate \
581 cr.patch &&
582 test_grep "Content-Transfer-Encoding: quoted-printable" msgtxt1
583'
584
585for enc in auto quoted-printable base64
586do
587 test_expect_success $PREREQ "--validate passes with encoding $enc" '
588 git send-email \
589 --from="Example <nobody@example.com>" \
590 --to=nobody@example.com \
591 --smtp-server="$(pwd)/fake.sendmail" \
592 --transfer-encoding=$enc \
593 --validate \
594 $patches longline.patch
595 '
596
597done
598
599test_expect_success $PREREQ "--validate respects relative core.hooksPath path" '
600 clean_fake_sendmail &&
601 mkdir my-hooks &&
602 test_when_finished "rm my-hooks.ran" &&
603 write_script my-hooks/sendemail-validate <<-\EOF &&
604 >my-hooks.ran
605 exit 1
606 EOF
607 test_config core.hooksPath "my-hooks" &&
608 test_must_fail git send-email \
609 --from="Example <nobody@example.com>" \
610 --to=nobody@example.com \
611 --smtp-server="$(pwd)/fake.sendmail" \
612 --validate \
613 longline.patch 2>actual &&
614 test_path_is_file my-hooks.ran &&
615 cat >expect <<-EOF &&
616 fatal: longline.patch: rejected by sendemail-validate hook
617 fatal: command '"'"'git hook run --ignore-missing sendemail-validate -- <patch> <header>'"'"' died with exit code 1
618 warning: no patches were sent
619 EOF
620 test_cmp expect actual
621'
622
623test_expect_success $PREREQ "--validate respects absolute core.hooksPath path" '
624 hooks_path="$(pwd)/my-hooks" &&
625 test_config core.hooksPath "$hooks_path" &&
626 test_when_finished "rm my-hooks.ran" &&
627 test_must_fail git send-email \
628 --from="Example <nobody@example.com>" \
629 --to=nobody@example.com \
630 --smtp-server="$(pwd)/fake.sendmail" \
631 --validate \
632 longline.patch 2>actual &&
633 test_path_is_file my-hooks.ran &&
634 cat >expect <<-EOF &&
635 fatal: longline.patch: rejected by sendemail-validate hook
636 fatal: command '"'"'git hook run --ignore-missing sendemail-validate -- <patch> <header>'"'"' died with exit code 1
637 warning: no patches were sent
638 EOF
639 test_cmp expect actual
640'
641
642test_expect_success $PREREQ "--validate hook supports multiple addresses in arguments" '
643 hooks_path="$(pwd)/my-hooks" &&
644 test_config core.hooksPath "$hooks_path" &&
645 test_when_finished "rm my-hooks.ran" &&
646 test_must_fail git send-email \
647 --from="Example <nobody@example.com>" \
648 --to=nobody@example.com,abc@example.com \
649 --smtp-server="$(pwd)/fake.sendmail" \
650 --validate \
651 longline.patch 2>actual &&
652 test_path_is_file my-hooks.ran &&
653 cat >expect <<-EOF &&
654 fatal: longline.patch: rejected by sendemail-validate hook
655 fatal: command '"'"'git hook run --ignore-missing sendemail-validate -- <patch> <header>'"'"' died with exit code 1
656 warning: no patches were sent
657 EOF
658 test_cmp expect actual
659'
660
661test_expect_success $PREREQ "--validate hook supports header argument" '
662 write_script my-hooks/sendemail-validate <<-\EOF &&
663 if test "$#" -ge 2
664 then
665 grep "X-test-header: v1.0" "$2"
666 else
667 echo "No header arg passed"
668 exit 1
669 fi
670 EOF
671 test_config core.hooksPath "my-hooks" &&
672 rm -fr outdir &&
673 git format-patch \
674 --add-header="X-test-header: v1.0" \
675 -n HEAD^1 -o outdir &&
676 git send-email \
677 --dry-run \
678 --to=nobody@example.com \
679 --smtp-server="$(pwd)/fake.sendmail" \
680 --validate \
681 outdir/000?-*.patch
682'
683
684test_expect_success $PREREQ 'clear message-id before parsing a new message' '
685 clean_fake_sendmail &&
686 echo true | write_script my-hooks/sendemail-validate &&
687 test_config core.hooksPath my-hooks &&
688 git send-email --validate --to=recipient@example.com \
689 --smtp-server="$(pwd)/fake.sendmail" \
690 $patches $threaded_patches &&
691 id0=$(grep "^Message-ID: " $threaded_patches) &&
692 id1=$(grep "^Message-ID: " msgtxt1) &&
693 id2=$(grep "^Message-ID: " msgtxt2) &&
694 test "z$id0" = "z$id2" &&
695 test "z$id1" != "z$id2"
696'
697
698for enc in 7bit 8bit quoted-printable base64
699do
700 test_expect_success $PREREQ "--transfer-encoding=$enc produces correct header" '
701 clean_fake_sendmail &&
702 git send-email \
703 --from="Example <nobody@example.com>" \
704 --to=nobody@example.com \
705 --smtp-server="$(pwd)/fake.sendmail" \
706 --transfer-encoding=$enc \
707 $patches &&
708 test_grep "Content-Transfer-Encoding: $enc" msgtxt1
709 '
710done
711
712test_expect_success $PREREQ 'Invalid In-Reply-To' '
713 clean_fake_sendmail &&
714 git send-email \
715 --from="Example <nobody@example.com>" \
716 --to=nobody@example.com \
717 --in-reply-to=" " \
718 --smtp-server="$(pwd)/fake.sendmail" \
719 $patches \
720 2>errors &&
721 test_grep ! "^In-Reply-To: < *>" msgtxt1
722'
723
724test_expect_success $PREREQ 'Valid In-Reply-To when prompting' '
725 clean_fake_sendmail &&
726 (echo "From Example <from@example.com>" &&
727 echo "To Example <to@example.com>" &&
728 echo ""
729 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
730 --smtp-server="$(pwd)/fake.sendmail" \
731 $patches 2>errors &&
732 test_grep ! "^In-Reply-To: < *>" msgtxt1
733'
734
735test_expect_success $PREREQ 'In-Reply-To without --chain-reply-to' '
736 clean_fake_sendmail &&
737 echo "<unique-message-id@example.com>" >expect &&
738 git send-email \
739 --from="Example <nobody@example.com>" \
740 --to=nobody@example.com \
741 --no-chain-reply-to \
742 --in-reply-to="$(cat expect)" \
743 --smtp-server="$(pwd)/fake.sendmail" \
744 $patches $patches $patches \
745 2>errors &&
746 # The first message is a reply to --in-reply-to
747 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
748 test_cmp expect actual &&
749 # Second and subsequent messages are replies to the first one
750 sed -n -e "s/^Message-ID: *\(.*\)/\1/p" msgtxt1 >expect &&
751 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
752 test_cmp expect actual &&
753 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
754 test_cmp expect actual
755'
756
757test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' '
758 clean_fake_sendmail &&
759 echo "<unique-message-id@example.com>" >expect &&
760 git send-email \
761 --from="Example <nobody@example.com>" \
762 --to=nobody@example.com \
763 --chain-reply-to \
764 --in-reply-to="$(cat expect)" \
765 --smtp-server="$(pwd)/fake.sendmail" \
766 $patches $patches $patches \
767 2>errors &&
768 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
769 test_cmp expect actual &&
770 sed -n -e "s/^Message-ID: *\(.*\)/\1/p" msgtxt1 >expect &&
771 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
772 test_cmp expect actual &&
773 sed -n -e "s/^Message-ID: *\(.*\)/\1/p" msgtxt2 >expect &&
774 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
775 test_cmp expect actual
776'
777
778test_set_editor "$(pwd)/fake-editor"
779
780test_expect_success $PREREQ 'setup erroring fake editor' '
781 write_script fake-editor <<-\EOF
782 echo >&2 "I am about to error"
783 exit 1
784 EOF
785'
786
787test_expect_success $PREREQ 'fake editor dies with error' '
788 clean_fake_sendmail &&
789 test_must_fail git send-email \
790 --compose --subject foo \
791 --from="Example <nobody@example.com>" \
792 --to=nobody@example.com \
793 --smtp-server="$(pwd)/fake.sendmail" \
794 $patches 2>err &&
795 test_grep "I am about to error" err &&
796 test_grep "the editor exited uncleanly, aborting everything" err
797'
798
799test_expect_success $PREREQ 'setup fake editor' '
800 write_script fake-editor <<-\EOF
801 echo fake edit >>"$1"
802 EOF
803'
804
805test_expect_success $PREREQ '--compose works' '
806 clean_fake_sendmail &&
807 git send-email \
808 --compose --subject foo \
809 --from="Example <nobody@example.com>" \
810 --to=nobody@example.com \
811 --smtp-server="$(pwd)/fake.sendmail" \
812 $patches \
813 2>errors
814'
815
816test_expect_success $PREREQ 'first message is compose text' '
817 test_grep "^fake edit" msgtxt1
818'
819
820test_expect_success $PREREQ 'second message is patch' '
821 test_grep "Subject:.*Second" msgtxt2
822'
823
824test_expect_success $PREREQ 'setup expect' "
825cat >expected-suppress-sob <<\EOF
8260001-Second.patch
827(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
828(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
829(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
830Dry-OK. Log says:
831Server: relay.example.com
832MAIL FROM:<from@example.com>
833RCPT TO:<to@example.com>
834RCPT TO:<cc@example.com>
835RCPT TO:<author@example.com>
836RCPT TO:<one@example.com>
837RCPT TO:<two@example.com>
838From: Example <from@example.com>
839To: to@example.com
840Cc: cc@example.com,
841 A <author@example.com>,
842 One <one@example.com>,
843 two@example.com
844Subject: [PATCH 1/1] Second.
845Date: DATE-STRING
846Message-ID: MESSAGE-ID-STRING
847X-Mailer: X-MAILER-STRING
848MIME-Version: 1.0
849Content-Transfer-Encoding: 8bit
850
851Result: OK
852EOF
853"
854
855test_suppression () {
856 git send-email \
857 --dry-run \
858 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
859 --from="Example <from@example.com>" \
860 --to=to@example.com \
861 --smtp-server relay.example.com \
862 $patches | replace_variable_fields \
863 >actual-suppress-$1${2+"-$2"} &&
864 test_cmp expected-suppress-$1${2+"-$2"} actual-suppress-$1${2+"-$2"}
865}
866
867test_expect_success $PREREQ 'sendemail.cc set' '
868 git config sendemail.cc cc@example.com &&
869 test_suppression sob
870'
871
872test_expect_success $PREREQ 'setup expect' "
873cat >expected-suppress-sob <<\EOF
8740001-Second.patch
875(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
876(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
877(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
878Dry-OK. Log says:
879Server: relay.example.com
880MAIL FROM:<from@example.com>
881RCPT TO:<to@example.com>
882RCPT TO:<author@example.com>
883RCPT TO:<one@example.com>
884RCPT TO:<two@example.com>
885From: Example <from@example.com>
886To: to@example.com
887Cc: A <author@example.com>,
888 One <one@example.com>,
889 two@example.com
890Subject: [PATCH 1/1] Second.
891Date: DATE-STRING
892Message-ID: MESSAGE-ID-STRING
893X-Mailer: X-MAILER-STRING
894MIME-Version: 1.0
895Content-Transfer-Encoding: 8bit
896
897Result: OK
898EOF
899"
900
901test_expect_success $PREREQ 'sendemail.cc unset' '
902 git config --unset sendemail.cc &&
903 test_suppression sob
904'
905
906test_expect_success $PREREQ 'setup expect' "
907cat >expected-suppress-cccmd <<\EOF
9080001-Second.patch
909(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
910(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
911(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
912(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
913Dry-OK. Log says:
914Server: relay.example.com
915MAIL FROM:<from@example.com>
916RCPT TO:<to@example.com>
917RCPT TO:<author@example.com>
918RCPT TO:<one@example.com>
919RCPT TO:<two@example.com>
920RCPT TO:<committer@example.com>
921From: Example <from@example.com>
922To: to@example.com
923Cc: A <author@example.com>,
924 One <one@example.com>,
925 two@example.com,
926 C O Mitter <committer@example.com>
927Subject: [PATCH 1/1] Second.
928Date: DATE-STRING
929Message-ID: MESSAGE-ID-STRING
930X-Mailer: X-MAILER-STRING
931MIME-Version: 1.0
932Content-Transfer-Encoding: 8bit
933
934Result: OK
935EOF
936"
937
938test_expect_success $PREREQ 'sendemail.cccmd' '
939 write_script cccmd <<-\EOF &&
940 echo cc-cmd@example.com
941 EOF
942 git config sendemail.cccmd ./cccmd &&
943 test_suppression cccmd
944'
945
946test_expect_success $PREREQ 'setup expect' '
947cat >expected-suppress-all <<\EOF
9480001-Second.patch
949Dry-OK. Log says:
950Server: relay.example.com
951MAIL FROM:<from@example.com>
952RCPT TO:<to@example.com>
953From: Example <from@example.com>
954To: to@example.com
955Subject: [PATCH 1/1] Second.
956Date: DATE-STRING
957Message-ID: MESSAGE-ID-STRING
958X-Mailer: X-MAILER-STRING
959MIME-Version: 1.0
960Content-Transfer-Encoding: 8bit
961
962Result: OK
963EOF
964'
965
966test_expect_success $PREREQ '--suppress-cc=all' '
967 test_suppression all
968'
969
970test_expect_success $PREREQ 'setup expect' "
971cat >expected-suppress-body <<\EOF
9720001-Second.patch
973(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
974(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
975(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
976(cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
977Dry-OK. Log says:
978Server: relay.example.com
979MAIL FROM:<from@example.com>
980RCPT TO:<to@example.com>
981RCPT TO:<author@example.com>
982RCPT TO:<one@example.com>
983RCPT TO:<two@example.com>
984RCPT TO:<cc-cmd@example.com>
985From: Example <from@example.com>
986To: to@example.com
987Cc: A <author@example.com>,
988 One <one@example.com>,
989 two@example.com,
990 cc-cmd@example.com
991Subject: [PATCH 1/1] Second.
992Date: DATE-STRING
993Message-ID: MESSAGE-ID-STRING
994X-Mailer: X-MAILER-STRING
995MIME-Version: 1.0
996Content-Transfer-Encoding: 8bit
997
998Result: OK
999EOF
1000"
1001
1002test_expect_success $PREREQ '--suppress-cc=body' '
1003 test_suppression body
1004'
1005
1006test_expect_success $PREREQ 'setup expect' "
1007cat >expected-suppress-body-cccmd <<\EOF
10080001-Second.patch
1009(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
1010(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
1011(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
1012Dry-OK. Log says:
1013Server: relay.example.com
1014MAIL FROM:<from@example.com>
1015RCPT TO:<to@example.com>
1016RCPT TO:<author@example.com>
1017RCPT TO:<one@example.com>
1018RCPT TO:<two@example.com>
1019From: Example <from@example.com>
1020To: to@example.com
1021Cc: A <author@example.com>,
1022 One <one@example.com>,
1023 two@example.com
1024Subject: [PATCH 1/1] Second.
1025Date: DATE-STRING
1026Message-ID: MESSAGE-ID-STRING
1027X-Mailer: X-MAILER-STRING
1028MIME-Version: 1.0
1029Content-Transfer-Encoding: 8bit
1030
1031Result: OK
1032EOF
1033"
1034
1035test_expect_success $PREREQ '--suppress-cc=body --suppress-cc=cccmd' '
1036 test_suppression body cccmd
1037'
1038
1039test_expect_success $PREREQ 'setup expect' "
1040cat >expected-suppress-sob <<\EOF
10410001-Second.patch
1042(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
1043(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
1044(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
1045Dry-OK. Log says:
1046Server: relay.example.com
1047MAIL FROM:<from@example.com>
1048RCPT TO:<to@example.com>
1049RCPT TO:<author@example.com>
1050RCPT TO:<one@example.com>
1051RCPT TO:<two@example.com>
1052From: Example <from@example.com>
1053To: to@example.com
1054Cc: A <author@example.com>,
1055 One <one@example.com>,
1056 two@example.com
1057Subject: [PATCH 1/1] Second.
1058Date: DATE-STRING
1059Message-ID: MESSAGE-ID-STRING
1060X-Mailer: X-MAILER-STRING
1061MIME-Version: 1.0
1062Content-Transfer-Encoding: 8bit
1063
1064Result: OK
1065EOF
1066"
1067
1068test_expect_success $PREREQ '--suppress-cc=sob' '
1069 test_might_fail git config --unset sendemail.cccmd &&
1070 test_suppression sob
1071'
1072
1073test_expect_success $PREREQ 'setup expect' "
1074cat >expected-suppress-bodycc <<\EOF
10750001-Second.patch
1076(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
1077(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
1078(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
1079(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
1080Dry-OK. Log says:
1081Server: relay.example.com
1082MAIL FROM:<from@example.com>
1083RCPT TO:<to@example.com>
1084RCPT TO:<author@example.com>
1085RCPT TO:<one@example.com>
1086RCPT TO:<two@example.com>
1087RCPT TO:<committer@example.com>
1088From: Example <from@example.com>
1089To: to@example.com
1090Cc: A <author@example.com>,
1091 One <one@example.com>,
1092 two@example.com,
1093 C O Mitter <committer@example.com>
1094Subject: [PATCH 1/1] Second.
1095Date: DATE-STRING
1096Message-ID: MESSAGE-ID-STRING
1097X-Mailer: X-MAILER-STRING
1098MIME-Version: 1.0
1099Content-Transfer-Encoding: 8bit
1100
1101Result: OK
1102EOF
1103"
1104
1105test_expect_success $PREREQ '--suppress-cc=bodycc' '
1106 test_suppression bodycc
1107'
1108
1109test_expect_success $PREREQ 'setup expect' "
1110cat >expected-suppress-cc <<\EOF
11110001-Second.patch
1112(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
1113(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
1114Dry-OK. Log says:
1115Server: relay.example.com
1116MAIL FROM:<from@example.com>
1117RCPT TO:<to@example.com>
1118RCPT TO:<author@example.com>
1119RCPT TO:<committer@example.com>
1120From: Example <from@example.com>
1121To: to@example.com
1122Cc: A <author@example.com>,
1123 C O Mitter <committer@example.com>
1124Subject: [PATCH 1/1] Second.
1125Date: DATE-STRING
1126Message-ID: MESSAGE-ID-STRING
1127X-Mailer: X-MAILER-STRING
1128MIME-Version: 1.0
1129Content-Transfer-Encoding: 8bit
1130
1131Result: OK
1132EOF
1133"
1134
1135test_expect_success $PREREQ '--suppress-cc=cc' '
1136 test_suppression cc
1137'
1138
1139test_confirm () {
1140 echo y | \
1141 GIT_SEND_EMAIL_NOTTY=1 \
1142 git send-email \
1143 --from="Example <nobody@example.com>" \
1144 --to=nobody@example.com \
1145 --smtp-server="$(pwd)/fake.sendmail" \
1146 $@ $patches >stdout &&
1147 grep "Send this email" stdout
1148}
1149
1150test_expect_success $PREREQ '--confirm=always' '
1151 test_confirm --confirm=always --suppress-cc=all
1152'
1153
1154test_expect_success $PREREQ '--confirm=auto' '
1155 test_confirm --confirm=auto
1156'
1157
1158test_expect_success $PREREQ '--confirm=cc' '
1159 test_confirm --confirm=cc
1160'
1161
1162test_expect_success $PREREQ '--confirm=compose' '
1163 test_confirm --confirm=compose --compose
1164'
1165
1166test_expect_success $PREREQ 'confirm by default (due to cc)' '
1167 test_when_finished git config sendemail.confirm never &&
1168 git config --unset sendemail.confirm &&
1169 test_confirm
1170'
1171
1172test_expect_success $PREREQ 'confirm by default (due to --compose)' '
1173 test_when_finished git config sendemail.confirm never &&
1174 git config --unset sendemail.confirm &&
1175 test_confirm --suppress-cc=all --compose
1176'
1177
1178test_expect_success $PREREQ 'confirm detects EOF (inform assumes y)' '
1179 test_when_finished git config sendemail.confirm never &&
1180 git config --unset sendemail.confirm &&
1181 rm -fr outdir &&
1182 git format-patch -2 -o outdir &&
1183 GIT_SEND_EMAIL_NOTTY=1 \
1184 git send-email \
1185 --from="Example <nobody@example.com>" \
1186 --to=nobody@example.com \
1187 --smtp-server="$(pwd)/fake.sendmail" \
1188 outdir/*.patch </dev/null
1189'
1190
1191test_expect_success $PREREQ 'confirm detects EOF (auto causes failure)' '
1192 test_when_finished git config sendemail.confirm never &&
1193 git config sendemail.confirm auto &&
1194 GIT_SEND_EMAIL_NOTTY=1 &&
1195 export GIT_SEND_EMAIL_NOTTY &&
1196 test_must_fail git send-email \
1197 --from="Example <nobody@example.com>" \
1198 --to=nobody@example.com \
1199 --smtp-server="$(pwd)/fake.sendmail" \
1200 $patches </dev/null
1201'
1202
1203test_expect_success $PREREQ 'confirm does not loop forever' '
1204 test_when_finished git config sendemail.confirm never &&
1205 git config sendemail.confirm auto &&
1206 GIT_SEND_EMAIL_NOTTY=1 &&
1207 export GIT_SEND_EMAIL_NOTTY &&
1208 yes "bogus" | test_must_fail git send-email \
1209 --from="Example <nobody@example.com>" \
1210 --to=nobody@example.com \
1211 --smtp-server="$(pwd)/fake.sendmail" \
1212 $patches
1213'
1214
1215test_expect_success $PREREQ 'utf8 Cc is rfc2047 encoded' '
1216 clean_fake_sendmail &&
1217 rm -fr outdir &&
1218 git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
1219 git send-email \
1220 --from="Example <nobody@example.com>" \
1221 --to=nobody@example.com \
1222 --smtp-server="$(pwd)/fake.sendmail" \
1223 outdir/*.patch &&
1224 grep "^ " msgtxt1 |
1225 grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
1226'
1227
1228test_expect_success $PREREQ '--compose adds MIME for utf8 body' '
1229 clean_fake_sendmail &&
1230 write_script fake-editor-utf8 <<-\EOF &&
1231 echo "utf8 body: àéìöú" >>"$1"
1232 EOF
1233 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1234 git send-email \
1235 --compose --subject foo \
1236 --from="Example <nobody@example.com>" \
1237 --to=nobody@example.com \
1238 --smtp-server="$(pwd)/fake.sendmail" \
1239 $patches &&
1240 test_grep "^utf8 body" msgtxt1 &&
1241 test_grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
1242'
1243
1244test_expect_success $PREREQ '--compose respects user mime type' '
1245 clean_fake_sendmail &&
1246 write_script fake-editor-utf8-mime <<-\EOF &&
1247 cat >"$1" <<-\EOM
1248 MIME-Version: 1.0
1249 Content-Type: text/plain; charset=iso-8859-1
1250 Content-Transfer-Encoding: 8bit
1251 Subject: foo
1252
1253 utf8 body: àéìöú
1254 EOM
1255 EOF
1256 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
1257 git send-email \
1258 --compose --subject foo \
1259 --from="Example <nobody@example.com>" \
1260 --to=nobody@example.com \
1261 --smtp-server="$(pwd)/fake.sendmail" \
1262 $patches &&
1263 test_grep "^utf8 body" msgtxt1 &&
1264 test_grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
1265 test_grep ! "^Content-Type: text/plain; charset=UTF-8" msgtxt1
1266'
1267
1268test_expect_success $PREREQ '--compose adds MIME for utf8 subject' '
1269 clean_fake_sendmail &&
1270 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
1271 git send-email \
1272 --compose --subject utf8-sübjëct \
1273 --from="Example <nobody@example.com>" \
1274 --to=nobody@example.com \
1275 --smtp-server="$(pwd)/fake.sendmail" \
1276 $patches &&
1277 test_grep "^fake edit" msgtxt1 &&
1278 test_grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
1279'
1280
1281test_expect_success $PREREQ 'utf8 author is correctly passed on' '
1282 clean_fake_sendmail &&
1283 test_commit weird_author &&
1284 test_when_finished "git reset --hard HEAD^" &&
1285 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
1286 git format-patch --stdout -1 >funny_name.patch &&
1287 git send-email --from="Example <nobody@example.com>" \
1288 --to=nobody@example.com \
1289 --smtp-server="$(pwd)/fake.sendmail" \
1290 funny_name.patch &&
1291 test_grep "^From: Füñný Nâmé <odd_?=mail@example.com>" msgtxt1
1292'
1293
1294test_expect_success $PREREQ 'utf8 sender is not duplicated' '
1295 clean_fake_sendmail &&
1296 test_commit weird_sender &&
1297 test_when_finished "git reset --hard HEAD^" &&
1298 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
1299 git format-patch --stdout -1 >funny_name.patch &&
1300 git send-email --from="Füñný Nâmé <odd_?=mail@example.com>" \
1301 --to=nobody@example.com \
1302 --smtp-server="$(pwd)/fake.sendmail" \
1303 funny_name.patch &&
1304 grep "^From: " msgtxt1 >msgfrom &&
1305 test_line_count = 1 msgfrom
1306'
1307
1308test_expect_success $PREREQ 'setup expect for cc list' "
1309cat >expected-cc <<\EOF
1310!recipient@example.com!
1311!author@example.com!
1312!one@example.com!
1313!os@example.com!
1314!odd_?=mail@example.com!
1315!doug@example.com!
1316!codev@example.com!
1317!thor.au@example.com!
1318EOF
1319"
1320
1321test_expect_success $PREREQ 'cc list is sanitized' '
1322 clean_fake_sendmail &&
1323 test_commit weird_cc_body &&
1324 test_when_finished "git reset --hard HEAD^" &&
1325 git commit --amend -F - <<-EOF &&
1326 Test Cc: sanitization.
1327
1328 Cc: Person, One <one@example.com>
1329 Cc: Ronnie O${SQ}Sullivan <os@example.com>
1330 Reviewed-by: Füñný Nâmé <odd_?=mail@example.com>
1331 Reported-by: bugger on Jira
1332 Reported-by: Douglas Reporter <doug@example.com> [from Jira profile]
1333 BugID: 12345should-not-appear
1334 Co-developed-by: "C. O. Developer" <codev@example.com>
1335 Signed-off-by: A. U. Thor <thor.au@example.com>
1336 EOF
1337 git send-email -1 --to=recipient@example.com \
1338 --smtp-server="$(pwd)/fake.sendmail" >actual-show-all-headers &&
1339 test_cmp expected-cc commandline1 &&
1340 test_grep "^(body) Adding cc: \"Person, One\" <one@example.com>" actual-show-all-headers &&
1341 test_grep "^(body) Adding cc: Ronnie O${SQ}Sullivan <os@example.com>" actual-show-all-headers &&
1342 test_grep "^(body) Adding cc: =?UTF-8?q?F=C3=BC=C3=B1n=C3=BD=20N=C3=A2m=C3=A9?="\
1343" <odd_?=mail@example.com>" actual-show-all-headers &&
1344 test_grep "^(body) Ignoring Reported-by .* bugger on Jira" actual-show-all-headers &&
1345 test_grep "^(body) Adding cc: Douglas Reporter <doug@example.com>" actual-show-all-headers &&
1346 test_grep ! "12345should-not-appear" actual-show-all-headers &&
1347 test_grep "^(body) Adding cc: \"C. O. Developer\" <codev@example.com>" actual-show-all-headers &&
1348 test_grep "^(body) Adding cc: \"A. U. Thor\" <thor.au@example.com>" actual-show-all-headers
1349'
1350
1351test_expect_success $PREREQ 'sendemail.composeencoding works' '
1352 clean_fake_sendmail &&
1353 git config sendemail.composeencoding iso-8859-1 &&
1354 write_script fake-editor-utf8 <<-\EOF &&
1355 echo "utf8 body: àéìöú" >>"$1"
1356 EOF
1357 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1358 git send-email \
1359 --compose --subject foo \
1360 --from="Example <nobody@example.com>" \
1361 --to=nobody@example.com \
1362 --smtp-server="$(pwd)/fake.sendmail" \
1363 $patches &&
1364 test_grep "^utf8 body" msgtxt1 &&
1365 test_grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1366'
1367
1368test_expect_success $PREREQ '--compose-encoding works' '
1369 clean_fake_sendmail &&
1370 write_script fake-editor-utf8 <<-\EOF &&
1371 echo "utf8 body: àéìöú" >>"$1"
1372 EOF
1373 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1374 git send-email \
1375 --compose-encoding iso-8859-1 \
1376 --compose --subject foo \
1377 --from="Example <nobody@example.com>" \
1378 --to=nobody@example.com \
1379 --smtp-server="$(pwd)/fake.sendmail" \
1380 $patches &&
1381 test_grep "^utf8 body" msgtxt1 &&
1382 test_grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1383'
1384
1385test_expect_success $PREREQ '--compose-encoding overrides sendemail.composeencoding' '
1386 clean_fake_sendmail &&
1387 git config sendemail.composeencoding iso-8859-1 &&
1388 write_script fake-editor-utf8 <<-\EOF &&
1389 echo "utf8 body: àéìöú" >>"$1"
1390 EOF
1391 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1392 git send-email \
1393 --compose-encoding iso-8859-2 \
1394 --compose --subject foo \
1395 --from="Example <nobody@example.com>" \
1396 --to=nobody@example.com \
1397 --smtp-server="$(pwd)/fake.sendmail" \
1398 $patches &&
1399 test_grep "^utf8 body" msgtxt1 &&
1400 test_grep "^Content-Type: text/plain; charset=iso-8859-2" msgtxt1
1401'
1402
1403test_expect_success $PREREQ '--compose-encoding adds correct MIME for subject' '
1404 clean_fake_sendmail &&
1405 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
1406 git send-email \
1407 --compose-encoding iso-8859-2 \
1408 --compose --subject utf8-sübjëct \
1409 --from="Example <nobody@example.com>" \
1410 --to=nobody@example.com \
1411 --smtp-server="$(pwd)/fake.sendmail" \
1412 $patches &&
1413 test_grep "^fake edit" msgtxt1 &&
1414 test_grep "^Subject: =?iso-8859-2?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
1415'
1416
1417test_expect_success $PREREQ 'detects ambiguous reference/file conflict' '
1418 echo main >main &&
1419 git add main &&
1420 git commit -m"add main" &&
1421 test_must_fail git send-email --dry-run main 2>errors &&
1422 test_grep disambiguate errors
1423'
1424
1425test_expect_success $PREREQ 'missing subject omits Perl location' '
1426 cat >no-subject.patch <<-\EOF &&
1427 This is the body.
1428 EOF
1429 test_must_fail git send-email \
1430 --dry-run \
1431 --from="Example <nobody@example.com>" \
1432 --to=nobody@example.com \
1433 no-subject.patch 2>actual &&
1434 cat >expect <<-\EOF &&
1435 No '\''Subject:'\'' line in '\''no-subject.patch'\''
1436 EOF
1437 test_cmp expect actual
1438'
1439
1440test_expect_success $PREREQ 'feed two files' '
1441 rm -fr outdir &&
1442 git format-patch -2 -o outdir &&
1443 git send-email \
1444 --dry-run \
1445 --from="Example <nobody@example.com>" \
1446 --to=nobody@example.com \
1447 outdir/000?-*.patch 2>errors >out &&
1448 grep "^Subject: " out >subjects &&
1449 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
1450 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add main"
1451'
1452
1453test_expect_success $PREREQ 'in-reply-to but no threading' '
1454 git send-email \
1455 --dry-run \
1456 --from="Example <nobody@example.com>" \
1457 --to=nobody@example.com \
1458 --in-reply-to="<in-reply-id@example.com>" \
1459 --no-thread \
1460 $patches >out &&
1461 test_grep "In-Reply-To: <in-reply-id@example.com>" out
1462'
1463
1464test_expect_success $PREREQ 'no in-reply-to and no threading' '
1465 git send-email \
1466 --dry-run \
1467 --from="Example <nobody@example.com>" \
1468 --to=nobody@example.com \
1469 --no-thread \
1470 $patches >stdout &&
1471 test_grep ! "In-Reply-To: " stdout
1472'
1473
1474test_expect_success $PREREQ 'threading but no chain-reply-to' '
1475 git send-email \
1476 --dry-run \
1477 --from="Example <nobody@example.com>" \
1478 --to=nobody@example.com \
1479 --thread \
1480 --no-chain-reply-to \
1481 $patches $patches >stdout &&
1482 test_grep "In-Reply-To: " stdout
1483'
1484
1485test_expect_success $PREREQ 'override in-reply-to if no threading' '
1486 git send-email \
1487 --dry-run \
1488 --from="Example <nobody@example.com>" \
1489 --to=nobody@example.com \
1490 --no-thread \
1491 --in-reply-to="override" \
1492 $threaded_patches >stdout &&
1493 test_grep "In-Reply-To: <override>" stdout
1494'
1495
1496test_expect_success $PREREQ 'sendemail.to works' '
1497 git config --replace-all sendemail.to "Somebody <somebody@ex.com>" &&
1498 git send-email \
1499 --dry-run \
1500 --from="Example <nobody@example.com>" \
1501 $patches >stdout &&
1502 test_grep "To: Somebody <somebody@ex.com>" stdout
1503'
1504
1505test_expect_success $PREREQ 'setup sendemail.identity' '
1506 git config --replace-all sendemail.to "default@example.com" &&
1507 git config --replace-all sendemail.isp.to "isp@example.com" &&
1508 git config --replace-all sendemail.cloud.to "cloud@example.com"
1509'
1510
1511test_expect_success $PREREQ 'sendemail.identity: reads the correct identity config' '
1512 git -c sendemail.identity=cloud send-email \
1513 --dry-run \
1514 --from="nobody@example.com" \
1515 $patches >stdout &&
1516 test_grep "To: cloud@example.com" stdout
1517'
1518
1519test_expect_success $PREREQ 'sendemail.identity: identity overrides sendemail.identity' '
1520 git -c sendemail.identity=cloud send-email \
1521 --identity=isp \
1522 --dry-run \
1523 --from="nobody@example.com" \
1524 $patches >stdout &&
1525 test_grep "To: isp@example.com" stdout
1526'
1527
1528test_expect_success $PREREQ 'sendemail.identity: --no-identity clears previous identity' '
1529 git -c sendemail.identity=cloud send-email \
1530 --no-identity \
1531 --dry-run \
1532 --from="nobody@example.com" \
1533 $patches >stdout &&
1534 test_grep "To: default@example.com" stdout
1535'
1536
1537test_expect_success $PREREQ 'sendemail.identity: bool identity variable existence overrides' '
1538 git -c sendemail.identity=cloud \
1539 -c sendemail.xmailer=true \
1540 -c sendemail.cloud.xmailer=false \
1541 send-email \
1542 --dry-run \
1543 --from="nobody@example.com" \
1544 $patches >stdout &&
1545 test_grep "To: cloud@example.com" stdout &&
1546 test_grep ! "X-Mailer" stdout
1547'
1548
1549test_expect_success $PREREQ 'sendemail.identity: bool variable fallback' '
1550 git -c sendemail.identity=cloud \
1551 -c sendemail.xmailer=false \
1552 send-email \
1553 --dry-run \
1554 --from="nobody@example.com" \
1555 $patches >stdout &&
1556 test_grep "To: cloud@example.com" stdout &&
1557 test_grep ! "X-Mailer" stdout
1558'
1559
1560test_expect_success $PREREQ 'sendemail.identity: bool variable without a value' '
1561 git -c sendemail.xmailer \
1562 send-email \
1563 --dry-run \
1564 --from="nobody@example.com" \
1565 $patches >stdout &&
1566 test_grep "To: default@example.com" stdout &&
1567 test_grep "X-Mailer" stdout
1568'
1569
1570test_expect_success $PREREQ '--no-to overrides sendemail.to' '
1571 git send-email \
1572 --dry-run \
1573 --from="Example <nobody@example.com>" \
1574 --no-to \
1575 --to=nobody@example.com \
1576 $patches >stdout &&
1577 test_grep "To: nobody@example.com" stdout &&
1578 test_grep ! "To: Somebody <somebody@ex.com>" stdout
1579'
1580
1581test_expect_success $PREREQ 'sendemail.cc works' '
1582 git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" &&
1583 git send-email \
1584 --dry-run \
1585 --from="Example <nobody@example.com>" \
1586 --to=nobody@example.com \
1587 $patches >stdout &&
1588 test_grep "Cc: Somebody <somebody@ex.com>" stdout
1589'
1590
1591test_expect_success $PREREQ '--no-cc overrides sendemail.cc' '
1592 git send-email \
1593 --dry-run \
1594 --from="Example <nobody@example.com>" \
1595 --no-cc \
1596 --cc=bodies@example.com \
1597 --to=nobody@example.com \
1598 $patches >stdout &&
1599 test_grep "Cc: bodies@example.com" stdout &&
1600 test_grep ! "Cc: Somebody <somebody@ex.com>" stdout
1601'
1602
1603test_expect_success $PREREQ 'sendemail.bcc works' '
1604 git config --replace-all sendemail.bcc "Other <other@ex.com>" &&
1605 git send-email \
1606 --dry-run \
1607 --from="Example <nobody@example.com>" \
1608 --to=nobody@example.com \
1609 --smtp-server relay.example.com \
1610 $patches >stdout &&
1611 test_grep "RCPT TO:<other@ex.com>" stdout
1612'
1613
1614test_expect_success $PREREQ '--no-bcc overrides sendemail.bcc' '
1615 git send-email \
1616 --dry-run \
1617 --from="Example <nobody@example.com>" \
1618 --no-bcc \
1619 --bcc=bodies@example.com \
1620 --to=nobody@example.com \
1621 --smtp-server relay.example.com \
1622 $patches >stdout &&
1623 test_grep "RCPT TO:<bodies@example.com>" stdout &&
1624 test_grep ! "RCPT TO:<other@ex.com>" stdout
1625'
1626
1627test_expect_success $PREREQ 'patches To headers are used by default' '
1628 patch=$(git format-patch -1 --to="bodies@example.com") &&
1629 test_when_finished "rm $patch" &&
1630 git send-email \
1631 --dry-run \
1632 --from="Example <nobody@example.com>" \
1633 --smtp-server relay.example.com \
1634 $patch >stdout &&
1635 test_grep "RCPT TO:<bodies@example.com>" stdout
1636'
1637
1638test_expect_success $PREREQ 'patches To headers are appended to' '
1639 patch=$(git format-patch -1 --to="bodies@example.com") &&
1640 test_when_finished "rm $patch" &&
1641 git send-email \
1642 --dry-run \
1643 --from="Example <nobody@example.com>" \
1644 --to=nobody@example.com \
1645 --smtp-server relay.example.com \
1646 $patch >stdout &&
1647 test_grep "RCPT TO:<bodies@example.com>" stdout &&
1648 test_grep "RCPT TO:<nobody@example.com>" stdout
1649'
1650
1651test_expect_success $PREREQ 'To headers from files reset each patch' '
1652 patch1=$(git format-patch -1 --to="bodies@example.com") &&
1653 patch2=$(git format-patch -1 --to="other@example.com" HEAD~) &&
1654 test_when_finished "rm $patch1 && rm $patch2" &&
1655 git send-email \
1656 --dry-run \
1657 --from="Example <nobody@example.com>" \
1658 --to="nobody@example.com" \
1659 --smtp-server relay.example.com \
1660 $patch1 $patch2 >stdout &&
1661 test $(grep -c "RCPT TO:<bodies@example.com>" stdout) = 1 &&
1662 test $(grep -c "RCPT TO:<nobody@example.com>" stdout) = 2 &&
1663 test $(grep -c "RCPT TO:<other@example.com>" stdout) = 1
1664'
1665
1666test_expect_success $PREREQ 'setup expect' '
1667# NOTE: do not quote this heredoc, Dash 0.5.13 has a bug with heredocs
1668# that contain multibyte chars.
1669cat >email-using-8bit <<EOF
1670From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1671Message-ID: <bogus-message-id@example.com>
1672From: author@example.com
1673Date: Sat, 12 Jun 2010 15:53:58 +0200
1674Subject: subject goes here
1675
1676Dieser deutsche Text enthält einen Umlaut!
1677EOF
1678'
1679
1680test_expect_success $PREREQ 'setup expect' '
1681 echo "Subject: subject goes here" >expected
1682'
1683
1684test_expect_success $PREREQ 'ASCII subject is not RFC2047 quoted' '
1685 clean_fake_sendmail &&
1686 echo bogus |
1687 git send-email --from=author@example.com --to=nobody@example.com \
1688 --smtp-server="$(pwd)/fake.sendmail" \
1689 --8bit-encoding=UTF-8 \
1690 email-using-8bit >stdout &&
1691 grep "Subject" msgtxt1 >actual &&
1692 test_cmp expected actual
1693'
1694
1695test_expect_success $PREREQ 'setup expect' '
1696 cat >content-type-decl <<-\EOF
1697 MIME-Version: 1.0
1698 Content-Type: text/plain; charset=UTF-8
1699 Content-Transfer-Encoding: 8bit
1700 EOF
1701'
1702
1703test_expect_success $PREREQ 'asks about and fixes 8bit encodings' '
1704 clean_fake_sendmail &&
1705 echo |
1706 git send-email --from=author@example.com --to=nobody@example.com \
1707 --smtp-server="$(pwd)/fake.sendmail" \
1708 email-using-8bit >stdout &&
1709 test_grep "do not declare a Content-Transfer-Encoding" stdout &&
1710 test_grep email-using-8bit stdout &&
1711 test_grep "Declare which 8bit encoding to use" stdout &&
1712 grep -E "Content|MIME" msgtxt1 >actual &&
1713 test_cmp content-type-decl actual
1714'
1715
1716test_expect_success $PREREQ 'sendemail.8bitEncoding works' '
1717 clean_fake_sendmail &&
1718 git config sendemail.assume8bitEncoding UTF-8 &&
1719 echo bogus |
1720 git send-email --from=author@example.com --to=nobody@example.com \
1721 --smtp-server="$(pwd)/fake.sendmail" \
1722 email-using-8bit >stdout &&
1723 grep -E "Content|MIME" msgtxt1 >actual &&
1724 test_cmp content-type-decl actual
1725'
1726
1727test_expect_success $PREREQ 'sendemail.8bitEncoding in .git/config overrides --global .gitconfig' '
1728 clean_fake_sendmail &&
1729 git config sendemail.assume8bitEncoding UTF-8 &&
1730 test_when_finished "rm -rf home" &&
1731 mkdir home &&
1732 git config -f home/.gitconfig sendemail.assume8bitEncoding "bogus too" &&
1733 echo bogus |
1734 env HOME="$(pwd)/home" DEBUG=1 \
1735 git send-email --from=author@example.com --to=nobody@example.com \
1736 --smtp-server="$(pwd)/fake.sendmail" \
1737 email-using-8bit >stdout &&
1738 grep -E "Content|MIME" msgtxt1 >actual &&
1739 test_cmp content-type-decl actual
1740'
1741
1742test_expect_success $PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
1743 clean_fake_sendmail &&
1744 git config sendemail.assume8bitEncoding "bogus too" &&
1745 echo bogus |
1746 git send-email --from=author@example.com --to=nobody@example.com \
1747 --smtp-server="$(pwd)/fake.sendmail" \
1748 --8bit-encoding=UTF-8 \
1749 email-using-8bit >stdout &&
1750 grep -E "Content|MIME" msgtxt1 >actual &&
1751 test_cmp content-type-decl actual
1752'
1753
1754test_expect_success $PREREQ 'setup expect' '
1755 # NOTE: do not quote this heredoc, Dash 0.5.13 has a bug with heredocs
1756 # that contain multibyte chars.
1757 cat >email-using-8bit <<-EOF
1758 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1759 Message-ID: <bogus-message-id@example.com>
1760 From: author@example.com
1761 Date: Sat, 12 Jun 2010 15:53:58 +0200
1762 Subject: Dieser Betreff enthält auch einen Umlaut!
1763
1764 Nothing to see here.
1765 EOF
1766'
1767
1768test_expect_success $PREREQ 'setup expect' '
1769 cat >expected <<-\EOF
1770 Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
1771 EOF
1772'
1773
1774test_expect_success $PREREQ '--8bit-encoding also treats subject' '
1775 clean_fake_sendmail &&
1776 echo bogus |
1777 git send-email --from=author@example.com --to=nobody@example.com \
1778 --smtp-server="$(pwd)/fake.sendmail" \
1779 --8bit-encoding=UTF-8 \
1780 email-using-8bit >stdout &&
1781 grep "Subject" msgtxt1 >actual &&
1782 test_cmp expected actual
1783'
1784
1785test_expect_success $PREREQ 'setup expect' '
1786 # NOTE: do not quote this heredoc, Dash 0.5.13 has a bug with heredocs
1787 # that contain multibyte chars.
1788 cat >email-using-8bit <<-EOF
1789 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1790 Message-ID: <bogus-message-id@example.com>
1791 From: A U Thor <author@example.com>
1792 Date: Sat, 12 Jun 2010 15:53:58 +0200
1793 Content-Type: text/plain; charset=UTF-8
1794 Subject: Nothing to see here.
1795
1796 Dieser Betreff enthält auch einen Umlaut!
1797 EOF
1798'
1799
1800test_expect_success $PREREQ '--transfer-encoding overrides sendemail.transferEncoding' '
1801 clean_fake_sendmail &&
1802 test_must_fail git -c sendemail.transferEncoding=8bit \
1803 send-email \
1804 --transfer-encoding=7bit \
1805 --smtp-server="$(pwd)/fake.sendmail" \
1806 email-using-8bit \
1807 2>errors >out &&
1808 test_grep "cannot send message as 7bit" errors &&
1809 test -z "$(ls msgtxt*)"
1810'
1811
1812test_expect_success $PREREQ 'sendemail.transferEncoding via config' '
1813 clean_fake_sendmail &&
1814 test_must_fail git -c sendemail.transferEncoding=7bit \
1815 send-email \
1816 --smtp-server="$(pwd)/fake.sendmail" \
1817 email-using-8bit \
1818 2>errors >out &&
1819 test_grep "cannot send message as 7bit" errors &&
1820 test -z "$(ls msgtxt*)"
1821'
1822
1823test_expect_success $PREREQ 'sendemail.transferEncoding via cli' '
1824 clean_fake_sendmail &&
1825 test_must_fail git send-email \
1826 --transfer-encoding=7bit \
1827 --smtp-server="$(pwd)/fake.sendmail" \
1828 email-using-8bit \
1829 2>errors >out &&
1830 test_grep "cannot send message as 7bit" errors &&
1831 test -z "$(ls msgtxt*)"
1832'
1833
1834test_expect_success $PREREQ 'setup expect' '
1835 cat >expected <<-\EOF
1836 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1837 EOF
1838'
1839
1840test_expect_success $PREREQ '8-bit and sendemail.transferencoding=quoted-printable' '
1841 clean_fake_sendmail &&
1842 git send-email \
1843 --transfer-encoding=quoted-printable \
1844 --smtp-server="$(pwd)/fake.sendmail" \
1845 email-using-8bit \
1846 2>errors >out &&
1847 sed "1,/^$/d" msgtxt1 >actual &&
1848 test_cmp expected actual
1849'
1850
1851test_expect_success $PREREQ 'setup expect' '
1852 cat >expected <<-\EOF
1853 RGllc2VyIEJldHJlZmYgZW50aMOkbHQgYXVjaCBlaW5lbiBVbWxhdXQhCg==
1854 EOF
1855'
1856
1857test_expect_success $PREREQ '8-bit and sendemail.transferencoding=base64' '
1858 clean_fake_sendmail &&
1859 git send-email \
1860 --transfer-encoding=base64 \
1861 --smtp-server="$(pwd)/fake.sendmail" \
1862 email-using-8bit \
1863 2>errors >out &&
1864 sed "1,/^$/d" msgtxt1 >actual &&
1865 test_cmp expected actual
1866'
1867
1868test_expect_success $PREREQ 'setup expect' '
1869 cat >email-using-qp <<-\EOF
1870 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1871 Message-ID: <bogus-message-id@example.com>
1872 From: A U Thor <author@example.com>
1873 Date: Sat, 12 Jun 2010 15:53:58 +0200
1874 MIME-Version: 1.0
1875 Content-Transfer-Encoding: quoted-printable
1876 Content-Type: text/plain; charset=UTF-8
1877 Subject: Nothing to see here.
1878
1879 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1880 EOF
1881'
1882
1883test_expect_success $PREREQ 'convert from quoted-printable to base64' '
1884 clean_fake_sendmail &&
1885 git send-email \
1886 --transfer-encoding=base64 \
1887 --smtp-server="$(pwd)/fake.sendmail" \
1888 email-using-qp \
1889 2>errors >out &&
1890 sed "1,/^$/d" msgtxt1 >actual &&
1891 test_cmp expected actual
1892'
1893
1894test_expect_success $PREREQ 'setup expect' "
1895tr -d '\\015' | tr '%' '\\015' >email-using-crlf <<EOF
1896From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1897Message-ID: <bogus-message-id@example.com>
1898From: A U Thor <author@example.com>
1899Date: Sat, 12 Jun 2010 15:53:58 +0200
1900Content-Type: text/plain; charset=UTF-8
1901Subject: Nothing to see here.
1902
1903Look, I have a CRLF and an = sign!%
1904EOF
1905"
1906
1907test_expect_success $PREREQ 'setup expect' '
1908 cat >expected <<-\EOF
1909 Look, I have a CRLF and an =3D sign!=0D
1910 EOF
1911'
1912
1913test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=quoted-printable' '
1914 clean_fake_sendmail &&
1915 git send-email \
1916 --transfer-encoding=quoted-printable \
1917 --smtp-server="$(pwd)/fake.sendmail" \
1918 email-using-crlf \
1919 2>errors >out &&
1920 sed "1,/^$/d" msgtxt1 >actual &&
1921 test_cmp expected actual
1922'
1923
1924test_expect_success $PREREQ 'setup expect' '
1925 cat >expected <<-\EOF
1926 TG9vaywgSSBoYXZlIGEgQ1JMRiBhbmQgYW4gPSBzaWduIQ0K
1927 EOF
1928'
1929
1930test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=base64' '
1931 clean_fake_sendmail &&
1932 git send-email \
1933 --transfer-encoding=base64 \
1934 --smtp-server="$(pwd)/fake.sendmail" \
1935 email-using-crlf \
1936 2>errors >out &&
1937 sed "1,/^$/d" msgtxt1 >actual &&
1938 test_cmp expected actual
1939'
1940
1941
1942# Note that the patches in this test are deliberately out of order; we
1943# want to make sure it works even if the cover-letter is not in the
1944# first mail.
1945test_expect_success $PREREQ 'refusing to send cover letter template' '
1946 clean_fake_sendmail &&
1947 rm -fr outdir &&
1948 git format-patch --cover-letter -2 -o outdir &&
1949 test_must_fail git send-email \
1950 --from="Example <nobody@example.com>" \
1951 --to=nobody@example.com \
1952 --smtp-server="$(pwd)/fake.sendmail" \
1953 outdir/0002-*.patch \
1954 outdir/0000-*.patch \
1955 outdir/0001-*.patch \
1956 2>errors >out &&
1957 test_grep "SUBJECT HERE" errors &&
1958 test -z "$(ls msgtxt*)"
1959'
1960
1961test_expect_success $PREREQ '--force sends cover letter template anyway' '
1962 clean_fake_sendmail &&
1963 rm -fr outdir &&
1964 git format-patch --cover-letter -2 -o outdir &&
1965 git send-email \
1966 --force \
1967 --from="Example <nobody@example.com>" \
1968 --to=nobody@example.com \
1969 --smtp-server="$(pwd)/fake.sendmail" \
1970 outdir/0002-*.patch \
1971 outdir/0000-*.patch \
1972 outdir/0001-*.patch \
1973 2>errors >out &&
1974 test_grep ! "SUBJECT HERE" errors &&
1975 test -n "$(ls msgtxt*)"
1976'
1977
1978test_cover_addresses () {
1979 header="$1"
1980 shift
1981 clean_fake_sendmail &&
1982 rm -fr outdir &&
1983 git format-patch --cover-letter -2 -o outdir &&
1984 cover=$(echo outdir/0000-*.patch) &&
1985 mv $cover cover-to-edit.patch &&
1986 perl -pe "s/^From:/$header: extra\@address.com\nFrom:/" cover-to-edit.patch >"$cover" &&
1987 git send-email \
1988 --force \
1989 --from="Example <nobody@example.com>" \
1990 --no-to --no-cc \
1991 "$@" \
1992 --smtp-server="$(pwd)/fake.sendmail" \
1993 outdir/0000-*.patch \
1994 outdir/0001-*.patch \
1995 outdir/0002-*.patch \
1996 2>errors >out &&
1997 grep "^$header: extra@address.com" msgtxt1 >to1 &&
1998 grep "^$header: extra@address.com" msgtxt2 >to2 &&
1999 grep "^$header: extra@address.com" msgtxt3 >to3 &&
2000 test_line_count = 1 to1 &&
2001 test_line_count = 1 to2 &&
2002 test_line_count = 1 to3
2003}
2004
2005test_expect_success $PREREQ 'to-cover adds To to all mail' '
2006 test_cover_addresses "To" --to-cover
2007'
2008
2009test_expect_success $PREREQ 'cc-cover adds Cc to all mail' '
2010 test_cover_addresses "Cc" --cc-cover
2011'
2012
2013test_expect_success $PREREQ 'tocover adds To to all mail' '
2014 test_config sendemail.tocover true &&
2015 test_cover_addresses "To"
2016'
2017
2018test_expect_success $PREREQ 'cccover adds Cc to all mail' '
2019 test_config sendemail.cccover true &&
2020 test_cover_addresses "Cc"
2021'
2022
2023test_expect_success $PREREQ 'escaped quotes in sendemail.aliasfiletype=mutt' '
2024 clean_fake_sendmail &&
2025 echo "alias sbd \\\"Dot U. Sir\\\" <somebody@example.org>" >.mutt &&
2026 git config --replace-all sendemail.aliasesfile "$(pwd)/.mutt" &&
2027 git config sendemail.aliasfiletype mutt &&
2028 git send-email \
2029 --from="Example <nobody@example.com>" \
2030 --to=sbd \
2031 --smtp-server="$(pwd)/fake.sendmail" \
2032 outdir/0001-*.patch \
2033 2>errors >out &&
2034 test_grep "^!somebody@example\.org!$" commandline1 &&
2035 test_grep -F "To: \"Dot U. Sir\" <somebody@example.org>" out
2036'
2037
2038test_expect_success $PREREQ 'sendemail.aliasfiletype=mailrc' '
2039 clean_fake_sendmail &&
2040 echo "alias sbd somebody@example.org" >.mailrc &&
2041 git config --replace-all sendemail.aliasesfile "$(pwd)/.mailrc" &&
2042 git config sendemail.aliasfiletype mailrc &&
2043 git send-email \
2044 --from="Example <nobody@example.com>" \
2045 --to=sbd \
2046 --smtp-server="$(pwd)/fake.sendmail" \
2047 outdir/0001-*.patch \
2048 2>errors >out &&
2049 test_grep "^!somebody@example\.org!$" commandline1
2050'
2051
2052test_expect_success $PREREQ 'sendemail.aliasesfile=~/.mailrc' '
2053 clean_fake_sendmail &&
2054 echo "alias sbd someone@example.org" >"$HOME/.mailrc" &&
2055 git config --replace-all sendemail.aliasesfile "~/.mailrc" &&
2056 git config sendemail.aliasfiletype mailrc &&
2057 git send-email \
2058 --from="Example <nobody@example.com>" \
2059 --to=sbd \
2060 --smtp-server="$(pwd)/fake.sendmail" \
2061 outdir/0001-*.patch \
2062 2>errors >out &&
2063 test_grep "^!someone@example\.org!$" commandline1
2064'
2065
2066test_dump_aliases () {
2067 msg="$1" && shift &&
2068 filetype="$1" && shift &&
2069 printf '%s\n' "$@" >expect &&
2070 cat >.tmp-email-aliases &&
2071
2072 test_expect_success $PREREQ "$msg" '
2073 clean_fake_sendmail && rm -fr outdir &&
2074 git config --replace-all sendemail.aliasesfile \
2075 "$(pwd)/.tmp-email-aliases" &&
2076 git config sendemail.aliasfiletype "$filetype" &&
2077 git send-email --dump-aliases 2>errors >actual &&
2078 test_cmp expect actual
2079 '
2080}
2081
2082test_dump_aliases '--dump-aliases sendmail format' \
2083 'sendmail' \
2084 'abgroup' \
2085 'alice' \
2086 'bcgrp' \
2087 'bob' \
2088 'chloe' <<-\EOF
2089 alice: Alice W Land <awol@example.com>
2090 bob: Robert Bobbyton <bob@example.com>
2091 chloe: chloe@example.com
2092 abgroup: alice, bob
2093 bcgrp: bob, chloe, Other <o@example.com>
2094 EOF
2095
2096test_dump_aliases '--dump-aliases mutt format' \
2097 'mutt' \
2098 'alice' \
2099 'bob' \
2100 'chloe' \
2101 'donald' <<-\EOF
2102 alias alice Alice W Land <awol@example.com>
2103 alias donald Donald C Carlton <donc@example.com>
2104 alias bob Robert Bobbyton <bob@example.com>
2105 alias chloe chloe@example.com
2106 EOF
2107
2108test_dump_aliases '--dump-aliases mailrc format' \
2109 'mailrc' \
2110 'alice' \
2111 'bob' \
2112 'chloe' \
2113 'eve' <<-\EOF
2114 alias alice "Alice W Land <awol@example.com>"
2115 alias eve "Eve <eve@example.com>"
2116 alias bob "Robert Bobbyton <bob@example.com>"
2117 alias chloe chloe@example.com
2118 EOF
2119
2120test_dump_aliases '--dump-aliases pine format' \
2121 'pine' \
2122 'alice' \
2123 'bcgrp' \
2124 'bob' \
2125 'chloe' \
2126 'eve' <<-\EOF
2127 alice Alice W Land awol@example.com Friend
2128 eve Eve eve@example.com
2129 bob Robert Bobbyton bob@example.com
2130 chloe chloe@example.com
2131 bcgrp (bob, chloe, Other <o@example.com>)
2132 EOF
2133
2134test_dump_aliases '--dump-aliases gnus format' \
2135 'gnus' \
2136 'alice' \
2137 'bob' \
2138 'chloe' \
2139 'eve' <<-\EOF
2140 (define-mail-alias "alice" "awol@example.com")
2141 (define-mail-alias "eve" "eve@example.com")
2142 (define-mail-alias "bob" "bob@example.com")
2143 (define-mail-alias "chloe" "chloe@example.com")
2144 EOF
2145
2146test_expect_success '--dump-aliases must be used alone' '
2147 test_must_fail git send-email --dump-aliases --to=janice@example.com -1 refs/heads/accounting
2148'
2149
2150test_translate_aliases () {
2151 msg="$1" && shift &&
2152 filetype="$1" && shift &&
2153 aliases="$1" && shift &&
2154 printf '%s\n' "$@" >expect &&
2155 cat >.tmp-email-aliases &&
2156 printf '%s\n' "$aliases" >aliases &&
2157
2158 test_expect_success $PREREQ "$msg" '
2159 clean_fake_sendmail && rm -fr outdir &&
2160 git config --replace-all sendemail.aliasesfile \
2161 "$(pwd)/.tmp-email-aliases" &&
2162 git config sendemail.aliasfiletype "$filetype" &&
2163 git send-email --translate-aliases <aliases 2>errors >actual &&
2164 test_cmp expect actual
2165 '
2166}
2167
2168test_translate_aliases '--translate-aliases sendmail format' \
2169 'sendmail' \
2170 'alice bcgrp' \
2171 'Alice W Land <awol@example.com>' \
2172 'Robert Bobbyton <bob@example.com>' \
2173 'chloe@example.com' \
2174 'Other <o@example.com>' <<-\EOF
2175 alice: Alice W Land <awol@example.com>
2176 bob: Robert Bobbyton <bob@example.com>
2177 chloe: chloe@example.com
2178 abgroup: alice, bob
2179 bcgrp: bob, chloe, Other <o@example.com>
2180 EOF
2181
2182test_translate_aliases '--translate-aliases mutt format' \
2183 'mutt' \
2184 'donald bob' \
2185 'Donald C Carlton <donc@example.com>' \
2186 'Robert Bobbyton <bob@example.com>' <<-\EOF
2187 alias alice Alice W Land <awol@example.com>
2188 alias donald Donald C Carlton <donc@example.com>
2189 alias bob Robert Bobbyton <bob@example.com>
2190 alias chloe chloe@example.com
2191 EOF
2192
2193test_translate_aliases '--translate-aliases mailrc format' \
2194 'mailrc' \
2195 'chloe eve alice' \
2196 'chloe@example.com' \
2197 'Eve <eve@example.com>' \
2198 'Alice W Land <awol@example.com>' <<-\EOF
2199 alias alice "Alice W Land <awol@example.com>"
2200 alias eve "Eve <eve@example.com>"
2201 alias bob "Robert Bobbyton <bob@example.com>"
2202 alias chloe chloe@example.com
2203 EOF
2204
2205test_translate_aliases '--translate-aliases pine format' \
2206 'pine' \
2207 'eve bob bcgrp' \
2208 'eve@example.com' \
2209 'bob@example.com' \
2210 'bob@example.com' \
2211 'chloe@example.com' \
2212 'Other <o@example.com>' <<-\EOF
2213 alice Alice W Land awol@example.com Friend
2214 eve Eve eve@example.com
2215 bob Robert Bobbyton bob@example.com
2216 chloe chloe@example.com
2217 bcgrp (bob, chloe, Other <o@example.com>)
2218 EOF
2219
2220test_translate_aliases '--translate-aliases gnus format' \
2221 'gnus' \
2222 'alice chloe eve' \
2223 'awol@example.com' \
2224 'chloe@example.com' \
2225 'eve@example.com' <<-\EOF
2226 (define-mail-alias "alice" "awol@example.com")
2227 (define-mail-alias "eve" "eve@example.com")
2228 (define-mail-alias "bob" "bob@example.com")
2229 (define-mail-alias "chloe" "chloe@example.com")
2230 EOF
2231
2232test_expect_success $PREREQ '--translate-aliases passes valid addresses through' '
2233 cat >expect <<-\EOF &&
2234 Other <o@example.com>
2235 EOF
2236 cat >aliases <<-\EOF &&
2237 Other <o@example.com>
2238 EOF
2239 git send-email --translate-aliases <aliases >actual &&
2240 test_cmp expect actual
2241'
2242
2243test_expect_success $PREREQ '--translate-aliases passes unknown aliases through' '
2244 cat >expect <<-\EOF &&
2245 blargh
2246 EOF
2247 cat >aliases <<-\EOF &&
2248 blargh
2249 EOF
2250 git send-email --translate-aliases <aliases >actual &&
2251 test_cmp expect actual
2252'
2253
2254test_expect_success $PREREQ 'aliases and sendemail.identity' '
2255 test_must_fail git \
2256 -c sendemail.identity=cloud \
2257 -c sendemail.aliasesfile=default-aliases \
2258 -c sendemail.cloud.aliasesfile=cloud-aliases \
2259 send-email -1 2>stderr &&
2260 test_grep "cloud-aliases" stderr
2261'
2262
2263test_sendmail_aliases () {
2264 msg="$1" && shift &&
2265 expect="$@" &&
2266 cat >.tmp-email-aliases &&
2267
2268 test_expect_success $PREREQ "$msg" '
2269 clean_fake_sendmail && rm -fr outdir &&
2270 git format-patch -1 -o outdir &&
2271 git config --replace-all sendemail.aliasesfile \
2272 "$(pwd)/.tmp-email-aliases" &&
2273 git config sendemail.aliasfiletype sendmail &&
2274 git send-email \
2275 --from="Example <nobody@example.com>" \
2276 --to=alice --to=bcgrp \
2277 --smtp-server="$(pwd)/fake.sendmail" \
2278 outdir/0001-*.patch \
2279 2>errors >out &&
2280 for i in $expect
2281 do
2282 test_grep "^!$i!$" commandline1 || return 1
2283 done
2284 '
2285}
2286
2287test_sendmail_aliases 'sendemail.aliasfiletype=sendmail' \
2288 'awol@example\.com' \
2289 'bob@example\.com' \
2290 'chloe@example\.com' \
2291 'o@example\.com' <<-\EOF
2292 alice: Alice W Land <awol@example.com>
2293 bob: Robert Bobbyton <bob@example.com>
2294 # this is a comment
2295 # this is also a comment
2296 chloe: chloe@example.com
2297 abgroup: alice, bob
2298 bcgrp: bob, chloe, Other <o@example.com>
2299 EOF
2300
2301test_sendmail_aliases 'sendmail aliases line folding' \
2302 alice1 \
2303 bob1 bob2 \
2304 chuck1 chuck2 \
2305 darla1 darla2 darla3 \
2306 elton1 elton2 elton3 \
2307 fred1 fred2 \
2308 greg1 <<-\EOF
2309 alice: alice1
2310 bob: bob1,\
2311 bob2
2312 chuck: chuck1,
2313 chuck2
2314 darla: darla1,\
2315 darla2,
2316 darla3
2317 elton: elton1,
2318 elton2,\
2319 elton3
2320 fred: fred1,\
2321 fred2
2322 greg: greg1
2323 bcgrp: bob, chuck, darla, elton, fred, greg
2324 EOF
2325
2326test_sendmail_aliases 'sendmail aliases tolerate bogus line folding' \
2327 alice1 bob1 <<-\EOF
2328 alice: alice1
2329 bcgrp: bob1\
2330 EOF
2331
2332test_sendmail_aliases 'sendmail aliases empty' alice bcgrp <<-\EOF
2333 EOF
2334
2335test_expect_success $PREREQ 'alias support in To header' '
2336 clean_fake_sendmail &&
2337 echo "alias sbd someone@example.org" >.mailrc &&
2338 test_config sendemail.aliasesfile ".mailrc" &&
2339 test_config sendemail.aliasfiletype mailrc &&
2340 git format-patch --stdout -1 --to=sbd >aliased.patch &&
2341 git send-email \
2342 --from="Example <nobody@example.com>" \
2343 --smtp-server="$(pwd)/fake.sendmail" \
2344 aliased.patch \
2345 2>errors >out &&
2346 test_grep "^!someone@example\.org!$" commandline1
2347'
2348
2349test_expect_success $PREREQ 'alias support in Cc header' '
2350 clean_fake_sendmail &&
2351 echo "alias sbd someone@example.org" >.mailrc &&
2352 test_config sendemail.aliasesfile ".mailrc" &&
2353 test_config sendemail.aliasfiletype mailrc &&
2354 git format-patch --stdout -1 --cc=sbd >aliased.patch &&
2355 git send-email \
2356 --from="Example <nobody@example.com>" \
2357 --smtp-server="$(pwd)/fake.sendmail" \
2358 aliased.patch \
2359 2>errors >out &&
2360 test_grep "^!someone@example\.org!$" commandline1
2361'
2362
2363test_expect_success $PREREQ 'tocmd works with aliases' '
2364 clean_fake_sendmail &&
2365 echo "alias sbd someone@example.org" >.mailrc &&
2366 test_config sendemail.aliasesfile ".mailrc" &&
2367 test_config sendemail.aliasfiletype mailrc &&
2368 git format-patch --stdout -1 >tocmd.patch &&
2369 echo tocmd--sbd >>tocmd.patch &&
2370 git send-email \
2371 --from="Example <nobody@example.com>" \
2372 --to-cmd=./tocmd-sed \
2373 --smtp-server="$(pwd)/fake.sendmail" \
2374 tocmd.patch \
2375 2>errors >out &&
2376 test_grep "^!someone@example\.org!$" commandline1
2377'
2378
2379test_expect_success $PREREQ 'cccmd works with aliases' '
2380 clean_fake_sendmail &&
2381 echo "alias sbd someone@example.org" >.mailrc &&
2382 test_config sendemail.aliasesfile ".mailrc" &&
2383 test_config sendemail.aliasfiletype mailrc &&
2384 git format-patch --stdout -1 >cccmd.patch &&
2385 echo cccmd--sbd >>cccmd.patch &&
2386 git send-email \
2387 --from="Example <nobody@example.com>" \
2388 --cc-cmd=./cccmd-sed \
2389 --smtp-server="$(pwd)/fake.sendmail" \
2390 cccmd.patch \
2391 2>errors >out &&
2392 test_grep "^!someone@example\.org!$" commandline1
2393'
2394
2395do_xmailer_test () {
2396 expected=$1 params=$2 &&
2397 git format-patch -1 &&
2398 git send-email \
2399 --from="Example <nobody@example.com>" \
2400 --to=someone@example.com \
2401 --smtp-server="$(pwd)/fake.sendmail" \
2402 $params \
2403 0001-*.patch \
2404 2>errors >out &&
2405 { grep '^X-Mailer:' out || :; } >mailer &&
2406 test_line_count = $expected mailer
2407}
2408
2409test_expect_success $PREREQ '--[no-]xmailer without any configuration' '
2410 do_xmailer_test 1 "--xmailer" &&
2411 do_xmailer_test 0 "--no-xmailer"
2412'
2413
2414test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=true' '
2415 test_config sendemail.xmailer true &&
2416 do_xmailer_test 1 "" &&
2417 do_xmailer_test 0 "--no-xmailer" &&
2418 do_xmailer_test 1 "--xmailer"
2419'
2420
2421test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer' '
2422 test_when_finished "test_unconfig sendemail.xmailer" &&
2423 cat >>.git/config <<-\EOF &&
2424 [sendemail]
2425 xmailer
2426 EOF
2427 test_config sendemail.xmailer true &&
2428 do_xmailer_test 1 "" &&
2429 do_xmailer_test 0 "--no-xmailer" &&
2430 do_xmailer_test 1 "--xmailer"
2431'
2432
2433test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=false' '
2434 test_config sendemail.xmailer false &&
2435 do_xmailer_test 0 "" &&
2436 do_xmailer_test 0 "--no-xmailer" &&
2437 do_xmailer_test 1 "--xmailer"
2438'
2439
2440test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=' '
2441 test_config sendemail.xmailer "" &&
2442 do_xmailer_test 0 "" &&
2443 do_xmailer_test 0 "--no-xmailer" &&
2444 do_xmailer_test 1 "--xmailer"
2445'
2446
2447test_expect_success $PREREQ 'setup expected-list' '
2448 git send-email \
2449 --dry-run \
2450 --from="Example <from@example.com>" \
2451 --to="To 1 <to1@example.com>" \
2452 --to="to2@example.com" \
2453 --to="to3@example.com" \
2454 --cc="Cc 1 <cc1@example.com>" \
2455 --cc="Cc2 <cc2@example.com>" \
2456 --bcc="bcc1@example.com" \
2457 --bcc="bcc2@example.com" \
2458 0001-add-main.patch | replace_variable_fields \
2459 >expected-list
2460'
2461
2462test_expect_success $PREREQ 'use email list in --cc --to and --bcc' '
2463 git send-email \
2464 --dry-run \
2465 --from="Example <from@example.com>" \
2466 --to="To 1 <to1@example.com>, to2@example.com" \
2467 --to="to3@example.com" \
2468 --cc="Cc 1 <cc1@example.com>, Cc2 <cc2@example.com>" \
2469 --bcc="bcc1@example.com, bcc2@example.com" \
2470 0001-add-main.patch | replace_variable_fields \
2471 >actual-list &&
2472 test_cmp expected-list actual-list
2473'
2474
2475test_expect_success $PREREQ 'aliases work with email list' '
2476 echo "alias to2 to2@example.com" >.mutt &&
2477 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt &&
2478 test_config sendemail.aliasesfile ".mutt" &&
2479 test_config sendemail.aliasfiletype mutt &&
2480 git send-email \
2481 --dry-run \
2482 --from="Example <from@example.com>" \
2483 --to="To 1 <to1@example.com>, to2, to3@example.com" \
2484 --cc="cc1, Cc2 <cc2@example.com>" \
2485 --bcc="bcc1@example.com, bcc2@example.com" \
2486 0001-add-main.patch | replace_variable_fields \
2487 >actual-list &&
2488 test_cmp expected-list actual-list
2489'
2490
2491test_expect_success $PREREQ 'leading and trailing whitespaces are removed' '
2492 echo "alias to2 to2@example.com" >.mutt &&
2493 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt &&
2494 test_config sendemail.aliasesfile ".mutt" &&
2495 test_config sendemail.aliasfiletype mutt &&
2496 TO1=$(echo "QTo 1 <to1@example.com>" | q_to_tab) &&
2497 TO2=$(echo "QZto2" | qz_to_tab_space) &&
2498 CC1=$(echo "cc1" | append_cr) &&
2499 BCC1=$(echo " bcc1@example.com Q" | q_to_nul) &&
2500 git send-email \
2501 --dry-run \
2502 --from=" Example <from@example.com>" \
2503 --to="$TO1" \
2504 --to="$TO2" \
2505 --to=" to3@example.com " \
2506 --cc="$CC1" \
2507 --cc="Cc2 <cc2@example.com>" \
2508 --bcc="$BCC1" \
2509 --bcc="bcc2@example.com" \
2510 0001-add-main.patch | replace_variable_fields \
2511 >actual-list &&
2512 test_cmp expected-list actual-list
2513'
2514
2515test_expect_success $PREREQ 'mailmap support with --to' '
2516 clean_fake_sendmail &&
2517 test_config mailmap.file "mailmap.test" &&
2518 cat >mailmap.test <<-EOF &&
2519 Some Body <someone@example.com> <someone@example.org>
2520 EOF
2521 git format-patch --stdout -1 >a.patch &&
2522 git send-email \
2523 --from="Example <nobody@example.com>" \
2524 --smtp-server="$(pwd)/fake.sendmail" \
2525 --to=someone@example.org \
2526 --mailmap \
2527 a.patch \
2528 2>errors >out &&
2529 test_grep "^!someone@example\.com!$" commandline1
2530'
2531
2532test_expect_success $PREREQ 'sendemail.mailmap configuration' '
2533 clean_fake_sendmail &&
2534 test_config mailmap.file "mailmap.test" &&
2535 test_config sendemail.mailmap "true" &&
2536 cat >mailmap.test <<-EOF &&
2537 Some Body <someone@example.com> <someone@example.org>
2538 EOF
2539 git format-patch --stdout -1 >a.patch &&
2540 git send-email \
2541 --from="Example <nobody@example.com>" \
2542 --smtp-server="$(pwd)/fake.sendmail" \
2543 --to=someone@example.org \
2544 a.patch \
2545 2>errors >out &&
2546 test_grep "^!someone@example\.com!$" commandline1
2547'
2548
2549test_expect_success $PREREQ 'sendemail.mailmap.file configuration' '
2550 clean_fake_sendmail &&
2551 test_config sendemail.mailmap.file "mailmap.test" &&
2552 test_config sendemail.mailmap "true" &&
2553 cat >mailmap.test <<-EOF &&
2554 Some Body <someone@example.com> <someone@example.org>
2555 EOF
2556 git format-patch --stdout -1 >a.patch &&
2557 git send-email \
2558 --from="Example <nobody@example.com>" \
2559 --smtp-server="$(pwd)/fake.sendmail" \
2560 --to=someone@example.org \
2561 a.patch \
2562 2>errors >out &&
2563 test_grep "^!someone@example\.com!$" commandline1
2564'
2565
2566test_expect_success $PREREQ 'sendemail.mailmap identity overrides configuration' '
2567 clean_fake_sendmail &&
2568 test_config sendemail.cloud.mailmap.file "mailmap.test" &&
2569 test_config sendemail.mailmap "false" &&
2570 test_config sendemail.cloud.mailmap "true" &&
2571 cat >mailmap.test <<-EOF &&
2572 Some Body <someone@example.com> <someone@example.org>
2573 EOF
2574 git format-patch --stdout -1 >a.patch &&
2575 git send-email \
2576 --from="Example <nobody@example.com>" \
2577 --smtp-server="$(pwd)/fake.sendmail" \
2578 --identity=cloud \
2579 --to=someone@example.org \
2580 a.patch \
2581 2>errors >out &&
2582 test_grep "^!someone@example\.com!$" commandline1
2583'
2584
2585test_expect_success $PREREQ '--no-mailmap overrides configuration' '
2586 clean_fake_sendmail &&
2587 test_config sendemail.cloud.mailmap.file "mailmap.test" &&
2588 test_config sendemail.mailmap "false" &&
2589 test_config sendemail.cloud.mailmap "true" &&
2590 cat >mailmap.test <<-EOF &&
2591 Some Body <someone@example.com> <someone@example.org>
2592 EOF
2593 git format-patch --stdout -1 >a.patch &&
2594 git send-email \
2595 --from="Example <nobody@example.com>" \
2596 --smtp-server="$(pwd)/fake.sendmail" \
2597 --identity=cloud \
2598 --to=someone@example.org \
2599 --no-mailmap \
2600 a.patch \
2601 2>errors >out &&
2602 test_grep "^!someone@example\.org!$" commandline1
2603'
2604
2605test_expect_success $PREREQ 'mailmap support in To header' '
2606 clean_fake_sendmail &&
2607 test_config mailmap.file "mailmap.test" &&
2608 cat >mailmap.test <<-EOF &&
2609 <someone@example.com> <someone@example.org>
2610 EOF
2611 git format-patch --stdout -1 --to=someone@example.org >a.patch &&
2612 git send-email \
2613 --from="Example <nobody@example.com>" \
2614 --smtp-server="$(pwd)/fake.sendmail" \
2615 --mailmap \
2616 a.patch \
2617 2>errors >out &&
2618 test_grep "^!someone@example\.com!$" commandline1
2619'
2620
2621test_expect_success $PREREQ 'mailmap support in Cc header' '
2622 clean_fake_sendmail &&
2623 test_config mailmap.file "mailmap.test" &&
2624 cat >mailmap.test <<-EOF &&
2625 <someone@example.com> <someone@example.org>
2626 EOF
2627 git format-patch --stdout -1 --cc=someone@example.org >a.patch &&
2628 git send-email \
2629 --from="Example <nobody@example.com>" \
2630 --smtp-server="$(pwd)/fake.sendmail" \
2631 --mailmap \
2632 a.patch \
2633 2>errors >out &&
2634 test_grep "^!someone@example\.com!$" commandline1
2635'
2636
2637test_expect_success $PREREQ 'test using command name with --sendmail-cmd' '
2638 clean_fake_sendmail &&
2639 PATH="$PWD:$PATH" \
2640 git send-email \
2641 --from="Example <nobody@example.com>" \
2642 --to=nobody@example.com \
2643 --sendmail-cmd="fake.sendmail" \
2644 HEAD^ &&
2645 test_path_is_file commandline1
2646'
2647
2648test_expect_success $PREREQ 'test using arguments with --sendmail-cmd' '
2649 clean_fake_sendmail &&
2650 git send-email \
2651 --from="Example <nobody@example.com>" \
2652 --to=nobody@example.com \
2653 --sendmail-cmd='\''"$(pwd)/fake.sendmail" -f nobody@example.com'\'' \
2654 HEAD^ &&
2655 test_path_is_file commandline1
2656'
2657
2658test_expect_success $PREREQ 'test shell expression with --sendmail-cmd' '
2659 clean_fake_sendmail &&
2660 git send-email \
2661 --from="Example <nobody@example.com>" \
2662 --to=nobody@example.com \
2663 --sendmail-cmd='\''f() { "$(pwd)/fake.sendmail" "$@"; };f'\'' \
2664 HEAD^ &&
2665 test_path_is_file commandline1
2666'
2667
2668test_expect_success $PREREQ 'set up in-reply-to/references patches' '
2669 cat >has-reply.patch <<-\EOF &&
2670 From: A U Thor <author@example.com>
2671 Subject: patch with in-reply-to
2672 Message-ID: <patch.with.in.reply.to@example.com>
2673 In-Reply-To: <replied.to@example.com>
2674 References: <replied.to@example.com>
2675
2676 This is the body.
2677 EOF
2678 cat >no-reply.patch <<-\EOF
2679 From: A U Thor <author@example.com>
2680 Subject: patch without in-reply-to
2681 Message-ID: <patch.without.in.reply.to@example.com>
2682
2683 This is the body.
2684 EOF
2685'
2686
2687test_expect_success $PREREQ 'patch reply headers correct with --no-thread' '
2688 clean_fake_sendmail &&
2689 git send-email \
2690 --no-thread \
2691 --to=nobody@example.com \
2692 --smtp-server="$(pwd)/fake.sendmail" \
2693 has-reply.patch no-reply.patch &&
2694 test_grep "In-Reply-To: <replied.to@example.com>" msgtxt1 &&
2695 test_grep "References: <replied.to@example.com>" msgtxt1 &&
2696 test_grep ! replied.to@example.com msgtxt2
2697'
2698
2699test_expect_success $PREREQ 'cmdline in-reply-to used with --no-thread' '
2700 clean_fake_sendmail &&
2701 git send-email \
2702 --no-thread \
2703 --in-reply-to="<cmdline.reply@example.com>" \
2704 --to=nobody@example.com \
2705 --smtp-server="$(pwd)/fake.sendmail" \
2706 has-reply.patch no-reply.patch &&
2707 test_grep "In-Reply-To: <cmdline.reply@example.com>" msgtxt1 &&
2708 test_grep "References: <cmdline.reply@example.com>" msgtxt1 &&
2709 test_grep "In-Reply-To: <cmdline.reply@example.com>" msgtxt2 &&
2710 test_grep "References: <cmdline.reply@example.com>" msgtxt2
2711'
2712
2713test_expect_success $PREREQ 'invoke hook' '
2714 test_hook sendemail-validate <<-\EOF &&
2715 # test that we have the correct environment variable, pwd, and
2716 # argument
2717 case "$GIT_DIR" in
2718 *.git)
2719 true
2720 ;;
2721 *)
2722 false
2723 ;;
2724 esac &&
2725 test -f 0001-add-main.patch &&
2726 grep "add main" "$1"
2727 EOF
2728
2729 mkdir subdir &&
2730 (
2731 # Test that it works even if we are not at the root of the
2732 # working tree
2733 cd subdir &&
2734 git send-email \
2735 --from="Example <nobody@example.com>" \
2736 --to=nobody@example.com \
2737 --smtp-server="$(pwd)/../fake.sendmail" \
2738 ../0001-add-main.patch &&
2739
2740 # Verify error message when a patch is rejected by the hook
2741 sed -e "s/add main/x/" ../0001-add-main.patch >../another.patch &&
2742 test_must_fail git send-email \
2743 --from="Example <nobody@example.com>" \
2744 --to=nobody@example.com \
2745 --smtp-server="$(pwd)/../fake.sendmail" \
2746 ../another.patch 2>err &&
2747 test_grep "rejected by sendemail-validate hook" err
2748 )
2749'
2750
2751expected_file_counter_output () {
2752 total=$1
2753 count=0
2754 while test $count -ne $total
2755 do
2756 count=$((count + 1)) &&
2757 echo "$count/$total" || return
2758 done
2759}
2760
2761test_expect_success $PREREQ '--validate hook allows counting of messages' '
2762 test_when_finished "rm -rf my-hooks.log" &&
2763 test_config core.hooksPath "my-hooks" &&
2764 mkdir -p my-hooks &&
2765
2766 write_script my-hooks/sendemail-validate <<-\EOF &&
2767 num=$GIT_SENDEMAIL_FILE_COUNTER &&
2768 tot=$GIT_SENDEMAIL_FILE_TOTAL &&
2769 echo "$num/$tot" >>my-hooks.log || exit 1
2770 EOF
2771
2772 >my-hooks.log &&
2773 expected_file_counter_output 4 >expect &&
2774 git send-email \
2775 --from="Example <from@example.com>" \
2776 --to=nobody@example.com \
2777 --smtp-server="$(pwd)/fake.sendmail" \
2778 --validate -3 --cover-letter --force &&
2779 test_cmp expect my-hooks.log
2780'
2781
2782test_expect_success $PREREQ 'test that send-email works outside a repo' '
2783 nongit git send-email \
2784 --from="Example <nobody@example.com>" \
2785 --to=nobody@example.com \
2786 --smtp-server="$(pwd)/fake.sendmail" \
2787 "$(pwd)/0001-add-main.patch"
2788'
2789
2790test_expect_success $PREREQ 'send-email relays -v 3 to format-patch' '
2791 test_when_finished "rm -f out" &&
2792 git send-email --dry-run -v 3 -1 >out &&
2793 test_grep "PATCH v3" out
2794'
2795
2796test_expect_success $PREREQ 'test that sendmail config is rejected' '
2797 test_config sendmail.program sendmail &&
2798 test_must_fail git send-email \
2799 --from="Example <nobody@example.com>" \
2800 --to=nobody@example.com \
2801 --smtp-server="$(pwd)/fake.sendmail" \
2802 HEAD^ 2>err &&
2803 test_grep "found configuration options for '"'"sendmail"'"'" err
2804'
2805
2806test_expect_success $PREREQ 'test that sendmail config rejection is specific' '
2807 test_config resendmail.program sendmail &&
2808 git send-email \
2809 --from="Example <nobody@example.com>" \
2810 --to=nobody@example.com \
2811 --smtp-server="$(pwd)/fake.sendmail" \
2812 HEAD^
2813'
2814
2815test_expect_success $PREREQ 'test forbidSendmailVariables behavior override' '
2816 test_config sendmail.program sendmail &&
2817 test_config sendemail.forbidSendmailVariables false &&
2818 git send-email \
2819 --from="Example <nobody@example.com>" \
2820 --to=nobody@example.com \
2821 --smtp-server="$(pwd)/fake.sendmail" \
2822 HEAD^
2823'
2824
2825test_expect_success $PREREQ '--compose handles lowercase headers' '
2826 write_script fake-editor <<-\EOF &&
2827 sed "s/^[Ff][Rr][Oo][Mm]:.*/from: edited-from@example.com/" "$1" >"$1.tmp" &&
2828 mv "$1.tmp" "$1"
2829 EOF
2830 clean_fake_sendmail &&
2831 git send-email \
2832 --compose \
2833 --from="Example <from@example.com>" \
2834 --to=nobody@example.com \
2835 --smtp-server="$(pwd)/fake.sendmail" \
2836 HEAD^ &&
2837 test_grep "From: edited-from@example.com" msgtxt1
2838'
2839
2840test_expect_success $PREREQ '--compose handles to headers' '
2841 write_script fake-editor <<-\EOF &&
2842 sed "s/^To: .*/&, edited-to@example.com/" <"$1" >"$1.tmp" &&
2843 echo this is the body >>"$1.tmp" &&
2844 mv "$1.tmp" "$1"
2845 EOF
2846 clean_fake_sendmail &&
2847 GIT_SEND_EMAIL_NOTTY=1 \
2848 git send-email \
2849 --compose \
2850 --from="Example <from@example.com>" \
2851 --to=nobody@example.com \
2852 --smtp-server="$(pwd)/fake.sendmail" \
2853 HEAD^ &&
2854 # Check both that the cover letter used our modified "to" line,
2855 # but also that it was picked up for the patch.
2856 q_to_tab >expect <<-\EOF &&
2857 To: nobody@example.com,
2858 Qedited-to@example.com
2859 EOF
2860 grep -A1 "^To:" msgtxt1 >msgtxt1.to &&
2861 test_cmp expect msgtxt1.to &&
2862 grep -A1 "^To:" msgtxt2 >msgtxt2.to &&
2863 test_cmp expect msgtxt2.to
2864'
2865
2866test_done