]> git.ipfire.org Git - thirdparty/git.git/blame - t/t9001-send-email.sh
send-email: extract execute_cmd from recipients_cmd
[thirdparty/git.git] / t / t9001-send-email.sh
CommitLineData
ce903018
RA
1#!/bin/sh
2
47a528ad 3test_description='git send-email'
a881baa2 4GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
334afbc7
JS
5export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
6
ab1f6926 7TEST_PASSES_SANITIZE_LEAK=true
ce903018
RA
8. ./test-lib.sh
9
57cd35e6
ÆAB
10# May be altered later in the test
11PREREQ="PERL"
1b19ccd2 12
ec3b4b06
CL
13replace_variable_fields () {
14 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
ba4324c4 15 -e "s/^\(Message-ID:\).*/\1 MESSAGE-ID-STRING/" \
ec3b4b06
CL
16 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/"
17}
18
aca56064 19test_expect_success $PREREQ 'prepare reference tree' '
03335f22
JH
20 echo "1A quick brown fox jumps over the" >file &&
21 echo "lazy dog" >>file &&
22 git add file &&
23 GIT_AUTHOR_NAME="A" git commit -a -m "Initial."
aca56064 24'
ce903018 25
aca56064 26test_expect_success $PREREQ 'Setup helper tool' '
acd72b56
JH
27 write_script fake.sendmail <<-\EOF &&
28 shift
29 output=1
30 while test -f commandline$output
31 do
32 output=$(($output+1))
33 done
34 for a
35 do
36 echo "!$a!"
37 done >commandline$output
38 cat >"msgtxt$output"
39 EOF
03335f22
JH
40 git add fake.sendmail &&
41 GIT_AUTHOR_NAME="A" git commit -a -m "Second."
aca56064 42'
ce903018 43
ee756a81 44clean_fake_sendmail () {
6d34a2ba
JK
45 rm -f commandline* msgtxt*
46}
47
57cd35e6 48test_expect_success $PREREQ 'Extract patches' '
f9f60d70
RA
49 patches=$(git format-patch -s --cc="One <one@example.com>" --cc=two@example.com -n HEAD^1) &&
50 threaded_patches=$(git format-patch -o threaded -s --in-reply-to="format" HEAD^1)
280242d1
JH
51'
52
c1f2aa45
JS
53# Test no confirm early to ensure remaining tests will not hang
54test_no_confirm () {
55 rm -f no_confirm_okay
56 echo n | \
57 GIT_SEND_EMAIL_NOTTY=1 \
58 git send-email \
59 --from="Example <from@example.com>" \
60 --to=nobody@example.com \
61 --smtp-server="$(pwd)/fake.sendmail" \
62 $@ \
ee756a81 63 $patches >stdout &&
c7cf9566 64 ! grep "Send this email" stdout &&
ee756a81 65 >no_confirm_okay
c1f2aa45
JS
66}
67
68# Exit immediately to prevent hang if a no-confirm test fails
69check_no_confirm () {
57cd35e6
ÆAB
70 if ! test -f no_confirm_okay
71 then
72 say 'confirm test failed; skipping remaining tests to prevent hanging'
73 PREREQ="$PREREQ,CHECK_NO_CONFIRM"
74 fi
75 return 0
c1f2aa45
JS
76}
77
57cd35e6
ÆAB
78test_expect_success $PREREQ 'No confirm with --suppress-cc' '
79 test_no_confirm --suppress-cc=sob &&
80 check_no_confirm
c1f2aa45 81'
c1f2aa45 82
57cd35e6
ÆAB
83
84test_expect_success $PREREQ 'No confirm with --confirm=never' '
85 test_no_confirm --confirm=never &&
86 check_no_confirm
c1f2aa45 87'
c1f2aa45
JS
88
89# leave sendemail.confirm set to never after this so that none of the
90# remaining tests prompt unintentionally.
57cd35e6 91test_expect_success $PREREQ 'No confirm with sendemail.confirm=never' '
c1f2aa45 92 git config sendemail.confirm never &&
57cd35e6
ÆAB
93 test_no_confirm --compose --subject=foo &&
94 check_no_confirm
c1f2aa45 95'
c1f2aa45 96
57cd35e6 97test_expect_success $PREREQ 'Send patches' '
03335f22 98 git send-email --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
280242d1 99'
ce903018 100
f9444147 101test_expect_success $PREREQ 'setup expect' '
0720a51b
JH
102 cat >expected <<-\EOF
103 !nobody@example.com!
104 !author@example.com!
105 !one@example.com!
106 !two@example.com!
107 EOF
f9444147
ÆAB
108'
109
aca56064
JH
110test_expect_success $PREREQ 'Verify commandline' '
111 test_cmp expected commandline1
112'
ce903018 113
57cd35e6 114test_expect_success $PREREQ 'Send patches with --envelope-sender' '
03335f22
JH
115 clean_fake_sendmail &&
116 git send-email --envelope-sender="Patch Contributor <patch@example.com>" --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
4f333bc1
JH
117'
118
f9444147 119test_expect_success $PREREQ 'setup expect' '
0720a51b
JH
120 cat >expected <<-\EOF
121 !patch@example.com!
122 !-i!
123 !nobody@example.com!
124 !author@example.com!
125 !one@example.com!
126 !two@example.com!
127 EOF
f9444147
ÆAB
128'
129
aca56064
JH
130test_expect_success $PREREQ 'Verify commandline' '
131 test_cmp expected commandline1
132'
4f333bc1 133
57cd35e6 134test_expect_success $PREREQ 'Send patches with --envelope-sender=auto' '
03335f22
JH
135 clean_fake_sendmail &&
136 git send-email --envelope-sender=auto --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
c89e3241
FC
137'
138
f9444147 139test_expect_success $PREREQ 'setup expect' '
0720a51b
JH
140 cat >expected <<-\EOF
141 !nobody@example.com!
142 !-i!
143 !nobody@example.com!
144 !author@example.com!
145 !one@example.com!
146 !two@example.com!
147 EOF
f9444147
ÆAB
148'
149
aca56064
JH
150test_expect_success $PREREQ 'Verify commandline' '
151 test_cmp expected commandline1
152'
c89e3241 153
e3fdbcc8
MM
154test_expect_success $PREREQ 'setup expect for cc trailer' "
155cat >expected-cc <<\EOF
156!recipient@example.com!
157!author@example.com!
158!one@example.com!
159!two@example.com!
160!three@example.com!
161!four@example.com!
cb2922fe
MM
162!five@example.com!
163!six@example.com!
e3fdbcc8
MM
164EOF
165"
166
167test_expect_success $PREREQ 'cc trailer with various syntax' '
168 test_commit cc-trailer &&
169 test_when_finished "git reset --hard HEAD^" &&
170 git commit --amend -F - <<-EOF &&
171 Test Cc: trailers.
172
173 Cc: one@example.com
9d334396
JH
174 Cc: <two@example.com> # trailing comments are ignored
175 Cc: <three@example.com>, <not.four@example.com> one address per line
176 Cc: "Some # Body" <four@example.com> [ <also.a.comment> ]
cb2922fe
MM
177 Cc: five@example.com # not.six@example.com
178 Cc: six@example.com, not.seven@example.com
e3fdbcc8
MM
179 EOF
180 clean_fake_sendmail &&
181 git send-email -1 --to=recipient@example.com \
182 --smtp-server="$(pwd)/fake.sendmail" &&
183 test_cmp expected-cc commandline1
184'
185
d60be8ac
AB
186test_expect_success $PREREQ 'setup fake get_maintainer.pl script for cc trailer' "
187 write_script expected-cc-script.sh <<-EOF
188 echo 'One Person <one@example.com> (supporter:THIS (FOO/bar))'
189 echo 'Two Person <two@example.com> (maintainer:THIS THING)'
190 echo 'Third List <three@example.com> (moderated list:THIS THING (FOO/bar))'
191 echo '<four@example.com> (moderated list:FOR THING)'
192 echo 'five@example.com (open list:FOR THING (FOO/bar))'
193 echo 'six@example.com (open list)'
194 EOF
195"
196
197test_expect_success $PREREQ 'cc trailer with get_maintainer.pl output' '
198 clean_fake_sendmail &&
199 git send-email -1 --to=recipient@example.com \
200 --cc-cmd=./expected-cc-script.sh \
201 --smtp-server="$(pwd)/fake.sendmail" &&
202 test_cmp expected-cc commandline1
203'
204
f9444147 205test_expect_success $PREREQ 'setup expect' "
b7f30e0a
DK
206cat >expected-show-all-headers <<\EOF
2070001-Second.patch
208(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
5012699d
JS
209(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
210(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
b7f30e0a
DK
211Dry-OK. Log says:
212Server: relay.example.com
213MAIL FROM:<from@example.com>
02461e0e
JP
214RCPT TO:<to@example.com>
215RCPT TO:<cc@example.com>
216RCPT TO:<author@example.com>
217RCPT TO:<one@example.com>
218RCPT TO:<two@example.com>
219RCPT TO:<bcc@example.com>
b7f30e0a
DK
220From: Example <from@example.com>
221To: to@example.com
02461e0e
JP
222Cc: cc@example.com,
223 A <author@example.com>,
224 One <one@example.com>,
225 two@example.com
b7f30e0a
DK
226Subject: [PATCH 1/1] Second.
227Date: DATE-STRING
ba4324c4 228Message-ID: MESSAGE-ID-STRING
b7f30e0a
DK
229X-Mailer: X-MAILER-STRING
230In-Reply-To: <unique-message-id@example.com>
231References: <unique-message-id@example.com>
d11c943c 232Reply-To: Reply <reply@example.com>
e67a228c 233MIME-Version: 1.0
234Content-Transfer-Encoding: 8bit
b7f30e0a
DK
235
236Result: OK
237EOF
f9444147 238"
b7f30e0a 239
5adcf2c6
MT
240test_suppress_self () {
241 test_commit $3 &&
242 test_when_finished "git reset --hard HEAD^" &&
243
244 write_script cccmd-sed <<-EOF &&
245 sed -n -e s/^cccmd--//p "\$1"
246 EOF
247
248 git commit --amend --author="$1 <$2>" -F - &&
249 clean_fake_sendmail &&
250 git format-patch --stdout -1 >"suppress-self-$3.patch" &&
251
252 git send-email --from="$1 <$2>" \
253 --to=nobody@example.com \
254 --cc-cmd=./cccmd-sed \
255 --suppress-cc=self \
256 --smtp-server="$(pwd)/fake.sendmail" \
257 suppress-self-$3.patch &&
258
259 mv msgtxt1 msgtxt1-$3 &&
260 sed -e '/^$/q' msgtxt1-$3 >"msghdr1-$3" &&
5adcf2c6
MT
261
262 (grep '^Cc:' msghdr1-$3 >"actual-no-cc-$3";
d3c6751b 263 test_must_be_empty actual-no-cc-$3)
5adcf2c6
MT
264}
265
266test_suppress_self_unquoted () {
267 test_suppress_self "$1" "$2" "unquoted-$3" <<-EOF
268 test suppress-cc.self unquoted-$3 with name $1 email $2
269
270 unquoted-$3
271
d6ee4456
MT
272 cccmd--$1 <$2>
273
5adcf2c6
MT
274 Cc: $1 <$2>
275 Signed-off-by: $1 <$2>
276 EOF
277}
278
dd29f0b4
MT
279test_suppress_self_quoted () {
280 test_suppress_self "$1" "$2" "quoted-$3" <<-EOF
281 test suppress-cc.self quoted-$3 with name $1 email $2
282
283 quoted-$3
284
285 cccmd--"$1" <$2>
286
287 Cc: $1 <$2>
288 Cc: "$1" <$2>
289 Signed-off-by: $1 <$2>
290 Signed-off-by: "$1" <$2>
291 EOF
292}
293
5adcf2c6 294test_expect_success $PREREQ 'self name is suppressed' "
d6ee4456 295 test_suppress_self_unquoted 'A U Thor' 'author@example.com' \
5adcf2c6
MT
296 'self_name_suppressed'
297"
298
dd29f0b4
MT
299test_expect_success $PREREQ 'self name with dot is suppressed' "
300 test_suppress_self_quoted 'A U. Thor' 'author@example.com' \
301 'self_name_dot_suppressed'
302"
303
4b45bcf7
MT
304test_expect_success $PREREQ 'non-ascii self name is suppressed' "
305 test_suppress_self_quoted 'Füñný Nâmé' 'odd_?=mail@example.com' \
306 'non_ascii_self_suppressed'
307"
308
ab47e2a5
РД
309# This name is long enough to force format-patch to split it into multiple
310# encoded-words, assuming it uses UTF-8 with the "Q" encoding.
311test_expect_success $PREREQ 'long non-ascii self name is suppressed' "
312 test_suppress_self_quoted 'Ƒüñníęř €. Nâṁé' 'odd_?=mail@example.com' \
313 'long_non_ascii_self_suppressed'
314"
315
14952666
MT
316test_expect_success $PREREQ 'sanitized self name is suppressed' "
317 test_suppress_self_unquoted '\"A U. Thor\"' 'author@example.com' \
318 'self_name_sanitized_suppressed'
319"
320
57cd35e6 321test_expect_success $PREREQ 'Show all headers' '
b7f30e0a
DK
322 git send-email \
323 --dry-run \
3531e270 324 --suppress-cc=sob \
b7f30e0a 325 --from="Example <from@example.com>" \
d11c943c 326 --reply-to="Reply <reply@example.com>" \
b7f30e0a
DK
327 --to=to@example.com \
328 --cc=cc@example.com \
329 --bcc=bcc@example.com \
330 --in-reply-to="<unique-message-id@example.com>" \
331 --smtp-server relay.example.com \
ec3b4b06 332 $patches | replace_variable_fields \
b7f30e0a 333 >actual-show-all-headers &&
82ebb0b6 334 test_cmp expected-show-all-headers actual-show-all-headers
b7f30e0a
DK
335'
336
57cd35e6 337test_expect_success $PREREQ 'Prompting works' '
0da43a68 338 clean_fake_sendmail &&
cff4243d 339 (echo "to@example.com" &&
0da43a68
JS
340 echo ""
341 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
342 --smtp-server="$(pwd)/fake.sendmail" \
343 $patches \
344 2>errors &&
8cac13dc 345 grep "^From: A U Thor <author@example.com>\$" msgtxt1 &&
9524cf29 346 grep "^To: to@example.com\$" msgtxt1
0da43a68
JS
347'
348
59defcc3
JK
349test_expect_success $PREREQ,AUTOIDENT 'implicit ident is allowed' '
350 clean_fake_sendmail &&
351 (sane_unset GIT_AUTHOR_NAME &&
352 sane_unset GIT_AUTHOR_EMAIL &&
353 sane_unset GIT_COMMITTER_NAME &&
354 sane_unset GIT_COMMITTER_EMAIL &&
355 GIT_SEND_EMAIL_NOTTY=1 git send-email \
356 --smtp-server="$(pwd)/fake.sendmail" \
357 --to=to@example.com \
358 $patches </dev/null 2>errors
359 )
360'
361
362test_expect_success $PREREQ,!AUTOIDENT 'broken implicit ident aborts send-email' '
363 clean_fake_sendmail &&
364 (sane_unset GIT_AUTHOR_NAME &&
365 sane_unset GIT_AUTHOR_EMAIL &&
366 sane_unset GIT_COMMITTER_NAME &&
367 sane_unset GIT_COMMITTER_EMAIL &&
368 GIT_SEND_EMAIL_NOTTY=1 && export GIT_SEND_EMAIL_NOTTY &&
369 test_must_fail git send-email \
370 --smtp-server="$(pwd)/fake.sendmail" \
371 --to=to@example.com \
372 $patches </dev/null 2>errors &&
373 test_i18ngrep "tell me who you are" errors
374 )
375'
376
62089fb8
RL
377test_expect_success $PREREQ 'setup tocmd and cccmd scripts' '
378 write_script tocmd-sed <<-\EOF &&
379 sed -n -e "s/^tocmd--//p" "$1"
380 EOF
381 write_script cccmd-sed <<-\EOF
382 sed -n -e "s/^cccmd--//p" "$1"
383 EOF
384'
385
6e74e075
JP
386test_expect_success $PREREQ 'tocmd works' '
387 clean_fake_sendmail &&
388 cp $patches tocmd.patch &&
389 echo tocmd--tocmd@example.com >>tocmd.patch &&
6e74e075
JP
390 git send-email \
391 --from="Example <nobody@example.com>" \
392 --to-cmd=./tocmd-sed \
393 --smtp-server="$(pwd)/fake.sendmail" \
394 tocmd.patch \
395 &&
396 grep "^To: tocmd@example.com" msgtxt1
397'
398
57cd35e6 399test_expect_success $PREREQ 'cccmd works' '
cb8a9bd5
PB
400 clean_fake_sendmail &&
401 cp $patches cccmd.patch &&
41ae8f1d 402 echo "cccmd-- cccmd@example.com" >>cccmd.patch &&
cb8a9bd5
PB
403 git send-email \
404 --from="Example <nobody@example.com>" \
405 --to=nobody@example.com \
406 --cc-cmd=./cccmd-sed \
407 --smtp-server="$(pwd)/fake.sendmail" \
408 cccmd.patch \
409 &&
02461e0e 410 grep "^ cccmd@example.com" msgtxt1
cb8a9bd5
PB
411'
412
57cd35e6 413test_expect_success $PREREQ 'reject long lines' '
f9444147
ÆAB
414 z8=zzzzzzzz &&
415 z64=$z8$z8$z8$z8$z8$z8$z8$z8 &&
416 z512=$z64$z64$z64$z64$z64$z64$z64$z64 &&
6d34a2ba 417 clean_fake_sendmail &&
747bbff9 418 cp $patches longline.patch &&
ea7811b3
ÆAB
419 cat >>longline.patch <<-EOF &&
420 $z512$z512
421 not a long line
422 $z512$z512
423 EOF
d492b31c 424 test_must_fail git send-email \
747bbff9
JK
425 --from="Example <nobody@example.com>" \
426 --to=nobody@example.com \
427 --smtp-server="$(pwd)/fake.sendmail" \
e67a228c 428 --transfer-encoding=8bit \
747bbff9 429 $patches longline.patch \
e585210e
ÆAB
430 2>actual &&
431 cat >expect <<-\EOF &&
ea7811b3 432 fatal: longline.patch:35 is longer than 998 characters
e585210e
ÆAB
433 warning: no patches were sent
434 EOF
435 test_cmp expect actual
747bbff9
JK
436'
437
57cd35e6 438test_expect_success $PREREQ 'no patch was sent' '
6d34a2ba 439 ! test -e commandline1
747bbff9
JK
440'
441
57cd35e6 442test_expect_success $PREREQ 'Author From: in message body' '
5012699d
JS
443 clean_fake_sendmail &&
444 git send-email \
445 --from="Example <nobody@example.com>" \
446 --to=nobody@example.com \
447 --smtp-server="$(pwd)/fake.sendmail" \
448 $patches &&
ee756a81 449 sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
5012699d
JS
450 grep "From: A <author@example.com>" msgbody1
451'
452
57cd35e6 453test_expect_success $PREREQ 'Author From: not in message body' '
5012699d
JS
454 clean_fake_sendmail &&
455 git send-email \
456 --from="A <author@example.com>" \
457 --to=nobody@example.com \
458 --smtp-server="$(pwd)/fake.sendmail" \
459 $patches &&
ee756a81 460 sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
5012699d
JS
461 ! grep "From: A <author@example.com>" msgbody1
462'
463
57cd35e6 464test_expect_success $PREREQ 'allow long lines with --no-validate' '
c764a0c2
JK
465 git send-email \
466 --from="Example <nobody@example.com>" \
467 --to=nobody@example.com \
468 --smtp-server="$(pwd)/fake.sendmail" \
f4714943 469 --no-validate \
c764a0c2
JK
470 $patches longline.patch \
471 2>errors
472'
473
7a36987f 474test_expect_success $PREREQ 'short lines with auto encoding are 8bit' '
475 clean_fake_sendmail &&
476 git send-email \
477 --from="A <author@example.com>" \
478 --to=nobody@example.com \
479 --smtp-server="$(pwd)/fake.sendmail" \
480 --transfer-encoding=auto \
481 $patches &&
482 grep "Content-Transfer-Encoding: 8bit" msgtxt1
483'
484
485test_expect_success $PREREQ 'long lines with auto encoding are quoted-printable' '
486 clean_fake_sendmail &&
487 git send-email \
488 --from="Example <nobody@example.com>" \
489 --to=nobody@example.com \
490 --smtp-server="$(pwd)/fake.sendmail" \
491 --transfer-encoding=auto \
492 --no-validate \
493 longline.patch &&
494 grep "Content-Transfer-Encoding: quoted-printable" msgtxt1
495'
496
74d76a17 497test_expect_success $PREREQ 'carriage returns with auto encoding are quoted-printable' '
498 clean_fake_sendmail &&
499 cp $patches cr.patch &&
500 printf "this is a line\r\n" >>cr.patch &&
501 git send-email \
502 --from="Example <nobody@example.com>" \
503 --to=nobody@example.com \
504 --smtp-server="$(pwd)/fake.sendmail" \
505 --transfer-encoding=auto \
506 --no-validate \
507 cr.patch &&
508 grep "Content-Transfer-Encoding: quoted-printable" msgtxt1
509'
510
f2d06fb1 511for enc in auto quoted-printable base64
512do
513 test_expect_success $PREREQ "--validate passes with encoding $enc" '
514 git send-email \
515 --from="Example <nobody@example.com>" \
516 --to=nobody@example.com \
517 --smtp-server="$(pwd)/fake.sendmail" \
518 --transfer-encoding=$enc \
519 --validate \
520 $patches longline.patch
521 '
3c88e46f
AL
522
523done
524
c8243933
RF
525test_expect_success $PREREQ "--validate respects relative core.hooksPath path" '
526 clean_fake_sendmail &&
527 mkdir my-hooks &&
528 test_when_finished "rm my-hooks.ran" &&
529 write_script my-hooks/sendemail-validate <<-\EOF &&
530 >my-hooks.ran
531 exit 1
532 EOF
533 test_config core.hooksPath "my-hooks" &&
534 test_must_fail git send-email \
535 --from="Example <nobody@example.com>" \
536 --to=nobody@example.com \
537 --smtp-server="$(pwd)/fake.sendmail" \
538 --validate \
e585210e 539 longline.patch 2>actual &&
c8243933 540 test_path_is_file my-hooks.ran &&
ea7811b3 541 cat >expect <<-EOF &&
e585210e 542 fatal: longline.patch: rejected by sendemail-validate hook
a7555304 543 fatal: command '"'"'git hook run --ignore-missing sendemail-validate -- <patch>'"'"' died with exit code 1
e585210e
ÆAB
544 warning: no patches were sent
545 EOF
546 test_cmp expect actual
c8243933
RF
547'
548
549test_expect_success $PREREQ "--validate respects absolute core.hooksPath path" '
2815326f
ÆAB
550 hooks_path="$(pwd)/my-hooks" &&
551 test_config core.hooksPath "$hooks_path" &&
c8243933
RF
552 test_when_finished "rm my-hooks.ran" &&
553 test_must_fail git send-email \
554 --from="Example <nobody@example.com>" \
555 --to=nobody@example.com \
556 --smtp-server="$(pwd)/fake.sendmail" \
557 --validate \
e585210e 558 longline.patch 2>actual &&
c8243933 559 test_path_is_file my-hooks.ran &&
ea7811b3 560 cat >expect <<-EOF &&
e585210e 561 fatal: longline.patch: rejected by sendemail-validate hook
a7555304 562 fatal: command '"'"'git hook run --ignore-missing sendemail-validate -- <patch>'"'"' died with exit code 1
e585210e
ÆAB
563 warning: no patches were sent
564 EOF
565 test_cmp expect actual
c8243933
RF
566'
567
3c88e46f
AL
568for enc in 7bit 8bit quoted-printable base64
569do
570 test_expect_success $PREREQ "--transfer-encoding=$enc produces correct header" '
571 clean_fake_sendmail &&
572 git send-email \
573 --from="Example <nobody@example.com>" \
574 --to=nobody@example.com \
575 --smtp-server="$(pwd)/fake.sendmail" \
576 --transfer-encoding=$enc \
577 $patches &&
578 grep "Content-Transfer-Encoding: $enc" msgtxt1
579 '
f2d06fb1 580done
581
57cd35e6 582test_expect_success $PREREQ 'Invalid In-Reply-To' '
6d34a2ba 583 clean_fake_sendmail &&
0fb7fc75
JS
584 git send-email \
585 --from="Example <nobody@example.com>" \
586 --to=nobody@example.com \
587 --in-reply-to=" " \
588 --smtp-server="$(pwd)/fake.sendmail" \
5b57413c 589 $patches \
cc7e8167 590 2>errors &&
6d34a2ba 591 ! grep "^In-Reply-To: < *>" msgtxt1
0fb7fc75
JS
592'
593
57cd35e6 594test_expect_success $PREREQ 'Valid In-Reply-To when prompting' '
6d34a2ba 595 clean_fake_sendmail &&
cff4243d
ES
596 (echo "From Example <from@example.com>" &&
597 echo "To Example <to@example.com>" &&
0fb7fc75 598 echo ""
6eca18ca 599 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
0fb7fc75
JS
600 --smtp-server="$(pwd)/fake.sendmail" \
601 $patches 2>errors &&
6d34a2ba 602 ! grep "^In-Reply-To: < *>" msgtxt1
0fb7fc75
JS
603'
604
54aae5e1
JH
605test_expect_success $PREREQ 'In-Reply-To without --chain-reply-to' '
606 clean_fake_sendmail &&
607 echo "<unique-message-id@example.com>" >expect &&
608 git send-email \
609 --from="Example <nobody@example.com>" \
610 --to=nobody@example.com \
f4714943 611 --no-chain-reply-to \
54aae5e1
JH
612 --in-reply-to="$(cat expect)" \
613 --smtp-server="$(pwd)/fake.sendmail" \
614 $patches $patches $patches \
615 2>errors &&
db54c8e7 616 # The first message is a reply to --in-reply-to
54aae5e1
JH
617 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
618 test_cmp expect actual &&
db54c8e7 619 # Second and subsequent messages are replies to the first one
ba4324c4 620 sed -n -e "s/^Message-ID: *\(.*\)/\1/p" msgtxt1 >expect &&
54aae5e1
JH
621 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
622 test_cmp expect actual &&
623 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
624 test_cmp expect actual
625'
626
627test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' '
628 clean_fake_sendmail &&
629 echo "<unique-message-id@example.com>" >expect &&
630 git send-email \
631 --from="Example <nobody@example.com>" \
632 --to=nobody@example.com \
633 --chain-reply-to \
634 --in-reply-to="$(cat expect)" \
635 --smtp-server="$(pwd)/fake.sendmail" \
636 $patches $patches $patches \
637 2>errors &&
638 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
639 test_cmp expect actual &&
ba4324c4 640 sed -n -e "s/^Message-ID: *\(.*\)/\1/p" msgtxt1 >expect &&
54aae5e1
JH
641 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
642 test_cmp expect actual &&
ba4324c4 643 sed -n -e "s/^Message-ID: *\(.*\)/\1/p" msgtxt2 >expect &&
54aae5e1
JH
644 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
645 test_cmp expect actual
646'
647
5b719b75
ÆAB
648test_set_editor "$(pwd)/fake-editor"
649
650test_expect_success $PREREQ 'setup erroring fake editor' '
651 write_script fake-editor <<-\EOF
652 echo >&2 "I am about to error"
653 exit 1
654 EOF
655'
656
657test_expect_success $PREREQ 'fake editor dies with error' '
658 clean_fake_sendmail &&
659 test_must_fail git send-email \
660 --compose --subject foo \
661 --from="Example <nobody@example.com>" \
662 --to=nobody@example.com \
663 --smtp-server="$(pwd)/fake.sendmail" \
664 $patches 2>err &&
665 grep "I am about to error" err &&
666 grep "the editor exited uncleanly, aborting everything" err
667'
668
57cd35e6 669test_expect_success $PREREQ 'setup fake editor' '
acd72b56
JH
670 write_script fake-editor <<-\EOF
671 echo fake edit >>"$1"
672 EOF
8a8bf469
JK
673'
674
57cd35e6 675test_expect_success $PREREQ '--compose works' '
8a8bf469 676 clean_fake_sendmail &&
c1f2aa45
JS
677 git send-email \
678 --compose --subject foo \
679 --from="Example <nobody@example.com>" \
680 --to=nobody@example.com \
681 --smtp-server="$(pwd)/fake.sendmail" \
682 $patches \
683 2>errors
8a8bf469
JK
684'
685
57cd35e6 686test_expect_success $PREREQ 'first message is compose text' '
8a8bf469
JK
687 grep "^fake edit" msgtxt1
688'
689
57cd35e6 690test_expect_success $PREREQ 'second message is patch' '
8a8bf469
JK
691 grep "Subject:.*Second" msgtxt2
692'
693
f9444147 694test_expect_success $PREREQ 'setup expect' "
3531e270 695cat >expected-suppress-sob <<\EOF
33c592dd
MV
6960001-Second.patch
697(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
5012699d
JS
698(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
699(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
33c592dd
MV
700Dry-OK. Log says:
701Server: relay.example.com
702MAIL FROM:<from@example.com>
02461e0e
JP
703RCPT TO:<to@example.com>
704RCPT TO:<cc@example.com>
705RCPT TO:<author@example.com>
706RCPT TO:<one@example.com>
707RCPT TO:<two@example.com>
33c592dd
MV
708From: Example <from@example.com>
709To: to@example.com
02461e0e
JP
710Cc: cc@example.com,
711 A <author@example.com>,
712 One <one@example.com>,
713 two@example.com
33c592dd
MV
714Subject: [PATCH 1/1] Second.
715Date: DATE-STRING
ba4324c4 716Message-ID: MESSAGE-ID-STRING
33c592dd 717X-Mailer: X-MAILER-STRING
e67a228c 718MIME-Version: 1.0
719Content-Transfer-Encoding: 8bit
33c592dd
MV
720
721Result: OK
722EOF
f9444147 723"
33c592dd 724
3531e270 725test_suppression () {
33c592dd
MV
726 git send-email \
727 --dry-run \
cb8a9bd5 728 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
33c592dd
MV
729 --from="Example <from@example.com>" \
730 --to=to@example.com \
731 --smtp-server relay.example.com \
d4cf11c2 732 $patches | replace_variable_fields \
cb8a9bd5
PB
733 >actual-suppress-$1${2+"-$2"} &&
734 test_cmp expected-suppress-$1${2+"-$2"} actual-suppress-$1${2+"-$2"}
3531e270
JS
735}
736
57cd35e6 737test_expect_success $PREREQ 'sendemail.cc set' '
3531e270
JS
738 git config sendemail.cc cc@example.com &&
739 test_suppression sob
33c592dd
MV
740'
741
f9444147 742test_expect_success $PREREQ 'setup expect' "
3531e270 743cat >expected-suppress-sob <<\EOF
33c592dd
MV
7440001-Second.patch
745(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
5012699d
JS
746(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
747(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
33c592dd
MV
748Dry-OK. Log says:
749Server: relay.example.com
750MAIL FROM:<from@example.com>
02461e0e
JP
751RCPT TO:<to@example.com>
752RCPT TO:<author@example.com>
753RCPT TO:<one@example.com>
754RCPT TO:<two@example.com>
33c592dd
MV
755From: Example <from@example.com>
756To: to@example.com
02461e0e
JP
757Cc: A <author@example.com>,
758 One <one@example.com>,
759 two@example.com
33c592dd
MV
760Subject: [PATCH 1/1] Second.
761Date: DATE-STRING
ba4324c4 762Message-ID: MESSAGE-ID-STRING
33c592dd 763X-Mailer: X-MAILER-STRING
e67a228c 764MIME-Version: 1.0
765Content-Transfer-Encoding: 8bit
33c592dd
MV
766
767Result: OK
768EOF
f9444147 769"
33c592dd 770
57cd35e6 771test_expect_success $PREREQ 'sendemail.cc unset' '
33c592dd 772 git config --unset sendemail.cc &&
3531e270
JS
773 test_suppression sob
774'
775
f9444147 776test_expect_success $PREREQ 'setup expect' "
cb8a9bd5
PB
777cat >expected-suppress-cccmd <<\EOF
7780001-Second.patch
779(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
780(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
781(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
782(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
783Dry-OK. Log says:
784Server: relay.example.com
785MAIL FROM:<from@example.com>
02461e0e
JP
786RCPT TO:<to@example.com>
787RCPT TO:<author@example.com>
788RCPT TO:<one@example.com>
789RCPT TO:<two@example.com>
790RCPT TO:<committer@example.com>
cb8a9bd5
PB
791From: Example <from@example.com>
792To: to@example.com
02461e0e
JP
793Cc: A <author@example.com>,
794 One <one@example.com>,
795 two@example.com,
796 C O Mitter <committer@example.com>
cb8a9bd5
PB
797Subject: [PATCH 1/1] Second.
798Date: DATE-STRING
ba4324c4 799Message-ID: MESSAGE-ID-STRING
cb8a9bd5 800X-Mailer: X-MAILER-STRING
e67a228c 801MIME-Version: 1.0
802Content-Transfer-Encoding: 8bit
cb8a9bd5
PB
803
804Result: OK
805EOF
f9444147 806"
cb8a9bd5 807
57cd35e6 808test_expect_success $PREREQ 'sendemail.cccmd' '
acd72b56
JH
809 write_script cccmd <<-\EOF &&
810 echo cc-cmd@example.com
811 EOF
cb8a9bd5
PB
812 git config sendemail.cccmd ./cccmd &&
813 test_suppression cccmd
814'
815
f9444147 816test_expect_success $PREREQ 'setup expect' '
3531e270
JS
817cat >expected-suppress-all <<\EOF
8180001-Second.patch
819Dry-OK. Log says:
820Server: relay.example.com
821MAIL FROM:<from@example.com>
822RCPT TO:<to@example.com>
823From: Example <from@example.com>
824To: to@example.com
825Subject: [PATCH 1/1] Second.
826Date: DATE-STRING
ba4324c4 827Message-ID: MESSAGE-ID-STRING
3531e270 828X-Mailer: X-MAILER-STRING
e67a228c 829MIME-Version: 1.0
830Content-Transfer-Encoding: 8bit
3531e270
JS
831
832Result: OK
833EOF
f9444147 834'
3531e270 835
57cd35e6 836test_expect_success $PREREQ '--suppress-cc=all' '
3531e270
JS
837 test_suppression all
838'
839
f9444147 840test_expect_success $PREREQ 'setup expect' "
3531e270
JS
841cat >expected-suppress-body <<\EOF
8420001-Second.patch
843(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
844(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
845(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
cb8a9bd5 846(cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
3531e270
JS
847Dry-OK. Log says:
848Server: relay.example.com
849MAIL FROM:<from@example.com>
02461e0e
JP
850RCPT TO:<to@example.com>
851RCPT TO:<author@example.com>
852RCPT TO:<one@example.com>
853RCPT TO:<two@example.com>
854RCPT TO:<cc-cmd@example.com>
3531e270
JS
855From: Example <from@example.com>
856To: to@example.com
02461e0e
JP
857Cc: A <author@example.com>,
858 One <one@example.com>,
859 two@example.com,
860 cc-cmd@example.com
3531e270
JS
861Subject: [PATCH 1/1] Second.
862Date: DATE-STRING
ba4324c4 863Message-ID: MESSAGE-ID-STRING
3531e270 864X-Mailer: X-MAILER-STRING
e67a228c 865MIME-Version: 1.0
866Content-Transfer-Encoding: 8bit
3531e270
JS
867
868Result: OK
869EOF
f9444147 870"
3531e270 871
57cd35e6 872test_expect_success $PREREQ '--suppress-cc=body' '
3531e270
JS
873 test_suppression body
874'
875
f9444147 876test_expect_success $PREREQ 'setup expect' "
cb8a9bd5
PB
877cat >expected-suppress-body-cccmd <<\EOF
8780001-Second.patch
879(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
880(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
881(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
882Dry-OK. Log says:
883Server: relay.example.com
884MAIL FROM:<from@example.com>
02461e0e
JP
885RCPT TO:<to@example.com>
886RCPT TO:<author@example.com>
887RCPT TO:<one@example.com>
888RCPT TO:<two@example.com>
cb8a9bd5
PB
889From: Example <from@example.com>
890To: to@example.com
02461e0e
JP
891Cc: A <author@example.com>,
892 One <one@example.com>,
893 two@example.com
cb8a9bd5
PB
894Subject: [PATCH 1/1] Second.
895Date: DATE-STRING
ba4324c4 896Message-ID: MESSAGE-ID-STRING
cb8a9bd5 897X-Mailer: X-MAILER-STRING
e67a228c 898MIME-Version: 1.0
899Content-Transfer-Encoding: 8bit
cb8a9bd5
PB
900
901Result: OK
902EOF
f9444147 903"
cb8a9bd5 904
57cd35e6 905test_expect_success $PREREQ '--suppress-cc=body --suppress-cc=cccmd' '
cb8a9bd5
PB
906 test_suppression body cccmd
907'
908
f9444147 909test_expect_success $PREREQ 'setup expect' "
3531e270
JS
910cat >expected-suppress-sob <<\EOF
9110001-Second.patch
912(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
913(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
914(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
915Dry-OK. Log says:
916Server: relay.example.com
917MAIL FROM:<from@example.com>
02461e0e
JP
918RCPT TO:<to@example.com>
919RCPT TO:<author@example.com>
920RCPT TO:<one@example.com>
921RCPT TO:<two@example.com>
3531e270
JS
922From: Example <from@example.com>
923To: to@example.com
02461e0e
JP
924Cc: A <author@example.com>,
925 One <one@example.com>,
926 two@example.com
3531e270
JS
927Subject: [PATCH 1/1] Second.
928Date: DATE-STRING
ba4324c4 929Message-ID: MESSAGE-ID-STRING
3531e270 930X-Mailer: X-MAILER-STRING
e67a228c 931MIME-Version: 1.0
932Content-Transfer-Encoding: 8bit
3531e270
JS
933
934Result: OK
935EOF
f9444147 936"
3531e270 937
57cd35e6 938test_expect_success $PREREQ '--suppress-cc=sob' '
cc7e8167 939 test_might_fail git config --unset sendemail.cccmd &&
3531e270
JS
940 test_suppression sob
941'
942
f9444147 943test_expect_success $PREREQ 'setup expect' "
3531e270
JS
944cat >expected-suppress-bodycc <<\EOF
9450001-Second.patch
946(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
947(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
948(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
949(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
950Dry-OK. Log says:
951Server: relay.example.com
952MAIL FROM:<from@example.com>
02461e0e
JP
953RCPT TO:<to@example.com>
954RCPT TO:<author@example.com>
955RCPT TO:<one@example.com>
956RCPT TO:<two@example.com>
957RCPT TO:<committer@example.com>
3531e270
JS
958From: Example <from@example.com>
959To: to@example.com
02461e0e
JP
960Cc: A <author@example.com>,
961 One <one@example.com>,
962 two@example.com,
963 C O Mitter <committer@example.com>
3531e270
JS
964Subject: [PATCH 1/1] Second.
965Date: DATE-STRING
ba4324c4 966Message-ID: MESSAGE-ID-STRING
3531e270 967X-Mailer: X-MAILER-STRING
e67a228c 968MIME-Version: 1.0
969Content-Transfer-Encoding: 8bit
3531e270
JS
970
971Result: OK
972EOF
f9444147 973"
3531e270 974
57cd35e6 975test_expect_success $PREREQ '--suppress-cc=bodycc' '
3531e270
JS
976 test_suppression bodycc
977'
978
f9444147 979test_expect_success $PREREQ 'setup expect' "
3531e270
JS
980cat >expected-suppress-cc <<\EOF
9810001-Second.patch
982(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
983(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
984Dry-OK. Log says:
985Server: relay.example.com
986MAIL FROM:<from@example.com>
02461e0e
JP
987RCPT TO:<to@example.com>
988RCPT TO:<author@example.com>
989RCPT TO:<committer@example.com>
3531e270
JS
990From: Example <from@example.com>
991To: to@example.com
02461e0e
JP
992Cc: A <author@example.com>,
993 C O Mitter <committer@example.com>
3531e270
JS
994Subject: [PATCH 1/1] Second.
995Date: DATE-STRING
ba4324c4 996Message-ID: MESSAGE-ID-STRING
3531e270 997X-Mailer: X-MAILER-STRING
e67a228c 998MIME-Version: 1.0
999Content-Transfer-Encoding: 8bit
3531e270
JS
1000
1001Result: OK
1002EOF
f9444147 1003"
3531e270 1004
57cd35e6 1005test_expect_success $PREREQ '--suppress-cc=cc' '
3531e270 1006 test_suppression cc
33c592dd
MV
1007'
1008
c1f2aa45
JS
1009test_confirm () {
1010 echo y | \
1011 GIT_SEND_EMAIL_NOTTY=1 \
1012 git send-email \
1013 --from="Example <nobody@example.com>" \
1014 --to=nobody@example.com \
1015 --smtp-server="$(pwd)/fake.sendmail" \
ee756a81 1016 $@ $patches >stdout &&
c18f75a1 1017 grep "Send this email" stdout
c1f2aa45
JS
1018}
1019
57cd35e6 1020test_expect_success $PREREQ '--confirm=always' '
c1f2aa45
JS
1021 test_confirm --confirm=always --suppress-cc=all
1022'
1023
57cd35e6 1024test_expect_success $PREREQ '--confirm=auto' '
c1f2aa45
JS
1025 test_confirm --confirm=auto
1026'
1027
57cd35e6 1028test_expect_success $PREREQ '--confirm=cc' '
c1f2aa45
JS
1029 test_confirm --confirm=cc
1030'
1031
57cd35e6 1032test_expect_success $PREREQ '--confirm=compose' '
c1f2aa45
JS
1033 test_confirm --confirm=compose --compose
1034'
1035
545871bf 1036test_expect_success $PREREQ 'confirm by default (due to cc)' '
fc99da1f 1037 test_when_finished git config sendemail.confirm never &&
c1f2aa45 1038 git config --unset sendemail.confirm &&
c18f75a1 1039 test_confirm
c1f2aa45
JS
1040'
1041
57cd35e6 1042test_expect_success $PREREQ 'confirm by default (due to --compose)' '
fc99da1f 1043 test_when_finished git config sendemail.confirm never &&
c1f2aa45
JS
1044 git config --unset sendemail.confirm &&
1045 test_confirm --suppress-cc=all --compose
c1f2aa45
JS
1046'
1047
57cd35e6 1048test_expect_success $PREREQ 'confirm detects EOF (inform assumes y)' '
fc99da1f 1049 test_when_finished git config sendemail.confirm never &&
c18f75a1 1050 git config --unset sendemail.confirm &&
dc1460aa
JS
1051 rm -fr outdir &&
1052 git format-patch -2 -o outdir &&
c18f75a1
JS
1053 GIT_SEND_EMAIL_NOTTY=1 \
1054 git send-email \
1055 --from="Example <nobody@example.com>" \
1056 --to=nobody@example.com \
1057 --smtp-server="$(pwd)/fake.sendmail" \
ee756a81 1058 outdir/*.patch </dev/null
c18f75a1
JS
1059'
1060
57cd35e6 1061test_expect_success $PREREQ 'confirm detects EOF (auto causes failure)' '
fc99da1f 1062 test_when_finished git config sendemail.confirm never &&
c18f75a1 1063 git config sendemail.confirm auto &&
3b3637c3
JS
1064 GIT_SEND_EMAIL_NOTTY=1 &&
1065 export GIT_SEND_EMAIL_NOTTY &&
c18f75a1
JS
1066 test_must_fail git send-email \
1067 --from="Example <nobody@example.com>" \
1068 --to=nobody@example.com \
1069 --smtp-server="$(pwd)/fake.sendmail" \
ee756a81 1070 $patches </dev/null
c18f75a1
JS
1071'
1072
41ccfdd9 1073test_expect_success $PREREQ 'confirm does not loop forever' '
fc99da1f 1074 test_when_finished git config sendemail.confirm never &&
c18f75a1 1075 git config sendemail.confirm auto &&
3b3637c3
JS
1076 GIT_SEND_EMAIL_NOTTY=1 &&
1077 export GIT_SEND_EMAIL_NOTTY &&
1078 yes "bogus" | test_must_fail git send-email \
c18f75a1
JS
1079 --from="Example <nobody@example.com>" \
1080 --to=nobody@example.com \
1081 --smtp-server="$(pwd)/fake.sendmail" \
1082 $patches
c18f75a1
JS
1083'
1084
57cd35e6 1085test_expect_success $PREREQ 'utf8 Cc is rfc2047 encoded' '
a61c0ffa
JS
1086 clean_fake_sendmail &&
1087 rm -fr outdir &&
1088 git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
1089 git send-email \
1090 --from="Example <nobody@example.com>" \
1091 --to=nobody@example.com \
1092 --smtp-server="$(pwd)/fake.sendmail" \
1093 outdir/*.patch &&
02461e0e 1094 grep "^ " msgtxt1 |
d1fff6fc 1095 grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
a61c0ffa
JS
1096'
1097
57cd35e6 1098test_expect_success $PREREQ '--compose adds MIME for utf8 body' '
0706bd19 1099 clean_fake_sendmail &&
acd72b56
JH
1100 write_script fake-editor-utf8 <<-\EOF &&
1101 echo "utf8 body: àéìöú" >>"$1"
1102 EOF
03335f22
JH
1103 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1104 git send-email \
1105 --compose --subject foo \
1106 --from="Example <nobody@example.com>" \
1107 --to=nobody@example.com \
1108 --smtp-server="$(pwd)/fake.sendmail" \
1109 $patches &&
0706bd19 1110 grep "^utf8 body" msgtxt1 &&
d1fff6fc 1111 grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
0706bd19
JK
1112'
1113
57cd35e6 1114test_expect_success $PREREQ '--compose respects user mime type' '
0706bd19 1115 clean_fake_sendmail &&
acd72b56
JH
1116 write_script fake-editor-utf8-mime <<-\EOF &&
1117 cat >"$1" <<-\EOM
1118 MIME-Version: 1.0
1119 Content-Type: text/plain; charset=iso-8859-1
1120 Content-Transfer-Encoding: 8bit
1121 Subject: foo
1122
1123 utf8 body: àéìöú
1124 EOM
1125 EOF
03335f22
JH
1126 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
1127 git send-email \
1128 --compose --subject foo \
1129 --from="Example <nobody@example.com>" \
1130 --to=nobody@example.com \
1131 --smtp-server="$(pwd)/fake.sendmail" \
1132 $patches &&
0706bd19
JK
1133 grep "^utf8 body" msgtxt1 &&
1134 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
d1fff6fc 1135 ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
0706bd19
JK
1136'
1137
57cd35e6 1138test_expect_success $PREREQ '--compose adds MIME for utf8 subject' '
d54eaaa2 1139 clean_fake_sendmail &&
03335f22
JH
1140 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
1141 git send-email \
1142 --compose --subject utf8-sübjëct \
1143 --from="Example <nobody@example.com>" \
1144 --to=nobody@example.com \
1145 --smtp-server="$(pwd)/fake.sendmail" \
1146 $patches &&
d54eaaa2 1147 grep "^fake edit" msgtxt1 &&
d1fff6fc 1148 grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
d54eaaa2
JK
1149'
1150
b622d4d1
TR
1151test_expect_success $PREREQ 'utf8 author is correctly passed on' '
1152 clean_fake_sendmail &&
1153 test_commit weird_author &&
1154 test_when_finished "git reset --hard HEAD^" &&
1155 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
1156 git format-patch --stdout -1 >funny_name.patch &&
1157 git send-email --from="Example <nobody@example.com>" \
03335f22
JH
1158 --to=nobody@example.com \
1159 --smtp-server="$(pwd)/fake.sendmail" \
1160 funny_name.patch &&
b622d4d1
TR
1161 grep "^From: Füñný Nâmé <odd_?=mail@example.com>" msgtxt1
1162'
1163
4cb46bdd 1164test_expect_success $PREREQ 'utf8 sender is not duplicated' '
f07075c2
MT
1165 clean_fake_sendmail &&
1166 test_commit weird_sender &&
1167 test_when_finished "git reset --hard HEAD^" &&
1168 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
1169 git format-patch --stdout -1 >funny_name.patch &&
1170 git send-email --from="Füñný Nâmé <odd_?=mail@example.com>" \
03335f22
JH
1171 --to=nobody@example.com \
1172 --smtp-server="$(pwd)/fake.sendmail" \
1173 funny_name.patch &&
f07075c2
MT
1174 grep "^From: " msgtxt1 >msgfrom &&
1175 test_line_count = 1 msgfrom
1176'
1177
62e00690
KM
1178test_expect_success $PREREQ 'sendemail.composeencoding works' '
1179 clean_fake_sendmail &&
1180 git config sendemail.composeencoding iso-8859-1 &&
acd72b56
JH
1181 write_script fake-editor-utf8 <<-\EOF &&
1182 echo "utf8 body: àéìöú" >>"$1"
1183 EOF
03335f22
JH
1184 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1185 git send-email \
1186 --compose --subject foo \
1187 --from="Example <nobody@example.com>" \
1188 --to=nobody@example.com \
1189 --smtp-server="$(pwd)/fake.sendmail" \
1190 $patches &&
62e00690
KM
1191 grep "^utf8 body" msgtxt1 &&
1192 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1193'
1194
1195test_expect_success $PREREQ '--compose-encoding works' '
1196 clean_fake_sendmail &&
acd72b56
JH
1197 write_script fake-editor-utf8 <<-\EOF &&
1198 echo "utf8 body: àéìöú" >>"$1"
1199 EOF
03335f22
JH
1200 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1201 git send-email \
1202 --compose-encoding iso-8859-1 \
1203 --compose --subject foo \
1204 --from="Example <nobody@example.com>" \
1205 --to=nobody@example.com \
1206 --smtp-server="$(pwd)/fake.sendmail" \
1207 $patches &&
62e00690
KM
1208 grep "^utf8 body" msgtxt1 &&
1209 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1210'
1211
1212test_expect_success $PREREQ '--compose-encoding overrides sendemail.composeencoding' '
1213 clean_fake_sendmail &&
1214 git config sendemail.composeencoding iso-8859-1 &&
acd72b56
JH
1215 write_script fake-editor-utf8 <<-\EOF &&
1216 echo "utf8 body: àéìöú" >>"$1"
1217 EOF
03335f22
JH
1218 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1219 git send-email \
1220 --compose-encoding iso-8859-2 \
1221 --compose --subject foo \
1222 --from="Example <nobody@example.com>" \
1223 --to=nobody@example.com \
1224 --smtp-server="$(pwd)/fake.sendmail" \
1225 $patches &&
62e00690
KM
1226 grep "^utf8 body" msgtxt1 &&
1227 grep "^Content-Type: text/plain; charset=iso-8859-2" msgtxt1
1228'
1229
4a47a4dd
KM
1230test_expect_success $PREREQ '--compose-encoding adds correct MIME for subject' '
1231 clean_fake_sendmail &&
03335f22
JH
1232 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
1233 git send-email \
1234 --compose-encoding iso-8859-2 \
1235 --compose --subject utf8-sübjëct \
1236 --from="Example <nobody@example.com>" \
1237 --to=nobody@example.com \
1238 --smtp-server="$(pwd)/fake.sendmail" \
1239 $patches &&
4a47a4dd
KM
1240 grep "^fake edit" msgtxt1 &&
1241 grep "^Subject: =?iso-8859-2?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
1242'
1243
57cd35e6 1244test_expect_success $PREREQ 'detects ambiguous reference/file conflict' '
a881baa2
JS
1245 echo main >main &&
1246 git add main &&
1247 git commit -m"add main" &&
1248 test_must_fail git send-email --dry-run main 2>errors &&
5df9fcf6
PH
1249 grep disambiguate errors
1250'
1251
57cd35e6 1252test_expect_success $PREREQ 'feed two files' '
69f4ce55
JH
1253 rm -fr outdir &&
1254 git format-patch -2 -o outdir &&
c1f2aa45 1255 git send-email \
03335f22
JH
1256 --dry-run \
1257 --from="Example <nobody@example.com>" \
1258 --to=nobody@example.com \
1259 outdir/000?-*.patch 2>errors >out &&
69f4ce55
JH
1260 grep "^Subject: " out >subjects &&
1261 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
a881baa2 1262 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add main"
69f4ce55
JH
1263'
1264
57cd35e6 1265test_expect_success $PREREQ 'in-reply-to but no threading' '
aaab4b9f
TR
1266 git send-email \
1267 --dry-run \
1268 --from="Example <nobody@example.com>" \
1269 --to=nobody@example.com \
1270 --in-reply-to="<in-reply-id@example.com>" \
f4714943 1271 --no-thread \
de26f02d
JS
1272 $patches >out &&
1273 grep "In-Reply-To: <in-reply-id@example.com>" out
aaab4b9f
TR
1274'
1275
57cd35e6 1276test_expect_success $PREREQ 'no in-reply-to and no threading' '
32ae8319
MH
1277 git send-email \
1278 --dry-run \
1279 --from="Example <nobody@example.com>" \
1280 --to=nobody@example.com \
f4714943 1281 --no-thread \
2554dd1a 1282 $patches >stdout &&
32ae8319
MH
1283 ! grep "In-Reply-To: " stdout
1284'
1285
57cd35e6 1286test_expect_success $PREREQ 'threading but no chain-reply-to' '
d67114a5
MH
1287 git send-email \
1288 --dry-run \
1289 --from="Example <nobody@example.com>" \
1290 --to=nobody@example.com \
1291 --thread \
f4714943 1292 --no-chain-reply-to \
d67114a5
MH
1293 $patches $patches >stdout &&
1294 grep "In-Reply-To: " stdout
1295'
1296
f9f60d70
RA
1297test_expect_success $PREREQ 'override in-reply-to if no threading' '
1298 git send-email \
1299 --dry-run \
1300 --from="Example <nobody@example.com>" \
1301 --to=nobody@example.com \
1302 --no-thread \
1303 --in-reply-to="override" \
1304 $threaded_patches >stdout &&
1305 grep "In-Reply-To: <override>" stdout
1306'
1307
57cd35e6 1308test_expect_success $PREREQ 'sendemail.to works' '
f434c083
SB
1309 git config --replace-all sendemail.to "Somebody <somebody@ex.com>" &&
1310 git send-email \
1311 --dry-run \
1312 --from="Example <nobody@example.com>" \
2554dd1a 1313 $patches >stdout &&
f434c083
SB
1314 grep "To: Somebody <somebody@ex.com>" stdout
1315'
1316
3ff15040
ÆAB
1317test_expect_success $PREREQ 'setup sendemail.identity' '
1318 git config --replace-all sendemail.to "default@example.com" &&
1319 git config --replace-all sendemail.isp.to "isp@example.com" &&
1320 git config --replace-all sendemail.cloud.to "cloud@example.com"
1321'
1322
1323test_expect_success $PREREQ 'sendemail.identity: reads the correct identity config' '
1324 git -c sendemail.identity=cloud send-email \
1325 --dry-run \
1326 --from="nobody@example.com" \
1327 $patches >stdout &&
1328 grep "To: cloud@example.com" stdout
1329'
1330
1331test_expect_success $PREREQ 'sendemail.identity: identity overrides sendemail.identity' '
1332 git -c sendemail.identity=cloud send-email \
1333 --identity=isp \
1334 --dry-run \
1335 --from="nobody@example.com" \
1336 $patches >stdout &&
1337 grep "To: isp@example.com" stdout
1338'
1339
1340test_expect_success $PREREQ 'sendemail.identity: --no-identity clears previous identity' '
1341 git -c sendemail.identity=cloud send-email \
1342 --no-identity \
1343 --dry-run \
1344 --from="nobody@example.com" \
1345 $patches >stdout &&
1346 grep "To: default@example.com" stdout
1347'
1348
4dc8b1c1 1349test_expect_success $PREREQ 'sendemail.identity: bool identity variable existence overrides' '
3ff15040
ÆAB
1350 git -c sendemail.identity=cloud \
1351 -c sendemail.xmailer=true \
1352 -c sendemail.cloud.xmailer=false \
1353 send-email \
1354 --dry-run \
1355 --from="nobody@example.com" \
1356 $patches >stdout &&
1357 grep "To: cloud@example.com" stdout &&
1358 ! grep "X-Mailer" stdout
1359'
1360
1361test_expect_success $PREREQ 'sendemail.identity: bool variable fallback' '
1362 git -c sendemail.identity=cloud \
1363 -c sendemail.xmailer=false \
1364 send-email \
1365 --dry-run \
1366 --from="nobody@example.com" \
1367 $patches >stdout &&
1368 grep "To: cloud@example.com" stdout &&
1369 ! grep "X-Mailer" stdout
1370'
1371
879be431
ÆAB
1372test_expect_success $PREREQ 'sendemail.identity: bool variable without a value' '
1373 git -c sendemail.xmailer \
1374 send-email \
1375 --dry-run \
1376 --from="nobody@example.com" \
1377 $patches >stdout &&
1378 grep "To: default@example.com" stdout &&
1379 grep "X-Mailer" stdout
1380'
1381
57cd35e6 1382test_expect_success $PREREQ '--no-to overrides sendemail.to' '
f434c083
SB
1383 git send-email \
1384 --dry-run \
1385 --from="Example <nobody@example.com>" \
1386 --no-to \
1387 --to=nobody@example.com \
2554dd1a 1388 $patches >stdout &&
f434c083
SB
1389 grep "To: nobody@example.com" stdout &&
1390 ! grep "To: Somebody <somebody@ex.com>" stdout
1391'
1392
57cd35e6 1393test_expect_success $PREREQ 'sendemail.cc works' '
f434c083
SB
1394 git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" &&
1395 git send-email \
1396 --dry-run \
1397 --from="Example <nobody@example.com>" \
1398 --to=nobody@example.com \
2554dd1a 1399 $patches >stdout &&
f434c083
SB
1400 grep "Cc: Somebody <somebody@ex.com>" stdout
1401'
1402
57cd35e6 1403test_expect_success $PREREQ '--no-cc overrides sendemail.cc' '
f434c083
SB
1404 git send-email \
1405 --dry-run \
1406 --from="Example <nobody@example.com>" \
1407 --no-cc \
1408 --cc=bodies@example.com \
1409 --to=nobody@example.com \
2554dd1a 1410 $patches >stdout &&
f434c083
SB
1411 grep "Cc: bodies@example.com" stdout &&
1412 ! grep "Cc: Somebody <somebody@ex.com>" stdout
1413'
1414
57cd35e6 1415test_expect_success $PREREQ 'sendemail.bcc works' '
f434c083
SB
1416 git config --replace-all sendemail.bcc "Other <other@ex.com>" &&
1417 git send-email \
1418 --dry-run \
1419 --from="Example <nobody@example.com>" \
1420 --to=nobody@example.com \
1421 --smtp-server relay.example.com \
2554dd1a 1422 $patches >stdout &&
f434c083
SB
1423 grep "RCPT TO:<other@ex.com>" stdout
1424'
1425
57cd35e6 1426test_expect_success $PREREQ '--no-bcc overrides sendemail.bcc' '
f434c083
SB
1427 git send-email \
1428 --dry-run \
1429 --from="Example <nobody@example.com>" \
1430 --no-bcc \
1431 --bcc=bodies@example.com \
1432 --to=nobody@example.com \
1433 --smtp-server relay.example.com \
2554dd1a 1434 $patches >stdout &&
f434c083
SB
1435 grep "RCPT TO:<bodies@example.com>" stdout &&
1436 ! grep "RCPT TO:<other@ex.com>" stdout
1437'
1438
21802cd3 1439test_expect_success $PREREQ 'patches To headers are used by default' '
bdf20f5e 1440 patch=$(git format-patch -1 --to="bodies@example.com") &&
21802cd3
SB
1441 test_when_finished "rm $patch" &&
1442 git send-email \
1443 --dry-run \
1444 --from="Example <nobody@example.com>" \
1445 --smtp-server relay.example.com \
1446 $patch >stdout &&
1447 grep "RCPT TO:<bodies@example.com>" stdout
1448'
1449
1450test_expect_success $PREREQ 'patches To headers are appended to' '
bdf20f5e 1451 patch=$(git format-patch -1 --to="bodies@example.com") &&
21802cd3
SB
1452 test_when_finished "rm $patch" &&
1453 git send-email \
1454 --dry-run \
1455 --from="Example <nobody@example.com>" \
1456 --to=nobody@example.com \
1457 --smtp-server relay.example.com \
1458 $patch >stdout &&
1459 grep "RCPT TO:<bodies@example.com>" stdout &&
1460 grep "RCPT TO:<nobody@example.com>" stdout
1461'
1462
3c3bb51c 1463test_expect_success $PREREQ 'To headers from files reset each patch' '
bdf20f5e
EP
1464 patch1=$(git format-patch -1 --to="bodies@example.com") &&
1465 patch2=$(git format-patch -1 --to="other@example.com" HEAD~) &&
3c3bb51c
SB
1466 test_when_finished "rm $patch1 && rm $patch2" &&
1467 git send-email \
1468 --dry-run \
1469 --from="Example <nobody@example.com>" \
1470 --to="nobody@example.com" \
1471 --smtp-server relay.example.com \
1472 $patch1 $patch2 >stdout &&
1473 test $(grep -c "RCPT TO:<bodies@example.com>" stdout) = 1 &&
1474 test $(grep -c "RCPT TO:<nobody@example.com>" stdout) = 2 &&
1475 test $(grep -c "RCPT TO:<other@example.com>" stdout) = 1
1476'
1477
f9444147 1478test_expect_success $PREREQ 'setup expect' '
0720a51b 1479cat >email-using-8bit <<\EOF
3cae7e5b 1480From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
ba4324c4 1481Message-ID: <bogus-message-id@example.com>
3cae7e5b
TR
1482From: author@example.com
1483Date: Sat, 12 Jun 2010 15:53:58 +0200
1484Subject: subject goes here
1485
1486Dieser deutsche Text enthält einen Umlaut!
1487EOF
f9444147 1488'
3cae7e5b 1489
5637d857 1490test_expect_success $PREREQ 'setup expect' '
0720a51b 1491 echo "Subject: subject goes here" >expected
5637d857
KM
1492'
1493
1494test_expect_success $PREREQ 'ASCII subject is not RFC2047 quoted' '
1495 clean_fake_sendmail &&
1496 echo bogus |
1497 git send-email --from=author@example.com --to=nobody@example.com \
1498 --smtp-server="$(pwd)/fake.sendmail" \
1499 --8bit-encoding=UTF-8 \
1500 email-using-8bit >stdout &&
1501 grep "Subject" msgtxt1 >actual &&
1502 test_cmp expected actual
1503'
1504
f9444147 1505test_expect_success $PREREQ 'setup expect' '
0720a51b
JH
1506 cat >content-type-decl <<-\EOF
1507 MIME-Version: 1.0
1508 Content-Type: text/plain; charset=UTF-8
1509 Content-Transfer-Encoding: 8bit
1510 EOF
f9444147 1511'
3cae7e5b 1512
57cd35e6 1513test_expect_success $PREREQ 'asks about and fixes 8bit encodings' '
3cae7e5b
TR
1514 clean_fake_sendmail &&
1515 echo |
1516 git send-email --from=author@example.com --to=nobody@example.com \
1517 --smtp-server="$(pwd)/fake.sendmail" \
1518 email-using-8bit >stdout &&
1519 grep "do not declare a Content-Transfer-Encoding" stdout &&
1520 grep email-using-8bit stdout &&
1521 grep "Which 8bit encoding" stdout &&
81580fa0 1522 grep -E "Content|MIME" msgtxt1 >actual &&
9c5b2fab 1523 test_cmp content-type-decl actual
3cae7e5b
TR
1524'
1525
57cd35e6 1526test_expect_success $PREREQ 'sendemail.8bitEncoding works' '
3cae7e5b
TR
1527 clean_fake_sendmail &&
1528 git config sendemail.assume8bitEncoding UTF-8 &&
1529 echo bogus |
1530 git send-email --from=author@example.com --to=nobody@example.com \
1531 --smtp-server="$(pwd)/fake.sendmail" \
1532 email-using-8bit >stdout &&
81580fa0 1533 grep -E "Content|MIME" msgtxt1 >actual &&
9c5b2fab 1534 test_cmp content-type-decl actual
3cae7e5b
TR
1535'
1536
b996f849
ÆAB
1537test_expect_success $PREREQ 'sendemail.8bitEncoding in .git/config overrides --global .gitconfig' '
1538 clean_fake_sendmail &&
1539 git config sendemail.assume8bitEncoding UTF-8 &&
1540 test_when_finished "rm -rf home" &&
1541 mkdir home &&
1542 git config -f home/.gitconfig sendemail.assume8bitEncoding "bogus too" &&
1543 echo bogus |
1544 env HOME="$(pwd)/home" DEBUG=1 \
1545 git send-email --from=author@example.com --to=nobody@example.com \
1546 --smtp-server="$(pwd)/fake.sendmail" \
1547 email-using-8bit >stdout &&
81580fa0 1548 grep -E "Content|MIME" msgtxt1 >actual &&
b996f849
ÆAB
1549 test_cmp content-type-decl actual
1550'
1551
57cd35e6 1552test_expect_success $PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
3cae7e5b
TR
1553 clean_fake_sendmail &&
1554 git config sendemail.assume8bitEncoding "bogus too" &&
1555 echo bogus |
1556 git send-email --from=author@example.com --to=nobody@example.com \
1557 --smtp-server="$(pwd)/fake.sendmail" \
1558 --8bit-encoding=UTF-8 \
1559 email-using-8bit >stdout &&
81580fa0 1560 grep -E "Content|MIME" msgtxt1 >actual &&
9c5b2fab 1561 test_cmp content-type-decl actual
3cae7e5b
TR
1562'
1563
f9444147 1564test_expect_success $PREREQ 'setup expect' '
0720a51b
JH
1565 cat >email-using-8bit <<-\EOF
1566 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
ba4324c4 1567 Message-ID: <bogus-message-id@example.com>
0720a51b
JH
1568 From: author@example.com
1569 Date: Sat, 12 Jun 2010 15:53:58 +0200
1570 Subject: Dieser Betreff enthält auch einen Umlaut!
1571
1572 Nothing to see here.
1573 EOF
f9444147 1574'
3cae7e5b 1575
f9444147 1576test_expect_success $PREREQ 'setup expect' '
0720a51b
JH
1577 cat >expected <<-\EOF
1578 Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
1579 EOF
f9444147 1580'
3cae7e5b 1581
57cd35e6 1582test_expect_success $PREREQ '--8bit-encoding also treats subject' '
3cae7e5b
TR
1583 clean_fake_sendmail &&
1584 echo bogus |
1585 git send-email --from=author@example.com --to=nobody@example.com \
1586 --smtp-server="$(pwd)/fake.sendmail" \
1587 --8bit-encoding=UTF-8 \
1588 email-using-8bit >stdout &&
1589 grep "Subject" msgtxt1 >actual &&
1590 test_cmp expected actual
1591'
1592
8d814084 1593test_expect_success $PREREQ 'setup expect' '
0720a51b
JH
1594 cat >email-using-8bit <<-\EOF
1595 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
ba4324c4 1596 Message-ID: <bogus-message-id@example.com>
0720a51b
JH
1597 From: A U Thor <author@example.com>
1598 Date: Sat, 12 Jun 2010 15:53:58 +0200
1599 Content-Type: text/plain; charset=UTF-8
1600 Subject: Nothing to see here.
1601
1602 Dieser Betreff enthält auch einen Umlaut!
1603 EOF
8d814084
PB
1604'
1605
a8aea5db 1606test_expect_success $PREREQ '--transfer-encoding overrides sendemail.transferEncoding' '
8d814084 1607 clean_fake_sendmail &&
a8aea5db
ÆAB
1608 test_must_fail git -c sendemail.transferEncoding=8bit \
1609 send-email \
03335f22
JH
1610 --transfer-encoding=7bit \
1611 --smtp-server="$(pwd)/fake.sendmail" \
1612 email-using-8bit \
1613 2>errors >out &&
8d814084
PB
1614 grep "cannot send message as 7bit" errors &&
1615 test -z "$(ls msgtxt*)"
1616'
1617
a8aea5db 1618test_expect_success $PREREQ 'sendemail.transferEncoding via config' '
8d814084 1619 clean_fake_sendmail &&
a8aea5db
ÆAB
1620 test_must_fail git -c sendemail.transferEncoding=7bit \
1621 send-email \
03335f22
JH
1622 --smtp-server="$(pwd)/fake.sendmail" \
1623 email-using-8bit \
1624 2>errors >out &&
8d814084
PB
1625 grep "cannot send message as 7bit" errors &&
1626 test -z "$(ls msgtxt*)"
1627'
1628
a8aea5db 1629test_expect_success $PREREQ 'sendemail.transferEncoding via cli' '
8d814084 1630 clean_fake_sendmail &&
a8aea5db
ÆAB
1631 test_must_fail git send-email \
1632 --transfer-encoding=7bit \
03335f22
JH
1633 --smtp-server="$(pwd)/fake.sendmail" \
1634 email-using-8bit \
1635 2>errors >out &&
a8aea5db
ÆAB
1636 grep "cannot send message as 7bit" errors &&
1637 test -z "$(ls msgtxt*)"
8d814084
PB
1638'
1639
1640test_expect_success $PREREQ 'setup expect' '
0720a51b
JH
1641 cat >expected <<-\EOF
1642 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1643 EOF
8d814084
PB
1644'
1645
1646test_expect_success $PREREQ '8-bit and sendemail.transferencoding=quoted-printable' '
1647 clean_fake_sendmail &&
1648 git send-email \
03335f22
JH
1649 --transfer-encoding=quoted-printable \
1650 --smtp-server="$(pwd)/fake.sendmail" \
1651 email-using-8bit \
1652 2>errors >out &&
c76b84a1 1653 sed "1,/^$/d" msgtxt1 >actual &&
8d814084
PB
1654 test_cmp expected actual
1655'
1656
1657test_expect_success $PREREQ 'setup expect' '
0720a51b
JH
1658 cat >expected <<-\EOF
1659 RGllc2VyIEJldHJlZmYgZW50aMOkbHQgYXVjaCBlaW5lbiBVbWxhdXQhCg==
1660 EOF
8d814084
PB
1661'
1662
1663test_expect_success $PREREQ '8-bit and sendemail.transferencoding=base64' '
1664 clean_fake_sendmail &&
1665 git send-email \
03335f22
JH
1666 --transfer-encoding=base64 \
1667 --smtp-server="$(pwd)/fake.sendmail" \
1668 email-using-8bit \
1669 2>errors >out &&
c76b84a1 1670 sed "1,/^$/d" msgtxt1 >actual &&
8d814084
PB
1671 test_cmp expected actual
1672'
1673
1674test_expect_success $PREREQ 'setup expect' '
0720a51b
JH
1675 cat >email-using-qp <<-\EOF
1676 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
ba4324c4 1677 Message-ID: <bogus-message-id@example.com>
0720a51b
JH
1678 From: A U Thor <author@example.com>
1679 Date: Sat, 12 Jun 2010 15:53:58 +0200
1680 MIME-Version: 1.0
1681 Content-Transfer-Encoding: quoted-printable
1682 Content-Type: text/plain; charset=UTF-8
1683 Subject: Nothing to see here.
8d814084 1684
0720a51b
JH
1685 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1686 EOF
8d814084
PB
1687'
1688
1689test_expect_success $PREREQ 'convert from quoted-printable to base64' '
1690 clean_fake_sendmail &&
1691 git send-email \
03335f22
JH
1692 --transfer-encoding=base64 \
1693 --smtp-server="$(pwd)/fake.sendmail" \
1694 email-using-qp \
1695 2>errors >out &&
c76b84a1 1696 sed "1,/^$/d" msgtxt1 >actual &&
8d814084
PB
1697 test_cmp expected actual
1698'
1699
1700test_expect_success $PREREQ 'setup expect' "
ee756a81 1701tr -d '\\015' | tr '%' '\\015' >email-using-crlf <<EOF
8d814084 1702From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
ba4324c4 1703Message-ID: <bogus-message-id@example.com>
8d814084
PB
1704From: A U Thor <author@example.com>
1705Date: Sat, 12 Jun 2010 15:53:58 +0200
1706Content-Type: text/plain; charset=UTF-8
1707Subject: Nothing to see here.
1708
1709Look, I have a CRLF and an = sign!%
1710EOF
1711"
1712
1713test_expect_success $PREREQ 'setup expect' '
0720a51b
JH
1714 cat >expected <<-\EOF
1715 Look, I have a CRLF and an =3D sign!=0D
1716 EOF
8d814084
PB
1717'
1718
1719test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=quoted-printable' '
1720 clean_fake_sendmail &&
1721 git send-email \
03335f22
JH
1722 --transfer-encoding=quoted-printable \
1723 --smtp-server="$(pwd)/fake.sendmail" \
1724 email-using-crlf \
1725 2>errors >out &&
c76b84a1 1726 sed "1,/^$/d" msgtxt1 >actual &&
8d814084
PB
1727 test_cmp expected actual
1728'
1729
1730test_expect_success $PREREQ 'setup expect' '
0720a51b
JH
1731 cat >expected <<-\EOF
1732 TG9vaywgSSBoYXZlIGEgQ1JMRiBhbmQgYW4gPSBzaWduIQ0K
1733 EOF
8d814084
PB
1734'
1735
1736test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=base64' '
1737 clean_fake_sendmail &&
1738 git send-email \
03335f22
JH
1739 --transfer-encoding=base64 \
1740 --smtp-server="$(pwd)/fake.sendmail" \
1741 email-using-crlf \
1742 2>errors >out &&
c76b84a1 1743 sed "1,/^$/d" msgtxt1 >actual &&
8d814084
PB
1744 test_cmp expected actual
1745'
1746
1747
a03bc5b6
TR
1748# Note that the patches in this test are deliberately out of order; we
1749# want to make sure it works even if the cover-letter is not in the
1750# first mail.
57da2042 1751test_expect_success $PREREQ 'refusing to send cover letter template' '
a03bc5b6
TR
1752 clean_fake_sendmail &&
1753 rm -fr outdir &&
1754 git format-patch --cover-letter -2 -o outdir &&
1755 test_must_fail git send-email \
03335f22
JH
1756 --from="Example <nobody@example.com>" \
1757 --to=nobody@example.com \
1758 --smtp-server="$(pwd)/fake.sendmail" \
1759 outdir/0002-*.patch \
1760 outdir/0000-*.patch \
1761 outdir/0001-*.patch \
1762 2>errors >out &&
a03bc5b6
TR
1763 grep "SUBJECT HERE" errors &&
1764 test -z "$(ls msgtxt*)"
1765'
1766
57da2042 1767test_expect_success $PREREQ '--force sends cover letter template anyway' '
a03bc5b6
TR
1768 clean_fake_sendmail &&
1769 rm -fr outdir &&
1770 git format-patch --cover-letter -2 -o outdir &&
1771 git send-email \
03335f22
JH
1772 --force \
1773 --from="Example <nobody@example.com>" \
1774 --to=nobody@example.com \
1775 --smtp-server="$(pwd)/fake.sendmail" \
1776 outdir/0002-*.patch \
1777 outdir/0000-*.patch \
1778 outdir/0001-*.patch \
1779 2>errors >out &&
a03bc5b6
TR
1780 ! grep "SUBJECT HERE" errors &&
1781 test -n "$(ls msgtxt*)"
1782'
1783
8ccc4e42
MT
1784test_cover_addresses () {
1785 header="$1"
1786 shift
1787 clean_fake_sendmail &&
1788 rm -fr outdir &&
1789 git format-patch --cover-letter -2 -o outdir &&
bdf20f5e 1790 cover=$(echo outdir/0000-*.patch) &&
8ccc4e42 1791 mv $cover cover-to-edit.patch &&
35ec002c 1792 perl -pe "s/^From:/$header: extra\@address.com\nFrom:/" cover-to-edit.patch >"$cover" &&
8ccc4e42 1793 git send-email \
03335f22
JH
1794 --force \
1795 --from="Example <nobody@example.com>" \
1796 --no-to --no-cc \
1797 "$@" \
1798 --smtp-server="$(pwd)/fake.sendmail" \
1799 outdir/0000-*.patch \
1800 outdir/0001-*.patch \
1801 outdir/0002-*.patch \
1802 2>errors >out &&
8ccc4e42
MT
1803 grep "^$header: extra@address.com" msgtxt1 >to1 &&
1804 grep "^$header: extra@address.com" msgtxt2 >to2 &&
1805 grep "^$header: extra@address.com" msgtxt3 >to3 &&
1806 test_line_count = 1 to1 &&
1807 test_line_count = 1 to2 &&
1808 test_line_count = 1 to3
1809}
1810
1811test_expect_success $PREREQ 'to-cover adds To to all mail' '
1812 test_cover_addresses "To" --to-cover
1813'
1814
1815test_expect_success $PREREQ 'cc-cover adds Cc to all mail' '
1816 test_cover_addresses "Cc" --cc-cover
1817'
1818
1819test_expect_success $PREREQ 'tocover adds To to all mail' '
1820 test_config sendemail.tocover true &&
1821 test_cover_addresses "To"
1822'
1823
1824test_expect_success $PREREQ 'cccover adds Cc to all mail' '
1825 test_config sendemail.cccover true &&
1826 test_cover_addresses "Cc"
1827'
1828
2c510f21
EW
1829test_expect_success $PREREQ 'escaped quotes in sendemail.aliasfiletype=mutt' '
1830 clean_fake_sendmail &&
1831 echo "alias sbd \\\"Dot U. Sir\\\" <somebody@example.org>" >.mutt &&
1832 git config --replace-all sendemail.aliasesfile "$(pwd)/.mutt" &&
1833 git config sendemail.aliasfiletype mutt &&
1834 git send-email \
1835 --from="Example <nobody@example.com>" \
1836 --to=sbd \
1837 --smtp-server="$(pwd)/fake.sendmail" \
1838 outdir/0001-*.patch \
1839 2>errors >out &&
1840 grep "^!somebody@example\.org!$" commandline1 &&
1841 grep -F "To: \"Dot U. Sir\" <somebody@example.org>" out
1842'
1843
463b0ea2
CS
1844test_expect_success $PREREQ 'sendemail.aliasfiletype=mailrc' '
1845 clean_fake_sendmail &&
1846 echo "alias sbd somebody@example.org" >.mailrc &&
1847 git config --replace-all sendemail.aliasesfile "$(pwd)/.mailrc" &&
1848 git config sendemail.aliasfiletype mailrc &&
1849 git send-email \
03335f22
JH
1850 --from="Example <nobody@example.com>" \
1851 --to=sbd \
1852 --smtp-server="$(pwd)/fake.sendmail" \
1853 outdir/0001-*.patch \
1854 2>errors >out &&
463b0ea2
CS
1855 grep "^!somebody@example\.org!$" commandline1
1856'
1857
6fc53692 1858test_expect_success $PREREQ 'sendemail.aliasesfile=~/.mailrc' '
463b0ea2 1859 clean_fake_sendmail &&
587089c1 1860 echo "alias sbd someone@example.org" >"$HOME/.mailrc" &&
463b0ea2
CS
1861 git config --replace-all sendemail.aliasesfile "~/.mailrc" &&
1862 git config sendemail.aliasfiletype mailrc &&
1863 git send-email \
03335f22
JH
1864 --from="Example <nobody@example.com>" \
1865 --to=sbd \
1866 --smtp-server="$(pwd)/fake.sendmail" \
1867 outdir/0001-*.patch \
1868 2>errors >out &&
463b0ea2
CS
1869 grep "^!someone@example\.org!$" commandline1
1870'
1871
17b7a832
JK
1872test_dump_aliases () {
1873 msg="$1" && shift &&
1874 filetype="$1" && shift &&
1875 printf '%s\n' "$@" >expect &&
1876 cat >.tmp-email-aliases &&
1877
1878 test_expect_success $PREREQ "$msg" '
1879 clean_fake_sendmail && rm -fr outdir &&
1880 git config --replace-all sendemail.aliasesfile \
1881 "$(pwd)/.tmp-email-aliases" &&
1882 git config sendemail.aliasfiletype "$filetype" &&
1883 git send-email --dump-aliases 2>errors >actual &&
1884 test_cmp expect actual
1885 '
1886}
1887
1888test_dump_aliases '--dump-aliases sendmail format' \
1889 'sendmail' \
1890 'abgroup' \
1891 'alice' \
1892 'bcgrp' \
1893 'bob' \
1894 'chloe' <<-\EOF
1895 alice: Alice W Land <awol@example.com>
1896 bob: Robert Bobbyton <bob@example.com>
1897 chloe: chloe@example.com
1898 abgroup: alice, bob
1899 bcgrp: bob, chloe, Other <o@example.com>
1900 EOF
1901
1902test_dump_aliases '--dump-aliases mutt format' \
1903 'mutt' \
1904 'alice' \
1905 'bob' \
1906 'chloe' \
1907 'donald' <<-\EOF
1908 alias alice Alice W Land <awol@example.com>
1909 alias donald Donald C Carlton <donc@example.com>
1910 alias bob Robert Bobbyton <bob@example.com>
1911 alias chloe chloe@example.com
1912 EOF
1913
1914test_dump_aliases '--dump-aliases mailrc format' \
1915 'mailrc' \
1916 'alice' \
1917 'bob' \
1918 'chloe' \
1919 'eve' <<-\EOF
1920 alias alice Alice W Land <awol@example.com>
1921 alias eve Eve <eve@example.com>
1922 alias bob Robert Bobbyton <bob@example.com>
1923 alias chloe chloe@example.com
1924 EOF
1925
1926test_dump_aliases '--dump-aliases pine format' \
1927 'pine' \
1928 'alice' \
1929 'bob' \
1930 'chloe' \
1931 'eve' <<-\EOF
1932 alice Alice W Land <awol@example.com>
1933 eve Eve <eve@example.com>
1934 bob Robert Bobbyton <bob@example.com>
1935 chloe chloe@example.com
1936 EOF
1937
1938test_dump_aliases '--dump-aliases gnus format' \
1939 'gnus' \
1940 'alice' \
1941 'bob' \
1942 'chloe' \
1943 'eve' <<-\EOF
1944 (define-mail-alias "alice" "awol@example.com")
1945 (define-mail-alias "eve" "eve@example.com")
1946 (define-mail-alias "bob" "bob@example.com")
1947 (define-mail-alias "chloe" "chloe@example.com")
1948 EOF
1949
1950test_expect_success '--dump-aliases must be used alone' '
1951 test_must_fail git send-email --dump-aliases --to=janice@example.com -1 refs/heads/accounting
1952'
1953
3ff15040
ÆAB
1954test_expect_success $PREREQ 'aliases and sendemail.identity' '
1955 test_must_fail git \
1956 -c sendemail.identity=cloud \
1957 -c sendemail.aliasesfile=default-aliases \
1958 -c sendemail.cloud.aliasesfile=cloud-aliases \
1959 send-email -1 2>stderr &&
1960 test_i18ngrep "cloud-aliases" stderr
1961'
1962
514554cf
ES
1963test_sendmail_aliases () {
1964 msg="$1" && shift &&
1965 expect="$@" &&
1966 cat >.tmp-email-aliases &&
1967
1968 test_expect_success $PREREQ "$msg" '
1969 clean_fake_sendmail && rm -fr outdir &&
1970 git format-patch -1 -o outdir &&
1971 git config --replace-all sendemail.aliasesfile \
1972 "$(pwd)/.tmp-email-aliases" &&
1973 git config sendemail.aliasfiletype sendmail &&
1974 git send-email \
1975 --from="Example <nobody@example.com>" \
1976 --to=alice --to=bcgrp \
1977 --smtp-server="$(pwd)/fake.sendmail" \
1978 outdir/0001-*.patch \
1979 2>errors >out &&
1980 for i in $expect
1981 do
1982 grep "^!$i!$" commandline1 || return 1
1983 done
1984 '
1985}
1986
1987test_sendmail_aliases 'sendemail.aliasfiletype=sendmail' \
1988 'awol@example\.com' \
1989 'bob@example\.com' \
1990 'chloe@example\.com' \
1991 'o@example\.com' <<-\EOF
3169e06d
AH
1992 alice: Alice W Land <awol@example.com>
1993 bob: Robert Bobbyton <bob@example.com>
1994 # this is a comment
1995 # this is also a comment
1996 chloe: chloe@example.com
1997 abgroup: alice, bob
1998 bcgrp: bob, chloe, Other <o@example.com>
1999 EOF
3169e06d 2000
6be02640
ES
2001test_sendmail_aliases 'sendmail aliases line folding' \
2002 alice1 \
2003 bob1 bob2 \
2004 chuck1 chuck2 \
2005 darla1 darla2 darla3 \
2006 elton1 elton2 elton3 \
2007 fred1 fred2 \
2008 greg1 <<-\EOF
2009 alice: alice1
2010 bob: bob1,\
2011 bob2
2012 chuck: chuck1,
2013 chuck2
2014 darla: darla1,\
2015 darla2,
2016 darla3
2017 elton: elton1,
2018 elton2,\
2019 elton3
2020 fred: fred1,\
2021 fred2
2022 greg: greg1
2023 bcgrp: bob, chuck, darla, elton, fred, greg
2024 EOF
2025
2026test_sendmail_aliases 'sendmail aliases tolerate bogus line folding' \
2027 alice1 bob1 <<-\EOF
2028 alice: alice1
2029 bcgrp: bob1\
2030 EOF
2031
2032test_sendmail_aliases 'sendmail aliases empty' alice bcgrp <<-\EOF
2033 EOF
2034
f6f79e5e
RL
2035test_expect_success $PREREQ 'alias support in To header' '
2036 clean_fake_sendmail &&
2037 echo "alias sbd someone@example.org" >.mailrc &&
2038 test_config sendemail.aliasesfile ".mailrc" &&
2039 test_config sendemail.aliasfiletype mailrc &&
2040 git format-patch --stdout -1 --to=sbd >aliased.patch &&
2041 git send-email \
2042 --from="Example <nobody@example.com>" \
2043 --smtp-server="$(pwd)/fake.sendmail" \
2044 aliased.patch \
2045 2>errors >out &&
2046 grep "^!someone@example\.org!$" commandline1
2047'
2048
2049test_expect_success $PREREQ 'alias support in Cc header' '
2050 clean_fake_sendmail &&
2051 echo "alias sbd someone@example.org" >.mailrc &&
2052 test_config sendemail.aliasesfile ".mailrc" &&
2053 test_config sendemail.aliasfiletype mailrc &&
2054 git format-patch --stdout -1 --cc=sbd >aliased.patch &&
2055 git send-email \
2056 --from="Example <nobody@example.com>" \
2057 --smtp-server="$(pwd)/fake.sendmail" \
2058 aliased.patch \
2059 2>errors >out &&
2060 grep "^!someone@example\.org!$" commandline1
2061'
2062
2063test_expect_success $PREREQ 'tocmd works with aliases' '
2064 clean_fake_sendmail &&
2065 echo "alias sbd someone@example.org" >.mailrc &&
2066 test_config sendemail.aliasesfile ".mailrc" &&
2067 test_config sendemail.aliasfiletype mailrc &&
2068 git format-patch --stdout -1 >tocmd.patch &&
2069 echo tocmd--sbd >>tocmd.patch &&
2070 git send-email \
2071 --from="Example <nobody@example.com>" \
2072 --to-cmd=./tocmd-sed \
2073 --smtp-server="$(pwd)/fake.sendmail" \
2074 tocmd.patch \
2075 2>errors >out &&
2076 grep "^!someone@example\.org!$" commandline1
2077'
2078
2079test_expect_success $PREREQ 'cccmd works with aliases' '
2080 clean_fake_sendmail &&
2081 echo "alias sbd someone@example.org" >.mailrc &&
2082 test_config sendemail.aliasesfile ".mailrc" &&
2083 test_config sendemail.aliasfiletype mailrc &&
2084 git format-patch --stdout -1 >cccmd.patch &&
2085 echo cccmd--sbd >>cccmd.patch &&
2086 git send-email \
2087 --from="Example <nobody@example.com>" \
2088 --cc-cmd=./cccmd-sed \
2089 --smtp-server="$(pwd)/fake.sendmail" \
2090 cccmd.patch \
2091 2>errors >out &&
2092 grep "^!someone@example\.org!$" commandline1
2093'
2094
2cf770f5
LH
2095do_xmailer_test () {
2096 expected=$1 params=$2 &&
2097 git format-patch -1 &&
2098 git send-email \
2099 --from="Example <nobody@example.com>" \
2100 --to=someone@example.com \
2101 --smtp-server="$(pwd)/fake.sendmail" \
2102 $params \
2103 0001-*.patch \
2104 2>errors >out &&
2105 { grep '^X-Mailer:' out || :; } >mailer &&
2106 test_line_count = $expected mailer
2107}
2108
2109test_expect_success $PREREQ '--[no-]xmailer without any configuration' '
2110 do_xmailer_test 1 "--xmailer" &&
2111 do_xmailer_test 0 "--no-xmailer"
2112'
2113
2114test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=true' '
2115 test_config sendemail.xmailer true &&
2116 do_xmailer_test 1 "" &&
2117 do_xmailer_test 0 "--no-xmailer" &&
2118 do_xmailer_test 1 "--xmailer"
2119'
2120
879be431
ÆAB
2121test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer' '
2122 test_when_finished "test_unconfig sendemail.xmailer" &&
2123 cat >>.git/config <<-\EOF &&
2124 [sendemail]
2125 xmailer
2126 EOF
2127 test_config sendemail.xmailer true &&
2128 do_xmailer_test 1 "" &&
2129 do_xmailer_test 0 "--no-xmailer" &&
2130 do_xmailer_test 1 "--xmailer"
2131'
2132
2cf770f5
LH
2133test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=false' '
2134 test_config sendemail.xmailer false &&
2135 do_xmailer_test 0 "" &&
2136 do_xmailer_test 0 "--no-xmailer" &&
2137 do_xmailer_test 1 "--xmailer"
2138'
2139
879be431
ÆAB
2140test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=' '
2141 test_config sendemail.xmailer "" &&
2142 do_xmailer_test 0 "" &&
2143 do_xmailer_test 0 "--no-xmailer" &&
2144 do_xmailer_test 1 "--xmailer"
2145'
2146
b1c8a11c
RL
2147test_expect_success $PREREQ 'setup expected-list' '
2148 git send-email \
2149 --dry-run \
2150 --from="Example <from@example.com>" \
2151 --to="To 1 <to1@example.com>" \
2152 --to="to2@example.com" \
2153 --to="to3@example.com" \
2154 --cc="Cc 1 <cc1@example.com>" \
2155 --cc="Cc2 <cc2@example.com>" \
2156 --bcc="bcc1@example.com" \
2157 --bcc="bcc2@example.com" \
a881baa2 2158 0001-add-main.patch | replace_variable_fields \
b1c8a11c
RL
2159 >expected-list
2160'
2161
2162test_expect_success $PREREQ 'use email list in --cc --to and --bcc' '
2163 git send-email \
2164 --dry-run \
2165 --from="Example <from@example.com>" \
2166 --to="To 1 <to1@example.com>, to2@example.com" \
2167 --to="to3@example.com" \
2168 --cc="Cc 1 <cc1@example.com>, Cc2 <cc2@example.com>" \
2169 --bcc="bcc1@example.com, bcc2@example.com" \
a881baa2 2170 0001-add-main.patch | replace_variable_fields \
b1c8a11c
RL
2171 >actual-list &&
2172 test_cmp expected-list actual-list
2173'
2174
2175test_expect_success $PREREQ 'aliases work with email list' '
2176 echo "alias to2 to2@example.com" >.mutt &&
2177 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt &&
2178 test_config sendemail.aliasesfile ".mutt" &&
2179 test_config sendemail.aliasfiletype mutt &&
2180 git send-email \
2181 --dry-run \
2182 --from="Example <from@example.com>" \
2183 --to="To 1 <to1@example.com>, to2, to3@example.com" \
2184 --cc="cc1, Cc2 <cc2@example.com>" \
2185 --bcc="bcc1@example.com, bcc2@example.com" \
a881baa2 2186 0001-add-main.patch | replace_variable_fields \
b1c8a11c
RL
2187 >actual-list &&
2188 test_cmp expected-list actual-list
2189'
2190
fa5b1aa9
RL
2191test_expect_success $PREREQ 'leading and trailing whitespaces are removed' '
2192 echo "alias to2 to2@example.com" >.mutt &&
2193 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt &&
2194 test_config sendemail.aliasesfile ".mutt" &&
2195 test_config sendemail.aliasfiletype mutt &&
2196 TO1=$(echo "QTo 1 <to1@example.com>" | q_to_tab) &&
2197 TO2=$(echo "QZto2" | qz_to_tab_space) &&
2198 CC1=$(echo "cc1" | append_cr) &&
c64368e3 2199 BCC1=$(echo " bcc1@example.com Q" | q_to_nul) &&
fa5b1aa9
RL
2200 git send-email \
2201 --dry-run \
2202 --from=" Example <from@example.com>" \
2203 --to="$TO1" \
2204 --to="$TO2" \
2205 --to=" to3@example.com " \
2206 --cc="$CC1" \
2207 --cc="Cc2 <cc2@example.com>" \
2208 --bcc="$BCC1" \
2209 --bcc="bcc2@example.com" \
a881baa2 2210 0001-add-main.patch | replace_variable_fields \
fa5b1aa9
RL
2211 >actual-list &&
2212 test_cmp expected-list actual-list
2213'
2214
cd5b33fb
GA
2215test_expect_success $PREREQ 'test using command name with --sendmail-cmd' '
2216 clean_fake_sendmail &&
f6a5af0f 2217 PATH="$PWD:$PATH" \
cd5b33fb
GA
2218 git send-email \
2219 --from="Example <nobody@example.com>" \
2220 --to=nobody@example.com \
2221 --sendmail-cmd="fake.sendmail" \
2222 HEAD^ &&
2223 test_path_is_file commandline1
2224'
2225
2226test_expect_success $PREREQ 'test using arguments with --sendmail-cmd' '
2227 clean_fake_sendmail &&
2228 git send-email \
2229 --from="Example <nobody@example.com>" \
2230 --to=nobody@example.com \
2231 --sendmail-cmd='\''"$(pwd)/fake.sendmail" -f nobody@example.com'\'' \
2232 HEAD^ &&
2233 test_path_is_file commandline1
2234'
2235
2236test_expect_success $PREREQ 'test shell expression with --sendmail-cmd' '
2237 clean_fake_sendmail &&
2238 git send-email \
2239 --from="Example <nobody@example.com>" \
2240 --to=nobody@example.com \
2241 --sendmail-cmd='\''f() { "$(pwd)/fake.sendmail" "$@"; };f'\'' \
2242 HEAD^ &&
2243 test_path_is_file commandline1
2244'
2245
e0821134
MH
2246test_expect_success $PREREQ 'set up in-reply-to/references patches' '
2247 cat >has-reply.patch <<-\EOF &&
2248 From: A U Thor <author@example.com>
2249 Subject: patch with in-reply-to
2250 Message-ID: <patch.with.in.reply.to@example.com>
2251 In-Reply-To: <replied.to@example.com>
2252 References: <replied.to@example.com>
2253
2254 This is the body.
2255 EOF
2256 cat >no-reply.patch <<-\EOF
2257 From: A U Thor <author@example.com>
2258 Subject: patch without in-reply-to
2259 Message-ID: <patch.without.in.reply.to@example.com>
2260
2261 This is the body.
2262 EOF
2263'
2264
2265test_expect_success $PREREQ 'patch reply headers correct with --no-thread' '
2266 clean_fake_sendmail &&
2267 git send-email \
2268 --no-thread \
2269 --to=nobody@example.com \
2270 --smtp-server="$(pwd)/fake.sendmail" \
2271 has-reply.patch no-reply.patch &&
2272 grep "In-Reply-To: <replied.to@example.com>" msgtxt1 &&
2273 grep "References: <replied.to@example.com>" msgtxt1 &&
2274 ! grep replied.to@example.com msgtxt2
2275'
2276
2277test_expect_success $PREREQ 'cmdline in-reply-to used with --no-thread' '
2278 clean_fake_sendmail &&
2279 git send-email \
2280 --no-thread \
2281 --in-reply-to="<cmdline.reply@example.com>" \
2282 --to=nobody@example.com \
2283 --smtp-server="$(pwd)/fake.sendmail" \
2284 has-reply.patch no-reply.patch &&
2285 grep "In-Reply-To: <cmdline.reply@example.com>" msgtxt1 &&
2286 grep "References: <cmdline.reply@example.com>" msgtxt1 &&
2287 grep "In-Reply-To: <cmdline.reply@example.com>" msgtxt2 &&
2288 grep "References: <cmdline.reply@example.com>" msgtxt2
2289'
2290
6489660b 2291test_expect_success $PREREQ 'invoke hook' '
bef805b7 2292 test_hook sendemail-validate <<-\EOF &&
6489660b
JT
2293 # test that we have the correct environment variable, pwd, and
2294 # argument
2295 case "$GIT_DIR" in
2296 *.git)
2297 true
2298 ;;
2299 *)
2300 false
2301 ;;
2302 esac &&
a881baa2
JS
2303 test -f 0001-add-main.patch &&
2304 grep "add main" "$1"
6489660b
JT
2305 EOF
2306
2307 mkdir subdir &&
2308 (
2309 # Test that it works even if we are not at the root of the
2310 # working tree
2311 cd subdir &&
2312 git send-email \
2313 --from="Example <nobody@example.com>" \
2314 --to=nobody@example.com \
2315 --smtp-server="$(pwd)/../fake.sendmail" \
a881baa2 2316 ../0001-add-main.patch &&
6489660b
JT
2317
2318 # Verify error message when a patch is rejected by the hook
a881baa2 2319 sed -e "s/add main/x/" ../0001-add-main.patch >../another.patch &&
be8c48d4 2320 test_must_fail git send-email \
6489660b
JT
2321 --from="Example <nobody@example.com>" \
2322 --to=nobody@example.com \
2323 --smtp-server="$(pwd)/../fake.sendmail" \
be8c48d4 2324 ../another.patch 2>err &&
6489660b
JT
2325 test_i18ngrep "rejected by sendemail-validate hook" err
2326 )
2327'
2328
3c8d3ade
RJ
2329expected_file_counter_output () {
2330 total=$1
2331 count=0
2332 while test $count -ne $total
2333 do
2334 count=$((count + 1)) &&
2335 echo "$count/$total" || return
2336 done
2337}
2338
2339test_expect_success $PREREQ '--validate hook allows counting of messages' '
2340 test_when_finished "rm -rf my-hooks.log" &&
2341 test_config core.hooksPath "my-hooks" &&
2342 mkdir -p my-hooks &&
2343
2344 write_script my-hooks/sendemail-validate <<-\EOF &&
2345 num=$GIT_SENDEMAIL_FILE_COUNTER &&
2346 tot=$GIT_SENDEMAIL_FILE_TOTAL &&
2347 echo "$num/$tot" >>my-hooks.log || exit 1
2348 EOF
2349
2350 >my-hooks.log &&
2351 expected_file_counter_output 4 >expect &&
2352 git send-email \
2353 --from="Example <from@example.com>" \
2354 --to=nobody@example.com \
2355 --smtp-server="$(pwd)/fake.sendmail" \
2356 --validate -3 --cover-letter --force &&
2357 test_cmp expect my-hooks.log
2358'
2359
177409e5
JT
2360test_expect_success $PREREQ 'test that send-email works outside a repo' '
2361 nongit git send-email \
2362 --from="Example <nobody@example.com>" \
2363 --to=nobody@example.com \
2364 --smtp-server="$(pwd)/fake.sendmail" \
a881baa2 2365 "$(pwd)/0001-add-main.patch"
177409e5
JT
2366'
2367
8774aa56
KM
2368test_expect_success $PREREQ 'send-email relays -v 3 to format-patch' '
2369 test_when_finished "rm -f out" &&
2370 git send-email --dry-run -v 3 -1 >out &&
2371 grep "PATCH v3" out
2372'
2373
dd84e528
DD
2374test_expect_success $PREREQ 'test that sendmail config is rejected' '
2375 test_config sendmail.program sendmail &&
2376 test_must_fail git send-email \
2377 --from="Example <nobody@example.com>" \
2378 --to=nobody@example.com \
2379 --smtp-server="$(pwd)/fake.sendmail" \
2380 HEAD^ 2>err &&
2381 test_i18ngrep "found configuration options for '"'"sendmail"'"'" err
2382'
2383
2384test_expect_success $PREREQ 'test that sendmail config rejection is specific' '
2385 test_config resendmail.program sendmail &&
2386 git send-email \
2387 --from="Example <nobody@example.com>" \
2388 --to=nobody@example.com \
2389 --smtp-server="$(pwd)/fake.sendmail" \
2390 HEAD^
2391'
2392
2393test_expect_success $PREREQ 'test forbidSendmailVariables behavior override' '
2394 test_config sendmail.program sendmail &&
2395 test_config sendemail.forbidSendmailVariables false &&
2396 git send-email \
2397 --from="Example <nobody@example.com>" \
2398 --to=nobody@example.com \
2399 --smtp-server="$(pwd)/fake.sendmail" \
2400 HEAD^
2401'
2402
ce903018 2403test_done