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