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