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