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