1#!/bin/sh
2
3test_description='git send-email'
4. ./test-lib.sh
5
6if ! test_have_prereq PERL; then
7 skip_all='skipping git send-email tests, perl not available'
8 test_done
9fi
10
11test_expect_success \
12 'prepare reference tree' \
13 'echo "1A quick brown fox jumps over the" >file &&
14 echo "lazy dog" >>file &&
15 git add file &&
16 GIT_AUTHOR_NAME="A" git commit -a -m "Initial."'
17
18test_expect_success \
19 'Setup helper tool' \
20 '(echo "#!$SHELL_PATH"
21 echo shift
22 echo output=1
23 echo "while test -f commandline\$output; do output=\$((\$output+1)); done"
24 echo for a
25 echo do
26 echo " echo \"!\$a!\""
27 echo "done >commandline\$output"
28 echo "cat > msgtxt\$output"
29 ) >fake.sendmail &&
30 chmod +x ./fake.sendmail &&
31 git add fake.sendmail &&
32 GIT_AUTHOR_NAME="A" git commit -a -m "Second."'
33
34clean_fake_sendmail() {
35 rm -f commandline* msgtxt*
36}
37
38test_expect_success 'Extract patches' '
39 patches=`git format-patch -s --cc="One <one@example.com>" --cc=two@example.com -n HEAD^1`
40'
41
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 $@ \
52 $patches > stdout &&
53 test_must_fail grep "Send this email" stdout &&
54 > no_confirm_okay
55}
56
57# Exit immediately to prevent hang if a no-confirm test fails
58check_no_confirm () {
59 test -f no_confirm_okay || {
60 skip_all='confirm test failed; skipping remaining tests to prevent hanging'
61 test_done
62 }
63}
64
65test_expect_success 'No confirm with --suppress-cc' '
66 test_no_confirm --suppress-cc=sob
67'
68check_no_confirm
69
70test_expect_success 'No confirm with --confirm=never' '
71 test_no_confirm --confirm=never
72'
73check_no_confirm
74
75# leave sendemail.confirm set to never after this so that none of the
76# remaining tests prompt unintentionally.
77test_expect_success 'No confirm with sendemail.confirm=never' '
78 git config sendemail.confirm never &&
79 test_no_confirm --compose --subject=foo
80'
81check_no_confirm
82
83test_expect_success 'Send patches' '
84 git send-email --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
85'
86
87cat >expected <<\EOF
88!nobody@example.com!
89!author@example.com!
90!one@example.com!
91!two@example.com!
92EOF
93test_expect_success \
94 'Verify commandline' \
95 'test_cmp expected commandline1'
96
97test_expect_success 'Send patches with --envelope-sender' '
98 clean_fake_sendmail &&
99 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
100'
101
102cat >expected <<\EOF
103!patch@example.com!
104!-i!
105!nobody@example.com!
106!author@example.com!
107!one@example.com!
108!two@example.com!
109EOF
110test_expect_success \
111 'Verify commandline' \
112 'test_cmp expected commandline1'
113
114test_expect_success 'Send patches with --envelope-sender=auto' '
115 clean_fake_sendmail &&
116 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
117'
118
119cat >expected <<\EOF
120!nobody@example.com!
121!-i!
122!nobody@example.com!
123!author@example.com!
124!one@example.com!
125!two@example.com!
126EOF
127test_expect_success \
128 'Verify commandline' \
129 'test_cmp expected commandline1'
130
131cat >expected-show-all-headers <<\EOF
1320001-Second.patch
133(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
134(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
135(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
136Dry-OK. Log says:
137Server: relay.example.com
138MAIL FROM:<from@example.com>
139RCPT TO:<to@example.com>
140RCPT TO:<cc@example.com>
141RCPT TO:<author@example.com>
142RCPT TO:<one@example.com>
143RCPT TO:<two@example.com>
144RCPT TO:<bcc@example.com>
145From: Example <from@example.com>
146To: to@example.com
147Cc: cc@example.com,
148 A <author@example.com>,
149 One <one@example.com>,
150 two@example.com
151Subject: [PATCH 1/1] Second.
152Date: DATE-STRING
153Message-Id: MESSAGE-ID-STRING
154X-Mailer: X-MAILER-STRING
155In-Reply-To: <unique-message-id@example.com>
156References: <unique-message-id@example.com>
157
158Result: OK
159EOF
160
161test_expect_success 'Show all headers' '
162 git send-email \
163 --dry-run \
164 --suppress-cc=sob \
165 --from="Example <from@example.com>" \
166 --to=to@example.com \
167 --cc=cc@example.com \
168 --bcc=bcc@example.com \
169 --in-reply-to="<unique-message-id@example.com>" \
170 --smtp-server relay.example.com \
171 $patches |
172 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
173 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
174 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
175 >actual-show-all-headers &&
176 test_cmp expected-show-all-headers actual-show-all-headers
177'
178
179test_expect_success 'Prompting works' '
180 clean_fake_sendmail &&
181 (echo "Example <from@example.com>"
182 echo "to@example.com"
183 echo ""
184 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
185 --smtp-server="$(pwd)/fake.sendmail" \
186 $patches \
187 2>errors &&
188 grep "^From: Example <from@example.com>\$" msgtxt1 &&
189 grep "^To: to@example.com\$" msgtxt1
190'
191
192test_expect_success 'cccmd works' '
193 clean_fake_sendmail &&
194 cp $patches cccmd.patch &&
195 echo cccmd--cccmd@example.com >>cccmd.patch &&
196 {
197 echo "#!$SHELL_PATH"
198 echo sed -n -e s/^cccmd--//p \"\$1\"
199 } > cccmd-sed &&
200 chmod +x cccmd-sed &&
201 git send-email \
202 --from="Example <nobody@example.com>" \
203 --to=nobody@example.com \
204 --cc-cmd=./cccmd-sed \
205 --smtp-server="$(pwd)/fake.sendmail" \
206 cccmd.patch \
207 &&
208 grep "^ cccmd@example.com" msgtxt1
209'
210
211z8=zzzzzzzz
212z64=$z8$z8$z8$z8$z8$z8$z8$z8
213z512=$z64$z64$z64$z64$z64$z64$z64$z64
214test_expect_success 'reject long lines' '
215 clean_fake_sendmail &&
216 cp $patches longline.patch &&
217 echo $z512$z512 >>longline.patch &&
218 test_must_fail git send-email \
219 --from="Example <nobody@example.com>" \
220 --to=nobody@example.com \
221 --smtp-server="$(pwd)/fake.sendmail" \
222 $patches longline.patch \
223 2>errors &&
224 grep longline.patch errors
225'
226
227test_expect_success 'no patch was sent' '
228 ! test -e commandline1
229'
230
231test_expect_success 'Author From: in message body' '
232 clean_fake_sendmail &&
233 git send-email \
234 --from="Example <nobody@example.com>" \
235 --to=nobody@example.com \
236 --smtp-server="$(pwd)/fake.sendmail" \
237 $patches &&
238 sed "1,/^\$/d" < msgtxt1 > msgbody1
239 grep "From: A <author@example.com>" msgbody1
240'
241
242test_expect_success 'Author From: not in message body' '
243 clean_fake_sendmail &&
244 git send-email \
245 --from="A <author@example.com>" \
246 --to=nobody@example.com \
247 --smtp-server="$(pwd)/fake.sendmail" \
248 $patches &&
249 sed "1,/^\$/d" < msgtxt1 > msgbody1
250 ! grep "From: A <author@example.com>" msgbody1
251'
252
253test_expect_success 'allow long lines with --no-validate' '
254 git send-email \
255 --from="Example <nobody@example.com>" \
256 --to=nobody@example.com \
257 --smtp-server="$(pwd)/fake.sendmail" \
258 --novalidate \
259 $patches longline.patch \
260 2>errors
261'
262
263test_expect_success 'Invalid In-Reply-To' '
264 clean_fake_sendmail &&
265 git send-email \
266 --from="Example <nobody@example.com>" \
267 --to=nobody@example.com \
268 --in-reply-to=" " \
269 --smtp-server="$(pwd)/fake.sendmail" \
270 $patches
271 2>errors
272 ! grep "^In-Reply-To: < *>" msgtxt1
273'
274
275test_expect_success 'Valid In-Reply-To when prompting' '
276 clean_fake_sendmail &&
277 (echo "From Example <from@example.com>"
278 echo "To Example <to@example.com>"
279 echo ""
280 ) | env GIT_SEND_EMAIL_NOTTY=1 git send-email \
281 --smtp-server="$(pwd)/fake.sendmail" \
282 $patches 2>errors &&
283 ! grep "^In-Reply-To: < *>" msgtxt1
284'
285
286test_expect_success 'setup fake editor' '
287 (echo "#!$SHELL_PATH" &&
288 echo "echo fake edit >>\"\$1\""
289 ) >fake-editor &&
290 chmod +x fake-editor
291'
292
293test_set_editor "$(pwd)/fake-editor"
294
295test_expect_success '--compose works' '
296 clean_fake_sendmail &&
297 git send-email \
298 --compose --subject foo \
299 --from="Example <nobody@example.com>" \
300 --to=nobody@example.com \
301 --smtp-server="$(pwd)/fake.sendmail" \
302 $patches \
303 2>errors
304'
305
306test_expect_success 'first message is compose text' '
307 grep "^fake edit" msgtxt1
308'
309
310test_expect_success 'second message is patch' '
311 grep "Subject:.*Second" msgtxt2
312'
313
314cat >expected-suppress-sob <<\EOF
3150001-Second.patch
316(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
317(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
318(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
319Dry-OK. Log says:
320Server: relay.example.com
321MAIL FROM:<from@example.com>
322RCPT TO:<to@example.com>
323RCPT TO:<cc@example.com>
324RCPT TO:<author@example.com>
325RCPT TO:<one@example.com>
326RCPT TO:<two@example.com>
327From: Example <from@example.com>
328To: to@example.com
329Cc: cc@example.com,
330 A <author@example.com>,
331 One <one@example.com>,
332 two@example.com
333Subject: [PATCH 1/1] Second.
334Date: DATE-STRING
335Message-Id: MESSAGE-ID-STRING
336X-Mailer: X-MAILER-STRING
337
338Result: OK
339EOF
340
341test_suppression () {
342 git send-email \
343 --dry-run \
344 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
345 --from="Example <from@example.com>" \
346 --to=to@example.com \
347 --smtp-server relay.example.com \
348 $patches |
349 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
350 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
351 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
352 >actual-suppress-$1${2+"-$2"} &&
353 test_cmp expected-suppress-$1${2+"-$2"} actual-suppress-$1${2+"-$2"}
354}
355
356test_expect_success 'sendemail.cc set' '
357 git config sendemail.cc cc@example.com &&
358 test_suppression sob
359'
360
361cat >expected-suppress-sob <<\EOF
3620001-Second.patch
363(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
364(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
365(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
366Dry-OK. Log says:
367Server: relay.example.com
368MAIL FROM:<from@example.com>
369RCPT TO:<to@example.com>
370RCPT TO:<author@example.com>
371RCPT TO:<one@example.com>
372RCPT TO:<two@example.com>
373From: Example <from@example.com>
374To: to@example.com
375Cc: A <author@example.com>,
376 One <one@example.com>,
377 two@example.com
378Subject: [PATCH 1/1] Second.
379Date: DATE-STRING
380Message-Id: MESSAGE-ID-STRING
381X-Mailer: X-MAILER-STRING
382
383Result: OK
384EOF
385
386test_expect_success 'sendemail.cc unset' '
387 git config --unset sendemail.cc &&
388 test_suppression sob
389'
390
391cat >expected-suppress-cccmd <<\EOF
3920001-Second.patch
393(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
394(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
395(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
396(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
397Dry-OK. Log says:
398Server: relay.example.com
399MAIL FROM:<from@example.com>
400RCPT TO:<to@example.com>
401RCPT TO:<author@example.com>
402RCPT TO:<one@example.com>
403RCPT TO:<two@example.com>
404RCPT TO:<committer@example.com>
405From: Example <from@example.com>
406To: to@example.com
407Cc: A <author@example.com>,
408 One <one@example.com>,
409 two@example.com,
410 C O Mitter <committer@example.com>
411Subject: [PATCH 1/1] Second.
412Date: DATE-STRING
413Message-Id: MESSAGE-ID-STRING
414X-Mailer: X-MAILER-STRING
415
416Result: OK
417EOF
418
419test_expect_success 'sendemail.cccmd' '
420 echo echo cc-cmd@example.com > cccmd &&
421 chmod +x cccmd &&
422 git config sendemail.cccmd ./cccmd &&
423 test_suppression cccmd
424'
425
426cat >expected-suppress-all <<\EOF
4270001-Second.patch
428Dry-OK. Log says:
429Server: relay.example.com
430MAIL FROM:<from@example.com>
431RCPT TO:<to@example.com>
432From: Example <from@example.com>
433To: to@example.com
434Subject: [PATCH 1/1] Second.
435Date: DATE-STRING
436Message-Id: MESSAGE-ID-STRING
437X-Mailer: X-MAILER-STRING
438
439Result: OK
440EOF
441
442test_expect_success '--suppress-cc=all' '
443 test_suppression all
444'
445
446cat >expected-suppress-body <<\EOF
4470001-Second.patch
448(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
449(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
450(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
451(cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
452Dry-OK. Log says:
453Server: relay.example.com
454MAIL FROM:<from@example.com>
455RCPT TO:<to@example.com>
456RCPT TO:<author@example.com>
457RCPT TO:<one@example.com>
458RCPT TO:<two@example.com>
459RCPT TO:<cc-cmd@example.com>
460From: Example <from@example.com>
461To: to@example.com
462Cc: A <author@example.com>,
463 One <one@example.com>,
464 two@example.com,
465 cc-cmd@example.com
466Subject: [PATCH 1/1] Second.
467Date: DATE-STRING
468Message-Id: MESSAGE-ID-STRING
469X-Mailer: X-MAILER-STRING
470
471Result: OK
472EOF
473
474test_expect_success '--suppress-cc=body' '
475 test_suppression body
476'
477
478cat >expected-suppress-body-cccmd <<\EOF
4790001-Second.patch
480(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
481(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
482(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
483Dry-OK. Log says:
484Server: relay.example.com
485MAIL FROM:<from@example.com>
486RCPT TO:<to@example.com>
487RCPT TO:<author@example.com>
488RCPT TO:<one@example.com>
489RCPT TO:<two@example.com>
490From: Example <from@example.com>
491To: to@example.com
492Cc: A <author@example.com>,
493 One <one@example.com>,
494 two@example.com
495Subject: [PATCH 1/1] Second.
496Date: DATE-STRING
497Message-Id: MESSAGE-ID-STRING
498X-Mailer: X-MAILER-STRING
499
500Result: OK
501EOF
502
503test_expect_success '--suppress-cc=body --suppress-cc=cccmd' '
504 test_suppression body cccmd
505'
506
507cat >expected-suppress-sob <<\EOF
5080001-Second.patch
509(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
510(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
511(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
512Dry-OK. Log says:
513Server: relay.example.com
514MAIL FROM:<from@example.com>
515RCPT TO:<to@example.com>
516RCPT TO:<author@example.com>
517RCPT TO:<one@example.com>
518RCPT TO:<two@example.com>
519From: Example <from@example.com>
520To: to@example.com
521Cc: A <author@example.com>,
522 One <one@example.com>,
523 two@example.com
524Subject: [PATCH 1/1] Second.
525Date: DATE-STRING
526Message-Id: MESSAGE-ID-STRING
527X-Mailer: X-MAILER-STRING
528
529Result: OK
530EOF
531
532test_expect_success '--suppress-cc=sob' '
533 git config --unset sendemail.cccmd
534 test_suppression sob
535'
536
537cat >expected-suppress-bodycc <<\EOF
5380001-Second.patch
539(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
540(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
541(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
542(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
543Dry-OK. Log says:
544Server: relay.example.com
545MAIL FROM:<from@example.com>
546RCPT TO:<to@example.com>
547RCPT TO:<author@example.com>
548RCPT TO:<one@example.com>
549RCPT TO:<two@example.com>
550RCPT TO:<committer@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,
556 C O Mitter <committer@example.com>
557Subject: [PATCH 1/1] Second.
558Date: DATE-STRING
559Message-Id: MESSAGE-ID-STRING
560X-Mailer: X-MAILER-STRING
561
562Result: OK
563EOF
564
565test_expect_success '--suppress-cc=bodycc' '
566 test_suppression bodycc
567'
568
569cat >expected-suppress-cc <<\EOF
5700001-Second.patch
571(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
572(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
573Dry-OK. Log says:
574Server: relay.example.com
575MAIL FROM:<from@example.com>
576RCPT TO:<to@example.com>
577RCPT TO:<author@example.com>
578RCPT TO:<committer@example.com>
579From: Example <from@example.com>
580To: to@example.com
581Cc: A <author@example.com>,
582 C O Mitter <committer@example.com>
583Subject: [PATCH 1/1] Second.
584Date: DATE-STRING
585Message-Id: MESSAGE-ID-STRING
586X-Mailer: X-MAILER-STRING
587
588Result: OK
589EOF
590
591test_expect_success '--suppress-cc=cc' '
592 test_suppression cc
593'
594
595test_confirm () {
596 echo y | \
597 GIT_SEND_EMAIL_NOTTY=1 \
598 git send-email \
599 --from="Example <nobody@example.com>" \
600 --to=nobody@example.com \
601 --smtp-server="$(pwd)/fake.sendmail" \
602 $@ $patches > stdout &&
603 grep "Send this email" stdout
604}
605
606test_expect_success '--confirm=always' '
607 test_confirm --confirm=always --suppress-cc=all
608'
609
610test_expect_success '--confirm=auto' '
611 test_confirm --confirm=auto
612'
613
614test_expect_success '--confirm=cc' '
615 test_confirm --confirm=cc
616'
617
618test_expect_success '--confirm=compose' '
619 test_confirm --confirm=compose --compose
620'
621
622test_expect_success 'confirm by default (due to cc)' '
623 CONFIRM=$(git config --get sendemail.confirm) &&
624 git config --unset sendemail.confirm &&
625 test_confirm
626 ret="$?"
627 git config sendemail.confirm ${CONFIRM:-never}
628 test $ret = "0"
629'
630
631test_expect_success 'confirm by default (due to --compose)' '
632 CONFIRM=$(git config --get sendemail.confirm) &&
633 git config --unset sendemail.confirm &&
634 test_confirm --suppress-cc=all --compose
635 ret="$?"
636 git config sendemail.confirm ${CONFIRM:-never}
637 test $ret = "0"
638'
639
640test_expect_success 'confirm detects EOF (inform assumes y)' '
641 CONFIRM=$(git config --get sendemail.confirm) &&
642 git config --unset sendemail.confirm &&
643 rm -fr outdir &&
644 git format-patch -2 -o outdir &&
645 GIT_SEND_EMAIL_NOTTY=1 \
646 git send-email \
647 --from="Example <nobody@example.com>" \
648 --to=nobody@example.com \
649 --smtp-server="$(pwd)/fake.sendmail" \
650 outdir/*.patch < /dev/null
651 ret="$?"
652 git config sendemail.confirm ${CONFIRM:-never}
653 test $ret = "0"
654'
655
656test_expect_success 'confirm detects EOF (auto causes failure)' '
657 CONFIRM=$(git config --get sendemail.confirm) &&
658 git config sendemail.confirm auto &&
659 GIT_SEND_EMAIL_NOTTY=1 &&
660 export GIT_SEND_EMAIL_NOTTY &&
661 test_must_fail git send-email \
662 --from="Example <nobody@example.com>" \
663 --to=nobody@example.com \
664 --smtp-server="$(pwd)/fake.sendmail" \
665 $patches < /dev/null
666 ret="$?"
667 git config sendemail.confirm ${CONFIRM:-never}
668 test $ret = "0"
669'
670
671test_expect_success 'confirm doesnt loop forever' '
672 CONFIRM=$(git config --get sendemail.confirm) &&
673 git config sendemail.confirm auto &&
674 GIT_SEND_EMAIL_NOTTY=1 &&
675 export GIT_SEND_EMAIL_NOTTY &&
676 yes "bogus" | test_must_fail git send-email \
677 --from="Example <nobody@example.com>" \
678 --to=nobody@example.com \
679 --smtp-server="$(pwd)/fake.sendmail" \
680 $patches
681 ret="$?"
682 git config sendemail.confirm ${CONFIRM:-never}
683 test $ret = "0"
684'
685
686test_expect_success 'utf8 Cc is rfc2047 encoded' '
687 clean_fake_sendmail &&
688 rm -fr outdir &&
689 git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
690 git send-email \
691 --from="Example <nobody@example.com>" \
692 --to=nobody@example.com \
693 --smtp-server="$(pwd)/fake.sendmail" \
694 outdir/*.patch &&
695 grep "^ " msgtxt1 |
696 grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
697'
698
699test_expect_success '--compose adds MIME for utf8 body' '
700 clean_fake_sendmail &&
701 (echo "#!$SHELL_PATH" &&
702 echo "echo utf8 body: àéìöú >>\"\$1\""
703 ) >fake-editor-utf8 &&
704 chmod +x fake-editor-utf8 &&
705 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
706 git send-email \
707 --compose --subject foo \
708 --from="Example <nobody@example.com>" \
709 --to=nobody@example.com \
710 --smtp-server="$(pwd)/fake.sendmail" \
711 $patches &&
712 grep "^utf8 body" msgtxt1 &&
713 grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
714'
715
716test_expect_success '--compose respects user mime type' '
717 clean_fake_sendmail &&
718 (echo "#!$SHELL_PATH" &&
719 echo "(echo MIME-Version: 1.0"
720 echo " echo Content-Type: text/plain\\; charset=iso-8859-1"
721 echo " echo Content-Transfer-Encoding: 8bit"
722 echo " echo Subject: foo"
723 echo " echo "
724 echo " echo utf8 body: àéìöú) >\"\$1\""
725 ) >fake-editor-utf8-mime &&
726 chmod +x fake-editor-utf8-mime &&
727 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
728 git send-email \
729 --compose --subject foo \
730 --from="Example <nobody@example.com>" \
731 --to=nobody@example.com \
732 --smtp-server="$(pwd)/fake.sendmail" \
733 $patches &&
734 grep "^utf8 body" msgtxt1 &&
735 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
736 ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
737'
738
739test_expect_success '--compose adds MIME for utf8 subject' '
740 clean_fake_sendmail &&
741 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
742 git send-email \
743 --compose --subject utf8-sübjëct \
744 --from="Example <nobody@example.com>" \
745 --to=nobody@example.com \
746 --smtp-server="$(pwd)/fake.sendmail" \
747 $patches &&
748 grep "^fake edit" msgtxt1 &&
749 grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
750'
751
752test_expect_success 'detects ambiguous reference/file conflict' '
753 echo master > master &&
754 git add master &&
755 git commit -m"add master" &&
756 test_must_fail git send-email --dry-run master 2>errors &&
757 grep disambiguate errors
758'
759
760test_expect_success 'feed two files' '
761 rm -fr outdir &&
762 git format-patch -2 -o outdir &&
763 git send-email \
764 --dry-run \
765 --from="Example <nobody@example.com>" \
766 --to=nobody@example.com \
767 outdir/000?-*.patch 2>errors >out &&
768 grep "^Subject: " out >subjects &&
769 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
770 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"
771'
772
773test_expect_success 'in-reply-to but no threading' '
774 git send-email \
775 --dry-run \
776 --from="Example <nobody@example.com>" \
777 --to=nobody@example.com \
778 --in-reply-to="<in-reply-id@example.com>" \
779 --nothread \
780 $patches |
781 grep "In-Reply-To: <in-reply-id@example.com>"
782'
783
784test_expect_success 'no in-reply-to and no threading' '
785 git send-email \
786 --dry-run \
787 --from="Example <nobody@example.com>" \
788 --to=nobody@example.com \
789 --nothread \
790 $patches $patches >stdout &&
791 ! grep "In-Reply-To: " stdout
792'
793
794test_expect_success 'threading but no chain-reply-to' '
795 git send-email \
796 --dry-run \
797 --from="Example <nobody@example.com>" \
798 --to=nobody@example.com \
799 --thread \
800 --nochain-reply-to \
801 $patches $patches >stdout &&
802 grep "In-Reply-To: " stdout
803'
804
805test_expect_success 'warning with an implicit --chain-reply-to' '
806 git send-email \
807 --dry-run \
808 --from="Example <nobody@example.com>" \
809 --to=nobody@example.com \
810 outdir/000?-*.patch 2>errors >out &&
811 grep "no-chain-reply-to" errors
812'
813
814test_expect_success 'no warning with an explicit --chain-reply-to' '
815 git send-email \
816 --dry-run \
817 --from="Example <nobody@example.com>" \
818 --to=nobody@example.com \
819 --chain-reply-to \
820 outdir/000?-*.patch 2>errors >out &&
821 ! grep "no-chain-reply-to" errors
822'
823
824test_expect_success 'no warning with an explicit --no-chain-reply-to' '
825 git send-email \
826 --dry-run \
827 --from="Example <nobody@example.com>" \
828 --to=nobody@example.com \
829 --nochain-reply-to \
830 outdir/000?-*.patch 2>errors >out &&
831 ! grep "no-chain-reply-to" errors
832'
833
834test_expect_success 'no warning with sendemail.chainreplyto = false' '
835 git config sendemail.chainreplyto false &&
836 git send-email \
837 --dry-run \
838 --from="Example <nobody@example.com>" \
839 --to=nobody@example.com \
840 outdir/000?-*.patch 2>errors >out &&
841 ! grep "no-chain-reply-to" errors
842'
843
844test_expect_success 'no warning with sendemail.chainreplyto = true' '
845 git config sendemail.chainreplyto true &&
846 git send-email \
847 --dry-run \
848 --from="Example <nobody@example.com>" \
849 --to=nobody@example.com \
850 outdir/000?-*.patch 2>errors >out &&
851 ! grep "no-chain-reply-to" errors
852'
853
854test_expect_success 'sendemail.to works' '
855 git config --replace-all sendemail.to "Somebody <somebody@ex.com>" &&
856 git send-email \
857 --dry-run \
858 --from="Example <nobody@example.com>" \
859 $patches $patches >stdout &&
860 grep "To: Somebody <somebody@ex.com>" stdout
861'
862
863test_expect_success '--no-to overrides sendemail.to' '
864 git send-email \
865 --dry-run \
866 --from="Example <nobody@example.com>" \
867 --no-to \
868 --to=nobody@example.com \
869 $patches $patches >stdout &&
870 grep "To: nobody@example.com" stdout &&
871 ! grep "To: Somebody <somebody@ex.com>" stdout
872'
873
874test_expect_success 'sendemail.cc works' '
875 git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" &&
876 git send-email \
877 --dry-run \
878 --from="Example <nobody@example.com>" \
879 --to=nobody@example.com \
880 $patches $patches >stdout &&
881 grep "Cc: Somebody <somebody@ex.com>" stdout
882'
883
884test_expect_success '--no-cc overrides sendemail.cc' '
885 git send-email \
886 --dry-run \
887 --from="Example <nobody@example.com>" \
888 --no-cc \
889 --cc=bodies@example.com \
890 --to=nobody@example.com \
891 $patches $patches >stdout &&
892 grep "Cc: bodies@example.com" stdout &&
893 ! grep "Cc: Somebody <somebody@ex.com>" stdout
894'
895
896test_expect_success 'sendemail.bcc works' '
897 git config --replace-all sendemail.bcc "Other <other@ex.com>" &&
898 git send-email \
899 --dry-run \
900 --from="Example <nobody@example.com>" \
901 --to=nobody@example.com \
902 --smtp-server relay.example.com \
903 $patches $patches >stdout &&
904 grep "RCPT TO:<other@ex.com>" stdout
905'
906
907test_expect_success '--no-bcc overrides sendemail.bcc' '
908 git send-email \
909 --dry-run \
910 --from="Example <nobody@example.com>" \
911 --no-bcc \
912 --bcc=bodies@example.com \
913 --to=nobody@example.com \
914 --smtp-server relay.example.com \
915 $patches $patches >stdout &&
916 grep "RCPT TO:<bodies@example.com>" stdout &&
917 ! grep "RCPT TO:<other@ex.com>" stdout
918'
919
920cat >email-using-8bit <<EOF
921From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
922Message-Id: <bogus-message-id@example.com>
923From: author@example.com
924Date: Sat, 12 Jun 2010 15:53:58 +0200
925Subject: subject goes here
926
927Dieser deutsche Text enthält einen Umlaut!
928EOF
929
930cat >content-type-decl <<EOF
931MIME-Version: 1.0
932Content-Type: text/plain; charset=UTF-8
933Content-Transfer-Encoding: 8bit
934EOF
935
936test_expect_success 'asks about and fixes 8bit encodings' '
937 clean_fake_sendmail &&
938 echo |
939 git send-email --from=author@example.com --to=nobody@example.com \
940 --smtp-server="$(pwd)/fake.sendmail" \
941 email-using-8bit >stdout &&
942 grep "do not declare a Content-Transfer-Encoding" stdout &&
943 grep email-using-8bit stdout &&
944 grep "Which 8bit encoding" stdout &&
945 egrep "Content|MIME" msgtxt1 >actual &&
946 test_cmp actual content-type-decl
947'
948
949test_expect_success 'sendemail.8bitEncoding works' '
950 clean_fake_sendmail &&
951 git config sendemail.assume8bitEncoding UTF-8 &&
952 echo bogus |
953 git send-email --from=author@example.com --to=nobody@example.com \
954 --smtp-server="$(pwd)/fake.sendmail" \
955 email-using-8bit >stdout &&
956 egrep "Content|MIME" msgtxt1 >actual &&
957 test_cmp actual content-type-decl
958'
959
960test_expect_success '--8bit-encoding overrides sendemail.8bitEncoding' '
961 clean_fake_sendmail &&
962 git config sendemail.assume8bitEncoding "bogus too" &&
963 echo bogus |
964 git send-email --from=author@example.com --to=nobody@example.com \
965 --smtp-server="$(pwd)/fake.sendmail" \
966 --8bit-encoding=UTF-8 \
967 email-using-8bit >stdout &&
968 egrep "Content|MIME" msgtxt1 >actual &&
969 test_cmp actual content-type-decl
970'
971
972cat >email-using-8bit <<EOF
973From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
974Message-Id: <bogus-message-id@example.com>
975From: author@example.com
976Date: Sat, 12 Jun 2010 15:53:58 +0200
977Subject: Dieser Betreff enthält auch einen Umlaut!
978
979Nothing to see here.
980EOF
981
982cat >expected <<EOF
983Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
984EOF
985
986test_expect_success '--8bit-encoding also treats subject' '
987 clean_fake_sendmail &&
988 echo bogus |
989 git send-email --from=author@example.com --to=nobody@example.com \
990 --smtp-server="$(pwd)/fake.sendmail" \
991 --8bit-encoding=UTF-8 \
992 email-using-8bit >stdout &&
993 grep "Subject" msgtxt1 >actual &&
994 test_cmp expected actual
995'
996
997test_done