]> git.ipfire.org Git - thirdparty/git.git/blame - t/t9001-send-email.sh
send-email: make --suppress-cc=self sanitize input
[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
57cd35e6 9test_expect_success $PREREQ \
ce903018
RA
10 'prepare reference tree' \
11 'echo "1A quick brown fox jumps over the" >file &&
12 echo "lazy dog" >>file &&
c0d45281 13 git add file &&
ce903018
RA
14 GIT_AUTHOR_NAME="A" git commit -a -m "Initial."'
15
57cd35e6 16test_expect_success $PREREQ \
ce903018 17 'Setup helper tool' \
bb3e4f03 18 '(echo "#!$SHELL_PATH"
2186d566 19 echo shift
6d34a2ba
JK
20 echo output=1
21 echo "while test -f commandline\$output; do output=\$((\$output+1)); done"
2186d566
JH
22 echo for a
23 echo do
24 echo " echo \"!\$a!\""
6d34a2ba 25 echo "done >commandline\$output"
72b5158b 26 test_have_prereq MINGW && echo "dos2unix commandline\$output"
6d34a2ba 27 echo "cat > msgtxt\$output"
c0d45281
JK
28 ) >fake.sendmail &&
29 chmod +x ./fake.sendmail &&
30 git add fake.sendmail &&
ce903018
RA
31 GIT_AUTHOR_NAME="A" git commit -a -m "Second."'
32
6d34a2ba
JK
33clean_fake_sendmail() {
34 rm -f commandline* msgtxt*
35}
36
57cd35e6 37test_expect_success $PREREQ 'Extract patches' '
3531e270 38 patches=`git format-patch -s --cc="One <one@example.com>" --cc=two@example.com -n HEAD^1`
280242d1
JH
39'
40
c1f2aa45
JS
41# Test no confirm early to ensure remaining tests will not hang
42test_no_confirm () {
43 rm -f no_confirm_okay
44 echo n | \
45 GIT_SEND_EMAIL_NOTTY=1 \
46 git send-email \
47 --from="Example <from@example.com>" \
48 --to=nobody@example.com \
49 --smtp-server="$(pwd)/fake.sendmail" \
50 $@ \
51 $patches > stdout &&
52 test_must_fail grep "Send this email" stdout &&
53 > no_confirm_okay
54}
55
56# Exit immediately to prevent hang if a no-confirm test fails
57check_no_confirm () {
57cd35e6
ÆAB
58 if ! test -f no_confirm_okay
59 then
60 say 'confirm test failed; skipping remaining tests to prevent hanging'
61 PREREQ="$PREREQ,CHECK_NO_CONFIRM"
62 fi
63 return 0
c1f2aa45
JS
64}
65
57cd35e6
ÆAB
66test_expect_success $PREREQ 'No confirm with --suppress-cc' '
67 test_no_confirm --suppress-cc=sob &&
68 check_no_confirm
c1f2aa45 69'
c1f2aa45 70
57cd35e6
ÆAB
71
72test_expect_success $PREREQ 'No confirm with --confirm=never' '
73 test_no_confirm --confirm=never &&
74 check_no_confirm
c1f2aa45 75'
c1f2aa45
JS
76
77# leave sendemail.confirm set to never after this so that none of the
78# remaining tests prompt unintentionally.
57cd35e6 79test_expect_success $PREREQ 'No confirm with sendemail.confirm=never' '
c1f2aa45 80 git config sendemail.confirm never &&
57cd35e6
ÆAB
81 test_no_confirm --compose --subject=foo &&
82 check_no_confirm
c1f2aa45 83'
c1f2aa45 84
57cd35e6 85test_expect_success $PREREQ 'Send patches' '
3531e270 86 git send-email --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
280242d1 87'
ce903018 88
f9444147 89test_expect_success $PREREQ 'setup expect' '
2186d566
JH
90cat >expected <<\EOF
91!nobody@example.com!
92!author@example.com!
5012699d
JS
93!one@example.com!
94!two@example.com!
2186d566 95EOF
f9444147
ÆAB
96'
97
57cd35e6 98test_expect_success $PREREQ \
ce903018 99 'Verify commandline' \
188c3827 100 'test_cmp expected commandline1'
ce903018 101
57cd35e6 102test_expect_success $PREREQ 'Send patches with --envelope-sender' '
4f333bc1 103 clean_fake_sendmail &&
41ccfdd9 104 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
105'
106
f9444147 107test_expect_success $PREREQ 'setup expect' '
4f333bc1
JH
108cat >expected <<\EOF
109!patch@example.com!
110!-i!
111!nobody@example.com!
112!author@example.com!
113!one@example.com!
114!two@example.com!
115EOF
f9444147
ÆAB
116'
117
57cd35e6 118test_expect_success $PREREQ \
4f333bc1
JH
119 'Verify commandline' \
120 'test_cmp expected commandline1'
121
57cd35e6 122test_expect_success $PREREQ 'Send patches with --envelope-sender=auto' '
c89e3241
FC
123 clean_fake_sendmail &&
124 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
125'
126
f9444147 127test_expect_success $PREREQ 'setup expect' '
c89e3241
FC
128cat >expected <<\EOF
129!nobody@example.com!
130!-i!
131!nobody@example.com!
132!author@example.com!
133!one@example.com!
134!two@example.com!
135EOF
f9444147
ÆAB
136'
137
57cd35e6 138test_expect_success $PREREQ \
c89e3241
FC
139 'Verify commandline' \
140 'test_cmp expected commandline1'
141
f9444147 142test_expect_success $PREREQ 'setup expect' "
b7f30e0a
DK
143cat >expected-show-all-headers <<\EOF
1440001-Second.patch
145(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
5012699d
JS
146(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
147(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
b7f30e0a
DK
148Dry-OK. Log says:
149Server: relay.example.com
150MAIL FROM:<from@example.com>
02461e0e
JP
151RCPT TO:<to@example.com>
152RCPT TO:<cc@example.com>
153RCPT TO:<author@example.com>
154RCPT TO:<one@example.com>
155RCPT TO:<two@example.com>
156RCPT TO:<bcc@example.com>
b7f30e0a
DK
157From: Example <from@example.com>
158To: to@example.com
02461e0e
JP
159Cc: cc@example.com,
160 A <author@example.com>,
161 One <one@example.com>,
162 two@example.com
b7f30e0a
DK
163Subject: [PATCH 1/1] Second.
164Date: DATE-STRING
165Message-Id: MESSAGE-ID-STRING
166X-Mailer: X-MAILER-STRING
167In-Reply-To: <unique-message-id@example.com>
168References: <unique-message-id@example.com>
169
170Result: OK
171EOF
f9444147 172"
b7f30e0a 173
5adcf2c6
MT
174test_suppress_self () {
175 test_commit $3 &&
176 test_when_finished "git reset --hard HEAD^" &&
177
178 write_script cccmd-sed <<-EOF &&
179 sed -n -e s/^cccmd--//p "\$1"
180 EOF
181
182 git commit --amend --author="$1 <$2>" -F - &&
183 clean_fake_sendmail &&
184 git format-patch --stdout -1 >"suppress-self-$3.patch" &&
185
186 git send-email --from="$1 <$2>" \
187 --to=nobody@example.com \
188 --cc-cmd=./cccmd-sed \
189 --suppress-cc=self \
190 --smtp-server="$(pwd)/fake.sendmail" \
191 suppress-self-$3.patch &&
192
193 mv msgtxt1 msgtxt1-$3 &&
194 sed -e '/^$/q' msgtxt1-$3 >"msghdr1-$3" &&
195 >"expected-no-cc-$3" &&
196
197 (grep '^Cc:' msghdr1-$3 >"actual-no-cc-$3";
198 test_cmp expected-no-cc-$3 actual-no-cc-$3)
199}
200
201test_suppress_self_unquoted () {
202 test_suppress_self "$1" "$2" "unquoted-$3" <<-EOF
203 test suppress-cc.self unquoted-$3 with name $1 email $2
204
205 unquoted-$3
206
d6ee4456
MT
207 cccmd--$1 <$2>
208
5adcf2c6
MT
209 Cc: $1 <$2>
210 Signed-off-by: $1 <$2>
211 EOF
212}
213
214test_expect_success $PREREQ 'self name is suppressed' "
d6ee4456 215 test_suppress_self_unquoted 'A U Thor' 'author@example.com' \
5adcf2c6
MT
216 'self_name_suppressed'
217"
218
57cd35e6 219test_expect_success $PREREQ 'Show all headers' '
b7f30e0a
DK
220 git send-email \
221 --dry-run \
3531e270 222 --suppress-cc=sob \
b7f30e0a
DK
223 --from="Example <from@example.com>" \
224 --to=to@example.com \
225 --cc=cc@example.com \
226 --bcc=bcc@example.com \
227 --in-reply-to="<unique-message-id@example.com>" \
228 --smtp-server relay.example.com \
229 $patches |
230 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
231 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
232 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
233 >actual-show-all-headers &&
82ebb0b6 234 test_cmp expected-show-all-headers actual-show-all-headers
b7f30e0a
DK
235'
236
57cd35e6 237test_expect_success $PREREQ 'Prompting works' '
0da43a68 238 clean_fake_sendmail &&
8cac13dc 239 (echo "to@example.com"
0da43a68
JS
240 echo ""
241 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
242 --smtp-server="$(pwd)/fake.sendmail" \
243 $patches \
244 2>errors &&
8cac13dc 245 grep "^From: A U Thor <author@example.com>\$" msgtxt1 &&
9524cf29 246 grep "^To: to@example.com\$" msgtxt1
0da43a68
JS
247'
248
59defcc3
JK
249test_expect_success $PREREQ,AUTOIDENT 'implicit ident is allowed' '
250 clean_fake_sendmail &&
251 (sane_unset GIT_AUTHOR_NAME &&
252 sane_unset GIT_AUTHOR_EMAIL &&
253 sane_unset GIT_COMMITTER_NAME &&
254 sane_unset GIT_COMMITTER_EMAIL &&
255 GIT_SEND_EMAIL_NOTTY=1 git send-email \
256 --smtp-server="$(pwd)/fake.sendmail" \
257 --to=to@example.com \
258 $patches </dev/null 2>errors
259 )
260'
261
262test_expect_success $PREREQ,!AUTOIDENT 'broken implicit ident aborts send-email' '
263 clean_fake_sendmail &&
264 (sane_unset GIT_AUTHOR_NAME &&
265 sane_unset GIT_AUTHOR_EMAIL &&
266 sane_unset GIT_COMMITTER_NAME &&
267 sane_unset GIT_COMMITTER_EMAIL &&
268 GIT_SEND_EMAIL_NOTTY=1 && export GIT_SEND_EMAIL_NOTTY &&
269 test_must_fail git send-email \
270 --smtp-server="$(pwd)/fake.sendmail" \
271 --to=to@example.com \
272 $patches </dev/null 2>errors &&
273 test_i18ngrep "tell me who you are" errors
274 )
275'
276
6e74e075
JP
277test_expect_success $PREREQ 'tocmd works' '
278 clean_fake_sendmail &&
279 cp $patches tocmd.patch &&
280 echo tocmd--tocmd@example.com >>tocmd.patch &&
281 {
282 echo "#!$SHELL_PATH"
283 echo sed -n -e s/^tocmd--//p \"\$1\"
284 } > tocmd-sed &&
285 chmod +x tocmd-sed &&
286 git send-email \
287 --from="Example <nobody@example.com>" \
288 --to-cmd=./tocmd-sed \
289 --smtp-server="$(pwd)/fake.sendmail" \
290 tocmd.patch \
291 &&
292 grep "^To: tocmd@example.com" msgtxt1
293'
294
57cd35e6 295test_expect_success $PREREQ 'cccmd works' '
cb8a9bd5
PB
296 clean_fake_sendmail &&
297 cp $patches cccmd.patch &&
41ae8f1d 298 echo "cccmd-- cccmd@example.com" >>cccmd.patch &&
977e289e
BC
299 {
300 echo "#!$SHELL_PATH"
301 echo sed -n -e s/^cccmd--//p \"\$1\"
302 } > cccmd-sed &&
cb8a9bd5
PB
303 chmod +x cccmd-sed &&
304 git send-email \
305 --from="Example <nobody@example.com>" \
306 --to=nobody@example.com \
307 --cc-cmd=./cccmd-sed \
308 --smtp-server="$(pwd)/fake.sendmail" \
309 cccmd.patch \
310 &&
02461e0e 311 grep "^ cccmd@example.com" msgtxt1
cb8a9bd5
PB
312'
313
57cd35e6 314test_expect_success $PREREQ 'reject long lines' '
f9444147
ÆAB
315 z8=zzzzzzzz &&
316 z64=$z8$z8$z8$z8$z8$z8$z8$z8 &&
317 z512=$z64$z64$z64$z64$z64$z64$z64$z64 &&
6d34a2ba 318 clean_fake_sendmail &&
747bbff9
JK
319 cp $patches longline.patch &&
320 echo $z512$z512 >>longline.patch &&
d492b31c 321 test_must_fail git send-email \
747bbff9
JK
322 --from="Example <nobody@example.com>" \
323 --to=nobody@example.com \
324 --smtp-server="$(pwd)/fake.sendmail" \
325 $patches longline.patch \
326 2>errors &&
327 grep longline.patch errors
328'
329
57cd35e6 330test_expect_success $PREREQ 'no patch was sent' '
6d34a2ba 331 ! test -e commandline1
747bbff9
JK
332'
333
57cd35e6 334test_expect_success $PREREQ 'Author From: in message body' '
5012699d
JS
335 clean_fake_sendmail &&
336 git send-email \
337 --from="Example <nobody@example.com>" \
338 --to=nobody@example.com \
339 --smtp-server="$(pwd)/fake.sendmail" \
340 $patches &&
cc7e8167 341 sed "1,/^\$/d" < msgtxt1 > msgbody1 &&
5012699d
JS
342 grep "From: A <author@example.com>" msgbody1
343'
344
57cd35e6 345test_expect_success $PREREQ 'Author From: not in message body' '
5012699d
JS
346 clean_fake_sendmail &&
347 git send-email \
348 --from="A <author@example.com>" \
349 --to=nobody@example.com \
350 --smtp-server="$(pwd)/fake.sendmail" \
351 $patches &&
cc7e8167 352 sed "1,/^\$/d" < msgtxt1 > msgbody1 &&
5012699d
JS
353 ! grep "From: A <author@example.com>" msgbody1
354'
355
57cd35e6 356test_expect_success $PREREQ 'allow long lines with --no-validate' '
c764a0c2
JK
357 git send-email \
358 --from="Example <nobody@example.com>" \
359 --to=nobody@example.com \
360 --smtp-server="$(pwd)/fake.sendmail" \
3fee1fe8 361 --novalidate \
c764a0c2
JK
362 $patches longline.patch \
363 2>errors
364'
365
57cd35e6 366test_expect_success $PREREQ 'Invalid In-Reply-To' '
6d34a2ba 367 clean_fake_sendmail &&
0fb7fc75
JS
368 git send-email \
369 --from="Example <nobody@example.com>" \
370 --to=nobody@example.com \
371 --in-reply-to=" " \
372 --smtp-server="$(pwd)/fake.sendmail" \
5b57413c 373 $patches \
cc7e8167 374 2>errors &&
6d34a2ba 375 ! grep "^In-Reply-To: < *>" msgtxt1
0fb7fc75
JS
376'
377
57cd35e6 378test_expect_success $PREREQ 'Valid In-Reply-To when prompting' '
6d34a2ba 379 clean_fake_sendmail &&
0fb7fc75
JS
380 (echo "From Example <from@example.com>"
381 echo "To Example <to@example.com>"
382 echo ""
383 ) | env GIT_SEND_EMAIL_NOTTY=1 git send-email \
384 --smtp-server="$(pwd)/fake.sendmail" \
385 $patches 2>errors &&
6d34a2ba 386 ! grep "^In-Reply-To: < *>" msgtxt1
0fb7fc75
JS
387'
388
54aae5e1
JH
389test_expect_success $PREREQ 'In-Reply-To without --chain-reply-to' '
390 clean_fake_sendmail &&
391 echo "<unique-message-id@example.com>" >expect &&
392 git send-email \
393 --from="Example <nobody@example.com>" \
394 --to=nobody@example.com \
d2559f73 395 --nochain-reply-to \
54aae5e1
JH
396 --in-reply-to="$(cat expect)" \
397 --smtp-server="$(pwd)/fake.sendmail" \
398 $patches $patches $patches \
399 2>errors &&
db54c8e7 400 # The first message is a reply to --in-reply-to
54aae5e1
JH
401 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
402 test_cmp expect actual &&
db54c8e7
AO
403 # Second and subsequent messages are replies to the first one
404 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
54aae5e1
JH
405 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
406 test_cmp expect actual &&
407 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
408 test_cmp expect actual
409'
410
411test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' '
412 clean_fake_sendmail &&
413 echo "<unique-message-id@example.com>" >expect &&
414 git send-email \
415 --from="Example <nobody@example.com>" \
416 --to=nobody@example.com \
417 --chain-reply-to \
418 --in-reply-to="$(cat expect)" \
419 --smtp-server="$(pwd)/fake.sendmail" \
420 $patches $patches $patches \
421 2>errors &&
422 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
423 test_cmp expect actual &&
424 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
425 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
426 test_cmp expect actual &&
427 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt2 >expect &&
428 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
429 test_cmp expect actual
430'
431
57cd35e6 432test_expect_success $PREREQ 'setup fake editor' '
bb3e4f03 433 (echo "#!$SHELL_PATH" &&
065096c2 434 echo "echo fake edit >>\"\$1\""
8a8bf469
JK
435 ) >fake-editor &&
436 chmod +x fake-editor
437'
438
7f0475c3 439test_set_editor "$(pwd)/fake-editor"
065096c2 440
57cd35e6 441test_expect_success $PREREQ '--compose works' '
8a8bf469 442 clean_fake_sendmail &&
c1f2aa45
JS
443 git send-email \
444 --compose --subject foo \
445 --from="Example <nobody@example.com>" \
446 --to=nobody@example.com \
447 --smtp-server="$(pwd)/fake.sendmail" \
448 $patches \
449 2>errors
8a8bf469
JK
450'
451
57cd35e6 452test_expect_success $PREREQ 'first message is compose text' '
8a8bf469
JK
453 grep "^fake edit" msgtxt1
454'
455
57cd35e6 456test_expect_success $PREREQ 'second message is patch' '
8a8bf469
JK
457 grep "Subject:.*Second" msgtxt2
458'
459
f9444147 460test_expect_success $PREREQ 'setup expect' "
3531e270 461cat >expected-suppress-sob <<\EOF
33c592dd
MV
4620001-Second.patch
463(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
5012699d
JS
464(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
465(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
33c592dd
MV
466Dry-OK. Log says:
467Server: relay.example.com
468MAIL FROM:<from@example.com>
02461e0e
JP
469RCPT TO:<to@example.com>
470RCPT TO:<cc@example.com>
471RCPT TO:<author@example.com>
472RCPT TO:<one@example.com>
473RCPT TO:<two@example.com>
33c592dd
MV
474From: Example <from@example.com>
475To: to@example.com
02461e0e
JP
476Cc: cc@example.com,
477 A <author@example.com>,
478 One <one@example.com>,
479 two@example.com
33c592dd
MV
480Subject: [PATCH 1/1] Second.
481Date: DATE-STRING
482Message-Id: MESSAGE-ID-STRING
483X-Mailer: X-MAILER-STRING
484
485Result: OK
486EOF
f9444147 487"
33c592dd 488
3531e270 489test_suppression () {
33c592dd
MV
490 git send-email \
491 --dry-run \
cb8a9bd5 492 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
33c592dd
MV
493 --from="Example <from@example.com>" \
494 --to=to@example.com \
495 --smtp-server relay.example.com \
496 $patches |
497 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
498 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
499 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
cb8a9bd5
PB
500 >actual-suppress-$1${2+"-$2"} &&
501 test_cmp expected-suppress-$1${2+"-$2"} actual-suppress-$1${2+"-$2"}
3531e270
JS
502}
503
57cd35e6 504test_expect_success $PREREQ 'sendemail.cc set' '
3531e270
JS
505 git config sendemail.cc cc@example.com &&
506 test_suppression sob
33c592dd
MV
507'
508
f9444147 509test_expect_success $PREREQ 'setup expect' "
3531e270 510cat >expected-suppress-sob <<\EOF
33c592dd
MV
5110001-Second.patch
512(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
5012699d
JS
513(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
514(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
33c592dd
MV
515Dry-OK. Log says:
516Server: relay.example.com
517MAIL FROM:<from@example.com>
02461e0e
JP
518RCPT TO:<to@example.com>
519RCPT TO:<author@example.com>
520RCPT TO:<one@example.com>
521RCPT TO:<two@example.com>
33c592dd
MV
522From: Example <from@example.com>
523To: to@example.com
02461e0e
JP
524Cc: A <author@example.com>,
525 One <one@example.com>,
526 two@example.com
33c592dd
MV
527Subject: [PATCH 1/1] Second.
528Date: DATE-STRING
529Message-Id: MESSAGE-ID-STRING
530X-Mailer: X-MAILER-STRING
531
532Result: OK
533EOF
f9444147 534"
33c592dd 535
57cd35e6 536test_expect_success $PREREQ 'sendemail.cc unset' '
33c592dd 537 git config --unset sendemail.cc &&
3531e270
JS
538 test_suppression sob
539'
540
f9444147 541test_expect_success $PREREQ 'setup expect' "
cb8a9bd5
PB
542cat >expected-suppress-cccmd <<\EOF
5430001-Second.patch
544(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
545(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
546(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
547(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
548Dry-OK. Log says:
549Server: relay.example.com
550MAIL FROM:<from@example.com>
02461e0e
JP
551RCPT TO:<to@example.com>
552RCPT TO:<author@example.com>
553RCPT TO:<one@example.com>
554RCPT TO:<two@example.com>
555RCPT TO:<committer@example.com>
cb8a9bd5
PB
556From: Example <from@example.com>
557To: to@example.com
02461e0e
JP
558Cc: A <author@example.com>,
559 One <one@example.com>,
560 two@example.com,
561 C O Mitter <committer@example.com>
cb8a9bd5
PB
562Subject: [PATCH 1/1] Second.
563Date: DATE-STRING
564Message-Id: MESSAGE-ID-STRING
565X-Mailer: X-MAILER-STRING
566
567Result: OK
568EOF
f9444147 569"
cb8a9bd5 570
57cd35e6 571test_expect_success $PREREQ 'sendemail.cccmd' '
cb8a9bd5
PB
572 echo echo cc-cmd@example.com > cccmd &&
573 chmod +x cccmd &&
574 git config sendemail.cccmd ./cccmd &&
575 test_suppression cccmd
576'
577
f9444147 578test_expect_success $PREREQ 'setup expect' '
3531e270
JS
579cat >expected-suppress-all <<\EOF
5800001-Second.patch
581Dry-OK. Log says:
582Server: relay.example.com
583MAIL FROM:<from@example.com>
584RCPT TO:<to@example.com>
585From: Example <from@example.com>
586To: to@example.com
587Subject: [PATCH 1/1] Second.
588Date: DATE-STRING
589Message-Id: MESSAGE-ID-STRING
590X-Mailer: X-MAILER-STRING
591
592Result: OK
593EOF
f9444147 594'
3531e270 595
57cd35e6 596test_expect_success $PREREQ '--suppress-cc=all' '
3531e270
JS
597 test_suppression all
598'
599
f9444147 600test_expect_success $PREREQ 'setup expect' "
3531e270
JS
601cat >expected-suppress-body <<\EOF
6020001-Second.patch
603(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
604(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
605(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
cb8a9bd5 606(cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
3531e270
JS
607Dry-OK. Log says:
608Server: relay.example.com
609MAIL FROM:<from@example.com>
02461e0e
JP
610RCPT TO:<to@example.com>
611RCPT TO:<author@example.com>
612RCPT TO:<one@example.com>
613RCPT TO:<two@example.com>
614RCPT TO:<cc-cmd@example.com>
3531e270
JS
615From: Example <from@example.com>
616To: to@example.com
02461e0e
JP
617Cc: A <author@example.com>,
618 One <one@example.com>,
619 two@example.com,
620 cc-cmd@example.com
3531e270
JS
621Subject: [PATCH 1/1] Second.
622Date: DATE-STRING
623Message-Id: MESSAGE-ID-STRING
624X-Mailer: X-MAILER-STRING
625
626Result: OK
627EOF
f9444147 628"
3531e270 629
57cd35e6 630test_expect_success $PREREQ '--suppress-cc=body' '
3531e270
JS
631 test_suppression body
632'
633
f9444147 634test_expect_success $PREREQ 'setup expect' "
cb8a9bd5
PB
635cat >expected-suppress-body-cccmd <<\EOF
6360001-Second.patch
637(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
638(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
639(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
640Dry-OK. Log says:
641Server: relay.example.com
642MAIL FROM:<from@example.com>
02461e0e
JP
643RCPT TO:<to@example.com>
644RCPT TO:<author@example.com>
645RCPT TO:<one@example.com>
646RCPT TO:<two@example.com>
cb8a9bd5
PB
647From: Example <from@example.com>
648To: to@example.com
02461e0e
JP
649Cc: A <author@example.com>,
650 One <one@example.com>,
651 two@example.com
cb8a9bd5
PB
652Subject: [PATCH 1/1] Second.
653Date: DATE-STRING
654Message-Id: MESSAGE-ID-STRING
655X-Mailer: X-MAILER-STRING
656
657Result: OK
658EOF
f9444147 659"
cb8a9bd5 660
57cd35e6 661test_expect_success $PREREQ '--suppress-cc=body --suppress-cc=cccmd' '
cb8a9bd5
PB
662 test_suppression body cccmd
663'
664
f9444147 665test_expect_success $PREREQ 'setup expect' "
3531e270
JS
666cat >expected-suppress-sob <<\EOF
6670001-Second.patch
668(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
669(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
670(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
671Dry-OK. Log says:
672Server: relay.example.com
673MAIL FROM:<from@example.com>
02461e0e
JP
674RCPT TO:<to@example.com>
675RCPT TO:<author@example.com>
676RCPT TO:<one@example.com>
677RCPT TO:<two@example.com>
3531e270
JS
678From: Example <from@example.com>
679To: to@example.com
02461e0e
JP
680Cc: A <author@example.com>,
681 One <one@example.com>,
682 two@example.com
3531e270
JS
683Subject: [PATCH 1/1] Second.
684Date: DATE-STRING
685Message-Id: MESSAGE-ID-STRING
686X-Mailer: X-MAILER-STRING
687
688Result: OK
689EOF
f9444147 690"
3531e270 691
57cd35e6 692test_expect_success $PREREQ '--suppress-cc=sob' '
cc7e8167 693 test_might_fail git config --unset sendemail.cccmd &&
3531e270
JS
694 test_suppression sob
695'
696
f9444147 697test_expect_success $PREREQ 'setup expect' "
3531e270
JS
698cat >expected-suppress-bodycc <<\EOF
6990001-Second.patch
700(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
701(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
702(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
703(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
704Dry-OK. Log says:
705Server: relay.example.com
706MAIL FROM:<from@example.com>
02461e0e
JP
707RCPT TO:<to@example.com>
708RCPT TO:<author@example.com>
709RCPT TO:<one@example.com>
710RCPT TO:<two@example.com>
711RCPT TO:<committer@example.com>
3531e270
JS
712From: Example <from@example.com>
713To: to@example.com
02461e0e
JP
714Cc: A <author@example.com>,
715 One <one@example.com>,
716 two@example.com,
717 C O Mitter <committer@example.com>
3531e270
JS
718Subject: [PATCH 1/1] Second.
719Date: DATE-STRING
720Message-Id: MESSAGE-ID-STRING
721X-Mailer: X-MAILER-STRING
722
723Result: OK
724EOF
f9444147 725"
3531e270 726
57cd35e6 727test_expect_success $PREREQ '--suppress-cc=bodycc' '
3531e270
JS
728 test_suppression bodycc
729'
730
f9444147 731test_expect_success $PREREQ 'setup expect' "
3531e270
JS
732cat >expected-suppress-cc <<\EOF
7330001-Second.patch
734(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
735(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
736Dry-OK. Log says:
737Server: relay.example.com
738MAIL FROM:<from@example.com>
02461e0e
JP
739RCPT TO:<to@example.com>
740RCPT TO:<author@example.com>
741RCPT TO:<committer@example.com>
3531e270
JS
742From: Example <from@example.com>
743To: to@example.com
02461e0e
JP
744Cc: A <author@example.com>,
745 C O Mitter <committer@example.com>
3531e270
JS
746Subject: [PATCH 1/1] Second.
747Date: DATE-STRING
748Message-Id: MESSAGE-ID-STRING
749X-Mailer: X-MAILER-STRING
750
751Result: OK
752EOF
f9444147 753"
3531e270 754
57cd35e6 755test_expect_success $PREREQ '--suppress-cc=cc' '
3531e270 756 test_suppression cc
33c592dd
MV
757'
758
c1f2aa45
JS
759test_confirm () {
760 echo y | \
761 GIT_SEND_EMAIL_NOTTY=1 \
762 git send-email \
763 --from="Example <nobody@example.com>" \
764 --to=nobody@example.com \
765 --smtp-server="$(pwd)/fake.sendmail" \
c18f75a1
JS
766 $@ $patches > stdout &&
767 grep "Send this email" stdout
c1f2aa45
JS
768}
769
57cd35e6 770test_expect_success $PREREQ '--confirm=always' '
c1f2aa45
JS
771 test_confirm --confirm=always --suppress-cc=all
772'
773
57cd35e6 774test_expect_success $PREREQ '--confirm=auto' '
c1f2aa45
JS
775 test_confirm --confirm=auto
776'
777
57cd35e6 778test_expect_success $PREREQ '--confirm=cc' '
c1f2aa45
JS
779 test_confirm --confirm=cc
780'
781
57cd35e6 782test_expect_success $PREREQ '--confirm=compose' '
c1f2aa45
JS
783 test_confirm --confirm=compose --compose
784'
785
57cd35e6 786test_expect_success $PREREQ 'confirm by default (due to cc)' '
c1f2aa45
JS
787 CONFIRM=$(git config --get sendemail.confirm) &&
788 git config --unset sendemail.confirm &&
c18f75a1
JS
789 test_confirm
790 ret="$?"
791 git config sendemail.confirm ${CONFIRM:-never}
792 test $ret = "0"
c1f2aa45
JS
793'
794
57cd35e6 795test_expect_success $PREREQ 'confirm by default (due to --compose)' '
c1f2aa45
JS
796 CONFIRM=$(git config --get sendemail.confirm) &&
797 git config --unset sendemail.confirm &&
798 test_confirm --suppress-cc=all --compose
799 ret="$?"
800 git config sendemail.confirm ${CONFIRM:-never}
801 test $ret = "0"
802'
803
57cd35e6 804test_expect_success $PREREQ 'confirm detects EOF (inform assumes y)' '
c18f75a1
JS
805 CONFIRM=$(git config --get sendemail.confirm) &&
806 git config --unset sendemail.confirm &&
dc1460aa
JS
807 rm -fr outdir &&
808 git format-patch -2 -o outdir &&
c18f75a1
JS
809 GIT_SEND_EMAIL_NOTTY=1 \
810 git send-email \
811 --from="Example <nobody@example.com>" \
812 --to=nobody@example.com \
813 --smtp-server="$(pwd)/fake.sendmail" \
dc1460aa 814 outdir/*.patch < /dev/null
c18f75a1
JS
815 ret="$?"
816 git config sendemail.confirm ${CONFIRM:-never}
817 test $ret = "0"
818'
819
57cd35e6 820test_expect_success $PREREQ 'confirm detects EOF (auto causes failure)' '
c18f75a1
JS
821 CONFIRM=$(git config --get sendemail.confirm) &&
822 git config sendemail.confirm auto &&
3b3637c3
JS
823 GIT_SEND_EMAIL_NOTTY=1 &&
824 export GIT_SEND_EMAIL_NOTTY &&
c18f75a1
JS
825 test_must_fail git send-email \
826 --from="Example <nobody@example.com>" \
827 --to=nobody@example.com \
828 --smtp-server="$(pwd)/fake.sendmail" \
829 $patches < /dev/null
830 ret="$?"
831 git config sendemail.confirm ${CONFIRM:-never}
832 test $ret = "0"
833'
834
41ccfdd9 835test_expect_success $PREREQ 'confirm does not loop forever' '
c18f75a1
JS
836 CONFIRM=$(git config --get sendemail.confirm) &&
837 git config sendemail.confirm auto &&
3b3637c3
JS
838 GIT_SEND_EMAIL_NOTTY=1 &&
839 export GIT_SEND_EMAIL_NOTTY &&
840 yes "bogus" | test_must_fail git send-email \
c18f75a1
JS
841 --from="Example <nobody@example.com>" \
842 --to=nobody@example.com \
843 --smtp-server="$(pwd)/fake.sendmail" \
844 $patches
845 ret="$?"
846 git config sendemail.confirm ${CONFIRM:-never}
847 test $ret = "0"
848'
849
57cd35e6 850test_expect_success $PREREQ 'utf8 Cc is rfc2047 encoded' '
a61c0ffa
JS
851 clean_fake_sendmail &&
852 rm -fr outdir &&
853 git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
854 git send-email \
855 --from="Example <nobody@example.com>" \
856 --to=nobody@example.com \
857 --smtp-server="$(pwd)/fake.sendmail" \
858 outdir/*.patch &&
02461e0e 859 grep "^ " msgtxt1 |
d1fff6fc 860 grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
a61c0ffa
JS
861'
862
57cd35e6 863test_expect_success $PREREQ '--compose adds MIME for utf8 body' '
0706bd19 864 clean_fake_sendmail &&
bb3e4f03 865 (echo "#!$SHELL_PATH" &&
c01cdde1 866 echo "echo utf8 body: àéìöú >>\"\$1\""
0706bd19
JK
867 ) >fake-editor-utf8 &&
868 chmod +x fake-editor-utf8 &&
c01cdde1 869 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
0706bd19
JK
870 git send-email \
871 --compose --subject foo \
872 --from="Example <nobody@example.com>" \
873 --to=nobody@example.com \
874 --smtp-server="$(pwd)/fake.sendmail" \
875 $patches &&
876 grep "^utf8 body" msgtxt1 &&
d1fff6fc 877 grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
0706bd19
JK
878'
879
57cd35e6 880test_expect_success $PREREQ '--compose respects user mime type' '
0706bd19 881 clean_fake_sendmail &&
bb3e4f03 882 (echo "#!$SHELL_PATH" &&
0706bd19
JK
883 echo "(echo MIME-Version: 1.0"
884 echo " echo Content-Type: text/plain\\; charset=iso-8859-1"
885 echo " echo Content-Transfer-Encoding: 8bit"
886 echo " echo Subject: foo"
887 echo " echo "
c01cdde1 888 echo " echo utf8 body: àéìöú) >\"\$1\""
0706bd19
JK
889 ) >fake-editor-utf8-mime &&
890 chmod +x fake-editor-utf8-mime &&
c01cdde1 891 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
0706bd19
JK
892 git send-email \
893 --compose --subject foo \
894 --from="Example <nobody@example.com>" \
895 --to=nobody@example.com \
896 --smtp-server="$(pwd)/fake.sendmail" \
897 $patches &&
898 grep "^utf8 body" msgtxt1 &&
899 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
d1fff6fc 900 ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
0706bd19
JK
901'
902
57cd35e6 903test_expect_success $PREREQ '--compose adds MIME for utf8 subject' '
d54eaaa2 904 clean_fake_sendmail &&
c01cdde1 905 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
d54eaaa2
JK
906 git send-email \
907 --compose --subject utf8-sübjëct \
908 --from="Example <nobody@example.com>" \
909 --to=nobody@example.com \
910 --smtp-server="$(pwd)/fake.sendmail" \
911 $patches &&
912 grep "^fake edit" msgtxt1 &&
d1fff6fc 913 grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
d54eaaa2
JK
914'
915
b622d4d1
TR
916test_expect_success $PREREQ 'utf8 author is correctly passed on' '
917 clean_fake_sendmail &&
918 test_commit weird_author &&
919 test_when_finished "git reset --hard HEAD^" &&
920 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
921 git format-patch --stdout -1 >funny_name.patch &&
922 git send-email --from="Example <nobody@example.com>" \
923 --to=nobody@example.com \
924 --smtp-server="$(pwd)/fake.sendmail" \
925 funny_name.patch &&
926 grep "^From: Füñný Nâmé <odd_?=mail@example.com>" msgtxt1
927'
928
62e00690
KM
929test_expect_success $PREREQ 'sendemail.composeencoding works' '
930 clean_fake_sendmail &&
931 git config sendemail.composeencoding iso-8859-1 &&
932 (echo "#!$SHELL_PATH" &&
933 echo "echo utf8 body: àéìöú >>\"\$1\""
934 ) >fake-editor-utf8 &&
935 chmod +x fake-editor-utf8 &&
936 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
937 git send-email \
938 --compose --subject foo \
939 --from="Example <nobody@example.com>" \
940 --to=nobody@example.com \
941 --smtp-server="$(pwd)/fake.sendmail" \
942 $patches &&
943 grep "^utf8 body" msgtxt1 &&
944 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
945'
946
947test_expect_success $PREREQ '--compose-encoding works' '
948 clean_fake_sendmail &&
949 (echo "#!$SHELL_PATH" &&
950 echo "echo utf8 body: àéìöú >>\"\$1\""
951 ) >fake-editor-utf8 &&
952 chmod +x fake-editor-utf8 &&
953 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
954 git send-email \
955 --compose-encoding iso-8859-1 \
956 --compose --subject foo \
957 --from="Example <nobody@example.com>" \
958 --to=nobody@example.com \
959 --smtp-server="$(pwd)/fake.sendmail" \
960 $patches &&
961 grep "^utf8 body" msgtxt1 &&
962 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
963'
964
965test_expect_success $PREREQ '--compose-encoding overrides sendemail.composeencoding' '
966 clean_fake_sendmail &&
967 git config sendemail.composeencoding iso-8859-1 &&
968 (echo "#!$SHELL_PATH" &&
969 echo "echo utf8 body: àéìöú >>\"\$1\""
970 ) >fake-editor-utf8 &&
971 chmod +x fake-editor-utf8 &&
972 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
973 git send-email \
974 --compose-encoding iso-8859-2 \
975 --compose --subject foo \
976 --from="Example <nobody@example.com>" \
977 --to=nobody@example.com \
978 --smtp-server="$(pwd)/fake.sendmail" \
979 $patches &&
980 grep "^utf8 body" msgtxt1 &&
981 grep "^Content-Type: text/plain; charset=iso-8859-2" msgtxt1
982'
983
4a47a4dd
KM
984test_expect_success $PREREQ '--compose-encoding adds correct MIME for subject' '
985 clean_fake_sendmail &&
986 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
987 git send-email \
988 --compose-encoding iso-8859-2 \
989 --compose --subject utf8-sübjëct \
990 --from="Example <nobody@example.com>" \
991 --to=nobody@example.com \
992 --smtp-server="$(pwd)/fake.sendmail" \
993 $patches &&
994 grep "^fake edit" msgtxt1 &&
995 grep "^Subject: =?iso-8859-2?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
996'
997
57cd35e6 998test_expect_success $PREREQ 'detects ambiguous reference/file conflict' '
5df9fcf6
PH
999 echo master > master &&
1000 git add master &&
1001 git commit -m"add master" &&
1002 test_must_fail git send-email --dry-run master 2>errors &&
1003 grep disambiguate errors
1004'
1005
57cd35e6 1006test_expect_success $PREREQ 'feed two files' '
69f4ce55
JH
1007 rm -fr outdir &&
1008 git format-patch -2 -o outdir &&
c1f2aa45 1009 git send-email \
69f4ce55
JH
1010 --dry-run \
1011 --from="Example <nobody@example.com>" \
1012 --to=nobody@example.com \
1013 outdir/000?-*.patch 2>errors >out &&
1014 grep "^Subject: " out >subjects &&
1015 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
1016 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"
1017'
1018
57cd35e6 1019test_expect_success $PREREQ 'in-reply-to but no threading' '
aaab4b9f
TR
1020 git send-email \
1021 --dry-run \
1022 --from="Example <nobody@example.com>" \
1023 --to=nobody@example.com \
1024 --in-reply-to="<in-reply-id@example.com>" \
84eeb687 1025 --nothread \
aaab4b9f
TR
1026 $patches |
1027 grep "In-Reply-To: <in-reply-id@example.com>"
1028'
1029
57cd35e6 1030test_expect_success $PREREQ 'no in-reply-to and no threading' '
32ae8319
MH
1031 git send-email \
1032 --dry-run \
1033 --from="Example <nobody@example.com>" \
1034 --to=nobody@example.com \
1035 --nothread \
1036 $patches $patches >stdout &&
1037 ! grep "In-Reply-To: " stdout
1038'
1039
57cd35e6 1040test_expect_success $PREREQ 'threading but no chain-reply-to' '
d67114a5
MH
1041 git send-email \
1042 --dry-run \
1043 --from="Example <nobody@example.com>" \
1044 --to=nobody@example.com \
1045 --thread \
1046 --nochain-reply-to \
1047 $patches $patches >stdout &&
1048 grep "In-Reply-To: " stdout
1049'
1050
57cd35e6 1051test_expect_success $PREREQ 'warning with an implicit --chain-reply-to' '
528fb087
NS
1052 git send-email \
1053 --dry-run \
1054 --from="Example <nobody@example.com>" \
1055 --to=nobody@example.com \
1056 outdir/000?-*.patch 2>errors >out &&
1057 grep "no-chain-reply-to" errors
1058'
1059
57cd35e6 1060test_expect_success $PREREQ 'no warning with an explicit --chain-reply-to' '
528fb087
NS
1061 git send-email \
1062 --dry-run \
1063 --from="Example <nobody@example.com>" \
1064 --to=nobody@example.com \
1065 --chain-reply-to \
1066 outdir/000?-*.patch 2>errors >out &&
1067 ! grep "no-chain-reply-to" errors
1068'
1069
57cd35e6 1070test_expect_success $PREREQ 'no warning with an explicit --no-chain-reply-to' '
528fb087
NS
1071 git send-email \
1072 --dry-run \
1073 --from="Example <nobody@example.com>" \
1074 --to=nobody@example.com \
907a0b1e 1075 --nochain-reply-to \
528fb087
NS
1076 outdir/000?-*.patch 2>errors >out &&
1077 ! grep "no-chain-reply-to" errors
1078'
1079
57cd35e6 1080test_expect_success $PREREQ 'no warning with sendemail.chainreplyto = false' '
528fb087
NS
1081 git config sendemail.chainreplyto false &&
1082 git send-email \
1083 --dry-run \
1084 --from="Example <nobody@example.com>" \
1085 --to=nobody@example.com \
1086 outdir/000?-*.patch 2>errors >out &&
1087 ! grep "no-chain-reply-to" errors
1088'
1089
57cd35e6 1090test_expect_success $PREREQ 'no warning with sendemail.chainreplyto = true' '
528fb087
NS
1091 git config sendemail.chainreplyto true &&
1092 git send-email \
1093 --dry-run \
1094 --from="Example <nobody@example.com>" \
1095 --to=nobody@example.com \
1096 outdir/000?-*.patch 2>errors >out &&
1097 ! grep "no-chain-reply-to" errors
1098'
1099
57cd35e6 1100test_expect_success $PREREQ 'sendemail.to works' '
f434c083
SB
1101 git config --replace-all sendemail.to "Somebody <somebody@ex.com>" &&
1102 git send-email \
1103 --dry-run \
1104 --from="Example <nobody@example.com>" \
1105 $patches $patches >stdout &&
1106 grep "To: Somebody <somebody@ex.com>" stdout
1107'
1108
57cd35e6 1109test_expect_success $PREREQ '--no-to overrides sendemail.to' '
f434c083
SB
1110 git send-email \
1111 --dry-run \
1112 --from="Example <nobody@example.com>" \
1113 --no-to \
1114 --to=nobody@example.com \
1115 $patches $patches >stdout &&
1116 grep "To: nobody@example.com" stdout &&
1117 ! grep "To: Somebody <somebody@ex.com>" stdout
1118'
1119
57cd35e6 1120test_expect_success $PREREQ 'sendemail.cc works' '
f434c083
SB
1121 git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" &&
1122 git send-email \
1123 --dry-run \
1124 --from="Example <nobody@example.com>" \
1125 --to=nobody@example.com \
1126 $patches $patches >stdout &&
1127 grep "Cc: Somebody <somebody@ex.com>" stdout
1128'
1129
57cd35e6 1130test_expect_success $PREREQ '--no-cc overrides sendemail.cc' '
f434c083
SB
1131 git send-email \
1132 --dry-run \
1133 --from="Example <nobody@example.com>" \
1134 --no-cc \
1135 --cc=bodies@example.com \
1136 --to=nobody@example.com \
1137 $patches $patches >stdout &&
1138 grep "Cc: bodies@example.com" stdout &&
1139 ! grep "Cc: Somebody <somebody@ex.com>" stdout
1140'
1141
57cd35e6 1142test_expect_success $PREREQ 'sendemail.bcc works' '
f434c083
SB
1143 git config --replace-all sendemail.bcc "Other <other@ex.com>" &&
1144 git send-email \
1145 --dry-run \
1146 --from="Example <nobody@example.com>" \
1147 --to=nobody@example.com \
1148 --smtp-server relay.example.com \
1149 $patches $patches >stdout &&
1150 grep "RCPT TO:<other@ex.com>" stdout
1151'
1152
57cd35e6 1153test_expect_success $PREREQ '--no-bcc overrides sendemail.bcc' '
f434c083
SB
1154 git send-email \
1155 --dry-run \
1156 --from="Example <nobody@example.com>" \
1157 --no-bcc \
1158 --bcc=bodies@example.com \
1159 --to=nobody@example.com \
1160 --smtp-server relay.example.com \
1161 $patches $patches >stdout &&
1162 grep "RCPT TO:<bodies@example.com>" stdout &&
1163 ! grep "RCPT TO:<other@ex.com>" stdout
1164'
1165
21802cd3
SB
1166test_expect_success $PREREQ 'patches To headers are used by default' '
1167 patch=`git format-patch -1 --to="bodies@example.com"` &&
1168 test_when_finished "rm $patch" &&
1169 git send-email \
1170 --dry-run \
1171 --from="Example <nobody@example.com>" \
1172 --smtp-server relay.example.com \
1173 $patch >stdout &&
1174 grep "RCPT TO:<bodies@example.com>" stdout
1175'
1176
1177test_expect_success $PREREQ 'patches To headers are appended to' '
1178 patch=`git format-patch -1 --to="bodies@example.com"` &&
1179 test_when_finished "rm $patch" &&
1180 git send-email \
1181 --dry-run \
1182 --from="Example <nobody@example.com>" \
1183 --to=nobody@example.com \
1184 --smtp-server relay.example.com \
1185 $patch >stdout &&
1186 grep "RCPT TO:<bodies@example.com>" stdout &&
1187 grep "RCPT TO:<nobody@example.com>" stdout
1188'
1189
3c3bb51c
SB
1190test_expect_success $PREREQ 'To headers from files reset each patch' '
1191 patch1=`git format-patch -1 --to="bodies@example.com"` &&
1192 patch2=`git format-patch -1 --to="other@example.com" HEAD~` &&
1193 test_when_finished "rm $patch1 && rm $patch2" &&
1194 git send-email \
1195 --dry-run \
1196 --from="Example <nobody@example.com>" \
1197 --to="nobody@example.com" \
1198 --smtp-server relay.example.com \
1199 $patch1 $patch2 >stdout &&
1200 test $(grep -c "RCPT TO:<bodies@example.com>" stdout) = 1 &&
1201 test $(grep -c "RCPT TO:<nobody@example.com>" stdout) = 2 &&
1202 test $(grep -c "RCPT TO:<other@example.com>" stdout) = 1
1203'
1204
f9444147 1205test_expect_success $PREREQ 'setup expect' '
3cae7e5b
TR
1206cat >email-using-8bit <<EOF
1207From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1208Message-Id: <bogus-message-id@example.com>
1209From: author@example.com
1210Date: Sat, 12 Jun 2010 15:53:58 +0200
1211Subject: subject goes here
1212
1213Dieser deutsche Text enthält einen Umlaut!
1214EOF
f9444147 1215'
3cae7e5b 1216
5637d857
KM
1217test_expect_success $PREREQ 'setup expect' '
1218cat >expected <<EOF
1219Subject: subject goes here
1220EOF
1221'
1222
1223test_expect_success $PREREQ 'ASCII subject is not RFC2047 quoted' '
1224 clean_fake_sendmail &&
1225 echo bogus |
1226 git send-email --from=author@example.com --to=nobody@example.com \
1227 --smtp-server="$(pwd)/fake.sendmail" \
1228 --8bit-encoding=UTF-8 \
1229 email-using-8bit >stdout &&
1230 grep "Subject" msgtxt1 >actual &&
1231 test_cmp expected actual
1232'
1233
f9444147 1234test_expect_success $PREREQ 'setup expect' '
3cae7e5b
TR
1235cat >content-type-decl <<EOF
1236MIME-Version: 1.0
1237Content-Type: text/plain; charset=UTF-8
1238Content-Transfer-Encoding: 8bit
1239EOF
f9444147 1240'
3cae7e5b 1241
57cd35e6 1242test_expect_success $PREREQ 'asks about and fixes 8bit encodings' '
3cae7e5b
TR
1243 clean_fake_sendmail &&
1244 echo |
1245 git send-email --from=author@example.com --to=nobody@example.com \
1246 --smtp-server="$(pwd)/fake.sendmail" \
1247 email-using-8bit >stdout &&
1248 grep "do not declare a Content-Transfer-Encoding" stdout &&
1249 grep email-using-8bit stdout &&
1250 grep "Which 8bit encoding" stdout &&
31832862 1251 egrep "Content|MIME" msgtxt1 >actual &&
3cae7e5b
TR
1252 test_cmp actual content-type-decl
1253'
1254
57cd35e6 1255test_expect_success $PREREQ 'sendemail.8bitEncoding works' '
3cae7e5b
TR
1256 clean_fake_sendmail &&
1257 git config sendemail.assume8bitEncoding UTF-8 &&
1258 echo bogus |
1259 git send-email --from=author@example.com --to=nobody@example.com \
1260 --smtp-server="$(pwd)/fake.sendmail" \
1261 email-using-8bit >stdout &&
31832862 1262 egrep "Content|MIME" msgtxt1 >actual &&
3cae7e5b
TR
1263 test_cmp actual content-type-decl
1264'
1265
57cd35e6 1266test_expect_success $PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
3cae7e5b
TR
1267 clean_fake_sendmail &&
1268 git config sendemail.assume8bitEncoding "bogus too" &&
1269 echo bogus |
1270 git send-email --from=author@example.com --to=nobody@example.com \
1271 --smtp-server="$(pwd)/fake.sendmail" \
1272 --8bit-encoding=UTF-8 \
1273 email-using-8bit >stdout &&
31832862 1274 egrep "Content|MIME" msgtxt1 >actual &&
3cae7e5b
TR
1275 test_cmp actual content-type-decl
1276'
1277
f9444147 1278test_expect_success $PREREQ 'setup expect' '
3cae7e5b
TR
1279cat >email-using-8bit <<EOF
1280From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1281Message-Id: <bogus-message-id@example.com>
1282From: author@example.com
1283Date: Sat, 12 Jun 2010 15:53:58 +0200
1284Subject: Dieser Betreff enthält auch einen Umlaut!
1285
1286Nothing to see here.
1287EOF
f9444147 1288'
3cae7e5b 1289
f9444147 1290test_expect_success $PREREQ 'setup expect' '
3cae7e5b
TR
1291cat >expected <<EOF
1292Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
1293EOF
f9444147 1294'
3cae7e5b 1295
57cd35e6 1296test_expect_success $PREREQ '--8bit-encoding also treats subject' '
3cae7e5b
TR
1297 clean_fake_sendmail &&
1298 echo bogus |
1299 git send-email --from=author@example.com --to=nobody@example.com \
1300 --smtp-server="$(pwd)/fake.sendmail" \
1301 --8bit-encoding=UTF-8 \
1302 email-using-8bit >stdout &&
1303 grep "Subject" msgtxt1 >actual &&
1304 test_cmp expected actual
1305'
1306
a03bc5b6
TR
1307# Note that the patches in this test are deliberately out of order; we
1308# want to make sure it works even if the cover-letter is not in the
1309# first mail.
57da2042 1310test_expect_success $PREREQ 'refusing to send cover letter template' '
a03bc5b6
TR
1311 clean_fake_sendmail &&
1312 rm -fr outdir &&
1313 git format-patch --cover-letter -2 -o outdir &&
1314 test_must_fail git send-email \
1315 --from="Example <nobody@example.com>" \
1316 --to=nobody@example.com \
1317 --smtp-server="$(pwd)/fake.sendmail" \
1318 outdir/0002-*.patch \
1319 outdir/0000-*.patch \
1320 outdir/0001-*.patch \
1321 2>errors >out &&
1322 grep "SUBJECT HERE" errors &&
1323 test -z "$(ls msgtxt*)"
1324'
1325
57da2042 1326test_expect_success $PREREQ '--force sends cover letter template anyway' '
a03bc5b6
TR
1327 clean_fake_sendmail &&
1328 rm -fr outdir &&
1329 git format-patch --cover-letter -2 -o outdir &&
1330 git send-email \
1331 --force \
1332 --from="Example <nobody@example.com>" \
1333 --to=nobody@example.com \
1334 --smtp-server="$(pwd)/fake.sendmail" \
1335 outdir/0002-*.patch \
1336 outdir/0000-*.patch \
1337 outdir/0001-*.patch \
1338 2>errors >out &&
1339 ! grep "SUBJECT HERE" errors &&
1340 test -n "$(ls msgtxt*)"
1341'
1342
463b0ea2
CS
1343test_expect_success $PREREQ 'sendemail.aliasfiletype=mailrc' '
1344 clean_fake_sendmail &&
1345 echo "alias sbd somebody@example.org" >.mailrc &&
1346 git config --replace-all sendemail.aliasesfile "$(pwd)/.mailrc" &&
1347 git config sendemail.aliasfiletype mailrc &&
1348 git send-email \
1349 --from="Example <nobody@example.com>" \
1350 --to=sbd \
1351 --smtp-server="$(pwd)/fake.sendmail" \
1352 outdir/0001-*.patch \
1353 2>errors >out &&
1354 grep "^!somebody@example\.org!$" commandline1
1355'
1356
1357test_expect_success $PREREQ 'sendemail.aliasfile=~/.mailrc' '
1358 clean_fake_sendmail &&
1359 echo "alias sbd someone@example.org" >~/.mailrc &&
1360 git config --replace-all sendemail.aliasesfile "~/.mailrc" &&
1361 git config sendemail.aliasfiletype mailrc &&
1362 git send-email \
1363 --from="Example <nobody@example.com>" \
1364 --to=sbd \
1365 --smtp-server="$(pwd)/fake.sendmail" \
1366 outdir/0001-*.patch \
1367 2>errors >out &&
1368 grep "^!someone@example\.org!$" commandline1
1369'
1370
ce903018 1371test_done