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