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