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