]> git.ipfire.org Git - thirdparty/git.git/blame - t/t9001-send-email.sh
Merge branch 'jk/reduce-gc-aggressive-depth' into maint
[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' '
bdf20f5e 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
62089fb8
RL
315test_expect_success $PREREQ 'setup tocmd and cccmd scripts' '
316 write_script tocmd-sed <<-\EOF &&
317 sed -n -e "s/^tocmd--//p" "$1"
318 EOF
319 write_script cccmd-sed <<-\EOF
320 sed -n -e "s/^cccmd--//p" "$1"
321 EOF
322'
323
6e74e075
JP
324test_expect_success $PREREQ 'tocmd works' '
325 clean_fake_sendmail &&
326 cp $patches tocmd.patch &&
327 echo tocmd--tocmd@example.com >>tocmd.patch &&
6e74e075
JP
328 git send-email \
329 --from="Example <nobody@example.com>" \
330 --to-cmd=./tocmd-sed \
331 --smtp-server="$(pwd)/fake.sendmail" \
332 tocmd.patch \
333 &&
334 grep "^To: tocmd@example.com" msgtxt1
335'
336
57cd35e6 337test_expect_success $PREREQ 'cccmd works' '
cb8a9bd5
PB
338 clean_fake_sendmail &&
339 cp $patches cccmd.patch &&
41ae8f1d 340 echo "cccmd-- cccmd@example.com" >>cccmd.patch &&
cb8a9bd5
PB
341 git send-email \
342 --from="Example <nobody@example.com>" \
343 --to=nobody@example.com \
344 --cc-cmd=./cccmd-sed \
345 --smtp-server="$(pwd)/fake.sendmail" \
346 cccmd.patch \
347 &&
02461e0e 348 grep "^ cccmd@example.com" msgtxt1
cb8a9bd5
PB
349'
350
57cd35e6 351test_expect_success $PREREQ 'reject long lines' '
f9444147
ÆAB
352 z8=zzzzzzzz &&
353 z64=$z8$z8$z8$z8$z8$z8$z8$z8 &&
354 z512=$z64$z64$z64$z64$z64$z64$z64$z64 &&
6d34a2ba 355 clean_fake_sendmail &&
747bbff9
JK
356 cp $patches longline.patch &&
357 echo $z512$z512 >>longline.patch &&
d492b31c 358 test_must_fail git send-email \
747bbff9
JK
359 --from="Example <nobody@example.com>" \
360 --to=nobody@example.com \
361 --smtp-server="$(pwd)/fake.sendmail" \
362 $patches longline.patch \
363 2>errors &&
364 grep longline.patch errors
365'
366
57cd35e6 367test_expect_success $PREREQ 'no patch was sent' '
6d34a2ba 368 ! test -e commandline1
747bbff9
JK
369'
370
57cd35e6 371test_expect_success $PREREQ 'Author From: in message body' '
5012699d
JS
372 clean_fake_sendmail &&
373 git send-email \
374 --from="Example <nobody@example.com>" \
375 --to=nobody@example.com \
376 --smtp-server="$(pwd)/fake.sendmail" \
377 $patches &&
ee756a81 378 sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
5012699d
JS
379 grep "From: A <author@example.com>" msgbody1
380'
381
57cd35e6 382test_expect_success $PREREQ 'Author From: not in message body' '
5012699d
JS
383 clean_fake_sendmail &&
384 git send-email \
385 --from="A <author@example.com>" \
386 --to=nobody@example.com \
387 --smtp-server="$(pwd)/fake.sendmail" \
388 $patches &&
ee756a81 389 sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
5012699d
JS
390 ! grep "From: A <author@example.com>" msgbody1
391'
392
57cd35e6 393test_expect_success $PREREQ 'allow long lines with --no-validate' '
c764a0c2
JK
394 git send-email \
395 --from="Example <nobody@example.com>" \
396 --to=nobody@example.com \
397 --smtp-server="$(pwd)/fake.sendmail" \
f4714943 398 --no-validate \
c764a0c2
JK
399 $patches longline.patch \
400 2>errors
401'
402
57cd35e6 403test_expect_success $PREREQ 'Invalid In-Reply-To' '
6d34a2ba 404 clean_fake_sendmail &&
0fb7fc75
JS
405 git send-email \
406 --from="Example <nobody@example.com>" \
407 --to=nobody@example.com \
408 --in-reply-to=" " \
409 --smtp-server="$(pwd)/fake.sendmail" \
5b57413c 410 $patches \
cc7e8167 411 2>errors &&
6d34a2ba 412 ! grep "^In-Reply-To: < *>" msgtxt1
0fb7fc75
JS
413'
414
57cd35e6 415test_expect_success $PREREQ 'Valid In-Reply-To when prompting' '
6d34a2ba 416 clean_fake_sendmail &&
0fb7fc75
JS
417 (echo "From Example <from@example.com>"
418 echo "To Example <to@example.com>"
419 echo ""
6eca18ca 420 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
0fb7fc75
JS
421 --smtp-server="$(pwd)/fake.sendmail" \
422 $patches 2>errors &&
6d34a2ba 423 ! grep "^In-Reply-To: < *>" msgtxt1
0fb7fc75
JS
424'
425
54aae5e1
JH
426test_expect_success $PREREQ 'In-Reply-To without --chain-reply-to' '
427 clean_fake_sendmail &&
428 echo "<unique-message-id@example.com>" >expect &&
429 git send-email \
430 --from="Example <nobody@example.com>" \
431 --to=nobody@example.com \
f4714943 432 --no-chain-reply-to \
54aae5e1
JH
433 --in-reply-to="$(cat expect)" \
434 --smtp-server="$(pwd)/fake.sendmail" \
435 $patches $patches $patches \
436 2>errors &&
db54c8e7 437 # The first message is a reply to --in-reply-to
54aae5e1
JH
438 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
439 test_cmp expect actual &&
db54c8e7
AO
440 # Second and subsequent messages are replies to the first one
441 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
54aae5e1
JH
442 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
443 test_cmp expect actual &&
444 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
445 test_cmp expect actual
446'
447
448test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' '
449 clean_fake_sendmail &&
450 echo "<unique-message-id@example.com>" >expect &&
451 git send-email \
452 --from="Example <nobody@example.com>" \
453 --to=nobody@example.com \
454 --chain-reply-to \
455 --in-reply-to="$(cat expect)" \
456 --smtp-server="$(pwd)/fake.sendmail" \
457 $patches $patches $patches \
458 2>errors &&
459 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
460 test_cmp expect actual &&
461 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
462 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
463 test_cmp expect actual &&
464 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt2 >expect &&
465 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
466 test_cmp expect actual
467'
468
57cd35e6 469test_expect_success $PREREQ 'setup fake editor' '
acd72b56
JH
470 write_script fake-editor <<-\EOF
471 echo fake edit >>"$1"
472 EOF
8a8bf469
JK
473'
474
7f0475c3 475test_set_editor "$(pwd)/fake-editor"
065096c2 476
57cd35e6 477test_expect_success $PREREQ '--compose works' '
8a8bf469 478 clean_fake_sendmail &&
c1f2aa45
JS
479 git send-email \
480 --compose --subject foo \
481 --from="Example <nobody@example.com>" \
482 --to=nobody@example.com \
483 --smtp-server="$(pwd)/fake.sendmail" \
484 $patches \
485 2>errors
8a8bf469
JK
486'
487
57cd35e6 488test_expect_success $PREREQ 'first message is compose text' '
8a8bf469
JK
489 grep "^fake edit" msgtxt1
490'
491
57cd35e6 492test_expect_success $PREREQ 'second message is patch' '
8a8bf469
JK
493 grep "Subject:.*Second" msgtxt2
494'
495
f9444147 496test_expect_success $PREREQ 'setup expect' "
3531e270 497cat >expected-suppress-sob <<\EOF
33c592dd
MV
4980001-Second.patch
499(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
5012699d
JS
500(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
501(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
33c592dd
MV
502Dry-OK. Log says:
503Server: relay.example.com
504MAIL FROM:<from@example.com>
02461e0e
JP
505RCPT TO:<to@example.com>
506RCPT TO:<cc@example.com>
507RCPT TO:<author@example.com>
508RCPT TO:<one@example.com>
509RCPT TO:<two@example.com>
33c592dd
MV
510From: Example <from@example.com>
511To: to@example.com
02461e0e
JP
512Cc: cc@example.com,
513 A <author@example.com>,
514 One <one@example.com>,
515 two@example.com
33c592dd
MV
516Subject: [PATCH 1/1] Second.
517Date: DATE-STRING
518Message-Id: MESSAGE-ID-STRING
519X-Mailer: X-MAILER-STRING
520
521Result: OK
522EOF
f9444147 523"
33c592dd 524
d4cf11c2
RL
525replace_variable_fields () {
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/"
529}
530
3531e270 531test_suppression () {
33c592dd
MV
532 git send-email \
533 --dry-run \
cb8a9bd5 534 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
33c592dd
MV
535 --from="Example <from@example.com>" \
536 --to=to@example.com \
537 --smtp-server relay.example.com \
d4cf11c2 538 $patches | replace_variable_fields \
cb8a9bd5
PB
539 >actual-suppress-$1${2+"-$2"} &&
540 test_cmp expected-suppress-$1${2+"-$2"} actual-suppress-$1${2+"-$2"}
3531e270
JS
541}
542
57cd35e6 543test_expect_success $PREREQ 'sendemail.cc set' '
3531e270
JS
544 git config sendemail.cc cc@example.com &&
545 test_suppression sob
33c592dd
MV
546'
547
f9444147 548test_expect_success $PREREQ 'setup expect' "
3531e270 549cat >expected-suppress-sob <<\EOF
33c592dd
MV
5500001-Second.patch
551(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
5012699d
JS
552(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
553(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
33c592dd
MV
554Dry-OK. Log says:
555Server: relay.example.com
556MAIL FROM:<from@example.com>
02461e0e
JP
557RCPT TO:<to@example.com>
558RCPT TO:<author@example.com>
559RCPT TO:<one@example.com>
560RCPT TO:<two@example.com>
33c592dd
MV
561From: Example <from@example.com>
562To: to@example.com
02461e0e
JP
563Cc: A <author@example.com>,
564 One <one@example.com>,
565 two@example.com
33c592dd
MV
566Subject: [PATCH 1/1] Second.
567Date: DATE-STRING
568Message-Id: MESSAGE-ID-STRING
569X-Mailer: X-MAILER-STRING
570
571Result: OK
572EOF
f9444147 573"
33c592dd 574
57cd35e6 575test_expect_success $PREREQ 'sendemail.cc unset' '
33c592dd 576 git config --unset sendemail.cc &&
3531e270
JS
577 test_suppression sob
578'
579
f9444147 580test_expect_success $PREREQ 'setup expect' "
cb8a9bd5
PB
581cat >expected-suppress-cccmd <<\EOF
5820001-Second.patch
583(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
584(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
585(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
586(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
587Dry-OK. Log says:
588Server: relay.example.com
589MAIL FROM:<from@example.com>
02461e0e
JP
590RCPT TO:<to@example.com>
591RCPT TO:<author@example.com>
592RCPT TO:<one@example.com>
593RCPT TO:<two@example.com>
594RCPT TO:<committer@example.com>
cb8a9bd5
PB
595From: Example <from@example.com>
596To: to@example.com
02461e0e
JP
597Cc: A <author@example.com>,
598 One <one@example.com>,
599 two@example.com,
600 C O Mitter <committer@example.com>
cb8a9bd5
PB
601Subject: [PATCH 1/1] Second.
602Date: DATE-STRING
603Message-Id: MESSAGE-ID-STRING
604X-Mailer: X-MAILER-STRING
605
606Result: OK
607EOF
f9444147 608"
cb8a9bd5 609
57cd35e6 610test_expect_success $PREREQ 'sendemail.cccmd' '
acd72b56
JH
611 write_script cccmd <<-\EOF &&
612 echo cc-cmd@example.com
613 EOF
cb8a9bd5
PB
614 git config sendemail.cccmd ./cccmd &&
615 test_suppression cccmd
616'
617
f9444147 618test_expect_success $PREREQ 'setup expect' '
3531e270
JS
619cat >expected-suppress-all <<\EOF
6200001-Second.patch
621Dry-OK. Log says:
622Server: relay.example.com
623MAIL FROM:<from@example.com>
624RCPT TO:<to@example.com>
625From: Example <from@example.com>
626To: to@example.com
627Subject: [PATCH 1/1] Second.
628Date: DATE-STRING
629Message-Id: MESSAGE-ID-STRING
630X-Mailer: X-MAILER-STRING
631
632Result: OK
633EOF
f9444147 634'
3531e270 635
57cd35e6 636test_expect_success $PREREQ '--suppress-cc=all' '
3531e270
JS
637 test_suppression all
638'
639
f9444147 640test_expect_success $PREREQ 'setup expect' "
3531e270
JS
641cat >expected-suppress-body <<\EOF
6420001-Second.patch
643(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
644(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
645(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
cb8a9bd5 646(cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
3531e270
JS
647Dry-OK. Log says:
648Server: relay.example.com
649MAIL FROM:<from@example.com>
02461e0e
JP
650RCPT TO:<to@example.com>
651RCPT TO:<author@example.com>
652RCPT TO:<one@example.com>
653RCPT TO:<two@example.com>
654RCPT TO:<cc-cmd@example.com>
3531e270
JS
655From: Example <from@example.com>
656To: to@example.com
02461e0e
JP
657Cc: A <author@example.com>,
658 One <one@example.com>,
659 two@example.com,
660 cc-cmd@example.com
3531e270
JS
661Subject: [PATCH 1/1] Second.
662Date: DATE-STRING
663Message-Id: MESSAGE-ID-STRING
664X-Mailer: X-MAILER-STRING
665
666Result: OK
667EOF
f9444147 668"
3531e270 669
57cd35e6 670test_expect_success $PREREQ '--suppress-cc=body' '
3531e270
JS
671 test_suppression body
672'
673
f9444147 674test_expect_success $PREREQ 'setup expect' "
cb8a9bd5
PB
675cat >expected-suppress-body-cccmd <<\EOF
6760001-Second.patch
677(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
678(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
679(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
680Dry-OK. Log says:
681Server: relay.example.com
682MAIL FROM:<from@example.com>
02461e0e
JP
683RCPT TO:<to@example.com>
684RCPT TO:<author@example.com>
685RCPT TO:<one@example.com>
686RCPT TO:<two@example.com>
cb8a9bd5
PB
687From: Example <from@example.com>
688To: to@example.com
02461e0e
JP
689Cc: A <author@example.com>,
690 One <one@example.com>,
691 two@example.com
cb8a9bd5
PB
692Subject: [PATCH 1/1] Second.
693Date: DATE-STRING
694Message-Id: MESSAGE-ID-STRING
695X-Mailer: X-MAILER-STRING
696
697Result: OK
698EOF
f9444147 699"
cb8a9bd5 700
57cd35e6 701test_expect_success $PREREQ '--suppress-cc=body --suppress-cc=cccmd' '
cb8a9bd5
PB
702 test_suppression body cccmd
703'
704
f9444147 705test_expect_success $PREREQ 'setup expect' "
3531e270
JS
706cat >expected-suppress-sob <<\EOF
7070001-Second.patch
708(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
709(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
710(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
711Dry-OK. Log says:
712Server: relay.example.com
713MAIL FROM:<from@example.com>
02461e0e
JP
714RCPT TO:<to@example.com>
715RCPT TO:<author@example.com>
716RCPT TO:<one@example.com>
717RCPT TO:<two@example.com>
3531e270
JS
718From: Example <from@example.com>
719To: to@example.com
02461e0e
JP
720Cc: A <author@example.com>,
721 One <one@example.com>,
722 two@example.com
3531e270
JS
723Subject: [PATCH 1/1] Second.
724Date: DATE-STRING
725Message-Id: MESSAGE-ID-STRING
726X-Mailer: X-MAILER-STRING
727
728Result: OK
729EOF
f9444147 730"
3531e270 731
57cd35e6 732test_expect_success $PREREQ '--suppress-cc=sob' '
cc7e8167 733 test_might_fail git config --unset sendemail.cccmd &&
3531e270
JS
734 test_suppression sob
735'
736
f9444147 737test_expect_success $PREREQ 'setup expect' "
3531e270
JS
738cat >expected-suppress-bodycc <<\EOF
7390001-Second.patch
740(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
741(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
742(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
743(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
744Dry-OK. Log says:
745Server: relay.example.com
746MAIL FROM:<from@example.com>
02461e0e
JP
747RCPT TO:<to@example.com>
748RCPT TO:<author@example.com>
749RCPT TO:<one@example.com>
750RCPT TO:<two@example.com>
751RCPT TO:<committer@example.com>
3531e270
JS
752From: Example <from@example.com>
753To: to@example.com
02461e0e
JP
754Cc: A <author@example.com>,
755 One <one@example.com>,
756 two@example.com,
757 C O Mitter <committer@example.com>
3531e270
JS
758Subject: [PATCH 1/1] Second.
759Date: DATE-STRING
760Message-Id: MESSAGE-ID-STRING
761X-Mailer: X-MAILER-STRING
762
763Result: OK
764EOF
f9444147 765"
3531e270 766
57cd35e6 767test_expect_success $PREREQ '--suppress-cc=bodycc' '
3531e270
JS
768 test_suppression bodycc
769'
770
f9444147 771test_expect_success $PREREQ 'setup expect' "
3531e270
JS
772cat >expected-suppress-cc <<\EOF
7730001-Second.patch
774(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
775(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
776Dry-OK. Log says:
777Server: relay.example.com
778MAIL FROM:<from@example.com>
02461e0e
JP
779RCPT TO:<to@example.com>
780RCPT TO:<author@example.com>
781RCPT TO:<committer@example.com>
3531e270
JS
782From: Example <from@example.com>
783To: to@example.com
02461e0e
JP
784Cc: A <author@example.com>,
785 C O Mitter <committer@example.com>
3531e270
JS
786Subject: [PATCH 1/1] Second.
787Date: DATE-STRING
788Message-Id: MESSAGE-ID-STRING
789X-Mailer: X-MAILER-STRING
790
791Result: OK
792EOF
f9444147 793"
3531e270 794
57cd35e6 795test_expect_success $PREREQ '--suppress-cc=cc' '
3531e270 796 test_suppression cc
33c592dd
MV
797'
798
c1f2aa45
JS
799test_confirm () {
800 echo y | \
801 GIT_SEND_EMAIL_NOTTY=1 \
802 git send-email \
803 --from="Example <nobody@example.com>" \
804 --to=nobody@example.com \
805 --smtp-server="$(pwd)/fake.sendmail" \
ee756a81 806 $@ $patches >stdout &&
c18f75a1 807 grep "Send this email" stdout
c1f2aa45
JS
808}
809
57cd35e6 810test_expect_success $PREREQ '--confirm=always' '
c1f2aa45
JS
811 test_confirm --confirm=always --suppress-cc=all
812'
813
57cd35e6 814test_expect_success $PREREQ '--confirm=auto' '
c1f2aa45
JS
815 test_confirm --confirm=auto
816'
817
57cd35e6 818test_expect_success $PREREQ '--confirm=cc' '
c1f2aa45
JS
819 test_confirm --confirm=cc
820'
821
57cd35e6 822test_expect_success $PREREQ '--confirm=compose' '
c1f2aa45
JS
823 test_confirm --confirm=compose --compose
824'
825
545871bf 826test_expect_success $PREREQ 'confirm by default (due to cc)' '
fc99da1f 827 test_when_finished git config sendemail.confirm never &&
c1f2aa45 828 git config --unset sendemail.confirm &&
c18f75a1 829 test_confirm
c1f2aa45
JS
830'
831
57cd35e6 832test_expect_success $PREREQ 'confirm by default (due to --compose)' '
fc99da1f 833 test_when_finished git config sendemail.confirm never &&
c1f2aa45
JS
834 git config --unset sendemail.confirm &&
835 test_confirm --suppress-cc=all --compose
c1f2aa45
JS
836'
837
57cd35e6 838test_expect_success $PREREQ 'confirm detects EOF (inform assumes y)' '
fc99da1f 839 test_when_finished git config sendemail.confirm never &&
c18f75a1 840 git config --unset sendemail.confirm &&
dc1460aa
JS
841 rm -fr outdir &&
842 git format-patch -2 -o outdir &&
c18f75a1
JS
843 GIT_SEND_EMAIL_NOTTY=1 \
844 git send-email \
845 --from="Example <nobody@example.com>" \
846 --to=nobody@example.com \
847 --smtp-server="$(pwd)/fake.sendmail" \
ee756a81 848 outdir/*.patch </dev/null
c18f75a1
JS
849'
850
57cd35e6 851test_expect_success $PREREQ 'confirm detects EOF (auto causes failure)' '
fc99da1f 852 test_when_finished git config sendemail.confirm never &&
c18f75a1 853 git config sendemail.confirm auto &&
3b3637c3
JS
854 GIT_SEND_EMAIL_NOTTY=1 &&
855 export GIT_SEND_EMAIL_NOTTY &&
c18f75a1
JS
856 test_must_fail git send-email \
857 --from="Example <nobody@example.com>" \
858 --to=nobody@example.com \
859 --smtp-server="$(pwd)/fake.sendmail" \
ee756a81 860 $patches </dev/null
c18f75a1
JS
861'
862
41ccfdd9 863test_expect_success $PREREQ 'confirm does not loop forever' '
fc99da1f 864 test_when_finished git config sendemail.confirm never &&
c18f75a1 865 git config sendemail.confirm auto &&
3b3637c3
JS
866 GIT_SEND_EMAIL_NOTTY=1 &&
867 export GIT_SEND_EMAIL_NOTTY &&
868 yes "bogus" | test_must_fail git send-email \
c18f75a1
JS
869 --from="Example <nobody@example.com>" \
870 --to=nobody@example.com \
871 --smtp-server="$(pwd)/fake.sendmail" \
872 $patches
c18f75a1
JS
873'
874
57cd35e6 875test_expect_success $PREREQ 'utf8 Cc is rfc2047 encoded' '
a61c0ffa
JS
876 clean_fake_sendmail &&
877 rm -fr outdir &&
878 git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
879 git send-email \
880 --from="Example <nobody@example.com>" \
881 --to=nobody@example.com \
882 --smtp-server="$(pwd)/fake.sendmail" \
883 outdir/*.patch &&
02461e0e 884 grep "^ " msgtxt1 |
d1fff6fc 885 grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
a61c0ffa
JS
886'
887
57cd35e6 888test_expect_success $PREREQ '--compose adds MIME for utf8 body' '
0706bd19 889 clean_fake_sendmail &&
acd72b56
JH
890 write_script fake-editor-utf8 <<-\EOF &&
891 echo "utf8 body: àéìöú" >>"$1"
892 EOF
03335f22
JH
893 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
894 git send-email \
895 --compose --subject foo \
896 --from="Example <nobody@example.com>" \
897 --to=nobody@example.com \
898 --smtp-server="$(pwd)/fake.sendmail" \
899 $patches &&
0706bd19 900 grep "^utf8 body" msgtxt1 &&
d1fff6fc 901 grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
0706bd19
JK
902'
903
57cd35e6 904test_expect_success $PREREQ '--compose respects user mime type' '
0706bd19 905 clean_fake_sendmail &&
acd72b56
JH
906 write_script fake-editor-utf8-mime <<-\EOF &&
907 cat >"$1" <<-\EOM
908 MIME-Version: 1.0
909 Content-Type: text/plain; charset=iso-8859-1
910 Content-Transfer-Encoding: 8bit
911 Subject: foo
912
913 utf8 body: àéìöú
914 EOM
915 EOF
03335f22
JH
916 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
917 git send-email \
918 --compose --subject foo \
919 --from="Example <nobody@example.com>" \
920 --to=nobody@example.com \
921 --smtp-server="$(pwd)/fake.sendmail" \
922 $patches &&
0706bd19
JK
923 grep "^utf8 body" msgtxt1 &&
924 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
d1fff6fc 925 ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
0706bd19
JK
926'
927
57cd35e6 928test_expect_success $PREREQ '--compose adds MIME for utf8 subject' '
d54eaaa2 929 clean_fake_sendmail &&
03335f22
JH
930 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
931 git send-email \
932 --compose --subject utf8-sübjëct \
933 --from="Example <nobody@example.com>" \
934 --to=nobody@example.com \
935 --smtp-server="$(pwd)/fake.sendmail" \
936 $patches &&
d54eaaa2 937 grep "^fake edit" msgtxt1 &&
d1fff6fc 938 grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
d54eaaa2
JK
939'
940
b622d4d1
TR
941test_expect_success $PREREQ 'utf8 author is correctly passed on' '
942 clean_fake_sendmail &&
943 test_commit weird_author &&
944 test_when_finished "git reset --hard HEAD^" &&
945 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
946 git format-patch --stdout -1 >funny_name.patch &&
947 git send-email --from="Example <nobody@example.com>" \
03335f22
JH
948 --to=nobody@example.com \
949 --smtp-server="$(pwd)/fake.sendmail" \
950 funny_name.patch &&
b622d4d1
TR
951 grep "^From: Füñný Nâmé <odd_?=mail@example.com>" msgtxt1
952'
953
4cb46bdd 954test_expect_success $PREREQ 'utf8 sender is not duplicated' '
f07075c2
MT
955 clean_fake_sendmail &&
956 test_commit weird_sender &&
957 test_when_finished "git reset --hard HEAD^" &&
958 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
959 git format-patch --stdout -1 >funny_name.patch &&
960 git send-email --from="Füñný Nâmé <odd_?=mail@example.com>" \
03335f22
JH
961 --to=nobody@example.com \
962 --smtp-server="$(pwd)/fake.sendmail" \
963 funny_name.patch &&
f07075c2
MT
964 grep "^From: " msgtxt1 >msgfrom &&
965 test_line_count = 1 msgfrom
966'
967
62e00690
KM
968test_expect_success $PREREQ 'sendemail.composeencoding works' '
969 clean_fake_sendmail &&
970 git config sendemail.composeencoding iso-8859-1 &&
acd72b56
JH
971 write_script fake-editor-utf8 <<-\EOF &&
972 echo "utf8 body: àéìöú" >>"$1"
973 EOF
03335f22
JH
974 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
975 git send-email \
976 --compose --subject foo \
977 --from="Example <nobody@example.com>" \
978 --to=nobody@example.com \
979 --smtp-server="$(pwd)/fake.sendmail" \
980 $patches &&
62e00690
KM
981 grep "^utf8 body" msgtxt1 &&
982 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
983'
984
985test_expect_success $PREREQ '--compose-encoding works' '
986 clean_fake_sendmail &&
acd72b56
JH
987 write_script fake-editor-utf8 <<-\EOF &&
988 echo "utf8 body: àéìöú" >>"$1"
989 EOF
03335f22
JH
990 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
991 git send-email \
992 --compose-encoding iso-8859-1 \
993 --compose --subject foo \
994 --from="Example <nobody@example.com>" \
995 --to=nobody@example.com \
996 --smtp-server="$(pwd)/fake.sendmail" \
997 $patches &&
62e00690
KM
998 grep "^utf8 body" msgtxt1 &&
999 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1000'
1001
1002test_expect_success $PREREQ '--compose-encoding overrides sendemail.composeencoding' '
1003 clean_fake_sendmail &&
1004 git config sendemail.composeencoding iso-8859-1 &&
acd72b56
JH
1005 write_script fake-editor-utf8 <<-\EOF &&
1006 echo "utf8 body: àéìöú" >>"$1"
1007 EOF
03335f22
JH
1008 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1009 git send-email \
1010 --compose-encoding iso-8859-2 \
1011 --compose --subject foo \
1012 --from="Example <nobody@example.com>" \
1013 --to=nobody@example.com \
1014 --smtp-server="$(pwd)/fake.sendmail" \
1015 $patches &&
62e00690
KM
1016 grep "^utf8 body" msgtxt1 &&
1017 grep "^Content-Type: text/plain; charset=iso-8859-2" msgtxt1
1018'
1019
4a47a4dd
KM
1020test_expect_success $PREREQ '--compose-encoding adds correct MIME for subject' '
1021 clean_fake_sendmail &&
03335f22
JH
1022 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
1023 git send-email \
1024 --compose-encoding iso-8859-2 \
1025 --compose --subject utf8-sübjëct \
1026 --from="Example <nobody@example.com>" \
1027 --to=nobody@example.com \
1028 --smtp-server="$(pwd)/fake.sendmail" \
1029 $patches &&
4a47a4dd
KM
1030 grep "^fake edit" msgtxt1 &&
1031 grep "^Subject: =?iso-8859-2?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
1032'
1033
57cd35e6 1034test_expect_success $PREREQ 'detects ambiguous reference/file conflict' '
ee756a81 1035 echo master >master &&
5df9fcf6
PH
1036 git add master &&
1037 git commit -m"add master" &&
1038 test_must_fail git send-email --dry-run master 2>errors &&
1039 grep disambiguate errors
1040'
1041
57cd35e6 1042test_expect_success $PREREQ 'feed two files' '
69f4ce55
JH
1043 rm -fr outdir &&
1044 git format-patch -2 -o outdir &&
c1f2aa45 1045 git send-email \
03335f22
JH
1046 --dry-run \
1047 --from="Example <nobody@example.com>" \
1048 --to=nobody@example.com \
1049 outdir/000?-*.patch 2>errors >out &&
69f4ce55
JH
1050 grep "^Subject: " out >subjects &&
1051 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
1052 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"
1053'
1054
57cd35e6 1055test_expect_success $PREREQ 'in-reply-to but no threading' '
aaab4b9f
TR
1056 git send-email \
1057 --dry-run \
1058 --from="Example <nobody@example.com>" \
1059 --to=nobody@example.com \
1060 --in-reply-to="<in-reply-id@example.com>" \
f4714943 1061 --no-thread \
aaab4b9f
TR
1062 $patches |
1063 grep "In-Reply-To: <in-reply-id@example.com>"
1064'
1065
57cd35e6 1066test_expect_success $PREREQ 'no in-reply-to and no threading' '
32ae8319
MH
1067 git send-email \
1068 --dry-run \
1069 --from="Example <nobody@example.com>" \
1070 --to=nobody@example.com \
f4714943 1071 --no-thread \
32ae8319
MH
1072 $patches $patches >stdout &&
1073 ! grep "In-Reply-To: " stdout
1074'
1075
57cd35e6 1076test_expect_success $PREREQ 'threading but no chain-reply-to' '
d67114a5
MH
1077 git send-email \
1078 --dry-run \
1079 --from="Example <nobody@example.com>" \
1080 --to=nobody@example.com \
1081 --thread \
f4714943 1082 --no-chain-reply-to \
d67114a5
MH
1083 $patches $patches >stdout &&
1084 grep "In-Reply-To: " stdout
1085'
1086
57cd35e6 1087test_expect_success $PREREQ 'sendemail.to works' '
f434c083
SB
1088 git config --replace-all sendemail.to "Somebody <somebody@ex.com>" &&
1089 git send-email \
1090 --dry-run \
1091 --from="Example <nobody@example.com>" \
1092 $patches $patches >stdout &&
1093 grep "To: Somebody <somebody@ex.com>" stdout
1094'
1095
57cd35e6 1096test_expect_success $PREREQ '--no-to overrides sendemail.to' '
f434c083
SB
1097 git send-email \
1098 --dry-run \
1099 --from="Example <nobody@example.com>" \
1100 --no-to \
1101 --to=nobody@example.com \
1102 $patches $patches >stdout &&
1103 grep "To: nobody@example.com" stdout &&
1104 ! grep "To: Somebody <somebody@ex.com>" stdout
1105'
1106
57cd35e6 1107test_expect_success $PREREQ 'sendemail.cc works' '
f434c083
SB
1108 git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" &&
1109 git send-email \
1110 --dry-run \
1111 --from="Example <nobody@example.com>" \
1112 --to=nobody@example.com \
1113 $patches $patches >stdout &&
1114 grep "Cc: Somebody <somebody@ex.com>" stdout
1115'
1116
57cd35e6 1117test_expect_success $PREREQ '--no-cc overrides sendemail.cc' '
f434c083
SB
1118 git send-email \
1119 --dry-run \
1120 --from="Example <nobody@example.com>" \
1121 --no-cc \
1122 --cc=bodies@example.com \
1123 --to=nobody@example.com \
1124 $patches $patches >stdout &&
1125 grep "Cc: bodies@example.com" stdout &&
1126 ! grep "Cc: Somebody <somebody@ex.com>" stdout
1127'
1128
57cd35e6 1129test_expect_success $PREREQ 'sendemail.bcc works' '
f434c083
SB
1130 git config --replace-all sendemail.bcc "Other <other@ex.com>" &&
1131 git send-email \
1132 --dry-run \
1133 --from="Example <nobody@example.com>" \
1134 --to=nobody@example.com \
1135 --smtp-server relay.example.com \
1136 $patches $patches >stdout &&
1137 grep "RCPT TO:<other@ex.com>" stdout
1138'
1139
57cd35e6 1140test_expect_success $PREREQ '--no-bcc overrides sendemail.bcc' '
f434c083
SB
1141 git send-email \
1142 --dry-run \
1143 --from="Example <nobody@example.com>" \
1144 --no-bcc \
1145 --bcc=bodies@example.com \
1146 --to=nobody@example.com \
1147 --smtp-server relay.example.com \
1148 $patches $patches >stdout &&
1149 grep "RCPT TO:<bodies@example.com>" stdout &&
1150 ! grep "RCPT TO:<other@ex.com>" stdout
1151'
1152
21802cd3 1153test_expect_success $PREREQ 'patches To headers are used by default' '
bdf20f5e 1154 patch=$(git format-patch -1 --to="bodies@example.com") &&
21802cd3
SB
1155 test_when_finished "rm $patch" &&
1156 git send-email \
1157 --dry-run \
1158 --from="Example <nobody@example.com>" \
1159 --smtp-server relay.example.com \
1160 $patch >stdout &&
1161 grep "RCPT TO:<bodies@example.com>" stdout
1162'
1163
1164test_expect_success $PREREQ 'patches To headers are appended to' '
bdf20f5e 1165 patch=$(git format-patch -1 --to="bodies@example.com") &&
21802cd3
SB
1166 test_when_finished "rm $patch" &&
1167 git send-email \
1168 --dry-run \
1169 --from="Example <nobody@example.com>" \
1170 --to=nobody@example.com \
1171 --smtp-server relay.example.com \
1172 $patch >stdout &&
1173 grep "RCPT TO:<bodies@example.com>" stdout &&
1174 grep "RCPT TO:<nobody@example.com>" stdout
1175'
1176
3c3bb51c 1177test_expect_success $PREREQ 'To headers from files reset each patch' '
bdf20f5e
EP
1178 patch1=$(git format-patch -1 --to="bodies@example.com") &&
1179 patch2=$(git format-patch -1 --to="other@example.com" HEAD~) &&
3c3bb51c
SB
1180 test_when_finished "rm $patch1 && rm $patch2" &&
1181 git send-email \
1182 --dry-run \
1183 --from="Example <nobody@example.com>" \
1184 --to="nobody@example.com" \
1185 --smtp-server relay.example.com \
1186 $patch1 $patch2 >stdout &&
1187 test $(grep -c "RCPT TO:<bodies@example.com>" stdout) = 1 &&
1188 test $(grep -c "RCPT TO:<nobody@example.com>" stdout) = 2 &&
1189 test $(grep -c "RCPT TO:<other@example.com>" stdout) = 1
1190'
1191
f9444147 1192test_expect_success $PREREQ 'setup expect' '
0720a51b 1193cat >email-using-8bit <<\EOF
3cae7e5b
TR
1194From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1195Message-Id: <bogus-message-id@example.com>
1196From: author@example.com
1197Date: Sat, 12 Jun 2010 15:53:58 +0200
1198Subject: subject goes here
1199
1200Dieser deutsche Text enthält einen Umlaut!
1201EOF
f9444147 1202'
3cae7e5b 1203
5637d857 1204test_expect_success $PREREQ 'setup expect' '
0720a51b 1205 echo "Subject: subject goes here" >expected
5637d857
KM
1206'
1207
1208test_expect_success $PREREQ 'ASCII subject is not RFC2047 quoted' '
1209 clean_fake_sendmail &&
1210 echo bogus |
1211 git send-email --from=author@example.com --to=nobody@example.com \
1212 --smtp-server="$(pwd)/fake.sendmail" \
1213 --8bit-encoding=UTF-8 \
1214 email-using-8bit >stdout &&
1215 grep "Subject" msgtxt1 >actual &&
1216 test_cmp expected actual
1217'
1218
f9444147 1219test_expect_success $PREREQ 'setup expect' '
0720a51b
JH
1220 cat >content-type-decl <<-\EOF
1221 MIME-Version: 1.0
1222 Content-Type: text/plain; charset=UTF-8
1223 Content-Transfer-Encoding: 8bit
1224 EOF
f9444147 1225'
3cae7e5b 1226
57cd35e6 1227test_expect_success $PREREQ 'asks about and fixes 8bit encodings' '
3cae7e5b
TR
1228 clean_fake_sendmail &&
1229 echo |
1230 git send-email --from=author@example.com --to=nobody@example.com \
1231 --smtp-server="$(pwd)/fake.sendmail" \
1232 email-using-8bit >stdout &&
1233 grep "do not declare a Content-Transfer-Encoding" stdout &&
1234 grep email-using-8bit stdout &&
1235 grep "Which 8bit encoding" stdout &&
31832862 1236 egrep "Content|MIME" msgtxt1 >actual &&
3cae7e5b
TR
1237 test_cmp actual content-type-decl
1238'
1239
57cd35e6 1240test_expect_success $PREREQ 'sendemail.8bitEncoding works' '
3cae7e5b
TR
1241 clean_fake_sendmail &&
1242 git config sendemail.assume8bitEncoding UTF-8 &&
1243 echo bogus |
1244 git send-email --from=author@example.com --to=nobody@example.com \
1245 --smtp-server="$(pwd)/fake.sendmail" \
1246 email-using-8bit >stdout &&
31832862 1247 egrep "Content|MIME" msgtxt1 >actual &&
3cae7e5b
TR
1248 test_cmp actual content-type-decl
1249'
1250
57cd35e6 1251test_expect_success $PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
3cae7e5b
TR
1252 clean_fake_sendmail &&
1253 git config sendemail.assume8bitEncoding "bogus too" &&
1254 echo bogus |
1255 git send-email --from=author@example.com --to=nobody@example.com \
1256 --smtp-server="$(pwd)/fake.sendmail" \
1257 --8bit-encoding=UTF-8 \
1258 email-using-8bit >stdout &&
31832862 1259 egrep "Content|MIME" msgtxt1 >actual &&
3cae7e5b
TR
1260 test_cmp actual content-type-decl
1261'
1262
f9444147 1263test_expect_success $PREREQ 'setup expect' '
0720a51b
JH
1264 cat >email-using-8bit <<-\EOF
1265 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1266 Message-Id: <bogus-message-id@example.com>
1267 From: author@example.com
1268 Date: Sat, 12 Jun 2010 15:53:58 +0200
1269 Subject: Dieser Betreff enthält auch einen Umlaut!
1270
1271 Nothing to see here.
1272 EOF
f9444147 1273'
3cae7e5b 1274
f9444147 1275test_expect_success $PREREQ 'setup expect' '
0720a51b
JH
1276 cat >expected <<-\EOF
1277 Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
1278 EOF
f9444147 1279'
3cae7e5b 1280
57cd35e6 1281test_expect_success $PREREQ '--8bit-encoding also treats subject' '
3cae7e5b
TR
1282 clean_fake_sendmail &&
1283 echo bogus |
1284 git send-email --from=author@example.com --to=nobody@example.com \
1285 --smtp-server="$(pwd)/fake.sendmail" \
1286 --8bit-encoding=UTF-8 \
1287 email-using-8bit >stdout &&
1288 grep "Subject" msgtxt1 >actual &&
1289 test_cmp expected actual
1290'
1291
8d814084 1292test_expect_success $PREREQ 'setup expect' '
0720a51b
JH
1293 cat >email-using-8bit <<-\EOF
1294 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1295 Message-Id: <bogus-message-id@example.com>
1296 From: A U Thor <author@example.com>
1297 Date: Sat, 12 Jun 2010 15:53:58 +0200
1298 Content-Type: text/plain; charset=UTF-8
1299 Subject: Nothing to see here.
1300
1301 Dieser Betreff enthält auch einen Umlaut!
1302 EOF
8d814084
PB
1303'
1304
1305test_expect_success $PREREQ 'sendemail.transferencoding=7bit fails on 8bit data' '
1306 clean_fake_sendmail &&
1307 git config sendemail.transferEncoding 7bit &&
1308 test_must_fail git send-email \
03335f22
JH
1309 --transfer-encoding=7bit \
1310 --smtp-server="$(pwd)/fake.sendmail" \
1311 email-using-8bit \
1312 2>errors >out &&
8d814084
PB
1313 grep "cannot send message as 7bit" errors &&
1314 test -z "$(ls msgtxt*)"
1315'
1316
1317test_expect_success $PREREQ '--transfer-encoding overrides sendemail.transferEncoding' '
1318 clean_fake_sendmail &&
99094a7a 1319 git config sendemail.transferEncoding 8bit &&
8d814084 1320 test_must_fail git send-email \
03335f22
JH
1321 --transfer-encoding=7bit \
1322 --smtp-server="$(pwd)/fake.sendmail" \
1323 email-using-8bit \
1324 2>errors >out &&
8d814084
PB
1325 grep "cannot send message as 7bit" errors &&
1326 test -z "$(ls msgtxt*)"
1327'
1328
1329test_expect_success $PREREQ 'sendemail.transferencoding=8bit' '
1330 clean_fake_sendmail &&
1331 git send-email \
03335f22
JH
1332 --transfer-encoding=8bit \
1333 --smtp-server="$(pwd)/fake.sendmail" \
1334 email-using-8bit \
1335 2>errors >out &&
8d814084
PB
1336 sed '1,/^$/d' msgtxt1 >actual &&
1337 sed '1,/^$/d' email-using-8bit >expected &&
1338 test_cmp expected actual
1339'
1340
1341test_expect_success $PREREQ 'setup expect' '
0720a51b
JH
1342 cat >expected <<-\EOF
1343 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1344 EOF
8d814084
PB
1345'
1346
1347test_expect_success $PREREQ '8-bit and sendemail.transferencoding=quoted-printable' '
1348 clean_fake_sendmail &&
1349 git send-email \
03335f22
JH
1350 --transfer-encoding=quoted-printable \
1351 --smtp-server="$(pwd)/fake.sendmail" \
1352 email-using-8bit \
1353 2>errors >out &&
8d814084
PB
1354 sed '1,/^$/d' msgtxt1 >actual &&
1355 test_cmp expected actual
1356'
1357
1358test_expect_success $PREREQ 'setup expect' '
0720a51b
JH
1359 cat >expected <<-\EOF
1360 RGllc2VyIEJldHJlZmYgZW50aMOkbHQgYXVjaCBlaW5lbiBVbWxhdXQhCg==
1361 EOF
8d814084
PB
1362'
1363
1364test_expect_success $PREREQ '8-bit and sendemail.transferencoding=base64' '
1365 clean_fake_sendmail &&
1366 git send-email \
03335f22
JH
1367 --transfer-encoding=base64 \
1368 --smtp-server="$(pwd)/fake.sendmail" \
1369 email-using-8bit \
1370 2>errors >out &&
8d814084
PB
1371 sed '1,/^$/d' msgtxt1 >actual &&
1372 test_cmp expected actual
1373'
1374
1375test_expect_success $PREREQ 'setup expect' '
0720a51b
JH
1376 cat >email-using-qp <<-\EOF
1377 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1378 Message-Id: <bogus-message-id@example.com>
1379 From: A U Thor <author@example.com>
1380 Date: Sat, 12 Jun 2010 15:53:58 +0200
1381 MIME-Version: 1.0
1382 Content-Transfer-Encoding: quoted-printable
1383 Content-Type: text/plain; charset=UTF-8
1384 Subject: Nothing to see here.
8d814084 1385
0720a51b
JH
1386 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1387 EOF
8d814084
PB
1388'
1389
1390test_expect_success $PREREQ 'convert from quoted-printable to base64' '
1391 clean_fake_sendmail &&
1392 git send-email \
03335f22
JH
1393 --transfer-encoding=base64 \
1394 --smtp-server="$(pwd)/fake.sendmail" \
1395 email-using-qp \
1396 2>errors >out &&
8d814084
PB
1397 sed '1,/^$/d' msgtxt1 >actual &&
1398 test_cmp expected actual
1399'
1400
1401test_expect_success $PREREQ 'setup expect' "
ee756a81 1402tr -d '\\015' | tr '%' '\\015' >email-using-crlf <<EOF
8d814084
PB
1403From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1404Message-Id: <bogus-message-id@example.com>
1405From: A U Thor <author@example.com>
1406Date: Sat, 12 Jun 2010 15:53:58 +0200
1407Content-Type: text/plain; charset=UTF-8
1408Subject: Nothing to see here.
1409
1410Look, I have a CRLF and an = sign!%
1411EOF
1412"
1413
1414test_expect_success $PREREQ 'setup expect' '
0720a51b
JH
1415 cat >expected <<-\EOF
1416 Look, I have a CRLF and an =3D sign!=0D
1417 EOF
8d814084
PB
1418'
1419
1420test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=quoted-printable' '
1421 clean_fake_sendmail &&
1422 git send-email \
03335f22
JH
1423 --transfer-encoding=quoted-printable \
1424 --smtp-server="$(pwd)/fake.sendmail" \
1425 email-using-crlf \
1426 2>errors >out &&
8d814084
PB
1427 sed '1,/^$/d' msgtxt1 >actual &&
1428 test_cmp expected actual
1429'
1430
1431test_expect_success $PREREQ 'setup expect' '
0720a51b
JH
1432 cat >expected <<-\EOF
1433 TG9vaywgSSBoYXZlIGEgQ1JMRiBhbmQgYW4gPSBzaWduIQ0K
1434 EOF
8d814084
PB
1435'
1436
1437test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=base64' '
1438 clean_fake_sendmail &&
1439 git send-email \
03335f22
JH
1440 --transfer-encoding=base64 \
1441 --smtp-server="$(pwd)/fake.sendmail" \
1442 email-using-crlf \
1443 2>errors >out &&
8d814084
PB
1444 sed '1,/^$/d' msgtxt1 >actual &&
1445 test_cmp expected actual
1446'
1447
1448
a03bc5b6
TR
1449# Note that the patches in this test are deliberately out of order; we
1450# want to make sure it works even if the cover-letter is not in the
1451# first mail.
57da2042 1452test_expect_success $PREREQ 'refusing to send cover letter template' '
a03bc5b6
TR
1453 clean_fake_sendmail &&
1454 rm -fr outdir &&
1455 git format-patch --cover-letter -2 -o outdir &&
1456 test_must_fail git send-email \
03335f22
JH
1457 --from="Example <nobody@example.com>" \
1458 --to=nobody@example.com \
1459 --smtp-server="$(pwd)/fake.sendmail" \
1460 outdir/0002-*.patch \
1461 outdir/0000-*.patch \
1462 outdir/0001-*.patch \
1463 2>errors >out &&
a03bc5b6
TR
1464 grep "SUBJECT HERE" errors &&
1465 test -z "$(ls msgtxt*)"
1466'
1467
57da2042 1468test_expect_success $PREREQ '--force sends cover letter template anyway' '
a03bc5b6
TR
1469 clean_fake_sendmail &&
1470 rm -fr outdir &&
1471 git format-patch --cover-letter -2 -o outdir &&
1472 git send-email \
03335f22
JH
1473 --force \
1474 --from="Example <nobody@example.com>" \
1475 --to=nobody@example.com \
1476 --smtp-server="$(pwd)/fake.sendmail" \
1477 outdir/0002-*.patch \
1478 outdir/0000-*.patch \
1479 outdir/0001-*.patch \
1480 2>errors >out &&
a03bc5b6
TR
1481 ! grep "SUBJECT HERE" errors &&
1482 test -n "$(ls msgtxt*)"
1483'
1484
8ccc4e42
MT
1485test_cover_addresses () {
1486 header="$1"
1487 shift
1488 clean_fake_sendmail &&
1489 rm -fr outdir &&
1490 git format-patch --cover-letter -2 -o outdir &&
bdf20f5e 1491 cover=$(echo outdir/0000-*.patch) &&
8ccc4e42 1492 mv $cover cover-to-edit.patch &&
35ec002c 1493 perl -pe "s/^From:/$header: extra\@address.com\nFrom:/" cover-to-edit.patch >"$cover" &&
8ccc4e42 1494 git send-email \
03335f22
JH
1495 --force \
1496 --from="Example <nobody@example.com>" \
1497 --no-to --no-cc \
1498 "$@" \
1499 --smtp-server="$(pwd)/fake.sendmail" \
1500 outdir/0000-*.patch \
1501 outdir/0001-*.patch \
1502 outdir/0002-*.patch \
1503 2>errors >out &&
8ccc4e42
MT
1504 grep "^$header: extra@address.com" msgtxt1 >to1 &&
1505 grep "^$header: extra@address.com" msgtxt2 >to2 &&
1506 grep "^$header: extra@address.com" msgtxt3 >to3 &&
1507 test_line_count = 1 to1 &&
1508 test_line_count = 1 to2 &&
1509 test_line_count = 1 to3
1510}
1511
1512test_expect_success $PREREQ 'to-cover adds To to all mail' '
1513 test_cover_addresses "To" --to-cover
1514'
1515
1516test_expect_success $PREREQ 'cc-cover adds Cc to all mail' '
1517 test_cover_addresses "Cc" --cc-cover
1518'
1519
1520test_expect_success $PREREQ 'tocover adds To to all mail' '
1521 test_config sendemail.tocover true &&
1522 test_cover_addresses "To"
1523'
1524
1525test_expect_success $PREREQ 'cccover adds Cc to all mail' '
1526 test_config sendemail.cccover true &&
1527 test_cover_addresses "Cc"
1528'
1529
2c510f21
EW
1530test_expect_success $PREREQ 'escaped quotes in sendemail.aliasfiletype=mutt' '
1531 clean_fake_sendmail &&
1532 echo "alias sbd \\\"Dot U. Sir\\\" <somebody@example.org>" >.mutt &&
1533 git config --replace-all sendemail.aliasesfile "$(pwd)/.mutt" &&
1534 git config sendemail.aliasfiletype mutt &&
1535 git send-email \
1536 --from="Example <nobody@example.com>" \
1537 --to=sbd \
1538 --smtp-server="$(pwd)/fake.sendmail" \
1539 outdir/0001-*.patch \
1540 2>errors >out &&
1541 grep "^!somebody@example\.org!$" commandline1 &&
1542 grep -F "To: \"Dot U. Sir\" <somebody@example.org>" out
1543'
1544
463b0ea2
CS
1545test_expect_success $PREREQ 'sendemail.aliasfiletype=mailrc' '
1546 clean_fake_sendmail &&
1547 echo "alias sbd somebody@example.org" >.mailrc &&
1548 git config --replace-all sendemail.aliasesfile "$(pwd)/.mailrc" &&
1549 git config sendemail.aliasfiletype mailrc &&
1550 git send-email \
03335f22
JH
1551 --from="Example <nobody@example.com>" \
1552 --to=sbd \
1553 --smtp-server="$(pwd)/fake.sendmail" \
1554 outdir/0001-*.patch \
1555 2>errors >out &&
463b0ea2
CS
1556 grep "^!somebody@example\.org!$" commandline1
1557'
1558
1559test_expect_success $PREREQ 'sendemail.aliasfile=~/.mailrc' '
1560 clean_fake_sendmail &&
587089c1 1561 echo "alias sbd someone@example.org" >"$HOME/.mailrc" &&
463b0ea2
CS
1562 git config --replace-all sendemail.aliasesfile "~/.mailrc" &&
1563 git config sendemail.aliasfiletype mailrc &&
1564 git send-email \
03335f22
JH
1565 --from="Example <nobody@example.com>" \
1566 --to=sbd \
1567 --smtp-server="$(pwd)/fake.sendmail" \
1568 outdir/0001-*.patch \
1569 2>errors >out &&
463b0ea2
CS
1570 grep "^!someone@example\.org!$" commandline1
1571'
1572
17b7a832
JK
1573test_dump_aliases () {
1574 msg="$1" && shift &&
1575 filetype="$1" && shift &&
1576 printf '%s\n' "$@" >expect &&
1577 cat >.tmp-email-aliases &&
1578
1579 test_expect_success $PREREQ "$msg" '
1580 clean_fake_sendmail && rm -fr outdir &&
1581 git config --replace-all sendemail.aliasesfile \
1582 "$(pwd)/.tmp-email-aliases" &&
1583 git config sendemail.aliasfiletype "$filetype" &&
1584 git send-email --dump-aliases 2>errors >actual &&
1585 test_cmp expect actual
1586 '
1587}
1588
1589test_dump_aliases '--dump-aliases sendmail format' \
1590 'sendmail' \
1591 'abgroup' \
1592 'alice' \
1593 'bcgrp' \
1594 'bob' \
1595 'chloe' <<-\EOF
1596 alice: Alice W Land <awol@example.com>
1597 bob: Robert Bobbyton <bob@example.com>
1598 chloe: chloe@example.com
1599 abgroup: alice, bob
1600 bcgrp: bob, chloe, Other <o@example.com>
1601 EOF
1602
1603test_dump_aliases '--dump-aliases mutt format' \
1604 'mutt' \
1605 'alice' \
1606 'bob' \
1607 'chloe' \
1608 'donald' <<-\EOF
1609 alias alice Alice W Land <awol@example.com>
1610 alias donald Donald C Carlton <donc@example.com>
1611 alias bob Robert Bobbyton <bob@example.com>
1612 alias chloe chloe@example.com
1613 EOF
1614
1615test_dump_aliases '--dump-aliases mailrc format' \
1616 'mailrc' \
1617 'alice' \
1618 'bob' \
1619 'chloe' \
1620 'eve' <<-\EOF
1621 alias alice Alice W Land <awol@example.com>
1622 alias eve Eve <eve@example.com>
1623 alias bob Robert Bobbyton <bob@example.com>
1624 alias chloe chloe@example.com
1625 EOF
1626
1627test_dump_aliases '--dump-aliases pine format' \
1628 'pine' \
1629 'alice' \
1630 'bob' \
1631 'chloe' \
1632 'eve' <<-\EOF
1633 alice Alice W Land <awol@example.com>
1634 eve Eve <eve@example.com>
1635 bob Robert Bobbyton <bob@example.com>
1636 chloe chloe@example.com
1637 EOF
1638
1639test_dump_aliases '--dump-aliases gnus format' \
1640 'gnus' \
1641 'alice' \
1642 'bob' \
1643 'chloe' \
1644 'eve' <<-\EOF
1645 (define-mail-alias "alice" "awol@example.com")
1646 (define-mail-alias "eve" "eve@example.com")
1647 (define-mail-alias "bob" "bob@example.com")
1648 (define-mail-alias "chloe" "chloe@example.com")
1649 EOF
1650
1651test_expect_success '--dump-aliases must be used alone' '
1652 test_must_fail git send-email --dump-aliases --to=janice@example.com -1 refs/heads/accounting
1653'
1654
514554cf
ES
1655test_sendmail_aliases () {
1656 msg="$1" && shift &&
1657 expect="$@" &&
1658 cat >.tmp-email-aliases &&
1659
1660 test_expect_success $PREREQ "$msg" '
1661 clean_fake_sendmail && rm -fr outdir &&
1662 git format-patch -1 -o outdir &&
1663 git config --replace-all sendemail.aliasesfile \
1664 "$(pwd)/.tmp-email-aliases" &&
1665 git config sendemail.aliasfiletype sendmail &&
1666 git send-email \
1667 --from="Example <nobody@example.com>" \
1668 --to=alice --to=bcgrp \
1669 --smtp-server="$(pwd)/fake.sendmail" \
1670 outdir/0001-*.patch \
1671 2>errors >out &&
1672 for i in $expect
1673 do
1674 grep "^!$i!$" commandline1 || return 1
1675 done
1676 '
1677}
1678
1679test_sendmail_aliases 'sendemail.aliasfiletype=sendmail' \
1680 'awol@example\.com' \
1681 'bob@example\.com' \
1682 'chloe@example\.com' \
1683 'o@example\.com' <<-\EOF
3169e06d
AH
1684 alice: Alice W Land <awol@example.com>
1685 bob: Robert Bobbyton <bob@example.com>
1686 # this is a comment
1687 # this is also a comment
1688 chloe: chloe@example.com
1689 abgroup: alice, bob
1690 bcgrp: bob, chloe, Other <o@example.com>
1691 EOF
3169e06d 1692
6be02640
ES
1693test_sendmail_aliases 'sendmail aliases line folding' \
1694 alice1 \
1695 bob1 bob2 \
1696 chuck1 chuck2 \
1697 darla1 darla2 darla3 \
1698 elton1 elton2 elton3 \
1699 fred1 fred2 \
1700 greg1 <<-\EOF
1701 alice: alice1
1702 bob: bob1,\
1703 bob2
1704 chuck: chuck1,
1705 chuck2
1706 darla: darla1,\
1707 darla2,
1708 darla3
1709 elton: elton1,
1710 elton2,\
1711 elton3
1712 fred: fred1,\
1713 fred2
1714 greg: greg1
1715 bcgrp: bob, chuck, darla, elton, fred, greg
1716 EOF
1717
1718test_sendmail_aliases 'sendmail aliases tolerate bogus line folding' \
1719 alice1 bob1 <<-\EOF
1720 alice: alice1
1721 bcgrp: bob1\
1722 EOF
1723
1724test_sendmail_aliases 'sendmail aliases empty' alice bcgrp <<-\EOF
1725 EOF
1726
f6f79e5e
RL
1727test_expect_success $PREREQ 'alias support in To header' '
1728 clean_fake_sendmail &&
1729 echo "alias sbd someone@example.org" >.mailrc &&
1730 test_config sendemail.aliasesfile ".mailrc" &&
1731 test_config sendemail.aliasfiletype mailrc &&
1732 git format-patch --stdout -1 --to=sbd >aliased.patch &&
1733 git send-email \
1734 --from="Example <nobody@example.com>" \
1735 --smtp-server="$(pwd)/fake.sendmail" \
1736 aliased.patch \
1737 2>errors >out &&
1738 grep "^!someone@example\.org!$" commandline1
1739'
1740
1741test_expect_success $PREREQ 'alias support in Cc header' '
1742 clean_fake_sendmail &&
1743 echo "alias sbd someone@example.org" >.mailrc &&
1744 test_config sendemail.aliasesfile ".mailrc" &&
1745 test_config sendemail.aliasfiletype mailrc &&
1746 git format-patch --stdout -1 --cc=sbd >aliased.patch &&
1747 git send-email \
1748 --from="Example <nobody@example.com>" \
1749 --smtp-server="$(pwd)/fake.sendmail" \
1750 aliased.patch \
1751 2>errors >out &&
1752 grep "^!someone@example\.org!$" commandline1
1753'
1754
1755test_expect_success $PREREQ 'tocmd works with aliases' '
1756 clean_fake_sendmail &&
1757 echo "alias sbd someone@example.org" >.mailrc &&
1758 test_config sendemail.aliasesfile ".mailrc" &&
1759 test_config sendemail.aliasfiletype mailrc &&
1760 git format-patch --stdout -1 >tocmd.patch &&
1761 echo tocmd--sbd >>tocmd.patch &&
1762 git send-email \
1763 --from="Example <nobody@example.com>" \
1764 --to-cmd=./tocmd-sed \
1765 --smtp-server="$(pwd)/fake.sendmail" \
1766 tocmd.patch \
1767 2>errors >out &&
1768 grep "^!someone@example\.org!$" commandline1
1769'
1770
1771test_expect_success $PREREQ 'cccmd works with aliases' '
1772 clean_fake_sendmail &&
1773 echo "alias sbd someone@example.org" >.mailrc &&
1774 test_config sendemail.aliasesfile ".mailrc" &&
1775 test_config sendemail.aliasfiletype mailrc &&
1776 git format-patch --stdout -1 >cccmd.patch &&
1777 echo cccmd--sbd >>cccmd.patch &&
1778 git send-email \
1779 --from="Example <nobody@example.com>" \
1780 --cc-cmd=./cccmd-sed \
1781 --smtp-server="$(pwd)/fake.sendmail" \
1782 cccmd.patch \
1783 2>errors >out &&
1784 grep "^!someone@example\.org!$" commandline1
1785'
1786
2cf770f5
LH
1787do_xmailer_test () {
1788 expected=$1 params=$2 &&
1789 git format-patch -1 &&
1790 git send-email \
1791 --from="Example <nobody@example.com>" \
1792 --to=someone@example.com \
1793 --smtp-server="$(pwd)/fake.sendmail" \
1794 $params \
1795 0001-*.patch \
1796 2>errors >out &&
1797 { grep '^X-Mailer:' out || :; } >mailer &&
1798 test_line_count = $expected mailer
1799}
1800
1801test_expect_success $PREREQ '--[no-]xmailer without any configuration' '
1802 do_xmailer_test 1 "--xmailer" &&
1803 do_xmailer_test 0 "--no-xmailer"
1804'
1805
1806test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=true' '
1807 test_config sendemail.xmailer true &&
1808 do_xmailer_test 1 "" &&
1809 do_xmailer_test 0 "--no-xmailer" &&
1810 do_xmailer_test 1 "--xmailer"
1811'
1812
1813test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=false' '
1814 test_config sendemail.xmailer false &&
1815 do_xmailer_test 0 "" &&
1816 do_xmailer_test 0 "--no-xmailer" &&
1817 do_xmailer_test 1 "--xmailer"
1818'
1819
b1c8a11c
RL
1820test_expect_success $PREREQ 'setup expected-list' '
1821 git send-email \
1822 --dry-run \
1823 --from="Example <from@example.com>" \
1824 --to="To 1 <to1@example.com>" \
1825 --to="to2@example.com" \
1826 --to="to3@example.com" \
1827 --cc="Cc 1 <cc1@example.com>" \
1828 --cc="Cc2 <cc2@example.com>" \
1829 --bcc="bcc1@example.com" \
1830 --bcc="bcc2@example.com" \
1831 0001-add-master.patch | replace_variable_fields \
1832 >expected-list
1833'
1834
1835test_expect_success $PREREQ 'use email list in --cc --to and --bcc' '
1836 git send-email \
1837 --dry-run \
1838 --from="Example <from@example.com>" \
1839 --to="To 1 <to1@example.com>, to2@example.com" \
1840 --to="to3@example.com" \
1841 --cc="Cc 1 <cc1@example.com>, Cc2 <cc2@example.com>" \
1842 --bcc="bcc1@example.com, bcc2@example.com" \
1843 0001-add-master.patch | replace_variable_fields \
1844 >actual-list &&
1845 test_cmp expected-list actual-list
1846'
1847
1848test_expect_success $PREREQ 'aliases work with email list' '
1849 echo "alias to2 to2@example.com" >.mutt &&
1850 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt &&
1851 test_config sendemail.aliasesfile ".mutt" &&
1852 test_config sendemail.aliasfiletype mutt &&
1853 git send-email \
1854 --dry-run \
1855 --from="Example <from@example.com>" \
1856 --to="To 1 <to1@example.com>, to2, to3@example.com" \
1857 --cc="cc1, Cc2 <cc2@example.com>" \
1858 --bcc="bcc1@example.com, bcc2@example.com" \
1859 0001-add-master.patch | replace_variable_fields \
1860 >actual-list &&
1861 test_cmp expected-list actual-list
1862'
1863
fa5b1aa9
RL
1864test_expect_success $PREREQ 'leading and trailing whitespaces are removed' '
1865 echo "alias to2 to2@example.com" >.mutt &&
1866 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt &&
1867 test_config sendemail.aliasesfile ".mutt" &&
1868 test_config sendemail.aliasfiletype mutt &&
1869 TO1=$(echo "QTo 1 <to1@example.com>" | q_to_tab) &&
1870 TO2=$(echo "QZto2" | qz_to_tab_space) &&
1871 CC1=$(echo "cc1" | append_cr) &&
1872 BCC1=$(echo "Q bcc1@example.com Q" | q_to_nul) &&
1873 git send-email \
1874 --dry-run \
1875 --from=" Example <from@example.com>" \
1876 --to="$TO1" \
1877 --to="$TO2" \
1878 --to=" to3@example.com " \
1879 --cc="$CC1" \
1880 --cc="Cc2 <cc2@example.com>" \
1881 --bcc="$BCC1" \
1882 --bcc="bcc2@example.com" \
1883 0001-add-master.patch | replace_variable_fields \
1884 >actual-list &&
1885 test_cmp expected-list actual-list
1886'
1887
ce903018 1888test_done