]> git.ipfire.org Git - thirdparty/git.git/blame - t/t9001-send-email.sh
The third batch
[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
cfa12094 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 49 patches=$(git format-patch -s --cc="One <one@example.com>" --cc=two@example.com -n HEAD^1) &&
3ece9bf0 50 threaded_patches=$(git format-patch -o threaded --thread=shallow -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 &&
b46d806e
OB
64 ! grep "Send this email" stdout &&
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" &&
c016726c 340 echo "my-message-id@example.com"
0da43a68
JS
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 &&
c016726c
JK
346 grep "^To: to@example.com\$" msgtxt1 &&
347 grep "^In-Reply-To: <my-message-id@example.com>" msgtxt1
0da43a68
JS
348'
349
59defcc3
JK
350test_expect_success $PREREQ,AUTOIDENT 'implicit ident is allowed' '
351 clean_fake_sendmail &&
352 (sane_unset GIT_AUTHOR_NAME &&
353 sane_unset GIT_AUTHOR_EMAIL &&
354 sane_unset GIT_COMMITTER_NAME &&
355 sane_unset GIT_COMMITTER_EMAIL &&
356 GIT_SEND_EMAIL_NOTTY=1 git send-email \
357 --smtp-server="$(pwd)/fake.sendmail" \
358 --to=to@example.com \
359 $patches </dev/null 2>errors
360 )
361'
362
363test_expect_success $PREREQ,!AUTOIDENT 'broken implicit ident aborts send-email' '
364 clean_fake_sendmail &&
365 (sane_unset GIT_AUTHOR_NAME &&
366 sane_unset GIT_AUTHOR_EMAIL &&
367 sane_unset GIT_COMMITTER_NAME &&
368 sane_unset GIT_COMMITTER_EMAIL &&
369 GIT_SEND_EMAIL_NOTTY=1 && export GIT_SEND_EMAIL_NOTTY &&
370 test_must_fail git send-email \
371 --smtp-server="$(pwd)/fake.sendmail" \
372 --to=to@example.com \
373 $patches </dev/null 2>errors &&
6789275d 374 test_grep "tell me who you are" errors
59defcc3
JK
375 )
376'
377
ba92106e 378test_expect_success $PREREQ 'setup cmd scripts' '
62089fb8
RL
379 write_script tocmd-sed <<-\EOF &&
380 sed -n -e "s/^tocmd--//p" "$1"
381 EOF
ba92106e 382 write_script cccmd-sed <<-\EOF &&
62089fb8
RL
383 sed -n -e "s/^cccmd--//p" "$1"
384 EOF
ba92106e
MC
385 write_script headercmd-sed <<-\EOF
386 sed -n -e "s/^headercmd--//p" "$1"
387 EOF
62089fb8
RL
388'
389
6e74e075
JP
390test_expect_success $PREREQ 'tocmd works' '
391 clean_fake_sendmail &&
392 cp $patches tocmd.patch &&
393 echo tocmd--tocmd@example.com >>tocmd.patch &&
6e74e075
JP
394 git send-email \
395 --from="Example <nobody@example.com>" \
396 --to-cmd=./tocmd-sed \
397 --smtp-server="$(pwd)/fake.sendmail" \
398 tocmd.patch \
399 &&
400 grep "^To: tocmd@example.com" msgtxt1
401'
402
57cd35e6 403test_expect_success $PREREQ 'cccmd works' '
cb8a9bd5
PB
404 clean_fake_sendmail &&
405 cp $patches cccmd.patch &&
41ae8f1d 406 echo "cccmd-- cccmd@example.com" >>cccmd.patch &&
cb8a9bd5
PB
407 git send-email \
408 --from="Example <nobody@example.com>" \
409 --to=nobody@example.com \
410 --cc-cmd=./cccmd-sed \
411 --smtp-server="$(pwd)/fake.sendmail" \
412 cccmd.patch \
413 &&
02461e0e 414 grep "^ cccmd@example.com" msgtxt1
cb8a9bd5
PB
415'
416
ba92106e
MC
417test_expect_success $PREREQ 'headercmd works' '
418 clean_fake_sendmail &&
419 cp $patches headercmd.patch &&
420 echo "headercmd--X-Debbugs-CC: dummy@example.com" >>headercmd.patch &&
421 git send-email \
422 --from="Example <nobody@example.com>" \
423 --to=nobody@example.com \
424 --header-cmd=./headercmd-sed \
425 --smtp-server="$(pwd)/fake.sendmail" \
426 headercmd.patch \
427 &&
428 grep "^X-Debbugs-CC: dummy@example.com" msgtxt1
429'
430
431test_expect_success $PREREQ '--no-header-cmd works' '
432 clean_fake_sendmail &&
433 cp $patches headercmd.patch &&
434 echo "headercmd--X-Debbugs-CC: dummy@example.com" >>headercmd.patch &&
435 git send-email \
436 --from="Example <nobody@example.com>" \
437 --to=nobody@example.com \
438 --header-cmd=./headercmd-sed \
439 --no-header-cmd \
440 --smtp-server="$(pwd)/fake.sendmail" \
441 headercmd.patch \
442 &&
443 ! grep "^X-Debbugs-CC: dummy@example.com" msgtxt1
444'
445
446test_expect_success $PREREQ 'multiline fields are correctly unfolded' '
447 clean_fake_sendmail &&
448 cp $patches headercmd.patch &&
449 write_script headercmd-multiline <<-\EOF &&
450 echo "X-Debbugs-CC: someone@example.com
451FoldedField: This is a tale
452 best told using
453 multiple lines."
454 EOF
455 git send-email \
456 --from="Example <nobody@example.com>" \
457 --to=nobody@example.com \
458 --header-cmd=./headercmd-multiline \
459 --smtp-server="$(pwd)/fake.sendmail" \
460 headercmd.patch &&
461 grep "^FoldedField: This is a tale best told using multiple lines.$" msgtxt1
462'
463
3a7a18a0
MC
464# Blank lines in the middle of the output of a command are invalid.
465test_expect_success $PREREQ 'malform output reported on blank lines in command output' '
466 clean_fake_sendmail &&
467 cp $patches headercmd.patch &&
468 write_script headercmd-malformed-output <<-\EOF &&
469 echo "X-Debbugs-CC: someone@example.com
470
471SomeOtherField: someone-else@example.com"
472 EOF
473 ! git send-email \
474 --from="Example <nobody@example.com>" \
475 --to=nobody@example.com \
476 --header-cmd=./headercmd-malformed-output \
477 --smtp-server="$(pwd)/fake.sendmail" \
478 headercmd.patch
479'
480
57cd35e6 481test_expect_success $PREREQ 'reject long lines' '
f9444147
ÆAB
482 z8=zzzzzzzz &&
483 z64=$z8$z8$z8$z8$z8$z8$z8$z8 &&
484 z512=$z64$z64$z64$z64$z64$z64$z64$z64 &&
6d34a2ba 485 clean_fake_sendmail &&
747bbff9 486 cp $patches longline.patch &&
ea7811b3
ÆAB
487 cat >>longline.patch <<-EOF &&
488 $z512$z512
489 not a long line
490 $z512$z512
491 EOF
d492b31c 492 test_must_fail git send-email \
747bbff9
JK
493 --from="Example <nobody@example.com>" \
494 --to=nobody@example.com \
495 --smtp-server="$(pwd)/fake.sendmail" \
e67a228c 496 --transfer-encoding=8bit \
747bbff9 497 $patches longline.patch \
e585210e
ÆAB
498 2>actual &&
499 cat >expect <<-\EOF &&
ea7811b3 500 fatal: longline.patch:35 is longer than 998 characters
e585210e
ÆAB
501 warning: no patches were sent
502 EOF
503 test_cmp expect actual
747bbff9
JK
504'
505
57cd35e6 506test_expect_success $PREREQ 'no patch was sent' '
6d34a2ba 507 ! test -e commandline1
747bbff9
JK
508'
509
57cd35e6 510test_expect_success $PREREQ 'Author From: in message body' '
5012699d
JS
511 clean_fake_sendmail &&
512 git send-email \
513 --from="Example <nobody@example.com>" \
514 --to=nobody@example.com \
515 --smtp-server="$(pwd)/fake.sendmail" \
516 $patches &&
ee756a81 517 sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
5012699d
JS
518 grep "From: A <author@example.com>" msgbody1
519'
520
57cd35e6 521test_expect_success $PREREQ 'Author From: not in message body' '
5012699d
JS
522 clean_fake_sendmail &&
523 git send-email \
524 --from="A <author@example.com>" \
525 --to=nobody@example.com \
526 --smtp-server="$(pwd)/fake.sendmail" \
527 $patches &&
ee756a81 528 sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
5012699d
JS
529 ! grep "From: A <author@example.com>" msgbody1
530'
531
57cd35e6 532test_expect_success $PREREQ 'allow long lines with --no-validate' '
c764a0c2
JK
533 git send-email \
534 --from="Example <nobody@example.com>" \
535 --to=nobody@example.com \
536 --smtp-server="$(pwd)/fake.sendmail" \
f4714943 537 --no-validate \
c764a0c2
JK
538 $patches longline.patch \
539 2>errors
540'
541
7a36987f 542test_expect_success $PREREQ 'short lines with auto encoding are 8bit' '
543 clean_fake_sendmail &&
544 git send-email \
545 --from="A <author@example.com>" \
546 --to=nobody@example.com \
547 --smtp-server="$(pwd)/fake.sendmail" \
548 --transfer-encoding=auto \
549 $patches &&
550 grep "Content-Transfer-Encoding: 8bit" msgtxt1
551'
552
553test_expect_success $PREREQ 'long lines with auto encoding are quoted-printable' '
554 clean_fake_sendmail &&
555 git send-email \
556 --from="Example <nobody@example.com>" \
557 --to=nobody@example.com \
558 --smtp-server="$(pwd)/fake.sendmail" \
559 --transfer-encoding=auto \
560 --no-validate \
561 longline.patch &&
562 grep "Content-Transfer-Encoding: quoted-printable" msgtxt1
563'
564
74d76a17 565test_expect_success $PREREQ 'carriage returns with auto encoding are quoted-printable' '
566 clean_fake_sendmail &&
567 cp $patches cr.patch &&
568 printf "this is a line\r\n" >>cr.patch &&
569 git send-email \
570 --from="Example <nobody@example.com>" \
571 --to=nobody@example.com \
572 --smtp-server="$(pwd)/fake.sendmail" \
573 --transfer-encoding=auto \
574 --no-validate \
575 cr.patch &&
576 grep "Content-Transfer-Encoding: quoted-printable" msgtxt1
577'
578
f2d06fb1 579for enc in auto quoted-printable base64
580do
581 test_expect_success $PREREQ "--validate passes with encoding $enc" '
582 git send-email \
583 --from="Example <nobody@example.com>" \
584 --to=nobody@example.com \
585 --smtp-server="$(pwd)/fake.sendmail" \
586 --transfer-encoding=$enc \
587 --validate \
588 $patches longline.patch
589 '
3c88e46f
AL
590
591done
592
c8243933
RF
593test_expect_success $PREREQ "--validate respects relative core.hooksPath path" '
594 clean_fake_sendmail &&
595 mkdir my-hooks &&
596 test_when_finished "rm my-hooks.ran" &&
597 write_script my-hooks/sendemail-validate <<-\EOF &&
598 >my-hooks.ran
599 exit 1
600 EOF
601 test_config core.hooksPath "my-hooks" &&
602 test_must_fail git send-email \
603 --from="Example <nobody@example.com>" \
604 --to=nobody@example.com \
605 --smtp-server="$(pwd)/fake.sendmail" \
606 --validate \
e585210e 607 longline.patch 2>actual &&
c8243933 608 test_path_is_file my-hooks.ran &&
ea7811b3 609 cat >expect <<-EOF &&
e585210e 610 fatal: longline.patch: rejected by sendemail-validate hook
a8022c5f 611 fatal: command '"'"'git hook run --ignore-missing sendemail-validate -- <patch> <header>'"'"' died with exit code 1
e585210e
ÆAB
612 warning: no patches were sent
613 EOF
614 test_cmp expect actual
c8243933
RF
615'
616
617test_expect_success $PREREQ "--validate respects absolute core.hooksPath path" '
2815326f
ÆAB
618 hooks_path="$(pwd)/my-hooks" &&
619 test_config core.hooksPath "$hooks_path" &&
c8243933
RF
620 test_when_finished "rm my-hooks.ran" &&
621 test_must_fail git send-email \
622 --from="Example <nobody@example.com>" \
623 --to=nobody@example.com \
624 --smtp-server="$(pwd)/fake.sendmail" \
625 --validate \
e585210e 626 longline.patch 2>actual &&
c8243933 627 test_path_is_file my-hooks.ran &&
ea7811b3 628 cat >expect <<-EOF &&
e585210e 629 fatal: longline.patch: rejected by sendemail-validate hook
a8022c5f 630 fatal: command '"'"'git hook run --ignore-missing sendemail-validate -- <patch> <header>'"'"' died with exit code 1
e585210e
ÆAB
631 warning: no patches were sent
632 EOF
633 test_cmp expect actual
c8243933
RF
634'
635
0d864703
MS
636test_expect_success $PREREQ "--validate hook supports multiple addresses in arguments" '
637 hooks_path="$(pwd)/my-hooks" &&
638 test_config core.hooksPath "$hooks_path" &&
639 test_when_finished "rm my-hooks.ran" &&
640 test_must_fail git send-email \
641 --from="Example <nobody@example.com>" \
642 --to=nobody@example.com,abc@example.com \
643 --smtp-server="$(pwd)/fake.sendmail" \
644 --validate \
645 longline.patch 2>actual &&
646 test_path_is_file my-hooks.ran &&
647 cat >expect <<-EOF &&
648 fatal: longline.patch: rejected by sendemail-validate hook
649 fatal: command '"'"'git hook run --ignore-missing sendemail-validate -- <patch> <header>'"'"' died with exit code 1
e585210e
ÆAB
650 warning: no patches were sent
651 EOF
652 test_cmp expect actual
c8243933
RF
653'
654
a8022c5f
MS
655test_expect_success $PREREQ "--validate hook supports header argument" '
656 write_script my-hooks/sendemail-validate <<-\EOF &&
657 if test "$#" -ge 2
658 then
659 grep "X-test-header: v1.0" "$2"
660 else
661 echo "No header arg passed"
662 exit 1
663 fi
664 EOF
665 test_config core.hooksPath "my-hooks" &&
666 rm -fr outdir &&
667 git format-patch \
668 --add-header="X-test-header: v1.0" \
669 -n HEAD^1 -o outdir &&
670 git send-email \
671 --dry-run \
672 --to=nobody@example.com \
673 --smtp-server="$(pwd)/fake.sendmail" \
674 --validate \
675 outdir/000?-*.patch
676'
677
3ece9bf0
JH
678test_expect_success $PREREQ 'clear message-id before parsing a new message' '
679 clean_fake_sendmail &&
680 echo true | write_script my-hooks/sendemail-validate &&
681 test_config core.hooksPath my-hooks &&
3ece9bf0
JH
682 git send-email --validate --to=recipient@example.com \
683 --smtp-server="$(pwd)/fake.sendmail" \
684 $patches $threaded_patches &&
685 id0=$(grep "^Message-ID: " $threaded_patches) &&
686 id1=$(grep "^Message-ID: " msgtxt1) &&
687 id2=$(grep "^Message-ID: " msgtxt2) &&
688 test "z$id0" = "z$id2" &&
689 test "z$id1" != "z$id2"
690'
691
3c88e46f
AL
692for enc in 7bit 8bit quoted-printable base64
693do
694 test_expect_success $PREREQ "--transfer-encoding=$enc produces correct header" '
695 clean_fake_sendmail &&
696 git send-email \
697 --from="Example <nobody@example.com>" \
698 --to=nobody@example.com \
699 --smtp-server="$(pwd)/fake.sendmail" \
700 --transfer-encoding=$enc \
701 $patches &&
702 grep "Content-Transfer-Encoding: $enc" msgtxt1
703 '
f2d06fb1 704done
705
57cd35e6 706test_expect_success $PREREQ 'Invalid In-Reply-To' '
6d34a2ba 707 clean_fake_sendmail &&
0fb7fc75
JS
708 git send-email \
709 --from="Example <nobody@example.com>" \
710 --to=nobody@example.com \
711 --in-reply-to=" " \
712 --smtp-server="$(pwd)/fake.sendmail" \
5b57413c 713 $patches \
cc7e8167 714 2>errors &&
6d34a2ba 715 ! grep "^In-Reply-To: < *>" msgtxt1
0fb7fc75
JS
716'
717
57cd35e6 718test_expect_success $PREREQ 'Valid In-Reply-To when prompting' '
6d34a2ba 719 clean_fake_sendmail &&
cff4243d
ES
720 (echo "From Example <from@example.com>" &&
721 echo "To Example <to@example.com>" &&
0fb7fc75 722 echo ""
6eca18ca 723 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
0fb7fc75
JS
724 --smtp-server="$(pwd)/fake.sendmail" \
725 $patches 2>errors &&
6d34a2ba 726 ! grep "^In-Reply-To: < *>" msgtxt1
0fb7fc75
JS
727'
728
54aae5e1
JH
729test_expect_success $PREREQ 'In-Reply-To without --chain-reply-to' '
730 clean_fake_sendmail &&
731 echo "<unique-message-id@example.com>" >expect &&
732 git send-email \
733 --from="Example <nobody@example.com>" \
734 --to=nobody@example.com \
f4714943 735 --no-chain-reply-to \
54aae5e1
JH
736 --in-reply-to="$(cat expect)" \
737 --smtp-server="$(pwd)/fake.sendmail" \
738 $patches $patches $patches \
739 2>errors &&
db54c8e7 740 # The first message is a reply to --in-reply-to
54aae5e1
JH
741 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
742 test_cmp expect actual &&
db54c8e7 743 # Second and subsequent messages are replies to the first one
ba4324c4 744 sed -n -e "s/^Message-ID: *\(.*\)/\1/p" msgtxt1 >expect &&
54aae5e1
JH
745 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
746 test_cmp expect actual &&
747 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
748 test_cmp expect actual
749'
750
751test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' '
752 clean_fake_sendmail &&
753 echo "<unique-message-id@example.com>" >expect &&
754 git send-email \
755 --from="Example <nobody@example.com>" \
756 --to=nobody@example.com \
757 --chain-reply-to \
758 --in-reply-to="$(cat expect)" \
759 --smtp-server="$(pwd)/fake.sendmail" \
760 $patches $patches $patches \
761 2>errors &&
762 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
763 test_cmp expect actual &&
ba4324c4 764 sed -n -e "s/^Message-ID: *\(.*\)/\1/p" msgtxt1 >expect &&
54aae5e1
JH
765 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
766 test_cmp expect actual &&
ba4324c4 767 sed -n -e "s/^Message-ID: *\(.*\)/\1/p" msgtxt2 >expect &&
54aae5e1
JH
768 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
769 test_cmp expect actual
770'
771
5b719b75
ÆAB
772test_set_editor "$(pwd)/fake-editor"
773
774test_expect_success $PREREQ 'setup erroring fake editor' '
775 write_script fake-editor <<-\EOF
776 echo >&2 "I am about to error"
777 exit 1
778 EOF
779'
780
781test_expect_success $PREREQ 'fake editor dies with error' '
782 clean_fake_sendmail &&
783 test_must_fail git send-email \
784 --compose --subject foo \
785 --from="Example <nobody@example.com>" \
786 --to=nobody@example.com \
787 --smtp-server="$(pwd)/fake.sendmail" \
788 $patches 2>err &&
789 grep "I am about to error" err &&
790 grep "the editor exited uncleanly, aborting everything" err
791'
792
57cd35e6 793test_expect_success $PREREQ 'setup fake editor' '
acd72b56
JH
794 write_script fake-editor <<-\EOF
795 echo fake edit >>"$1"
796 EOF
8a8bf469
JK
797'
798
57cd35e6 799test_expect_success $PREREQ '--compose works' '
8a8bf469 800 clean_fake_sendmail &&
c1f2aa45
JS
801 git send-email \
802 --compose --subject foo \
803 --from="Example <nobody@example.com>" \
804 --to=nobody@example.com \
805 --smtp-server="$(pwd)/fake.sendmail" \
806 $patches \
807 2>errors
8a8bf469
JK
808'
809
57cd35e6 810test_expect_success $PREREQ 'first message is compose text' '
8a8bf469
JK
811 grep "^fake edit" msgtxt1
812'
813
57cd35e6 814test_expect_success $PREREQ 'second message is patch' '
8a8bf469
JK
815 grep "Subject:.*Second" msgtxt2
816'
817
f9444147 818test_expect_success $PREREQ 'setup expect' "
3531e270 819cat >expected-suppress-sob <<\EOF
33c592dd
MV
8200001-Second.patch
821(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
5012699d
JS
822(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
823(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
33c592dd
MV
824Dry-OK. Log says:
825Server: relay.example.com
826MAIL FROM:<from@example.com>
02461e0e
JP
827RCPT TO:<to@example.com>
828RCPT TO:<cc@example.com>
829RCPT TO:<author@example.com>
830RCPT TO:<one@example.com>
831RCPT TO:<two@example.com>
33c592dd
MV
832From: Example <from@example.com>
833To: to@example.com
02461e0e
JP
834Cc: cc@example.com,
835 A <author@example.com>,
836 One <one@example.com>,
837 two@example.com
33c592dd
MV
838Subject: [PATCH 1/1] Second.
839Date: DATE-STRING
ba4324c4 840Message-ID: MESSAGE-ID-STRING
33c592dd 841X-Mailer: X-MAILER-STRING
e67a228c 842MIME-Version: 1.0
843Content-Transfer-Encoding: 8bit
33c592dd
MV
844
845Result: OK
846EOF
f9444147 847"
33c592dd 848
3531e270 849test_suppression () {
33c592dd
MV
850 git send-email \
851 --dry-run \
cb8a9bd5 852 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
33c592dd
MV
853 --from="Example <from@example.com>" \
854 --to=to@example.com \
855 --smtp-server relay.example.com \
d4cf11c2 856 $patches | replace_variable_fields \
cb8a9bd5
PB
857 >actual-suppress-$1${2+"-$2"} &&
858 test_cmp expected-suppress-$1${2+"-$2"} actual-suppress-$1${2+"-$2"}
3531e270
JS
859}
860
57cd35e6 861test_expect_success $PREREQ 'sendemail.cc set' '
3531e270
JS
862 git config sendemail.cc cc@example.com &&
863 test_suppression sob
33c592dd
MV
864'
865
f9444147 866test_expect_success $PREREQ 'setup expect' "
3531e270 867cat >expected-suppress-sob <<\EOF
33c592dd
MV
8680001-Second.patch
869(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
5012699d
JS
870(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
871(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
33c592dd
MV
872Dry-OK. Log says:
873Server: relay.example.com
874MAIL FROM:<from@example.com>
02461e0e
JP
875RCPT TO:<to@example.com>
876RCPT TO:<author@example.com>
877RCPT TO:<one@example.com>
878RCPT TO:<two@example.com>
33c592dd
MV
879From: Example <from@example.com>
880To: to@example.com
02461e0e
JP
881Cc: A <author@example.com>,
882 One <one@example.com>,
883 two@example.com
33c592dd
MV
884Subject: [PATCH 1/1] Second.
885Date: DATE-STRING
ba4324c4 886Message-ID: MESSAGE-ID-STRING
33c592dd 887X-Mailer: X-MAILER-STRING
e67a228c 888MIME-Version: 1.0
889Content-Transfer-Encoding: 8bit
33c592dd
MV
890
891Result: OK
892EOF
f9444147 893"
33c592dd 894
57cd35e6 895test_expect_success $PREREQ 'sendemail.cc unset' '
33c592dd 896 git config --unset sendemail.cc &&
3531e270
JS
897 test_suppression sob
898'
899
f9444147 900test_expect_success $PREREQ 'setup expect' "
cb8a9bd5
PB
901cat >expected-suppress-cccmd <<\EOF
9020001-Second.patch
903(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
904(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
905(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
906(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
907Dry-OK. Log says:
908Server: relay.example.com
909MAIL FROM:<from@example.com>
02461e0e
JP
910RCPT TO:<to@example.com>
911RCPT TO:<author@example.com>
912RCPT TO:<one@example.com>
913RCPT TO:<two@example.com>
914RCPT TO:<committer@example.com>
cb8a9bd5
PB
915From: Example <from@example.com>
916To: to@example.com
02461e0e
JP
917Cc: A <author@example.com>,
918 One <one@example.com>,
919 two@example.com,
920 C O Mitter <committer@example.com>
cb8a9bd5
PB
921Subject: [PATCH 1/1] Second.
922Date: DATE-STRING
ba4324c4 923Message-ID: MESSAGE-ID-STRING
cb8a9bd5 924X-Mailer: X-MAILER-STRING
e67a228c 925MIME-Version: 1.0
926Content-Transfer-Encoding: 8bit
cb8a9bd5
PB
927
928Result: OK
929EOF
f9444147 930"
cb8a9bd5 931
57cd35e6 932test_expect_success $PREREQ 'sendemail.cccmd' '
acd72b56
JH
933 write_script cccmd <<-\EOF &&
934 echo cc-cmd@example.com
935 EOF
cb8a9bd5
PB
936 git config sendemail.cccmd ./cccmd &&
937 test_suppression cccmd
938'
939
f9444147 940test_expect_success $PREREQ 'setup expect' '
3531e270
JS
941cat >expected-suppress-all <<\EOF
9420001-Second.patch
943Dry-OK. Log says:
944Server: relay.example.com
945MAIL FROM:<from@example.com>
946RCPT TO:<to@example.com>
947From: Example <from@example.com>
948To: to@example.com
949Subject: [PATCH 1/1] Second.
950Date: DATE-STRING
ba4324c4 951Message-ID: MESSAGE-ID-STRING
3531e270 952X-Mailer: X-MAILER-STRING
e67a228c 953MIME-Version: 1.0
954Content-Transfer-Encoding: 8bit
3531e270
JS
955
956Result: OK
957EOF
f9444147 958'
3531e270 959
57cd35e6 960test_expect_success $PREREQ '--suppress-cc=all' '
3531e270
JS
961 test_suppression all
962'
963
f9444147 964test_expect_success $PREREQ 'setup expect' "
3531e270
JS
965cat >expected-suppress-body <<\EOF
9660001-Second.patch
967(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
968(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
969(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
cb8a9bd5 970(cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
3531e270
JS
971Dry-OK. Log says:
972Server: relay.example.com
973MAIL FROM:<from@example.com>
02461e0e
JP
974RCPT TO:<to@example.com>
975RCPT TO:<author@example.com>
976RCPT TO:<one@example.com>
977RCPT TO:<two@example.com>
978RCPT TO:<cc-cmd@example.com>
3531e270
JS
979From: Example <from@example.com>
980To: to@example.com
02461e0e
JP
981Cc: A <author@example.com>,
982 One <one@example.com>,
983 two@example.com,
984 cc-cmd@example.com
3531e270
JS
985Subject: [PATCH 1/1] Second.
986Date: DATE-STRING
ba4324c4 987Message-ID: MESSAGE-ID-STRING
3531e270 988X-Mailer: X-MAILER-STRING
e67a228c 989MIME-Version: 1.0
990Content-Transfer-Encoding: 8bit
3531e270
JS
991
992Result: OK
993EOF
f9444147 994"
3531e270 995
57cd35e6 996test_expect_success $PREREQ '--suppress-cc=body' '
3531e270
JS
997 test_suppression body
998'
999
f9444147 1000test_expect_success $PREREQ 'setup expect' "
cb8a9bd5
PB
1001cat >expected-suppress-body-cccmd <<\EOF
10020001-Second.patch
1003(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
1004(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
1005(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
1006Dry-OK. Log says:
1007Server: relay.example.com
1008MAIL FROM:<from@example.com>
02461e0e
JP
1009RCPT TO:<to@example.com>
1010RCPT TO:<author@example.com>
1011RCPT TO:<one@example.com>
1012RCPT TO:<two@example.com>
cb8a9bd5
PB
1013From: Example <from@example.com>
1014To: to@example.com
02461e0e
JP
1015Cc: A <author@example.com>,
1016 One <one@example.com>,
1017 two@example.com
cb8a9bd5
PB
1018Subject: [PATCH 1/1] Second.
1019Date: DATE-STRING
ba4324c4 1020Message-ID: MESSAGE-ID-STRING
cb8a9bd5 1021X-Mailer: X-MAILER-STRING
e67a228c 1022MIME-Version: 1.0
1023Content-Transfer-Encoding: 8bit
cb8a9bd5
PB
1024
1025Result: OK
1026EOF
f9444147 1027"
cb8a9bd5 1028
57cd35e6 1029test_expect_success $PREREQ '--suppress-cc=body --suppress-cc=cccmd' '
cb8a9bd5
PB
1030 test_suppression body cccmd
1031'
1032
f9444147 1033test_expect_success $PREREQ 'setup expect' "
3531e270
JS
1034cat >expected-suppress-sob <<\EOF
10350001-Second.patch
1036(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
1037(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
1038(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
1039Dry-OK. Log says:
1040Server: relay.example.com
1041MAIL FROM:<from@example.com>
02461e0e
JP
1042RCPT TO:<to@example.com>
1043RCPT TO:<author@example.com>
1044RCPT TO:<one@example.com>
1045RCPT TO:<two@example.com>
3531e270
JS
1046From: Example <from@example.com>
1047To: to@example.com
02461e0e
JP
1048Cc: A <author@example.com>,
1049 One <one@example.com>,
1050 two@example.com
3531e270
JS
1051Subject: [PATCH 1/1] Second.
1052Date: DATE-STRING
ba4324c4 1053Message-ID: MESSAGE-ID-STRING
3531e270 1054X-Mailer: X-MAILER-STRING
e67a228c 1055MIME-Version: 1.0
1056Content-Transfer-Encoding: 8bit
3531e270
JS
1057
1058Result: OK
1059EOF
f9444147 1060"
3531e270 1061
57cd35e6 1062test_expect_success $PREREQ '--suppress-cc=sob' '
cc7e8167 1063 test_might_fail git config --unset sendemail.cccmd &&
3531e270
JS
1064 test_suppression sob
1065'
1066
f9444147 1067test_expect_success $PREREQ 'setup expect' "
3531e270
JS
1068cat >expected-suppress-bodycc <<\EOF
10690001-Second.patch
1070(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
1071(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
1072(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
1073(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
1074Dry-OK. Log says:
1075Server: relay.example.com
1076MAIL FROM:<from@example.com>
02461e0e
JP
1077RCPT TO:<to@example.com>
1078RCPT TO:<author@example.com>
1079RCPT TO:<one@example.com>
1080RCPT TO:<two@example.com>
1081RCPT TO:<committer@example.com>
3531e270
JS
1082From: Example <from@example.com>
1083To: to@example.com
02461e0e
JP
1084Cc: A <author@example.com>,
1085 One <one@example.com>,
1086 two@example.com,
1087 C O Mitter <committer@example.com>
3531e270
JS
1088Subject: [PATCH 1/1] Second.
1089Date: DATE-STRING
ba4324c4 1090Message-ID: MESSAGE-ID-STRING
3531e270 1091X-Mailer: X-MAILER-STRING
e67a228c 1092MIME-Version: 1.0
1093Content-Transfer-Encoding: 8bit
3531e270
JS
1094
1095Result: OK
1096EOF
f9444147 1097"
3531e270 1098
57cd35e6 1099test_expect_success $PREREQ '--suppress-cc=bodycc' '
3531e270
JS
1100 test_suppression bodycc
1101'
1102
f9444147 1103test_expect_success $PREREQ 'setup expect' "
3531e270
JS
1104cat >expected-suppress-cc <<\EOF
11050001-Second.patch
1106(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
1107(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
1108Dry-OK. Log says:
1109Server: relay.example.com
1110MAIL FROM:<from@example.com>
02461e0e
JP
1111RCPT TO:<to@example.com>
1112RCPT TO:<author@example.com>
1113RCPT TO:<committer@example.com>
3531e270
JS
1114From: Example <from@example.com>
1115To: to@example.com
02461e0e
JP
1116Cc: A <author@example.com>,
1117 C O Mitter <committer@example.com>
3531e270
JS
1118Subject: [PATCH 1/1] Second.
1119Date: DATE-STRING
ba4324c4 1120Message-ID: MESSAGE-ID-STRING
3531e270 1121X-Mailer: X-MAILER-STRING
e67a228c 1122MIME-Version: 1.0
1123Content-Transfer-Encoding: 8bit
3531e270
JS
1124
1125Result: OK
1126EOF
f9444147 1127"
3531e270 1128
57cd35e6 1129test_expect_success $PREREQ '--suppress-cc=cc' '
3531e270 1130 test_suppression cc
33c592dd
MV
1131'
1132
c1f2aa45
JS
1133test_confirm () {
1134 echo y | \
1135 GIT_SEND_EMAIL_NOTTY=1 \
1136 git send-email \
1137 --from="Example <nobody@example.com>" \
1138 --to=nobody@example.com \
1139 --smtp-server="$(pwd)/fake.sendmail" \
ee756a81 1140 $@ $patches >stdout &&
c18f75a1 1141 grep "Send this email" stdout
c1f2aa45
JS
1142}
1143
57cd35e6 1144test_expect_success $PREREQ '--confirm=always' '
c1f2aa45
JS
1145 test_confirm --confirm=always --suppress-cc=all
1146'
1147
57cd35e6 1148test_expect_success $PREREQ '--confirm=auto' '
c1f2aa45
JS
1149 test_confirm --confirm=auto
1150'
1151
57cd35e6 1152test_expect_success $PREREQ '--confirm=cc' '
c1f2aa45
JS
1153 test_confirm --confirm=cc
1154'
1155
57cd35e6 1156test_expect_success $PREREQ '--confirm=compose' '
c1f2aa45
JS
1157 test_confirm --confirm=compose --compose
1158'
1159
545871bf 1160test_expect_success $PREREQ 'confirm by default (due to cc)' '
fc99da1f 1161 test_when_finished git config sendemail.confirm never &&
c1f2aa45 1162 git config --unset sendemail.confirm &&
c18f75a1 1163 test_confirm
c1f2aa45
JS
1164'
1165
57cd35e6 1166test_expect_success $PREREQ 'confirm by default (due to --compose)' '
fc99da1f 1167 test_when_finished git config sendemail.confirm never &&
c1f2aa45
JS
1168 git config --unset sendemail.confirm &&
1169 test_confirm --suppress-cc=all --compose
c1f2aa45
JS
1170'
1171
57cd35e6 1172test_expect_success $PREREQ 'confirm detects EOF (inform assumes y)' '
fc99da1f 1173 test_when_finished git config sendemail.confirm never &&
c18f75a1 1174 git config --unset sendemail.confirm &&
dc1460aa
JS
1175 rm -fr outdir &&
1176 git format-patch -2 -o outdir &&
c18f75a1
JS
1177 GIT_SEND_EMAIL_NOTTY=1 \
1178 git send-email \
1179 --from="Example <nobody@example.com>" \
1180 --to=nobody@example.com \
1181 --smtp-server="$(pwd)/fake.sendmail" \
ee756a81 1182 outdir/*.patch </dev/null
c18f75a1
JS
1183'
1184
57cd35e6 1185test_expect_success $PREREQ 'confirm detects EOF (auto causes failure)' '
fc99da1f 1186 test_when_finished git config sendemail.confirm never &&
c18f75a1 1187 git config sendemail.confirm auto &&
3b3637c3
JS
1188 GIT_SEND_EMAIL_NOTTY=1 &&
1189 export GIT_SEND_EMAIL_NOTTY &&
c18f75a1
JS
1190 test_must_fail git send-email \
1191 --from="Example <nobody@example.com>" \
1192 --to=nobody@example.com \
1193 --smtp-server="$(pwd)/fake.sendmail" \
ee756a81 1194 $patches </dev/null
c18f75a1
JS
1195'
1196
41ccfdd9 1197test_expect_success $PREREQ 'confirm does not loop forever' '
fc99da1f 1198 test_when_finished git config sendemail.confirm never &&
c18f75a1 1199 git config sendemail.confirm auto &&
3b3637c3
JS
1200 GIT_SEND_EMAIL_NOTTY=1 &&
1201 export GIT_SEND_EMAIL_NOTTY &&
1202 yes "bogus" | test_must_fail git send-email \
c18f75a1
JS
1203 --from="Example <nobody@example.com>" \
1204 --to=nobody@example.com \
1205 --smtp-server="$(pwd)/fake.sendmail" \
1206 $patches
c18f75a1
JS
1207'
1208
57cd35e6 1209test_expect_success $PREREQ 'utf8 Cc is rfc2047 encoded' '
a61c0ffa
JS
1210 clean_fake_sendmail &&
1211 rm -fr outdir &&
1212 git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
1213 git send-email \
1214 --from="Example <nobody@example.com>" \
1215 --to=nobody@example.com \
1216 --smtp-server="$(pwd)/fake.sendmail" \
1217 outdir/*.patch &&
02461e0e 1218 grep "^ " msgtxt1 |
d1fff6fc 1219 grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
a61c0ffa
JS
1220'
1221
57cd35e6 1222test_expect_success $PREREQ '--compose adds MIME for utf8 body' '
0706bd19 1223 clean_fake_sendmail &&
acd72b56
JH
1224 write_script fake-editor-utf8 <<-\EOF &&
1225 echo "utf8 body: àéìöú" >>"$1"
1226 EOF
03335f22
JH
1227 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1228 git send-email \
1229 --compose --subject foo \
1230 --from="Example <nobody@example.com>" \
1231 --to=nobody@example.com \
1232 --smtp-server="$(pwd)/fake.sendmail" \
1233 $patches &&
0706bd19 1234 grep "^utf8 body" msgtxt1 &&
d1fff6fc 1235 grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
0706bd19
JK
1236'
1237
57cd35e6 1238test_expect_success $PREREQ '--compose respects user mime type' '
0706bd19 1239 clean_fake_sendmail &&
acd72b56
JH
1240 write_script fake-editor-utf8-mime <<-\EOF &&
1241 cat >"$1" <<-\EOM
1242 MIME-Version: 1.0
1243 Content-Type: text/plain; charset=iso-8859-1
1244 Content-Transfer-Encoding: 8bit
1245 Subject: foo
1246
1247 utf8 body: àéìöú
1248 EOM
1249 EOF
03335f22
JH
1250 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
1251 git send-email \
1252 --compose --subject foo \
1253 --from="Example <nobody@example.com>" \
1254 --to=nobody@example.com \
1255 --smtp-server="$(pwd)/fake.sendmail" \
1256 $patches &&
0706bd19
JK
1257 grep "^utf8 body" msgtxt1 &&
1258 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
d1fff6fc 1259 ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
0706bd19
JK
1260'
1261
57cd35e6 1262test_expect_success $PREREQ '--compose adds MIME for utf8 subject' '
d54eaaa2 1263 clean_fake_sendmail &&
03335f22
JH
1264 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
1265 git send-email \
1266 --compose --subject utf8-sübjëct \
1267 --from="Example <nobody@example.com>" \
1268 --to=nobody@example.com \
1269 --smtp-server="$(pwd)/fake.sendmail" \
1270 $patches &&
d54eaaa2 1271 grep "^fake edit" msgtxt1 &&
d1fff6fc 1272 grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
d54eaaa2
JK
1273'
1274
b622d4d1
TR
1275test_expect_success $PREREQ 'utf8 author is correctly passed on' '
1276 clean_fake_sendmail &&
1277 test_commit weird_author &&
1278 test_when_finished "git reset --hard HEAD^" &&
1279 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
1280 git format-patch --stdout -1 >funny_name.patch &&
1281 git send-email --from="Example <nobody@example.com>" \
03335f22
JH
1282 --to=nobody@example.com \
1283 --smtp-server="$(pwd)/fake.sendmail" \
1284 funny_name.patch &&
b622d4d1
TR
1285 grep "^From: Füñný Nâmé <odd_?=mail@example.com>" msgtxt1
1286'
1287
4cb46bdd 1288test_expect_success $PREREQ 'utf8 sender is not duplicated' '
f07075c2
MT
1289 clean_fake_sendmail &&
1290 test_commit weird_sender &&
1291 test_when_finished "git reset --hard HEAD^" &&
1292 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
1293 git format-patch --stdout -1 >funny_name.patch &&
1294 git send-email --from="Füñný Nâmé <odd_?=mail@example.com>" \
03335f22
JH
1295 --to=nobody@example.com \
1296 --smtp-server="$(pwd)/fake.sendmail" \
1297 funny_name.patch &&
f07075c2
MT
1298 grep "^From: " msgtxt1 >msgfrom &&
1299 test_line_count = 1 msgfrom
1300'
1301
62e00690
KM
1302test_expect_success $PREREQ 'sendemail.composeencoding works' '
1303 clean_fake_sendmail &&
1304 git config sendemail.composeencoding iso-8859-1 &&
acd72b56
JH
1305 write_script fake-editor-utf8 <<-\EOF &&
1306 echo "utf8 body: àéìöú" >>"$1"
1307 EOF
03335f22
JH
1308 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1309 git send-email \
1310 --compose --subject foo \
1311 --from="Example <nobody@example.com>" \
1312 --to=nobody@example.com \
1313 --smtp-server="$(pwd)/fake.sendmail" \
1314 $patches &&
62e00690
KM
1315 grep "^utf8 body" msgtxt1 &&
1316 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1317'
1318
1319test_expect_success $PREREQ '--compose-encoding works' '
1320 clean_fake_sendmail &&
acd72b56
JH
1321 write_script fake-editor-utf8 <<-\EOF &&
1322 echo "utf8 body: àéìöú" >>"$1"
1323 EOF
03335f22
JH
1324 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1325 git send-email \
1326 --compose-encoding iso-8859-1 \
1327 --compose --subject foo \
1328 --from="Example <nobody@example.com>" \
1329 --to=nobody@example.com \
1330 --smtp-server="$(pwd)/fake.sendmail" \
1331 $patches &&
62e00690
KM
1332 grep "^utf8 body" msgtxt1 &&
1333 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1334'
1335
1336test_expect_success $PREREQ '--compose-encoding overrides sendemail.composeencoding' '
1337 clean_fake_sendmail &&
1338 git config sendemail.composeencoding iso-8859-1 &&
acd72b56
JH
1339 write_script fake-editor-utf8 <<-\EOF &&
1340 echo "utf8 body: àéìöú" >>"$1"
1341 EOF
03335f22
JH
1342 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1343 git send-email \
1344 --compose-encoding iso-8859-2 \
1345 --compose --subject foo \
1346 --from="Example <nobody@example.com>" \
1347 --to=nobody@example.com \
1348 --smtp-server="$(pwd)/fake.sendmail" \
1349 $patches &&
62e00690
KM
1350 grep "^utf8 body" msgtxt1 &&
1351 grep "^Content-Type: text/plain; charset=iso-8859-2" msgtxt1
1352'
1353
4a47a4dd
KM
1354test_expect_success $PREREQ '--compose-encoding adds correct MIME for subject' '
1355 clean_fake_sendmail &&
03335f22
JH
1356 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
1357 git send-email \
1358 --compose-encoding iso-8859-2 \
1359 --compose --subject utf8-sübjëct \
1360 --from="Example <nobody@example.com>" \
1361 --to=nobody@example.com \
1362 --smtp-server="$(pwd)/fake.sendmail" \
1363 $patches &&
4a47a4dd
KM
1364 grep "^fake edit" msgtxt1 &&
1365 grep "^Subject: =?iso-8859-2?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
1366'
1367
57cd35e6 1368test_expect_success $PREREQ 'detects ambiguous reference/file conflict' '
a881baa2
JS
1369 echo main >main &&
1370 git add main &&
1371 git commit -m"add main" &&
1372 test_must_fail git send-email --dry-run main 2>errors &&
5df9fcf6
PH
1373 grep disambiguate errors
1374'
1375
57cd35e6 1376test_expect_success $PREREQ 'feed two files' '
69f4ce55
JH
1377 rm -fr outdir &&
1378 git format-patch -2 -o outdir &&
c1f2aa45 1379 git send-email \
03335f22
JH
1380 --dry-run \
1381 --from="Example <nobody@example.com>" \
1382 --to=nobody@example.com \
1383 outdir/000?-*.patch 2>errors >out &&
69f4ce55
JH
1384 grep "^Subject: " out >subjects &&
1385 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
a881baa2 1386 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add main"
69f4ce55
JH
1387'
1388
57cd35e6 1389test_expect_success $PREREQ 'in-reply-to but no threading' '
aaab4b9f
TR
1390 git send-email \
1391 --dry-run \
1392 --from="Example <nobody@example.com>" \
1393 --to=nobody@example.com \
1394 --in-reply-to="<in-reply-id@example.com>" \
f4714943 1395 --no-thread \
de26f02d
JS
1396 $patches >out &&
1397 grep "In-Reply-To: <in-reply-id@example.com>" out
aaab4b9f
TR
1398'
1399
57cd35e6 1400test_expect_success $PREREQ 'no in-reply-to and no threading' '
32ae8319
MH
1401 git send-email \
1402 --dry-run \
1403 --from="Example <nobody@example.com>" \
1404 --to=nobody@example.com \
f4714943 1405 --no-thread \
2554dd1a 1406 $patches >stdout &&
32ae8319
MH
1407 ! grep "In-Reply-To: " stdout
1408'
1409
57cd35e6 1410test_expect_success $PREREQ 'threading but no chain-reply-to' '
d67114a5
MH
1411 git send-email \
1412 --dry-run \
1413 --from="Example <nobody@example.com>" \
1414 --to=nobody@example.com \
1415 --thread \
f4714943 1416 --no-chain-reply-to \
d67114a5
MH
1417 $patches $patches >stdout &&
1418 grep "In-Reply-To: " stdout
1419'
1420
f9f60d70
RA
1421test_expect_success $PREREQ 'override in-reply-to if no threading' '
1422 git send-email \
1423 --dry-run \
1424 --from="Example <nobody@example.com>" \
1425 --to=nobody@example.com \
1426 --no-thread \
1427 --in-reply-to="override" \
1428 $threaded_patches >stdout &&
1429 grep "In-Reply-To: <override>" stdout
1430'
1431
57cd35e6 1432test_expect_success $PREREQ 'sendemail.to works' '
f434c083
SB
1433 git config --replace-all sendemail.to "Somebody <somebody@ex.com>" &&
1434 git send-email \
1435 --dry-run \
1436 --from="Example <nobody@example.com>" \
2554dd1a 1437 $patches >stdout &&
f434c083
SB
1438 grep "To: Somebody <somebody@ex.com>" stdout
1439'
1440
3ff15040
ÆAB
1441test_expect_success $PREREQ 'setup sendemail.identity' '
1442 git config --replace-all sendemail.to "default@example.com" &&
1443 git config --replace-all sendemail.isp.to "isp@example.com" &&
1444 git config --replace-all sendemail.cloud.to "cloud@example.com"
1445'
1446
1447test_expect_success $PREREQ 'sendemail.identity: reads the correct identity config' '
1448 git -c sendemail.identity=cloud send-email \
1449 --dry-run \
1450 --from="nobody@example.com" \
1451 $patches >stdout &&
1452 grep "To: cloud@example.com" stdout
1453'
1454
1455test_expect_success $PREREQ 'sendemail.identity: identity overrides sendemail.identity' '
1456 git -c sendemail.identity=cloud send-email \
1457 --identity=isp \
1458 --dry-run \
1459 --from="nobody@example.com" \
1460 $patches >stdout &&
1461 grep "To: isp@example.com" stdout
1462'
1463
1464test_expect_success $PREREQ 'sendemail.identity: --no-identity clears previous identity' '
1465 git -c sendemail.identity=cloud send-email \
1466 --no-identity \
1467 --dry-run \
1468 --from="nobody@example.com" \
1469 $patches >stdout &&
1470 grep "To: default@example.com" stdout
1471'
1472
4dc8b1c1 1473test_expect_success $PREREQ 'sendemail.identity: bool identity variable existence overrides' '
3ff15040
ÆAB
1474 git -c sendemail.identity=cloud \
1475 -c sendemail.xmailer=true \
1476 -c sendemail.cloud.xmailer=false \
1477 send-email \
1478 --dry-run \
1479 --from="nobody@example.com" \
1480 $patches >stdout &&
1481 grep "To: cloud@example.com" stdout &&
1482 ! grep "X-Mailer" stdout
1483'
1484
1485test_expect_success $PREREQ 'sendemail.identity: bool variable fallback' '
1486 git -c sendemail.identity=cloud \
1487 -c sendemail.xmailer=false \
1488 send-email \
1489 --dry-run \
1490 --from="nobody@example.com" \
1491 $patches >stdout &&
1492 grep "To: cloud@example.com" stdout &&
1493 ! grep "X-Mailer" stdout
1494'
1495
879be431
ÆAB
1496test_expect_success $PREREQ 'sendemail.identity: bool variable without a value' '
1497 git -c sendemail.xmailer \
1498 send-email \
1499 --dry-run \
1500 --from="nobody@example.com" \
1501 $patches >stdout &&
1502 grep "To: default@example.com" stdout &&
1503 grep "X-Mailer" stdout
1504'
1505
57cd35e6 1506test_expect_success $PREREQ '--no-to overrides sendemail.to' '
f434c083
SB
1507 git send-email \
1508 --dry-run \
1509 --from="Example <nobody@example.com>" \
1510 --no-to \
1511 --to=nobody@example.com \
2554dd1a 1512 $patches >stdout &&
f434c083
SB
1513 grep "To: nobody@example.com" stdout &&
1514 ! grep "To: Somebody <somebody@ex.com>" stdout
1515'
1516
57cd35e6 1517test_expect_success $PREREQ 'sendemail.cc works' '
f434c083
SB
1518 git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" &&
1519 git send-email \
1520 --dry-run \
1521 --from="Example <nobody@example.com>" \
1522 --to=nobody@example.com \
2554dd1a 1523 $patches >stdout &&
f434c083
SB
1524 grep "Cc: Somebody <somebody@ex.com>" stdout
1525'
1526
57cd35e6 1527test_expect_success $PREREQ '--no-cc overrides sendemail.cc' '
f434c083
SB
1528 git send-email \
1529 --dry-run \
1530 --from="Example <nobody@example.com>" \
1531 --no-cc \
1532 --cc=bodies@example.com \
1533 --to=nobody@example.com \
2554dd1a 1534 $patches >stdout &&
f434c083
SB
1535 grep "Cc: bodies@example.com" stdout &&
1536 ! grep "Cc: Somebody <somebody@ex.com>" stdout
1537'
1538
57cd35e6 1539test_expect_success $PREREQ 'sendemail.bcc works' '
f434c083
SB
1540 git config --replace-all sendemail.bcc "Other <other@ex.com>" &&
1541 git send-email \
1542 --dry-run \
1543 --from="Example <nobody@example.com>" \
1544 --to=nobody@example.com \
1545 --smtp-server relay.example.com \
2554dd1a 1546 $patches >stdout &&
f434c083
SB
1547 grep "RCPT TO:<other@ex.com>" stdout
1548'
1549
57cd35e6 1550test_expect_success $PREREQ '--no-bcc overrides sendemail.bcc' '
f434c083
SB
1551 git send-email \
1552 --dry-run \
1553 --from="Example <nobody@example.com>" \
1554 --no-bcc \
1555 --bcc=bodies@example.com \
1556 --to=nobody@example.com \
1557 --smtp-server relay.example.com \
2554dd1a 1558 $patches >stdout &&
f434c083
SB
1559 grep "RCPT TO:<bodies@example.com>" stdout &&
1560 ! grep "RCPT TO:<other@ex.com>" stdout
1561'
1562
21802cd3 1563test_expect_success $PREREQ 'patches To headers are used by default' '
bdf20f5e 1564 patch=$(git format-patch -1 --to="bodies@example.com") &&
21802cd3
SB
1565 test_when_finished "rm $patch" &&
1566 git send-email \
1567 --dry-run \
1568 --from="Example <nobody@example.com>" \
1569 --smtp-server relay.example.com \
1570 $patch >stdout &&
1571 grep "RCPT TO:<bodies@example.com>" stdout
1572'
1573
1574test_expect_success $PREREQ 'patches To headers are appended to' '
bdf20f5e 1575 patch=$(git format-patch -1 --to="bodies@example.com") &&
21802cd3
SB
1576 test_when_finished "rm $patch" &&
1577 git send-email \
1578 --dry-run \
1579 --from="Example <nobody@example.com>" \
1580 --to=nobody@example.com \
1581 --smtp-server relay.example.com \
1582 $patch >stdout &&
1583 grep "RCPT TO:<bodies@example.com>" stdout &&
1584 grep "RCPT TO:<nobody@example.com>" stdout
1585'
1586
3c3bb51c 1587test_expect_success $PREREQ 'To headers from files reset each patch' '
bdf20f5e
EP
1588 patch1=$(git format-patch -1 --to="bodies@example.com") &&
1589 patch2=$(git format-patch -1 --to="other@example.com" HEAD~) &&
3c3bb51c
SB
1590 test_when_finished "rm $patch1 && rm $patch2" &&
1591 git send-email \
1592 --dry-run \
1593 --from="Example <nobody@example.com>" \
1594 --to="nobody@example.com" \
1595 --smtp-server relay.example.com \
1596 $patch1 $patch2 >stdout &&
1597 test $(grep -c "RCPT TO:<bodies@example.com>" stdout) = 1 &&
1598 test $(grep -c "RCPT TO:<nobody@example.com>" stdout) = 2 &&
1599 test $(grep -c "RCPT TO:<other@example.com>" stdout) = 1
1600'
1601
f9444147 1602test_expect_success $PREREQ 'setup expect' '
0720a51b 1603cat >email-using-8bit <<\EOF
3cae7e5b 1604From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
ba4324c4 1605Message-ID: <bogus-message-id@example.com>
3cae7e5b
TR
1606From: author@example.com
1607Date: Sat, 12 Jun 2010 15:53:58 +0200
1608Subject: subject goes here
1609
1610Dieser deutsche Text enthält einen Umlaut!
1611EOF
f9444147 1612'
3cae7e5b 1613
5637d857 1614test_expect_success $PREREQ 'setup expect' '
0720a51b 1615 echo "Subject: subject goes here" >expected
5637d857
KM
1616'
1617
1618test_expect_success $PREREQ 'ASCII subject is not RFC2047 quoted' '
1619 clean_fake_sendmail &&
1620 echo bogus |
1621 git send-email --from=author@example.com --to=nobody@example.com \
1622 --smtp-server="$(pwd)/fake.sendmail" \
1623 --8bit-encoding=UTF-8 \
1624 email-using-8bit >stdout &&
1625 grep "Subject" msgtxt1 >actual &&
1626 test_cmp expected actual
1627'
1628
f9444147 1629test_expect_success $PREREQ 'setup expect' '
0720a51b
JH
1630 cat >content-type-decl <<-\EOF
1631 MIME-Version: 1.0
1632 Content-Type: text/plain; charset=UTF-8
1633 Content-Transfer-Encoding: 8bit
1634 EOF
f9444147 1635'
3cae7e5b 1636
57cd35e6 1637test_expect_success $PREREQ 'asks about and fixes 8bit encodings' '
3cae7e5b
TR
1638 clean_fake_sendmail &&
1639 echo |
1640 git send-email --from=author@example.com --to=nobody@example.com \
1641 --smtp-server="$(pwd)/fake.sendmail" \
1642 email-using-8bit >stdout &&
1643 grep "do not declare a Content-Transfer-Encoding" stdout &&
1644 grep email-using-8bit stdout &&
1645 grep "Which 8bit encoding" stdout &&
81580fa0 1646 grep -E "Content|MIME" msgtxt1 >actual &&
9c5b2fab 1647 test_cmp content-type-decl actual
3cae7e5b
TR
1648'
1649
57cd35e6 1650test_expect_success $PREREQ 'sendemail.8bitEncoding works' '
3cae7e5b
TR
1651 clean_fake_sendmail &&
1652 git config sendemail.assume8bitEncoding UTF-8 &&
1653 echo bogus |
1654 git send-email --from=author@example.com --to=nobody@example.com \
1655 --smtp-server="$(pwd)/fake.sendmail" \
1656 email-using-8bit >stdout &&
81580fa0 1657 grep -E "Content|MIME" msgtxt1 >actual &&
9c5b2fab 1658 test_cmp content-type-decl actual
3cae7e5b
TR
1659'
1660
b996f849
ÆAB
1661test_expect_success $PREREQ 'sendemail.8bitEncoding in .git/config overrides --global .gitconfig' '
1662 clean_fake_sendmail &&
1663 git config sendemail.assume8bitEncoding UTF-8 &&
1664 test_when_finished "rm -rf home" &&
1665 mkdir home &&
1666 git config -f home/.gitconfig sendemail.assume8bitEncoding "bogus too" &&
1667 echo bogus |
1668 env HOME="$(pwd)/home" DEBUG=1 \
1669 git send-email --from=author@example.com --to=nobody@example.com \
1670 --smtp-server="$(pwd)/fake.sendmail" \
1671 email-using-8bit >stdout &&
81580fa0 1672 grep -E "Content|MIME" msgtxt1 >actual &&
b996f849
ÆAB
1673 test_cmp content-type-decl actual
1674'
1675
57cd35e6 1676test_expect_success $PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
3cae7e5b
TR
1677 clean_fake_sendmail &&
1678 git config sendemail.assume8bitEncoding "bogus too" &&
1679 echo bogus |
1680 git send-email --from=author@example.com --to=nobody@example.com \
1681 --smtp-server="$(pwd)/fake.sendmail" \
1682 --8bit-encoding=UTF-8 \
1683 email-using-8bit >stdout &&
81580fa0 1684 grep -E "Content|MIME" msgtxt1 >actual &&
9c5b2fab 1685 test_cmp content-type-decl actual
3cae7e5b
TR
1686'
1687
f9444147 1688test_expect_success $PREREQ 'setup expect' '
0720a51b
JH
1689 cat >email-using-8bit <<-\EOF
1690 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
ba4324c4 1691 Message-ID: <bogus-message-id@example.com>
0720a51b
JH
1692 From: author@example.com
1693 Date: Sat, 12 Jun 2010 15:53:58 +0200
1694 Subject: Dieser Betreff enthält auch einen Umlaut!
1695
1696 Nothing to see here.
1697 EOF
f9444147 1698'
3cae7e5b 1699
f9444147 1700test_expect_success $PREREQ 'setup expect' '
0720a51b
JH
1701 cat >expected <<-\EOF
1702 Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
1703 EOF
f9444147 1704'
3cae7e5b 1705
57cd35e6 1706test_expect_success $PREREQ '--8bit-encoding also treats subject' '
3cae7e5b
TR
1707 clean_fake_sendmail &&
1708 echo bogus |
1709 git send-email --from=author@example.com --to=nobody@example.com \
1710 --smtp-server="$(pwd)/fake.sendmail" \
1711 --8bit-encoding=UTF-8 \
1712 email-using-8bit >stdout &&
1713 grep "Subject" msgtxt1 >actual &&
1714 test_cmp expected actual
1715'
1716
8d814084 1717test_expect_success $PREREQ 'setup expect' '
0720a51b
JH
1718 cat >email-using-8bit <<-\EOF
1719 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
ba4324c4 1720 Message-ID: <bogus-message-id@example.com>
0720a51b
JH
1721 From: A U Thor <author@example.com>
1722 Date: Sat, 12 Jun 2010 15:53:58 +0200
1723 Content-Type: text/plain; charset=UTF-8
1724 Subject: Nothing to see here.
1725
1726 Dieser Betreff enthält auch einen Umlaut!
1727 EOF
8d814084
PB
1728'
1729
a8aea5db 1730test_expect_success $PREREQ '--transfer-encoding overrides sendemail.transferEncoding' '
8d814084 1731 clean_fake_sendmail &&
a8aea5db
ÆAB
1732 test_must_fail git -c sendemail.transferEncoding=8bit \
1733 send-email \
03335f22
JH
1734 --transfer-encoding=7bit \
1735 --smtp-server="$(pwd)/fake.sendmail" \
1736 email-using-8bit \
1737 2>errors >out &&
8d814084
PB
1738 grep "cannot send message as 7bit" errors &&
1739 test -z "$(ls msgtxt*)"
1740'
1741
a8aea5db 1742test_expect_success $PREREQ 'sendemail.transferEncoding via config' '
8d814084 1743 clean_fake_sendmail &&
a8aea5db
ÆAB
1744 test_must_fail git -c sendemail.transferEncoding=7bit \
1745 send-email \
03335f22
JH
1746 --smtp-server="$(pwd)/fake.sendmail" \
1747 email-using-8bit \
1748 2>errors >out &&
8d814084
PB
1749 grep "cannot send message as 7bit" errors &&
1750 test -z "$(ls msgtxt*)"
1751'
1752
a8aea5db 1753test_expect_success $PREREQ 'sendemail.transferEncoding via cli' '
8d814084 1754 clean_fake_sendmail &&
a8aea5db
ÆAB
1755 test_must_fail git send-email \
1756 --transfer-encoding=7bit \
03335f22
JH
1757 --smtp-server="$(pwd)/fake.sendmail" \
1758 email-using-8bit \
1759 2>errors >out &&
a8aea5db
ÆAB
1760 grep "cannot send message as 7bit" errors &&
1761 test -z "$(ls msgtxt*)"
8d814084
PB
1762'
1763
1764test_expect_success $PREREQ 'setup expect' '
0720a51b
JH
1765 cat >expected <<-\EOF
1766 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1767 EOF
8d814084
PB
1768'
1769
1770test_expect_success $PREREQ '8-bit and sendemail.transferencoding=quoted-printable' '
1771 clean_fake_sendmail &&
1772 git send-email \
03335f22
JH
1773 --transfer-encoding=quoted-printable \
1774 --smtp-server="$(pwd)/fake.sendmail" \
1775 email-using-8bit \
1776 2>errors >out &&
c76b84a1 1777 sed "1,/^$/d" msgtxt1 >actual &&
8d814084
PB
1778 test_cmp expected actual
1779'
1780
1781test_expect_success $PREREQ 'setup expect' '
0720a51b
JH
1782 cat >expected <<-\EOF
1783 RGllc2VyIEJldHJlZmYgZW50aMOkbHQgYXVjaCBlaW5lbiBVbWxhdXQhCg==
1784 EOF
8d814084
PB
1785'
1786
1787test_expect_success $PREREQ '8-bit and sendemail.transferencoding=base64' '
1788 clean_fake_sendmail &&
1789 git send-email \
03335f22
JH
1790 --transfer-encoding=base64 \
1791 --smtp-server="$(pwd)/fake.sendmail" \
1792 email-using-8bit \
1793 2>errors >out &&
c76b84a1 1794 sed "1,/^$/d" msgtxt1 >actual &&
8d814084
PB
1795 test_cmp expected actual
1796'
1797
1798test_expect_success $PREREQ 'setup expect' '
0720a51b
JH
1799 cat >email-using-qp <<-\EOF
1800 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
ba4324c4 1801 Message-ID: <bogus-message-id@example.com>
0720a51b
JH
1802 From: A U Thor <author@example.com>
1803 Date: Sat, 12 Jun 2010 15:53:58 +0200
1804 MIME-Version: 1.0
1805 Content-Transfer-Encoding: quoted-printable
1806 Content-Type: text/plain; charset=UTF-8
1807 Subject: Nothing to see here.
8d814084 1808
0720a51b
JH
1809 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1810 EOF
8d814084
PB
1811'
1812
1813test_expect_success $PREREQ 'convert from quoted-printable to base64' '
1814 clean_fake_sendmail &&
1815 git send-email \
03335f22
JH
1816 --transfer-encoding=base64 \
1817 --smtp-server="$(pwd)/fake.sendmail" \
1818 email-using-qp \
1819 2>errors >out &&
c76b84a1 1820 sed "1,/^$/d" msgtxt1 >actual &&
8d814084
PB
1821 test_cmp expected actual
1822'
1823
1824test_expect_success $PREREQ 'setup expect' "
ee756a81 1825tr -d '\\015' | tr '%' '\\015' >email-using-crlf <<EOF
8d814084 1826From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
ba4324c4 1827Message-ID: <bogus-message-id@example.com>
8d814084
PB
1828From: A U Thor <author@example.com>
1829Date: Sat, 12 Jun 2010 15:53:58 +0200
1830Content-Type: text/plain; charset=UTF-8
1831Subject: Nothing to see here.
1832
1833Look, I have a CRLF and an = sign!%
1834EOF
1835"
1836
1837test_expect_success $PREREQ 'setup expect' '
0720a51b
JH
1838 cat >expected <<-\EOF
1839 Look, I have a CRLF and an =3D sign!=0D
1840 EOF
8d814084
PB
1841'
1842
1843test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=quoted-printable' '
1844 clean_fake_sendmail &&
1845 git send-email \
03335f22
JH
1846 --transfer-encoding=quoted-printable \
1847 --smtp-server="$(pwd)/fake.sendmail" \
1848 email-using-crlf \
1849 2>errors >out &&
c76b84a1 1850 sed "1,/^$/d" msgtxt1 >actual &&
8d814084
PB
1851 test_cmp expected actual
1852'
1853
1854test_expect_success $PREREQ 'setup expect' '
0720a51b
JH
1855 cat >expected <<-\EOF
1856 TG9vaywgSSBoYXZlIGEgQ1JMRiBhbmQgYW4gPSBzaWduIQ0K
1857 EOF
8d814084
PB
1858'
1859
1860test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=base64' '
1861 clean_fake_sendmail &&
1862 git send-email \
03335f22
JH
1863 --transfer-encoding=base64 \
1864 --smtp-server="$(pwd)/fake.sendmail" \
1865 email-using-crlf \
1866 2>errors >out &&
c76b84a1 1867 sed "1,/^$/d" msgtxt1 >actual &&
8d814084
PB
1868 test_cmp expected actual
1869'
1870
1871
a03bc5b6
TR
1872# Note that the patches in this test are deliberately out of order; we
1873# want to make sure it works even if the cover-letter is not in the
1874# first mail.
57da2042 1875test_expect_success $PREREQ 'refusing to send cover letter template' '
a03bc5b6
TR
1876 clean_fake_sendmail &&
1877 rm -fr outdir &&
1878 git format-patch --cover-letter -2 -o outdir &&
1879 test_must_fail git send-email \
03335f22
JH
1880 --from="Example <nobody@example.com>" \
1881 --to=nobody@example.com \
1882 --smtp-server="$(pwd)/fake.sendmail" \
1883 outdir/0002-*.patch \
1884 outdir/0000-*.patch \
1885 outdir/0001-*.patch \
1886 2>errors >out &&
a03bc5b6
TR
1887 grep "SUBJECT HERE" errors &&
1888 test -z "$(ls msgtxt*)"
1889'
1890
57da2042 1891test_expect_success $PREREQ '--force sends cover letter template anyway' '
a03bc5b6
TR
1892 clean_fake_sendmail &&
1893 rm -fr outdir &&
1894 git format-patch --cover-letter -2 -o outdir &&
1895 git send-email \
03335f22
JH
1896 --force \
1897 --from="Example <nobody@example.com>" \
1898 --to=nobody@example.com \
1899 --smtp-server="$(pwd)/fake.sendmail" \
1900 outdir/0002-*.patch \
1901 outdir/0000-*.patch \
1902 outdir/0001-*.patch \
1903 2>errors >out &&
a03bc5b6
TR
1904 ! grep "SUBJECT HERE" errors &&
1905 test -n "$(ls msgtxt*)"
1906'
1907
8ccc4e42
MT
1908test_cover_addresses () {
1909 header="$1"
1910 shift
1911 clean_fake_sendmail &&
1912 rm -fr outdir &&
1913 git format-patch --cover-letter -2 -o outdir &&
bdf20f5e 1914 cover=$(echo outdir/0000-*.patch) &&
8ccc4e42 1915 mv $cover cover-to-edit.patch &&
35ec002c 1916 perl -pe "s/^From:/$header: extra\@address.com\nFrom:/" cover-to-edit.patch >"$cover" &&
8ccc4e42 1917 git send-email \
03335f22
JH
1918 --force \
1919 --from="Example <nobody@example.com>" \
1920 --no-to --no-cc \
1921 "$@" \
1922 --smtp-server="$(pwd)/fake.sendmail" \
1923 outdir/0000-*.patch \
1924 outdir/0001-*.patch \
1925 outdir/0002-*.patch \
1926 2>errors >out &&
8ccc4e42
MT
1927 grep "^$header: extra@address.com" msgtxt1 >to1 &&
1928 grep "^$header: extra@address.com" msgtxt2 >to2 &&
1929 grep "^$header: extra@address.com" msgtxt3 >to3 &&
1930 test_line_count = 1 to1 &&
1931 test_line_count = 1 to2 &&
1932 test_line_count = 1 to3
1933}
1934
1935test_expect_success $PREREQ 'to-cover adds To to all mail' '
1936 test_cover_addresses "To" --to-cover
1937'
1938
1939test_expect_success $PREREQ 'cc-cover adds Cc to all mail' '
1940 test_cover_addresses "Cc" --cc-cover
1941'
1942
1943test_expect_success $PREREQ 'tocover adds To to all mail' '
1944 test_config sendemail.tocover true &&
1945 test_cover_addresses "To"
1946'
1947
1948test_expect_success $PREREQ 'cccover adds Cc to all mail' '
1949 test_config sendemail.cccover true &&
1950 test_cover_addresses "Cc"
1951'
1952
2c510f21
EW
1953test_expect_success $PREREQ 'escaped quotes in sendemail.aliasfiletype=mutt' '
1954 clean_fake_sendmail &&
1955 echo "alias sbd \\\"Dot U. Sir\\\" <somebody@example.org>" >.mutt &&
1956 git config --replace-all sendemail.aliasesfile "$(pwd)/.mutt" &&
1957 git config sendemail.aliasfiletype mutt &&
1958 git send-email \
1959 --from="Example <nobody@example.com>" \
1960 --to=sbd \
1961 --smtp-server="$(pwd)/fake.sendmail" \
1962 outdir/0001-*.patch \
1963 2>errors >out &&
1964 grep "^!somebody@example\.org!$" commandline1 &&
1965 grep -F "To: \"Dot U. Sir\" <somebody@example.org>" out
1966'
1967
463b0ea2
CS
1968test_expect_success $PREREQ 'sendemail.aliasfiletype=mailrc' '
1969 clean_fake_sendmail &&
1970 echo "alias sbd somebody@example.org" >.mailrc &&
1971 git config --replace-all sendemail.aliasesfile "$(pwd)/.mailrc" &&
1972 git config sendemail.aliasfiletype mailrc &&
1973 git send-email \
03335f22
JH
1974 --from="Example <nobody@example.com>" \
1975 --to=sbd \
1976 --smtp-server="$(pwd)/fake.sendmail" \
1977 outdir/0001-*.patch \
1978 2>errors >out &&
463b0ea2
CS
1979 grep "^!somebody@example\.org!$" commandline1
1980'
1981
6fc53692 1982test_expect_success $PREREQ 'sendemail.aliasesfile=~/.mailrc' '
463b0ea2 1983 clean_fake_sendmail &&
587089c1 1984 echo "alias sbd someone@example.org" >"$HOME/.mailrc" &&
463b0ea2
CS
1985 git config --replace-all sendemail.aliasesfile "~/.mailrc" &&
1986 git config sendemail.aliasfiletype mailrc &&
1987 git send-email \
03335f22
JH
1988 --from="Example <nobody@example.com>" \
1989 --to=sbd \
1990 --smtp-server="$(pwd)/fake.sendmail" \
1991 outdir/0001-*.patch \
1992 2>errors >out &&
463b0ea2
CS
1993 grep "^!someone@example\.org!$" commandline1
1994'
1995
17b7a832
JK
1996test_dump_aliases () {
1997 msg="$1" && shift &&
1998 filetype="$1" && shift &&
1999 printf '%s\n' "$@" >expect &&
2000 cat >.tmp-email-aliases &&
2001
2002 test_expect_success $PREREQ "$msg" '
2003 clean_fake_sendmail && rm -fr outdir &&
2004 git config --replace-all sendemail.aliasesfile \
2005 "$(pwd)/.tmp-email-aliases" &&
2006 git config sendemail.aliasfiletype "$filetype" &&
2007 git send-email --dump-aliases 2>errors >actual &&
2008 test_cmp expect actual
2009 '
2010}
2011
2012test_dump_aliases '--dump-aliases sendmail format' \
2013 'sendmail' \
2014 'abgroup' \
2015 'alice' \
2016 'bcgrp' \
2017 'bob' \
2018 'chloe' <<-\EOF
2019 alice: Alice W Land <awol@example.com>
2020 bob: Robert Bobbyton <bob@example.com>
2021 chloe: chloe@example.com
2022 abgroup: alice, bob
2023 bcgrp: bob, chloe, Other <o@example.com>
2024 EOF
2025
2026test_dump_aliases '--dump-aliases mutt format' \
2027 'mutt' \
2028 'alice' \
2029 'bob' \
2030 'chloe' \
2031 'donald' <<-\EOF
2032 alias alice Alice W Land <awol@example.com>
2033 alias donald Donald C Carlton <donc@example.com>
2034 alias bob Robert Bobbyton <bob@example.com>
2035 alias chloe chloe@example.com
2036 EOF
2037
2038test_dump_aliases '--dump-aliases mailrc format' \
2039 'mailrc' \
2040 'alice' \
2041 'bob' \
2042 'chloe' \
2043 'eve' <<-\EOF
2044 alias alice Alice W Land <awol@example.com>
2045 alias eve Eve <eve@example.com>
2046 alias bob Robert Bobbyton <bob@example.com>
2047 alias chloe chloe@example.com
2048 EOF
2049
2050test_dump_aliases '--dump-aliases pine format' \
2051 'pine' \
2052 'alice' \
2053 'bob' \
2054 'chloe' \
2055 'eve' <<-\EOF
2056 alice Alice W Land <awol@example.com>
2057 eve Eve <eve@example.com>
2058 bob Robert Bobbyton <bob@example.com>
2059 chloe chloe@example.com
2060 EOF
2061
2062test_dump_aliases '--dump-aliases gnus format' \
2063 'gnus' \
2064 'alice' \
2065 'bob' \
2066 'chloe' \
2067 'eve' <<-\EOF
2068 (define-mail-alias "alice" "awol@example.com")
2069 (define-mail-alias "eve" "eve@example.com")
2070 (define-mail-alias "bob" "bob@example.com")
2071 (define-mail-alias "chloe" "chloe@example.com")
2072 EOF
2073
2074test_expect_success '--dump-aliases must be used alone' '
2075 test_must_fail git send-email --dump-aliases --to=janice@example.com -1 refs/heads/accounting
2076'
2077
3ff15040
ÆAB
2078test_expect_success $PREREQ 'aliases and sendemail.identity' '
2079 test_must_fail git \
2080 -c sendemail.identity=cloud \
2081 -c sendemail.aliasesfile=default-aliases \
2082 -c sendemail.cloud.aliasesfile=cloud-aliases \
2083 send-email -1 2>stderr &&
6789275d 2084 test_grep "cloud-aliases" stderr
3ff15040
ÆAB
2085'
2086
514554cf
ES
2087test_sendmail_aliases () {
2088 msg="$1" && shift &&
2089 expect="$@" &&
2090 cat >.tmp-email-aliases &&
2091
2092 test_expect_success $PREREQ "$msg" '
2093 clean_fake_sendmail && rm -fr outdir &&
2094 git format-patch -1 -o outdir &&
2095 git config --replace-all sendemail.aliasesfile \
2096 "$(pwd)/.tmp-email-aliases" &&
2097 git config sendemail.aliasfiletype sendmail &&
2098 git send-email \
2099 --from="Example <nobody@example.com>" \
2100 --to=alice --to=bcgrp \
2101 --smtp-server="$(pwd)/fake.sendmail" \
2102 outdir/0001-*.patch \
2103 2>errors >out &&
2104 for i in $expect
2105 do
2106 grep "^!$i!$" commandline1 || return 1
2107 done
2108 '
2109}
2110
2111test_sendmail_aliases 'sendemail.aliasfiletype=sendmail' \
2112 'awol@example\.com' \
2113 'bob@example\.com' \
2114 'chloe@example\.com' \
2115 'o@example\.com' <<-\EOF
3169e06d
AH
2116 alice: Alice W Land <awol@example.com>
2117 bob: Robert Bobbyton <bob@example.com>
2118 # this is a comment
2119 # this is also a comment
2120 chloe: chloe@example.com
2121 abgroup: alice, bob
2122 bcgrp: bob, chloe, Other <o@example.com>
2123 EOF
3169e06d 2124
6be02640
ES
2125test_sendmail_aliases 'sendmail aliases line folding' \
2126 alice1 \
2127 bob1 bob2 \
2128 chuck1 chuck2 \
2129 darla1 darla2 darla3 \
2130 elton1 elton2 elton3 \
2131 fred1 fred2 \
2132 greg1 <<-\EOF
2133 alice: alice1
2134 bob: bob1,\
2135 bob2
2136 chuck: chuck1,
2137 chuck2
2138 darla: darla1,\
2139 darla2,
2140 darla3
2141 elton: elton1,
2142 elton2,\
2143 elton3
2144 fred: fred1,\
2145 fred2
2146 greg: greg1
2147 bcgrp: bob, chuck, darla, elton, fred, greg
2148 EOF
2149
2150test_sendmail_aliases 'sendmail aliases tolerate bogus line folding' \
2151 alice1 bob1 <<-\EOF
2152 alice: alice1
2153 bcgrp: bob1\
2154 EOF
2155
2156test_sendmail_aliases 'sendmail aliases empty' alice bcgrp <<-\EOF
2157 EOF
2158
f6f79e5e
RL
2159test_expect_success $PREREQ 'alias support in To header' '
2160 clean_fake_sendmail &&
2161 echo "alias sbd someone@example.org" >.mailrc &&
2162 test_config sendemail.aliasesfile ".mailrc" &&
2163 test_config sendemail.aliasfiletype mailrc &&
2164 git format-patch --stdout -1 --to=sbd >aliased.patch &&
2165 git send-email \
2166 --from="Example <nobody@example.com>" \
2167 --smtp-server="$(pwd)/fake.sendmail" \
2168 aliased.patch \
2169 2>errors >out &&
2170 grep "^!someone@example\.org!$" commandline1
2171'
2172
2173test_expect_success $PREREQ 'alias support in Cc header' '
2174 clean_fake_sendmail &&
2175 echo "alias sbd someone@example.org" >.mailrc &&
2176 test_config sendemail.aliasesfile ".mailrc" &&
2177 test_config sendemail.aliasfiletype mailrc &&
2178 git format-patch --stdout -1 --cc=sbd >aliased.patch &&
2179 git send-email \
2180 --from="Example <nobody@example.com>" \
2181 --smtp-server="$(pwd)/fake.sendmail" \
2182 aliased.patch \
2183 2>errors >out &&
2184 grep "^!someone@example\.org!$" commandline1
2185'
2186
2187test_expect_success $PREREQ 'tocmd works with aliases' '
2188 clean_fake_sendmail &&
2189 echo "alias sbd someone@example.org" >.mailrc &&
2190 test_config sendemail.aliasesfile ".mailrc" &&
2191 test_config sendemail.aliasfiletype mailrc &&
2192 git format-patch --stdout -1 >tocmd.patch &&
2193 echo tocmd--sbd >>tocmd.patch &&
2194 git send-email \
2195 --from="Example <nobody@example.com>" \
2196 --to-cmd=./tocmd-sed \
2197 --smtp-server="$(pwd)/fake.sendmail" \
2198 tocmd.patch \
2199 2>errors >out &&
2200 grep "^!someone@example\.org!$" commandline1
2201'
2202
2203test_expect_success $PREREQ 'cccmd works with aliases' '
2204 clean_fake_sendmail &&
2205 echo "alias sbd someone@example.org" >.mailrc &&
2206 test_config sendemail.aliasesfile ".mailrc" &&
2207 test_config sendemail.aliasfiletype mailrc &&
2208 git format-patch --stdout -1 >cccmd.patch &&
2209 echo cccmd--sbd >>cccmd.patch &&
2210 git send-email \
2211 --from="Example <nobody@example.com>" \
2212 --cc-cmd=./cccmd-sed \
2213 --smtp-server="$(pwd)/fake.sendmail" \
2214 cccmd.patch \
2215 2>errors >out &&
2216 grep "^!someone@example\.org!$" commandline1
2217'
2218
2cf770f5
LH
2219do_xmailer_test () {
2220 expected=$1 params=$2 &&
2221 git format-patch -1 &&
2222 git send-email \
2223 --from="Example <nobody@example.com>" \
2224 --to=someone@example.com \
2225 --smtp-server="$(pwd)/fake.sendmail" \
2226 $params \
2227 0001-*.patch \
2228 2>errors >out &&
2229 { grep '^X-Mailer:' out || :; } >mailer &&
2230 test_line_count = $expected mailer
2231}
2232
2233test_expect_success $PREREQ '--[no-]xmailer without any configuration' '
2234 do_xmailer_test 1 "--xmailer" &&
2235 do_xmailer_test 0 "--no-xmailer"
2236'
2237
2238test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=true' '
2239 test_config sendemail.xmailer true &&
2240 do_xmailer_test 1 "" &&
2241 do_xmailer_test 0 "--no-xmailer" &&
2242 do_xmailer_test 1 "--xmailer"
2243'
2244
879be431
ÆAB
2245test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer' '
2246 test_when_finished "test_unconfig sendemail.xmailer" &&
2247 cat >>.git/config <<-\EOF &&
2248 [sendemail]
2249 xmailer
2250 EOF
2251 test_config sendemail.xmailer true &&
2252 do_xmailer_test 1 "" &&
2253 do_xmailer_test 0 "--no-xmailer" &&
2254 do_xmailer_test 1 "--xmailer"
2255'
2256
2cf770f5
LH
2257test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=false' '
2258 test_config sendemail.xmailer false &&
2259 do_xmailer_test 0 "" &&
2260 do_xmailer_test 0 "--no-xmailer" &&
2261 do_xmailer_test 1 "--xmailer"
2262'
2263
879be431
ÆAB
2264test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=' '
2265 test_config sendemail.xmailer "" &&
2266 do_xmailer_test 0 "" &&
2267 do_xmailer_test 0 "--no-xmailer" &&
2268 do_xmailer_test 1 "--xmailer"
2269'
2270
b1c8a11c
RL
2271test_expect_success $PREREQ 'setup expected-list' '
2272 git send-email \
2273 --dry-run \
2274 --from="Example <from@example.com>" \
2275 --to="To 1 <to1@example.com>" \
2276 --to="to2@example.com" \
2277 --to="to3@example.com" \
2278 --cc="Cc 1 <cc1@example.com>" \
2279 --cc="Cc2 <cc2@example.com>" \
2280 --bcc="bcc1@example.com" \
2281 --bcc="bcc2@example.com" \
a881baa2 2282 0001-add-main.patch | replace_variable_fields \
b1c8a11c
RL
2283 >expected-list
2284'
2285
2286test_expect_success $PREREQ 'use email list in --cc --to and --bcc' '
2287 git send-email \
2288 --dry-run \
2289 --from="Example <from@example.com>" \
2290 --to="To 1 <to1@example.com>, to2@example.com" \
2291 --to="to3@example.com" \
2292 --cc="Cc 1 <cc1@example.com>, Cc2 <cc2@example.com>" \
2293 --bcc="bcc1@example.com, bcc2@example.com" \
a881baa2 2294 0001-add-main.patch | replace_variable_fields \
b1c8a11c
RL
2295 >actual-list &&
2296 test_cmp expected-list actual-list
2297'
2298
2299test_expect_success $PREREQ 'aliases work with email list' '
2300 echo "alias to2 to2@example.com" >.mutt &&
2301 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt &&
2302 test_config sendemail.aliasesfile ".mutt" &&
2303 test_config sendemail.aliasfiletype mutt &&
2304 git send-email \
2305 --dry-run \
2306 --from="Example <from@example.com>" \
2307 --to="To 1 <to1@example.com>, to2, to3@example.com" \
2308 --cc="cc1, Cc2 <cc2@example.com>" \
2309 --bcc="bcc1@example.com, bcc2@example.com" \
a881baa2 2310 0001-add-main.patch | replace_variable_fields \
b1c8a11c
RL
2311 >actual-list &&
2312 test_cmp expected-list actual-list
2313'
2314
fa5b1aa9
RL
2315test_expect_success $PREREQ 'leading and trailing whitespaces are removed' '
2316 echo "alias to2 to2@example.com" >.mutt &&
2317 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt &&
2318 test_config sendemail.aliasesfile ".mutt" &&
2319 test_config sendemail.aliasfiletype mutt &&
2320 TO1=$(echo "QTo 1 <to1@example.com>" | q_to_tab) &&
2321 TO2=$(echo "QZto2" | qz_to_tab_space) &&
2322 CC1=$(echo "cc1" | append_cr) &&
c64368e3 2323 BCC1=$(echo " bcc1@example.com Q" | q_to_nul) &&
fa5b1aa9
RL
2324 git send-email \
2325 --dry-run \
2326 --from=" Example <from@example.com>" \
2327 --to="$TO1" \
2328 --to="$TO2" \
2329 --to=" to3@example.com " \
2330 --cc="$CC1" \
2331 --cc="Cc2 <cc2@example.com>" \
2332 --bcc="$BCC1" \
2333 --bcc="bcc2@example.com" \
a881baa2 2334 0001-add-main.patch | replace_variable_fields \
fa5b1aa9
RL
2335 >actual-list &&
2336 test_cmp expected-list actual-list
2337'
2338
cd5b33fb
GA
2339test_expect_success $PREREQ 'test using command name with --sendmail-cmd' '
2340 clean_fake_sendmail &&
f6a5af0f 2341 PATH="$PWD:$PATH" \
cd5b33fb
GA
2342 git send-email \
2343 --from="Example <nobody@example.com>" \
2344 --to=nobody@example.com \
2345 --sendmail-cmd="fake.sendmail" \
2346 HEAD^ &&
2347 test_path_is_file commandline1
2348'
2349
2350test_expect_success $PREREQ 'test using arguments with --sendmail-cmd' '
2351 clean_fake_sendmail &&
2352 git send-email \
2353 --from="Example <nobody@example.com>" \
2354 --to=nobody@example.com \
2355 --sendmail-cmd='\''"$(pwd)/fake.sendmail" -f nobody@example.com'\'' \
2356 HEAD^ &&
2357 test_path_is_file commandline1
2358'
2359
2360test_expect_success $PREREQ 'test shell expression with --sendmail-cmd' '
2361 clean_fake_sendmail &&
2362 git send-email \
2363 --from="Example <nobody@example.com>" \
2364 --to=nobody@example.com \
2365 --sendmail-cmd='\''f() { "$(pwd)/fake.sendmail" "$@"; };f'\'' \
2366 HEAD^ &&
2367 test_path_is_file commandline1
2368'
2369
e0821134
MH
2370test_expect_success $PREREQ 'set up in-reply-to/references patches' '
2371 cat >has-reply.patch <<-\EOF &&
2372 From: A U Thor <author@example.com>
2373 Subject: patch with in-reply-to
2374 Message-ID: <patch.with.in.reply.to@example.com>
2375 In-Reply-To: <replied.to@example.com>
2376 References: <replied.to@example.com>
2377
2378 This is the body.
2379 EOF
2380 cat >no-reply.patch <<-\EOF
2381 From: A U Thor <author@example.com>
2382 Subject: patch without in-reply-to
2383 Message-ID: <patch.without.in.reply.to@example.com>
2384
2385 This is the body.
2386 EOF
2387'
2388
2389test_expect_success $PREREQ 'patch reply headers correct with --no-thread' '
2390 clean_fake_sendmail &&
2391 git send-email \
2392 --no-thread \
2393 --to=nobody@example.com \
2394 --smtp-server="$(pwd)/fake.sendmail" \
2395 has-reply.patch no-reply.patch &&
2396 grep "In-Reply-To: <replied.to@example.com>" msgtxt1 &&
2397 grep "References: <replied.to@example.com>" msgtxt1 &&
2398 ! grep replied.to@example.com msgtxt2
2399'
2400
2401test_expect_success $PREREQ 'cmdline in-reply-to used with --no-thread' '
2402 clean_fake_sendmail &&
2403 git send-email \
2404 --no-thread \
2405 --in-reply-to="<cmdline.reply@example.com>" \
2406 --to=nobody@example.com \
2407 --smtp-server="$(pwd)/fake.sendmail" \
2408 has-reply.patch no-reply.patch &&
2409 grep "In-Reply-To: <cmdline.reply@example.com>" msgtxt1 &&
2410 grep "References: <cmdline.reply@example.com>" msgtxt1 &&
2411 grep "In-Reply-To: <cmdline.reply@example.com>" msgtxt2 &&
2412 grep "References: <cmdline.reply@example.com>" msgtxt2
2413'
2414
6489660b 2415test_expect_success $PREREQ 'invoke hook' '
bef805b7 2416 test_hook sendemail-validate <<-\EOF &&
6489660b
JT
2417 # test that we have the correct environment variable, pwd, and
2418 # argument
2419 case "$GIT_DIR" in
2420 *.git)
2421 true
2422 ;;
2423 *)
2424 false
2425 ;;
2426 esac &&
a881baa2
JS
2427 test -f 0001-add-main.patch &&
2428 grep "add main" "$1"
6489660b
JT
2429 EOF
2430
2431 mkdir subdir &&
2432 (
2433 # Test that it works even if we are not at the root of the
2434 # working tree
2435 cd subdir &&
2436 git send-email \
2437 --from="Example <nobody@example.com>" \
2438 --to=nobody@example.com \
2439 --smtp-server="$(pwd)/../fake.sendmail" \
a881baa2 2440 ../0001-add-main.patch &&
6489660b
JT
2441
2442 # Verify error message when a patch is rejected by the hook
a881baa2 2443 sed -e "s/add main/x/" ../0001-add-main.patch >../another.patch &&
be8c48d4 2444 test_must_fail git send-email \
6489660b
JT
2445 --from="Example <nobody@example.com>" \
2446 --to=nobody@example.com \
2447 --smtp-server="$(pwd)/../fake.sendmail" \
be8c48d4 2448 ../another.patch 2>err &&
6789275d 2449 test_grep "rejected by sendemail-validate hook" err
6489660b
JT
2450 )
2451'
2452
3c8d3ade
RJ
2453expected_file_counter_output () {
2454 total=$1
2455 count=0
2456 while test $count -ne $total
2457 do
2458 count=$((count + 1)) &&
2459 echo "$count/$total" || return
2460 done
2461}
2462
2463test_expect_success $PREREQ '--validate hook allows counting of messages' '
2464 test_when_finished "rm -rf my-hooks.log" &&
2465 test_config core.hooksPath "my-hooks" &&
2466 mkdir -p my-hooks &&
2467
2468 write_script my-hooks/sendemail-validate <<-\EOF &&
2469 num=$GIT_SENDEMAIL_FILE_COUNTER &&
2470 tot=$GIT_SENDEMAIL_FILE_TOTAL &&
2471 echo "$num/$tot" >>my-hooks.log || exit 1
2472 EOF
2473
2474 >my-hooks.log &&
2475 expected_file_counter_output 4 >expect &&
2476 git send-email \
2477 --from="Example <from@example.com>" \
2478 --to=nobody@example.com \
2479 --smtp-server="$(pwd)/fake.sendmail" \
2480 --validate -3 --cover-letter --force &&
2481 test_cmp expect my-hooks.log
2482'
2483
177409e5
JT
2484test_expect_success $PREREQ 'test that send-email works outside a repo' '
2485 nongit git send-email \
2486 --from="Example <nobody@example.com>" \
2487 --to=nobody@example.com \
2488 --smtp-server="$(pwd)/fake.sendmail" \
a881baa2 2489 "$(pwd)/0001-add-main.patch"
177409e5
JT
2490'
2491
8774aa56
KM
2492test_expect_success $PREREQ 'send-email relays -v 3 to format-patch' '
2493 test_when_finished "rm -f out" &&
2494 git send-email --dry-run -v 3 -1 >out &&
2495 grep "PATCH v3" out
2496'
2497
dd84e528
DD
2498test_expect_success $PREREQ 'test that sendmail config is rejected' '
2499 test_config sendmail.program sendmail &&
2500 test_must_fail git send-email \
2501 --from="Example <nobody@example.com>" \
2502 --to=nobody@example.com \
2503 --smtp-server="$(pwd)/fake.sendmail" \
2504 HEAD^ 2>err &&
6789275d 2505 test_grep "found configuration options for '"'"sendmail"'"'" err
dd84e528
DD
2506'
2507
2508test_expect_success $PREREQ 'test that sendmail config rejection is specific' '
2509 test_config resendmail.program sendmail &&
2510 git send-email \
2511 --from="Example <nobody@example.com>" \
2512 --to=nobody@example.com \
2513 --smtp-server="$(pwd)/fake.sendmail" \
2514 HEAD^
2515'
2516
2517test_expect_success $PREREQ 'test forbidSendmailVariables behavior override' '
2518 test_config sendmail.program sendmail &&
2519 test_config sendemail.forbidSendmailVariables false &&
2520 git send-email \
2521 --from="Example <nobody@example.com>" \
2522 --to=nobody@example.com \
2523 --smtp-server="$(pwd)/fake.sendmail" \
2524 HEAD^
2525'
2526
637e8944
JK
2527test_expect_success $PREREQ '--compose handles lowercase headers' '
2528 write_script fake-editor <<-\EOF &&
2529 sed "s/^From:.*/from: edited-from@example.com/i" "$1" >"$1.tmp" &&
2530 mv "$1.tmp" "$1"
2531 EOF
2532 clean_fake_sendmail &&
2533 git send-email \
2534 --compose \
2535 --from="Example <from@example.com>" \
2536 --to=nobody@example.com \
2537 --smtp-server="$(pwd)/fake.sendmail" \
2538 HEAD^ &&
2539 grep "From: edited-from@example.com" msgtxt1
2540'
2541
2542test_expect_success $PREREQ '--compose handles to headers' '
2543 write_script fake-editor <<-\EOF &&
3ec61675 2544 sed "s/^To: .*/&, edited-to@example.com/" <"$1" >"$1.tmp" &&
637e8944
JK
2545 echo this is the body >>"$1.tmp" &&
2546 mv "$1.tmp" "$1"
2547 EOF
2548 clean_fake_sendmail &&
2549 GIT_SEND_EMAIL_NOTTY=1 \
2550 git send-email \
2551 --compose \
2552 --from="Example <from@example.com>" \
2553 --to=nobody@example.com \
2554 --smtp-server="$(pwd)/fake.sendmail" \
2555 HEAD^ &&
3ec61675
JK
2556 # Check both that the cover letter used our modified "to" line,
2557 # but also that it was picked up for the patch.
2558 q_to_tab >expect <<-\EOF &&
2559 To: nobody@example.com,
2560 Qedited-to@example.com
2561 EOF
2562 grep -A1 "^To:" msgtxt1 >msgtxt1.to &&
2563 test_cmp expect msgtxt1.to &&
2564 grep -A1 "^To:" msgtxt2 >msgtxt2.to &&
2565 test_cmp expect msgtxt2.to
637e8944
JK
2566'
2567
ce903018 2568test_done