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 'prepare reference tree' '
10 echo "1A quick brown fox jumps over the" >file &&
11 echo "lazy dog" >>file &&
12 git add file &&
13 GIT_AUTHOR_NAME="A" git commit -a -m "Initial."
14'
15
16test_expect_success $PREREQ 'Setup helper tool' '
17 write_script fake.sendmail <<-\EOF &&
18 shift
19 output=1
20 while test -f commandline$output
21 do
22 output=$(($output+1))
23 done
24 for a
25 do
26 echo "!$a!"
27 done >commandline$output
28 cat >"msgtxt$output"
29 EOF
30 git add fake.sendmail &&
31 GIT_AUTHOR_NAME="A" git commit -a -m "Second."
32'
33
34clean_fake_sendmail () {
35 rm -f commandline* msgtxt*
36}
37
38test_expect_success $PREREQ '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 ! 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 if ! test -f no_confirm_okay
60 then
61 say 'confirm test failed; skipping remaining tests to prevent hanging'
62 PREREQ="$PREREQ,CHECK_NO_CONFIRM"
63 fi
64 return 0
65}
66
67test_expect_success $PREREQ 'No confirm with --suppress-cc' '
68 test_no_confirm --suppress-cc=sob &&
69 check_no_confirm
70'
71
72
73test_expect_success $PREREQ 'No confirm with --confirm=never' '
74 test_no_confirm --confirm=never &&
75 check_no_confirm
76'
77
78# leave sendemail.confirm set to never after this so that none of the
79# remaining tests prompt unintentionally.
80test_expect_success $PREREQ 'No confirm with sendemail.confirm=never' '
81 git config sendemail.confirm never &&
82 test_no_confirm --compose --subject=foo &&
83 check_no_confirm
84'
85
86test_expect_success $PREREQ 'Send patches' '
87 git send-email --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
88'
89
90test_expect_success $PREREQ 'setup expect' '
91 cat >expected <<-\EOF
92 !nobody@example.com!
93 !author@example.com!
94 !one@example.com!
95 !two@example.com!
96 EOF
97'
98
99test_expect_success $PREREQ 'Verify commandline' '
100 test_cmp expected commandline1
101'
102
103test_expect_success $PREREQ 'Send patches with --envelope-sender' '
104 clean_fake_sendmail &&
105 git send-email --envelope-sender="Patch Contributor <patch@example.com>" --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
106'
107
108test_expect_success $PREREQ 'setup expect' '
109 cat >expected <<-\EOF
110 !patch@example.com!
111 !-i!
112 !nobody@example.com!
113 !author@example.com!
114 !one@example.com!
115 !two@example.com!
116 EOF
117'
118
119test_expect_success $PREREQ 'Verify commandline' '
120 test_cmp expected commandline1
121'
122
123test_expect_success $PREREQ 'Send patches with --envelope-sender=auto' '
124 clean_fake_sendmail &&
125 git send-email --envelope-sender=auto --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
126'
127
128test_expect_success $PREREQ 'setup expect' '
129 cat >expected <<-\EOF
130 !nobody@example.com!
131 !-i!
132 !nobody@example.com!
133 !author@example.com!
134 !one@example.com!
135 !two@example.com!
136 EOF
137'
138
139test_expect_success $PREREQ 'Verify commandline' '
140 test_cmp expected commandline1
141'
142
143test_expect_success $PREREQ 'setup expect for cc trailer' "
144cat >expected-cc <<\EOF
145!recipient@example.com!
146!author@example.com!
147!one@example.com!
148!two@example.com!
149!three@example.com!
150!four@example.com!
151!five@example.com!
152!six@example.com!
153EOF
154"
155
156test_expect_success $PREREQ 'cc trailer with various syntax' '
157 test_commit cc-trailer &&
158 test_when_finished "git reset --hard HEAD^" &&
159 git commit --amend -F - <<-EOF &&
160 Test Cc: trailers.
161
162 Cc: one@example.com
163 Cc: <two@example.com> # trailing comments are ignored
164 Cc: <three@example.com>, <not.four@example.com> one address per line
165 Cc: "Some # Body" <four@example.com> [ <also.a.comment> ]
166 Cc: five@example.com # not.six@example.com
167 Cc: six@example.com, not.seven@example.com
168 EOF
169 clean_fake_sendmail &&
170 git send-email -1 --to=recipient@example.com \
171 --smtp-server="$(pwd)/fake.sendmail" &&
172 test_cmp expected-cc commandline1
173'
174
175test_expect_success $PREREQ 'setup fake get_maintainer.pl script for cc trailer' "
176 write_script expected-cc-script.sh <<-EOF
177 echo 'One Person <one@example.com> (supporter:THIS (FOO/bar))'
178 echo 'Two Person <two@example.com> (maintainer:THIS THING)'
179 echo 'Third List <three@example.com> (moderated list:THIS THING (FOO/bar))'
180 echo '<four@example.com> (moderated list:FOR THING)'
181 echo 'five@example.com (open list:FOR THING (FOO/bar))'
182 echo 'six@example.com (open list)'
183 EOF
184"
185
186test_expect_success $PREREQ 'cc trailer with get_maintainer.pl output' '
187 clean_fake_sendmail &&
188 git send-email -1 --to=recipient@example.com \
189 --cc-cmd=./expected-cc-script.sh \
190 --smtp-server="$(pwd)/fake.sendmail" &&
191 test_cmp expected-cc commandline1
192'
193
194test_expect_success $PREREQ 'setup expect' "
195cat >expected-show-all-headers <<\EOF
1960001-Second.patch
197(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
198(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
199(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
200Dry-OK. Log says:
201Server: relay.example.com
202MAIL FROM:<from@example.com>
203RCPT TO:<to@example.com>
204RCPT TO:<cc@example.com>
205RCPT TO:<author@example.com>
206RCPT TO:<one@example.com>
207RCPT TO:<two@example.com>
208RCPT TO:<bcc@example.com>
209From: Example <from@example.com>
210To: to@example.com
211Cc: cc@example.com,
212 A <author@example.com>,
213 One <one@example.com>,
214 two@example.com
215Subject: [PATCH 1/1] Second.
216Date: DATE-STRING
217Message-Id: MESSAGE-ID-STRING
218X-Mailer: X-MAILER-STRING
219In-Reply-To: <unique-message-id@example.com>
220References: <unique-message-id@example.com>
221
222Result: OK
223EOF
224"
225
226test_suppress_self () {
227 test_commit $3 &&
228 test_when_finished "git reset --hard HEAD^" &&
229
230 write_script cccmd-sed <<-EOF &&
231 sed -n -e s/^cccmd--//p "\$1"
232 EOF
233
234 git commit --amend --author="$1 <$2>" -F - &&
235 clean_fake_sendmail &&
236 git format-patch --stdout -1 >"suppress-self-$3.patch" &&
237
238 git send-email --from="$1 <$2>" \
239 --to=nobody@example.com \
240 --cc-cmd=./cccmd-sed \
241 --suppress-cc=self \
242 --smtp-server="$(pwd)/fake.sendmail" \
243 suppress-self-$3.patch &&
244
245 mv msgtxt1 msgtxt1-$3 &&
246 sed -e '/^$/q' msgtxt1-$3 >"msghdr1-$3" &&
247 >"expected-no-cc-$3" &&
248
249 (grep '^Cc:' msghdr1-$3 >"actual-no-cc-$3";
250 test_cmp expected-no-cc-$3 actual-no-cc-$3)
251}
252
253test_suppress_self_unquoted () {
254 test_suppress_self "$1" "$2" "unquoted-$3" <<-EOF
255 test suppress-cc.self unquoted-$3 with name $1 email $2
256
257 unquoted-$3
258
259 cccmd--$1 <$2>
260
261 Cc: $1 <$2>
262 Signed-off-by: $1 <$2>
263 EOF
264}
265
266test_suppress_self_quoted () {
267 test_suppress_self "$1" "$2" "quoted-$3" <<-EOF
268 test suppress-cc.self quoted-$3 with name $1 email $2
269
270 quoted-$3
271
272 cccmd--"$1" <$2>
273
274 Cc: $1 <$2>
275 Cc: "$1" <$2>
276 Signed-off-by: $1 <$2>
277 Signed-off-by: "$1" <$2>
278 EOF
279}
280
281test_expect_success $PREREQ 'self name is suppressed' "
282 test_suppress_self_unquoted 'A U Thor' 'author@example.com' \
283 'self_name_suppressed'
284"
285
286test_expect_success $PREREQ 'self name with dot is suppressed' "
287 test_suppress_self_quoted 'A U. Thor' 'author@example.com' \
288 'self_name_dot_suppressed'
289"
290
291test_expect_success $PREREQ 'non-ascii self name is suppressed' "
292 test_suppress_self_quoted 'Füñný Nâmé' 'odd_?=mail@example.com' \
293 'non_ascii_self_suppressed'
294"
295
296# This name is long enough to force format-patch to split it into multiple
297# encoded-words, assuming it uses UTF-8 with the "Q" encoding.
298test_expect_success $PREREQ 'long non-ascii self name is suppressed' "
299 test_suppress_self_quoted 'Ƒüñníęř €. Nâṁé' 'odd_?=mail@example.com' \
300 'long_non_ascii_self_suppressed'
301"
302
303test_expect_success $PREREQ 'sanitized self name is suppressed' "
304 test_suppress_self_unquoted '\"A U. Thor\"' 'author@example.com' \
305 'self_name_sanitized_suppressed'
306"
307
308test_expect_success $PREREQ 'Show all headers' '
309 git send-email \
310 --dry-run \
311 --suppress-cc=sob \
312 --from="Example <from@example.com>" \
313 --to=to@example.com \
314 --cc=cc@example.com \
315 --bcc=bcc@example.com \
316 --in-reply-to="<unique-message-id@example.com>" \
317 --smtp-server relay.example.com \
318 $patches |
319 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
320 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
321 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
322 >actual-show-all-headers &&
323 test_cmp expected-show-all-headers actual-show-all-headers
324'
325
326test_expect_success $PREREQ 'Prompting works' '
327 clean_fake_sendmail &&
328 (echo "to@example.com"
329 echo ""
330 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
331 --smtp-server="$(pwd)/fake.sendmail" \
332 $patches \
333 2>errors &&
334 grep "^From: A U Thor <author@example.com>\$" msgtxt1 &&
335 grep "^To: to@example.com\$" msgtxt1
336'
337
338test_expect_success $PREREQ,AUTOIDENT 'implicit ident is allowed' '
339 clean_fake_sendmail &&
340 (sane_unset GIT_AUTHOR_NAME &&
341 sane_unset GIT_AUTHOR_EMAIL &&
342 sane_unset GIT_COMMITTER_NAME &&
343 sane_unset GIT_COMMITTER_EMAIL &&
344 GIT_SEND_EMAIL_NOTTY=1 git send-email \
345 --smtp-server="$(pwd)/fake.sendmail" \
346 --to=to@example.com \
347 $patches </dev/null 2>errors
348 )
349'
350
351test_expect_success $PREREQ,!AUTOIDENT 'broken implicit ident aborts send-email' '
352 clean_fake_sendmail &&
353 (sane_unset GIT_AUTHOR_NAME &&
354 sane_unset GIT_AUTHOR_EMAIL &&
355 sane_unset GIT_COMMITTER_NAME &&
356 sane_unset GIT_COMMITTER_EMAIL &&
357 GIT_SEND_EMAIL_NOTTY=1 && export GIT_SEND_EMAIL_NOTTY &&
358 test_must_fail git send-email \
359 --smtp-server="$(pwd)/fake.sendmail" \
360 --to=to@example.com \
361 $patches </dev/null 2>errors &&
362 test_i18ngrep "tell me who you are" errors
363 )
364'
365
366test_expect_success $PREREQ 'setup tocmd and cccmd scripts' '
367 write_script tocmd-sed <<-\EOF &&
368 sed -n -e "s/^tocmd--//p" "$1"
369 EOF
370 write_script cccmd-sed <<-\EOF
371 sed -n -e "s/^cccmd--//p" "$1"
372 EOF
373'
374
375test_expect_success $PREREQ 'tocmd works' '
376 clean_fake_sendmail &&
377 cp $patches tocmd.patch &&
378 echo tocmd--tocmd@example.com >>tocmd.patch &&
379 git send-email \
380 --from="Example <nobody@example.com>" \
381 --to-cmd=./tocmd-sed \
382 --smtp-server="$(pwd)/fake.sendmail" \
383 tocmd.patch \
384 &&
385 grep "^To: tocmd@example.com" msgtxt1
386'
387
388test_expect_success $PREREQ 'cccmd works' '
389 clean_fake_sendmail &&
390 cp $patches cccmd.patch &&
391 echo "cccmd-- cccmd@example.com" >>cccmd.patch &&
392 git send-email \
393 --from="Example <nobody@example.com>" \
394 --to=nobody@example.com \
395 --cc-cmd=./cccmd-sed \
396 --smtp-server="$(pwd)/fake.sendmail" \
397 cccmd.patch \
398 &&
399 grep "^ cccmd@example.com" msgtxt1
400'
401
402test_expect_success $PREREQ 'reject long lines' '
403 z8=zzzzzzzz &&
404 z64=$z8$z8$z8$z8$z8$z8$z8$z8 &&
405 z512=$z64$z64$z64$z64$z64$z64$z64$z64 &&
406 clean_fake_sendmail &&
407 cp $patches longline.patch &&
408 echo $z512$z512 >>longline.patch &&
409 test_must_fail git send-email \
410 --from="Example <nobody@example.com>" \
411 --to=nobody@example.com \
412 --smtp-server="$(pwd)/fake.sendmail" \
413 $patches longline.patch \
414 2>errors &&
415 grep longline.patch errors
416'
417
418test_expect_success $PREREQ 'no patch was sent' '
419 ! test -e commandline1
420'
421
422test_expect_success $PREREQ 'Author From: in message body' '
423 clean_fake_sendmail &&
424 git send-email \
425 --from="Example <nobody@example.com>" \
426 --to=nobody@example.com \
427 --smtp-server="$(pwd)/fake.sendmail" \
428 $patches &&
429 sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
430 grep "From: A <author@example.com>" msgbody1
431'
432
433test_expect_success $PREREQ 'Author From: not in message body' '
434 clean_fake_sendmail &&
435 git send-email \
436 --from="A <author@example.com>" \
437 --to=nobody@example.com \
438 --smtp-server="$(pwd)/fake.sendmail" \
439 $patches &&
440 sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
441 ! grep "From: A <author@example.com>" msgbody1
442'
443
444test_expect_success $PREREQ 'allow long lines with --no-validate' '
445 git send-email \
446 --from="Example <nobody@example.com>" \
447 --to=nobody@example.com \
448 --smtp-server="$(pwd)/fake.sendmail" \
449 --no-validate \
450 $patches longline.patch \
451 2>errors
452'
453
454test_expect_success $PREREQ 'Invalid In-Reply-To' '
455 clean_fake_sendmail &&
456 git send-email \
457 --from="Example <nobody@example.com>" \
458 --to=nobody@example.com \
459 --in-reply-to=" " \
460 --smtp-server="$(pwd)/fake.sendmail" \
461 $patches \
462 2>errors &&
463 ! grep "^In-Reply-To: < *>" msgtxt1
464'
465
466test_expect_success $PREREQ 'Valid In-Reply-To when prompting' '
467 clean_fake_sendmail &&
468 (echo "From Example <from@example.com>"
469 echo "To Example <to@example.com>"
470 echo ""
471 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
472 --smtp-server="$(pwd)/fake.sendmail" \
473 $patches 2>errors &&
474 ! grep "^In-Reply-To: < *>" msgtxt1
475'
476
477test_expect_success $PREREQ 'In-Reply-To without --chain-reply-to' '
478 clean_fake_sendmail &&
479 echo "<unique-message-id@example.com>" >expect &&
480 git send-email \
481 --from="Example <nobody@example.com>" \
482 --to=nobody@example.com \
483 --no-chain-reply-to \
484 --in-reply-to="$(cat expect)" \
485 --smtp-server="$(pwd)/fake.sendmail" \
486 $patches $patches $patches \
487 2>errors &&
488 # The first message is a reply to --in-reply-to
489 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
490 test_cmp expect actual &&
491 # Second and subsequent messages are replies to the first one
492 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
493 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
494 test_cmp expect actual &&
495 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
496 test_cmp expect actual
497'
498
499test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' '
500 clean_fake_sendmail &&
501 echo "<unique-message-id@example.com>" >expect &&
502 git send-email \
503 --from="Example <nobody@example.com>" \
504 --to=nobody@example.com \
505 --chain-reply-to \
506 --in-reply-to="$(cat expect)" \
507 --smtp-server="$(pwd)/fake.sendmail" \
508 $patches $patches $patches \
509 2>errors &&
510 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
511 test_cmp expect actual &&
512 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
513 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
514 test_cmp expect actual &&
515 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt2 >expect &&
516 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
517 test_cmp expect actual
518'
519
520test_expect_success $PREREQ 'setup fake editor' '
521 write_script fake-editor <<-\EOF
522 echo fake edit >>"$1"
523 EOF
524'
525
526test_set_editor "$(pwd)/fake-editor"
527
528test_expect_success $PREREQ '--compose works' '
529 clean_fake_sendmail &&
530 git send-email \
531 --compose --subject foo \
532 --from="Example <nobody@example.com>" \
533 --to=nobody@example.com \
534 --smtp-server="$(pwd)/fake.sendmail" \
535 $patches \
536 2>errors
537'
538
539test_expect_success $PREREQ 'first message is compose text' '
540 grep "^fake edit" msgtxt1
541'
542
543test_expect_success $PREREQ 'second message is patch' '
544 grep "Subject:.*Second" msgtxt2
545'
546
547test_expect_success $PREREQ 'setup expect' "
548cat >expected-suppress-sob <<\EOF
5490001-Second.patch
550(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
551(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
552(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
553Dry-OK. Log says:
554Server: relay.example.com
555MAIL FROM:<from@example.com>
556RCPT TO:<to@example.com>
557RCPT TO:<cc@example.com>
558RCPT TO:<author@example.com>
559RCPT TO:<one@example.com>
560RCPT TO:<two@example.com>
561From: Example <from@example.com>
562To: to@example.com
563Cc: cc@example.com,
564 A <author@example.com>,
565 One <one@example.com>,
566 two@example.com
567Subject: [PATCH 1/1] Second.
568Date: DATE-STRING
569Message-Id: MESSAGE-ID-STRING
570X-Mailer: X-MAILER-STRING
571
572Result: OK
573EOF
574"
575
576replace_variable_fields () {
577 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
578 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
579 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/"
580}
581
582test_suppression () {
583 git send-email \
584 --dry-run \
585 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
586 --from="Example <from@example.com>" \
587 --to=to@example.com \
588 --smtp-server relay.example.com \
589 $patches | replace_variable_fields \
590 >actual-suppress-$1${2+"-$2"} &&
591 test_cmp expected-suppress-$1${2+"-$2"} actual-suppress-$1${2+"-$2"}
592}
593
594test_expect_success $PREREQ 'sendemail.cc set' '
595 git config sendemail.cc cc@example.com &&
596 test_suppression sob
597'
598
599test_expect_success $PREREQ 'setup expect' "
600cat >expected-suppress-sob <<\EOF
6010001-Second.patch
602(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
603(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
604(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
605Dry-OK. Log says:
606Server: relay.example.com
607MAIL FROM:<from@example.com>
608RCPT TO:<to@example.com>
609RCPT TO:<author@example.com>
610RCPT TO:<one@example.com>
611RCPT TO:<two@example.com>
612From: Example <from@example.com>
613To: to@example.com
614Cc: A <author@example.com>,
615 One <one@example.com>,
616 two@example.com
617Subject: [PATCH 1/1] Second.
618Date: DATE-STRING
619Message-Id: MESSAGE-ID-STRING
620X-Mailer: X-MAILER-STRING
621
622Result: OK
623EOF
624"
625
626test_expect_success $PREREQ 'sendemail.cc unset' '
627 git config --unset sendemail.cc &&
628 test_suppression sob
629'
630
631test_expect_success $PREREQ 'setup expect' "
632cat >expected-suppress-cccmd <<\EOF
6330001-Second.patch
634(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
635(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
636(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
637(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
638Dry-OK. Log says:
639Server: relay.example.com
640MAIL FROM:<from@example.com>
641RCPT TO:<to@example.com>
642RCPT TO:<author@example.com>
643RCPT TO:<one@example.com>
644RCPT TO:<two@example.com>
645RCPT TO:<committer@example.com>
646From: Example <from@example.com>
647To: to@example.com
648Cc: A <author@example.com>,
649 One <one@example.com>,
650 two@example.com,
651 C O Mitter <committer@example.com>
652Subject: [PATCH 1/1] Second.
653Date: DATE-STRING
654Message-Id: MESSAGE-ID-STRING
655X-Mailer: X-MAILER-STRING
656
657Result: OK
658EOF
659"
660
661test_expect_success $PREREQ 'sendemail.cccmd' '
662 write_script cccmd <<-\EOF &&
663 echo cc-cmd@example.com
664 EOF
665 git config sendemail.cccmd ./cccmd &&
666 test_suppression cccmd
667'
668
669test_expect_success $PREREQ 'setup expect' '
670cat >expected-suppress-all <<\EOF
6710001-Second.patch
672Dry-OK. Log says:
673Server: relay.example.com
674MAIL FROM:<from@example.com>
675RCPT TO:<to@example.com>
676From: Example <from@example.com>
677To: to@example.com
678Subject: [PATCH 1/1] Second.
679Date: DATE-STRING
680Message-Id: MESSAGE-ID-STRING
681X-Mailer: X-MAILER-STRING
682
683Result: OK
684EOF
685'
686
687test_expect_success $PREREQ '--suppress-cc=all' '
688 test_suppression all
689'
690
691test_expect_success $PREREQ 'setup expect' "
692cat >expected-suppress-body <<\EOF
6930001-Second.patch
694(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
695(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
696(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
697(cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
698Dry-OK. Log says:
699Server: relay.example.com
700MAIL FROM:<from@example.com>
701RCPT TO:<to@example.com>
702RCPT TO:<author@example.com>
703RCPT TO:<one@example.com>
704RCPT TO:<two@example.com>
705RCPT TO:<cc-cmd@example.com>
706From: Example <from@example.com>
707To: to@example.com
708Cc: A <author@example.com>,
709 One <one@example.com>,
710 two@example.com,
711 cc-cmd@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=body' '
722 test_suppression body
723'
724
725test_expect_success $PREREQ 'setup expect' "
726cat >expected-suppress-body-cccmd <<\EOF
7270001-Second.patch
728(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
729(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
730(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
731Dry-OK. Log says:
732Server: relay.example.com
733MAIL FROM:<from@example.com>
734RCPT TO:<to@example.com>
735RCPT TO:<author@example.com>
736RCPT TO:<one@example.com>
737RCPT TO:<two@example.com>
738From: Example <from@example.com>
739To: to@example.com
740Cc: A <author@example.com>,
741 One <one@example.com>,
742 two@example.com
743Subject: [PATCH 1/1] Second.
744Date: DATE-STRING
745Message-Id: MESSAGE-ID-STRING
746X-Mailer: X-MAILER-STRING
747
748Result: OK
749EOF
750"
751
752test_expect_success $PREREQ '--suppress-cc=body --suppress-cc=cccmd' '
753 test_suppression body cccmd
754'
755
756test_expect_success $PREREQ 'setup expect' "
757cat >expected-suppress-sob <<\EOF
7580001-Second.patch
759(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
760(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
761(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
762Dry-OK. Log says:
763Server: relay.example.com
764MAIL FROM:<from@example.com>
765RCPT TO:<to@example.com>
766RCPT TO:<author@example.com>
767RCPT TO:<one@example.com>
768RCPT TO:<two@example.com>
769From: Example <from@example.com>
770To: to@example.com
771Cc: A <author@example.com>,
772 One <one@example.com>,
773 two@example.com
774Subject: [PATCH 1/1] Second.
775Date: DATE-STRING
776Message-Id: MESSAGE-ID-STRING
777X-Mailer: X-MAILER-STRING
778
779Result: OK
780EOF
781"
782
783test_expect_success $PREREQ '--suppress-cc=sob' '
784 test_might_fail git config --unset sendemail.cccmd &&
785 test_suppression sob
786'
787
788test_expect_success $PREREQ 'setup expect' "
789cat >expected-suppress-bodycc <<\EOF
7900001-Second.patch
791(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
792(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
793(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
794(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
795Dry-OK. Log says:
796Server: relay.example.com
797MAIL FROM:<from@example.com>
798RCPT TO:<to@example.com>
799RCPT TO:<author@example.com>
800RCPT TO:<one@example.com>
801RCPT TO:<two@example.com>
802RCPT TO:<committer@example.com>
803From: Example <from@example.com>
804To: to@example.com
805Cc: A <author@example.com>,
806 One <one@example.com>,
807 two@example.com,
808 C O Mitter <committer@example.com>
809Subject: [PATCH 1/1] Second.
810Date: DATE-STRING
811Message-Id: MESSAGE-ID-STRING
812X-Mailer: X-MAILER-STRING
813
814Result: OK
815EOF
816"
817
818test_expect_success $PREREQ '--suppress-cc=bodycc' '
819 test_suppression bodycc
820'
821
822test_expect_success $PREREQ 'setup expect' "
823cat >expected-suppress-cc <<\EOF
8240001-Second.patch
825(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
826(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
827Dry-OK. Log says:
828Server: relay.example.com
829MAIL FROM:<from@example.com>
830RCPT TO:<to@example.com>
831RCPT TO:<author@example.com>
832RCPT TO:<committer@example.com>
833From: Example <from@example.com>
834To: to@example.com
835Cc: A <author@example.com>,
836 C O Mitter <committer@example.com>
837Subject: [PATCH 1/1] Second.
838Date: DATE-STRING
839Message-Id: MESSAGE-ID-STRING
840X-Mailer: X-MAILER-STRING
841
842Result: OK
843EOF
844"
845
846test_expect_success $PREREQ '--suppress-cc=cc' '
847 test_suppression cc
848'
849
850test_confirm () {
851 echo y | \
852 GIT_SEND_EMAIL_NOTTY=1 \
853 git send-email \
854 --from="Example <nobody@example.com>" \
855 --to=nobody@example.com \
856 --smtp-server="$(pwd)/fake.sendmail" \
857 $@ $patches >stdout &&
858 grep "Send this email" stdout
859}
860
861test_expect_success $PREREQ '--confirm=always' '
862 test_confirm --confirm=always --suppress-cc=all
863'
864
865test_expect_success $PREREQ '--confirm=auto' '
866 test_confirm --confirm=auto
867'
868
869test_expect_success $PREREQ '--confirm=cc' '
870 test_confirm --confirm=cc
871'
872
873test_expect_success $PREREQ '--confirm=compose' '
874 test_confirm --confirm=compose --compose
875'
876
877test_expect_success $PREREQ 'confirm by default (due to cc)' '
878 test_when_finished git config sendemail.confirm never &&
879 git config --unset sendemail.confirm &&
880 test_confirm
881'
882
883test_expect_success $PREREQ 'confirm by default (due to --compose)' '
884 test_when_finished git config sendemail.confirm never &&
885 git config --unset sendemail.confirm &&
886 test_confirm --suppress-cc=all --compose
887'
888
889test_expect_success $PREREQ 'confirm detects EOF (inform assumes y)' '
890 test_when_finished git config sendemail.confirm never &&
891 git config --unset sendemail.confirm &&
892 rm -fr outdir &&
893 git format-patch -2 -o outdir &&
894 GIT_SEND_EMAIL_NOTTY=1 \
895 git send-email \
896 --from="Example <nobody@example.com>" \
897 --to=nobody@example.com \
898 --smtp-server="$(pwd)/fake.sendmail" \
899 outdir/*.patch </dev/null
900'
901
902test_expect_success $PREREQ 'confirm detects EOF (auto causes failure)' '
903 test_when_finished git config sendemail.confirm never &&
904 git config sendemail.confirm auto &&
905 GIT_SEND_EMAIL_NOTTY=1 &&
906 export GIT_SEND_EMAIL_NOTTY &&
907 test_must_fail git send-email \
908 --from="Example <nobody@example.com>" \
909 --to=nobody@example.com \
910 --smtp-server="$(pwd)/fake.sendmail" \
911 $patches </dev/null
912'
913
914test_expect_success $PREREQ 'confirm does not loop forever' '
915 test_when_finished git config sendemail.confirm never &&
916 git config sendemail.confirm auto &&
917 GIT_SEND_EMAIL_NOTTY=1 &&
918 export GIT_SEND_EMAIL_NOTTY &&
919 yes "bogus" | test_must_fail git send-email \
920 --from="Example <nobody@example.com>" \
921 --to=nobody@example.com \
922 --smtp-server="$(pwd)/fake.sendmail" \
923 $patches
924'
925
926test_expect_success $PREREQ 'utf8 Cc is rfc2047 encoded' '
927 clean_fake_sendmail &&
928 rm -fr outdir &&
929 git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
930 git send-email \
931 --from="Example <nobody@example.com>" \
932 --to=nobody@example.com \
933 --smtp-server="$(pwd)/fake.sendmail" \
934 outdir/*.patch &&
935 grep "^ " msgtxt1 |
936 grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
937'
938
939test_expect_success $PREREQ '--compose adds MIME for utf8 body' '
940 clean_fake_sendmail &&
941 write_script fake-editor-utf8 <<-\EOF &&
942 echo "utf8 body: àéìöú" >>"$1"
943 EOF
944 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
945 git send-email \
946 --compose --subject foo \
947 --from="Example <nobody@example.com>" \
948 --to=nobody@example.com \
949 --smtp-server="$(pwd)/fake.sendmail" \
950 $patches &&
951 grep "^utf8 body" msgtxt1 &&
952 grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
953'
954
955test_expect_success $PREREQ '--compose respects user mime type' '
956 clean_fake_sendmail &&
957 write_script fake-editor-utf8-mime <<-\EOF &&
958 cat >"$1" <<-\EOM
959 MIME-Version: 1.0
960 Content-Type: text/plain; charset=iso-8859-1
961 Content-Transfer-Encoding: 8bit
962 Subject: foo
963
964 utf8 body: àéìöú
965 EOM
966 EOF
967 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
968 git send-email \
969 --compose --subject foo \
970 --from="Example <nobody@example.com>" \
971 --to=nobody@example.com \
972 --smtp-server="$(pwd)/fake.sendmail" \
973 $patches &&
974 grep "^utf8 body" msgtxt1 &&
975 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
976 ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
977'
978
979test_expect_success $PREREQ '--compose adds MIME for utf8 subject' '
980 clean_fake_sendmail &&
981 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
982 git send-email \
983 --compose --subject utf8-sübjëct \
984 --from="Example <nobody@example.com>" \
985 --to=nobody@example.com \
986 --smtp-server="$(pwd)/fake.sendmail" \
987 $patches &&
988 grep "^fake edit" msgtxt1 &&
989 grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
990'
991
992test_expect_success $PREREQ 'utf8 author is correctly passed on' '
993 clean_fake_sendmail &&
994 test_commit weird_author &&
995 test_when_finished "git reset --hard HEAD^" &&
996 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
997 git format-patch --stdout -1 >funny_name.patch &&
998 git send-email --from="Example <nobody@example.com>" \
999 --to=nobody@example.com \
1000 --smtp-server="$(pwd)/fake.sendmail" \
1001 funny_name.patch &&
1002 grep "^From: Füñný Nâmé <odd_?=mail@example.com>" msgtxt1
1003'
1004
1005test_expect_success $PREREQ 'utf8 sender is not duplicated' '
1006 clean_fake_sendmail &&
1007 test_commit weird_sender &&
1008 test_when_finished "git reset --hard HEAD^" &&
1009 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
1010 git format-patch --stdout -1 >funny_name.patch &&
1011 git send-email --from="Füñný Nâmé <odd_?=mail@example.com>" \
1012 --to=nobody@example.com \
1013 --smtp-server="$(pwd)/fake.sendmail" \
1014 funny_name.patch &&
1015 grep "^From: " msgtxt1 >msgfrom &&
1016 test_line_count = 1 msgfrom
1017'
1018
1019test_expect_success $PREREQ 'sendemail.composeencoding works' '
1020 clean_fake_sendmail &&
1021 git config sendemail.composeencoding iso-8859-1 &&
1022 write_script fake-editor-utf8 <<-\EOF &&
1023 echo "utf8 body: àéìöú" >>"$1"
1024 EOF
1025 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1026 git send-email \
1027 --compose --subject foo \
1028 --from="Example <nobody@example.com>" \
1029 --to=nobody@example.com \
1030 --smtp-server="$(pwd)/fake.sendmail" \
1031 $patches &&
1032 grep "^utf8 body" msgtxt1 &&
1033 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1034'
1035
1036test_expect_success $PREREQ '--compose-encoding works' '
1037 clean_fake_sendmail &&
1038 write_script fake-editor-utf8 <<-\EOF &&
1039 echo "utf8 body: àéìöú" >>"$1"
1040 EOF
1041 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1042 git send-email \
1043 --compose-encoding iso-8859-1 \
1044 --compose --subject foo \
1045 --from="Example <nobody@example.com>" \
1046 --to=nobody@example.com \
1047 --smtp-server="$(pwd)/fake.sendmail" \
1048 $patches &&
1049 grep "^utf8 body" msgtxt1 &&
1050 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1051'
1052
1053test_expect_success $PREREQ '--compose-encoding overrides sendemail.composeencoding' '
1054 clean_fake_sendmail &&
1055 git config sendemail.composeencoding iso-8859-1 &&
1056 write_script fake-editor-utf8 <<-\EOF &&
1057 echo "utf8 body: àéìöú" >>"$1"
1058 EOF
1059 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1060 git send-email \
1061 --compose-encoding iso-8859-2 \
1062 --compose --subject foo \
1063 --from="Example <nobody@example.com>" \
1064 --to=nobody@example.com \
1065 --smtp-server="$(pwd)/fake.sendmail" \
1066 $patches &&
1067 grep "^utf8 body" msgtxt1 &&
1068 grep "^Content-Type: text/plain; charset=iso-8859-2" msgtxt1
1069'
1070
1071test_expect_success $PREREQ '--compose-encoding adds correct MIME for subject' '
1072 clean_fake_sendmail &&
1073 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
1074 git send-email \
1075 --compose-encoding iso-8859-2 \
1076 --compose --subject utf8-sübjëct \
1077 --from="Example <nobody@example.com>" \
1078 --to=nobody@example.com \
1079 --smtp-server="$(pwd)/fake.sendmail" \
1080 $patches &&
1081 grep "^fake edit" msgtxt1 &&
1082 grep "^Subject: =?iso-8859-2?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
1083'
1084
1085test_expect_success $PREREQ 'detects ambiguous reference/file conflict' '
1086 echo master >master &&
1087 git add master &&
1088 git commit -m"add master" &&
1089 test_must_fail git send-email --dry-run master 2>errors &&
1090 grep disambiguate errors
1091'
1092
1093test_expect_success $PREREQ 'feed two files' '
1094 rm -fr outdir &&
1095 git format-patch -2 -o outdir &&
1096 git send-email \
1097 --dry-run \
1098 --from="Example <nobody@example.com>" \
1099 --to=nobody@example.com \
1100 outdir/000?-*.patch 2>errors >out &&
1101 grep "^Subject: " out >subjects &&
1102 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
1103 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"
1104'
1105
1106test_expect_success $PREREQ 'in-reply-to but no threading' '
1107 git send-email \
1108 --dry-run \
1109 --from="Example <nobody@example.com>" \
1110 --to=nobody@example.com \
1111 --in-reply-to="<in-reply-id@example.com>" \
1112 --no-thread \
1113 $patches |
1114 grep "In-Reply-To: <in-reply-id@example.com>"
1115'
1116
1117test_expect_success $PREREQ 'no in-reply-to and no threading' '
1118 git send-email \
1119 --dry-run \
1120 --from="Example <nobody@example.com>" \
1121 --to=nobody@example.com \
1122 --no-thread \
1123 $patches $patches >stdout &&
1124 ! grep "In-Reply-To: " stdout
1125'
1126
1127test_expect_success $PREREQ 'threading but no chain-reply-to' '
1128 git send-email \
1129 --dry-run \
1130 --from="Example <nobody@example.com>" \
1131 --to=nobody@example.com \
1132 --thread \
1133 --no-chain-reply-to \
1134 $patches $patches >stdout &&
1135 grep "In-Reply-To: " stdout
1136'
1137
1138test_expect_success $PREREQ 'sendemail.to works' '
1139 git config --replace-all sendemail.to "Somebody <somebody@ex.com>" &&
1140 git send-email \
1141 --dry-run \
1142 --from="Example <nobody@example.com>" \
1143 $patches $patches >stdout &&
1144 grep "To: Somebody <somebody@ex.com>" stdout
1145'
1146
1147test_expect_success $PREREQ '--no-to overrides sendemail.to' '
1148 git send-email \
1149 --dry-run \
1150 --from="Example <nobody@example.com>" \
1151 --no-to \
1152 --to=nobody@example.com \
1153 $patches $patches >stdout &&
1154 grep "To: nobody@example.com" stdout &&
1155 ! grep "To: Somebody <somebody@ex.com>" stdout
1156'
1157
1158test_expect_success $PREREQ 'sendemail.cc works' '
1159 git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" &&
1160 git send-email \
1161 --dry-run \
1162 --from="Example <nobody@example.com>" \
1163 --to=nobody@example.com \
1164 $patches $patches >stdout &&
1165 grep "Cc: Somebody <somebody@ex.com>" stdout
1166'
1167
1168test_expect_success $PREREQ '--no-cc overrides sendemail.cc' '
1169 git send-email \
1170 --dry-run \
1171 --from="Example <nobody@example.com>" \
1172 --no-cc \
1173 --cc=bodies@example.com \
1174 --to=nobody@example.com \
1175 $patches $patches >stdout &&
1176 grep "Cc: bodies@example.com" stdout &&
1177 ! grep "Cc: Somebody <somebody@ex.com>" stdout
1178'
1179
1180test_expect_success $PREREQ 'sendemail.bcc works' '
1181 git config --replace-all sendemail.bcc "Other <other@ex.com>" &&
1182 git send-email \
1183 --dry-run \
1184 --from="Example <nobody@example.com>" \
1185 --to=nobody@example.com \
1186 --smtp-server relay.example.com \
1187 $patches $patches >stdout &&
1188 grep "RCPT TO:<other@ex.com>" stdout
1189'
1190
1191test_expect_success $PREREQ '--no-bcc overrides sendemail.bcc' '
1192 git send-email \
1193 --dry-run \
1194 --from="Example <nobody@example.com>" \
1195 --no-bcc \
1196 --bcc=bodies@example.com \
1197 --to=nobody@example.com \
1198 --smtp-server relay.example.com \
1199 $patches $patches >stdout &&
1200 grep "RCPT TO:<bodies@example.com>" stdout &&
1201 ! grep "RCPT TO:<other@ex.com>" stdout
1202'
1203
1204test_expect_success $PREREQ 'patches To headers are used by default' '
1205 patch=$(git format-patch -1 --to="bodies@example.com") &&
1206 test_when_finished "rm $patch" &&
1207 git send-email \
1208 --dry-run \
1209 --from="Example <nobody@example.com>" \
1210 --smtp-server relay.example.com \
1211 $patch >stdout &&
1212 grep "RCPT TO:<bodies@example.com>" stdout
1213'
1214
1215test_expect_success $PREREQ 'patches To headers are appended to' '
1216 patch=$(git format-patch -1 --to="bodies@example.com") &&
1217 test_when_finished "rm $patch" &&
1218 git send-email \
1219 --dry-run \
1220 --from="Example <nobody@example.com>" \
1221 --to=nobody@example.com \
1222 --smtp-server relay.example.com \
1223 $patch >stdout &&
1224 grep "RCPT TO:<bodies@example.com>" stdout &&
1225 grep "RCPT TO:<nobody@example.com>" stdout
1226'
1227
1228test_expect_success $PREREQ 'To headers from files reset each patch' '
1229 patch1=$(git format-patch -1 --to="bodies@example.com") &&
1230 patch2=$(git format-patch -1 --to="other@example.com" HEAD~) &&
1231 test_when_finished "rm $patch1 && rm $patch2" &&
1232 git send-email \
1233 --dry-run \
1234 --from="Example <nobody@example.com>" \
1235 --to="nobody@example.com" \
1236 --smtp-server relay.example.com \
1237 $patch1 $patch2 >stdout &&
1238 test $(grep -c "RCPT TO:<bodies@example.com>" stdout) = 1 &&
1239 test $(grep -c "RCPT TO:<nobody@example.com>" stdout) = 2 &&
1240 test $(grep -c "RCPT TO:<other@example.com>" stdout) = 1
1241'
1242
1243test_expect_success $PREREQ 'setup expect' '
1244cat >email-using-8bit <<\EOF
1245From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1246Message-Id: <bogus-message-id@example.com>
1247From: author@example.com
1248Date: Sat, 12 Jun 2010 15:53:58 +0200
1249Subject: subject goes here
1250
1251Dieser deutsche Text enthält einen Umlaut!
1252EOF
1253'
1254
1255test_expect_success $PREREQ 'setup expect' '
1256 echo "Subject: subject goes here" >expected
1257'
1258
1259test_expect_success $PREREQ 'ASCII subject is not RFC2047 quoted' '
1260 clean_fake_sendmail &&
1261 echo bogus |
1262 git send-email --from=author@example.com --to=nobody@example.com \
1263 --smtp-server="$(pwd)/fake.sendmail" \
1264 --8bit-encoding=UTF-8 \
1265 email-using-8bit >stdout &&
1266 grep "Subject" msgtxt1 >actual &&
1267 test_cmp expected actual
1268'
1269
1270test_expect_success $PREREQ 'setup expect' '
1271 cat >content-type-decl <<-\EOF
1272 MIME-Version: 1.0
1273 Content-Type: text/plain; charset=UTF-8
1274 Content-Transfer-Encoding: 8bit
1275 EOF
1276'
1277
1278test_expect_success $PREREQ 'asks about and fixes 8bit encodings' '
1279 clean_fake_sendmail &&
1280 echo |
1281 git send-email --from=author@example.com --to=nobody@example.com \
1282 --smtp-server="$(pwd)/fake.sendmail" \
1283 email-using-8bit >stdout &&
1284 grep "do not declare a Content-Transfer-Encoding" stdout &&
1285 grep email-using-8bit stdout &&
1286 grep "Which 8bit encoding" stdout &&
1287 egrep "Content|MIME" msgtxt1 >actual &&
1288 test_cmp content-type-decl actual
1289'
1290
1291test_expect_success $PREREQ 'sendemail.8bitEncoding works' '
1292 clean_fake_sendmail &&
1293 git config sendemail.assume8bitEncoding UTF-8 &&
1294 echo bogus |
1295 git send-email --from=author@example.com --to=nobody@example.com \
1296 --smtp-server="$(pwd)/fake.sendmail" \
1297 email-using-8bit >stdout &&
1298 egrep "Content|MIME" msgtxt1 >actual &&
1299 test_cmp content-type-decl actual
1300'
1301
1302test_expect_success $PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
1303 clean_fake_sendmail &&
1304 git config sendemail.assume8bitEncoding "bogus too" &&
1305 echo bogus |
1306 git send-email --from=author@example.com --to=nobody@example.com \
1307 --smtp-server="$(pwd)/fake.sendmail" \
1308 --8bit-encoding=UTF-8 \
1309 email-using-8bit >stdout &&
1310 egrep "Content|MIME" msgtxt1 >actual &&
1311 test_cmp content-type-decl actual
1312'
1313
1314test_expect_success $PREREQ 'setup expect' '
1315 cat >email-using-8bit <<-\EOF
1316 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1317 Message-Id: <bogus-message-id@example.com>
1318 From: author@example.com
1319 Date: Sat, 12 Jun 2010 15:53:58 +0200
1320 Subject: Dieser Betreff enthält auch einen Umlaut!
1321
1322 Nothing to see here.
1323 EOF
1324'
1325
1326test_expect_success $PREREQ 'setup expect' '
1327 cat >expected <<-\EOF
1328 Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
1329 EOF
1330'
1331
1332test_expect_success $PREREQ '--8bit-encoding also treats subject' '
1333 clean_fake_sendmail &&
1334 echo bogus |
1335 git send-email --from=author@example.com --to=nobody@example.com \
1336 --smtp-server="$(pwd)/fake.sendmail" \
1337 --8bit-encoding=UTF-8 \
1338 email-using-8bit >stdout &&
1339 grep "Subject" msgtxt1 >actual &&
1340 test_cmp expected actual
1341'
1342
1343test_expect_success $PREREQ 'setup expect' '
1344 cat >email-using-8bit <<-\EOF
1345 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1346 Message-Id: <bogus-message-id@example.com>
1347 From: A U Thor <author@example.com>
1348 Date: Sat, 12 Jun 2010 15:53:58 +0200
1349 Content-Type: text/plain; charset=UTF-8
1350 Subject: Nothing to see here.
1351
1352 Dieser Betreff enthält auch einen Umlaut!
1353 EOF
1354'
1355
1356test_expect_success $PREREQ 'sendemail.transferencoding=7bit fails on 8bit data' '
1357 clean_fake_sendmail &&
1358 git config sendemail.transferEncoding 7bit &&
1359 test_must_fail git send-email \
1360 --transfer-encoding=7bit \
1361 --smtp-server="$(pwd)/fake.sendmail" \
1362 email-using-8bit \
1363 2>errors >out &&
1364 grep "cannot send message as 7bit" errors &&
1365 test -z "$(ls msgtxt*)"
1366'
1367
1368test_expect_success $PREREQ '--transfer-encoding overrides sendemail.transferEncoding' '
1369 clean_fake_sendmail &&
1370 git config sendemail.transferEncoding 8bit &&
1371 test_must_fail git send-email \
1372 --transfer-encoding=7bit \
1373 --smtp-server="$(pwd)/fake.sendmail" \
1374 email-using-8bit \
1375 2>errors >out &&
1376 grep "cannot send message as 7bit" errors &&
1377 test -z "$(ls msgtxt*)"
1378'
1379
1380test_expect_success $PREREQ 'sendemail.transferencoding=8bit' '
1381 clean_fake_sendmail &&
1382 git send-email \
1383 --transfer-encoding=8bit \
1384 --smtp-server="$(pwd)/fake.sendmail" \
1385 email-using-8bit \
1386 2>errors >out &&
1387 sed '1,/^$/d' msgtxt1 >actual &&
1388 sed '1,/^$/d' email-using-8bit >expected &&
1389 test_cmp expected actual
1390'
1391
1392test_expect_success $PREREQ 'setup expect' '
1393 cat >expected <<-\EOF
1394 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1395 EOF
1396'
1397
1398test_expect_success $PREREQ '8-bit and sendemail.transferencoding=quoted-printable' '
1399 clean_fake_sendmail &&
1400 git send-email \
1401 --transfer-encoding=quoted-printable \
1402 --smtp-server="$(pwd)/fake.sendmail" \
1403 email-using-8bit \
1404 2>errors >out &&
1405 sed '1,/^$/d' msgtxt1 >actual &&
1406 test_cmp expected actual
1407'
1408
1409test_expect_success $PREREQ 'setup expect' '
1410 cat >expected <<-\EOF
1411 RGllc2VyIEJldHJlZmYgZW50aMOkbHQgYXVjaCBlaW5lbiBVbWxhdXQhCg==
1412 EOF
1413'
1414
1415test_expect_success $PREREQ '8-bit and sendemail.transferencoding=base64' '
1416 clean_fake_sendmail &&
1417 git send-email \
1418 --transfer-encoding=base64 \
1419 --smtp-server="$(pwd)/fake.sendmail" \
1420 email-using-8bit \
1421 2>errors >out &&
1422 sed '1,/^$/d' msgtxt1 >actual &&
1423 test_cmp expected actual
1424'
1425
1426test_expect_success $PREREQ 'setup expect' '
1427 cat >email-using-qp <<-\EOF
1428 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1429 Message-Id: <bogus-message-id@example.com>
1430 From: A U Thor <author@example.com>
1431 Date: Sat, 12 Jun 2010 15:53:58 +0200
1432 MIME-Version: 1.0
1433 Content-Transfer-Encoding: quoted-printable
1434 Content-Type: text/plain; charset=UTF-8
1435 Subject: Nothing to see here.
1436
1437 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1438 EOF
1439'
1440
1441test_expect_success $PREREQ 'convert from quoted-printable to base64' '
1442 clean_fake_sendmail &&
1443 git send-email \
1444 --transfer-encoding=base64 \
1445 --smtp-server="$(pwd)/fake.sendmail" \
1446 email-using-qp \
1447 2>errors >out &&
1448 sed '1,/^$/d' msgtxt1 >actual &&
1449 test_cmp expected actual
1450'
1451
1452test_expect_success $PREREQ 'setup expect' "
1453tr -d '\\015' | tr '%' '\\015' >email-using-crlf <<EOF
1454From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1455Message-Id: <bogus-message-id@example.com>
1456From: A U Thor <author@example.com>
1457Date: Sat, 12 Jun 2010 15:53:58 +0200
1458Content-Type: text/plain; charset=UTF-8
1459Subject: Nothing to see here.
1460
1461Look, I have a CRLF and an = sign!%
1462EOF
1463"
1464
1465test_expect_success $PREREQ 'setup expect' '
1466 cat >expected <<-\EOF
1467 Look, I have a CRLF and an =3D sign!=0D
1468 EOF
1469'
1470
1471test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=quoted-printable' '
1472 clean_fake_sendmail &&
1473 git send-email \
1474 --transfer-encoding=quoted-printable \
1475 --smtp-server="$(pwd)/fake.sendmail" \
1476 email-using-crlf \
1477 2>errors >out &&
1478 sed '1,/^$/d' msgtxt1 >actual &&
1479 test_cmp expected actual
1480'
1481
1482test_expect_success $PREREQ 'setup expect' '
1483 cat >expected <<-\EOF
1484 TG9vaywgSSBoYXZlIGEgQ1JMRiBhbmQgYW4gPSBzaWduIQ0K
1485 EOF
1486'
1487
1488test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=base64' '
1489 clean_fake_sendmail &&
1490 git send-email \
1491 --transfer-encoding=base64 \
1492 --smtp-server="$(pwd)/fake.sendmail" \
1493 email-using-crlf \
1494 2>errors >out &&
1495 sed '1,/^$/d' msgtxt1 >actual &&
1496 test_cmp expected actual
1497'
1498
1499
1500# Note that the patches in this test are deliberately out of order; we
1501# want to make sure it works even if the cover-letter is not in the
1502# first mail.
1503test_expect_success $PREREQ 'refusing to send cover letter template' '
1504 clean_fake_sendmail &&
1505 rm -fr outdir &&
1506 git format-patch --cover-letter -2 -o outdir &&
1507 test_must_fail git send-email \
1508 --from="Example <nobody@example.com>" \
1509 --to=nobody@example.com \
1510 --smtp-server="$(pwd)/fake.sendmail" \
1511 outdir/0002-*.patch \
1512 outdir/0000-*.patch \
1513 outdir/0001-*.patch \
1514 2>errors >out &&
1515 grep "SUBJECT HERE" errors &&
1516 test -z "$(ls msgtxt*)"
1517'
1518
1519test_expect_success $PREREQ '--force sends cover letter template anyway' '
1520 clean_fake_sendmail &&
1521 rm -fr outdir &&
1522 git format-patch --cover-letter -2 -o outdir &&
1523 git send-email \
1524 --force \
1525 --from="Example <nobody@example.com>" \
1526 --to=nobody@example.com \
1527 --smtp-server="$(pwd)/fake.sendmail" \
1528 outdir/0002-*.patch \
1529 outdir/0000-*.patch \
1530 outdir/0001-*.patch \
1531 2>errors >out &&
1532 ! grep "SUBJECT HERE" errors &&
1533 test -n "$(ls msgtxt*)"
1534'
1535
1536test_cover_addresses () {
1537 header="$1"
1538 shift
1539 clean_fake_sendmail &&
1540 rm -fr outdir &&
1541 git format-patch --cover-letter -2 -o outdir &&
1542 cover=$(echo outdir/0000-*.patch) &&
1543 mv $cover cover-to-edit.patch &&
1544 perl -pe "s/^From:/$header: extra\@address.com\nFrom:/" cover-to-edit.patch >"$cover" &&
1545 git send-email \
1546 --force \
1547 --from="Example <nobody@example.com>" \
1548 --no-to --no-cc \
1549 "$@" \
1550 --smtp-server="$(pwd)/fake.sendmail" \
1551 outdir/0000-*.patch \
1552 outdir/0001-*.patch \
1553 outdir/0002-*.patch \
1554 2>errors >out &&
1555 grep "^$header: extra@address.com" msgtxt1 >to1 &&
1556 grep "^$header: extra@address.com" msgtxt2 >to2 &&
1557 grep "^$header: extra@address.com" msgtxt3 >to3 &&
1558 test_line_count = 1 to1 &&
1559 test_line_count = 1 to2 &&
1560 test_line_count = 1 to3
1561}
1562
1563test_expect_success $PREREQ 'to-cover adds To to all mail' '
1564 test_cover_addresses "To" --to-cover
1565'
1566
1567test_expect_success $PREREQ 'cc-cover adds Cc to all mail' '
1568 test_cover_addresses "Cc" --cc-cover
1569'
1570
1571test_expect_success $PREREQ 'tocover adds To to all mail' '
1572 test_config sendemail.tocover true &&
1573 test_cover_addresses "To"
1574'
1575
1576test_expect_success $PREREQ 'cccover adds Cc to all mail' '
1577 test_config sendemail.cccover true &&
1578 test_cover_addresses "Cc"
1579'
1580
1581test_expect_success $PREREQ 'escaped quotes in sendemail.aliasfiletype=mutt' '
1582 clean_fake_sendmail &&
1583 echo "alias sbd \\\"Dot U. Sir\\\" <somebody@example.org>" >.mutt &&
1584 git config --replace-all sendemail.aliasesfile "$(pwd)/.mutt" &&
1585 git config sendemail.aliasfiletype mutt &&
1586 git send-email \
1587 --from="Example <nobody@example.com>" \
1588 --to=sbd \
1589 --smtp-server="$(pwd)/fake.sendmail" \
1590 outdir/0001-*.patch \
1591 2>errors >out &&
1592 grep "^!somebody@example\.org!$" commandline1 &&
1593 grep -F "To: \"Dot U. Sir\" <somebody@example.org>" out
1594'
1595
1596test_expect_success $PREREQ 'sendemail.aliasfiletype=mailrc' '
1597 clean_fake_sendmail &&
1598 echo "alias sbd somebody@example.org" >.mailrc &&
1599 git config --replace-all sendemail.aliasesfile "$(pwd)/.mailrc" &&
1600 git config sendemail.aliasfiletype mailrc &&
1601 git send-email \
1602 --from="Example <nobody@example.com>" \
1603 --to=sbd \
1604 --smtp-server="$(pwd)/fake.sendmail" \
1605 outdir/0001-*.patch \
1606 2>errors >out &&
1607 grep "^!somebody@example\.org!$" commandline1
1608'
1609
1610test_expect_success $PREREQ 'sendemail.aliasfile=~/.mailrc' '
1611 clean_fake_sendmail &&
1612 echo "alias sbd someone@example.org" >"$HOME/.mailrc" &&
1613 git config --replace-all sendemail.aliasesfile "~/.mailrc" &&
1614 git config sendemail.aliasfiletype mailrc &&
1615 git send-email \
1616 --from="Example <nobody@example.com>" \
1617 --to=sbd \
1618 --smtp-server="$(pwd)/fake.sendmail" \
1619 outdir/0001-*.patch \
1620 2>errors >out &&
1621 grep "^!someone@example\.org!$" commandline1
1622'
1623
1624test_dump_aliases () {
1625 msg="$1" && shift &&
1626 filetype="$1" && shift &&
1627 printf '%s\n' "$@" >expect &&
1628 cat >.tmp-email-aliases &&
1629
1630 test_expect_success $PREREQ "$msg" '
1631 clean_fake_sendmail && rm -fr outdir &&
1632 git config --replace-all sendemail.aliasesfile \
1633 "$(pwd)/.tmp-email-aliases" &&
1634 git config sendemail.aliasfiletype "$filetype" &&
1635 git send-email --dump-aliases 2>errors >actual &&
1636 test_cmp expect actual
1637 '
1638}
1639
1640test_dump_aliases '--dump-aliases sendmail format' \
1641 'sendmail' \
1642 'abgroup' \
1643 'alice' \
1644 'bcgrp' \
1645 'bob' \
1646 'chloe' <<-\EOF
1647 alice: Alice W Land <awol@example.com>
1648 bob: Robert Bobbyton <bob@example.com>
1649 chloe: chloe@example.com
1650 abgroup: alice, bob
1651 bcgrp: bob, chloe, Other <o@example.com>
1652 EOF
1653
1654test_dump_aliases '--dump-aliases mutt format' \
1655 'mutt' \
1656 'alice' \
1657 'bob' \
1658 'chloe' \
1659 'donald' <<-\EOF
1660 alias alice Alice W Land <awol@example.com>
1661 alias donald Donald C Carlton <donc@example.com>
1662 alias bob Robert Bobbyton <bob@example.com>
1663 alias chloe chloe@example.com
1664 EOF
1665
1666test_dump_aliases '--dump-aliases mailrc format' \
1667 'mailrc' \
1668 'alice' \
1669 'bob' \
1670 'chloe' \
1671 'eve' <<-\EOF
1672 alias alice Alice W Land <awol@example.com>
1673 alias eve Eve <eve@example.com>
1674 alias bob Robert Bobbyton <bob@example.com>
1675 alias chloe chloe@example.com
1676 EOF
1677
1678test_dump_aliases '--dump-aliases pine format' \
1679 'pine' \
1680 'alice' \
1681 'bob' \
1682 'chloe' \
1683 'eve' <<-\EOF
1684 alice Alice W Land <awol@example.com>
1685 eve Eve <eve@example.com>
1686 bob Robert Bobbyton <bob@example.com>
1687 chloe chloe@example.com
1688 EOF
1689
1690test_dump_aliases '--dump-aliases gnus format' \
1691 'gnus' \
1692 'alice' \
1693 'bob' \
1694 'chloe' \
1695 'eve' <<-\EOF
1696 (define-mail-alias "alice" "awol@example.com")
1697 (define-mail-alias "eve" "eve@example.com")
1698 (define-mail-alias "bob" "bob@example.com")
1699 (define-mail-alias "chloe" "chloe@example.com")
1700 EOF
1701
1702test_expect_success '--dump-aliases must be used alone' '
1703 test_must_fail git send-email --dump-aliases --to=janice@example.com -1 refs/heads/accounting
1704'
1705
1706test_sendmail_aliases () {
1707 msg="$1" && shift &&
1708 expect="$@" &&
1709 cat >.tmp-email-aliases &&
1710
1711 test_expect_success $PREREQ "$msg" '
1712 clean_fake_sendmail && rm -fr outdir &&
1713 git format-patch -1 -o outdir &&
1714 git config --replace-all sendemail.aliasesfile \
1715 "$(pwd)/.tmp-email-aliases" &&
1716 git config sendemail.aliasfiletype sendmail &&
1717 git send-email \
1718 --from="Example <nobody@example.com>" \
1719 --to=alice --to=bcgrp \
1720 --smtp-server="$(pwd)/fake.sendmail" \
1721 outdir/0001-*.patch \
1722 2>errors >out &&
1723 for i in $expect
1724 do
1725 grep "^!$i!$" commandline1 || return 1
1726 done
1727 '
1728}
1729
1730test_sendmail_aliases 'sendemail.aliasfiletype=sendmail' \
1731 'awol@example\.com' \
1732 'bob@example\.com' \
1733 'chloe@example\.com' \
1734 'o@example\.com' <<-\EOF
1735 alice: Alice W Land <awol@example.com>
1736 bob: Robert Bobbyton <bob@example.com>
1737 # this is a comment
1738 # this is also a comment
1739 chloe: chloe@example.com
1740 abgroup: alice, bob
1741 bcgrp: bob, chloe, Other <o@example.com>
1742 EOF
1743
1744test_sendmail_aliases 'sendmail aliases line folding' \
1745 alice1 \
1746 bob1 bob2 \
1747 chuck1 chuck2 \
1748 darla1 darla2 darla3 \
1749 elton1 elton2 elton3 \
1750 fred1 fred2 \
1751 greg1 <<-\EOF
1752 alice: alice1
1753 bob: bob1,\
1754 bob2
1755 chuck: chuck1,
1756 chuck2
1757 darla: darla1,\
1758 darla2,
1759 darla3
1760 elton: elton1,
1761 elton2,\
1762 elton3
1763 fred: fred1,\
1764 fred2
1765 greg: greg1
1766 bcgrp: bob, chuck, darla, elton, fred, greg
1767 EOF
1768
1769test_sendmail_aliases 'sendmail aliases tolerate bogus line folding' \
1770 alice1 bob1 <<-\EOF
1771 alice: alice1
1772 bcgrp: bob1\
1773 EOF
1774
1775test_sendmail_aliases 'sendmail aliases empty' alice bcgrp <<-\EOF
1776 EOF
1777
1778test_expect_success $PREREQ 'alias support in To header' '
1779 clean_fake_sendmail &&
1780 echo "alias sbd someone@example.org" >.mailrc &&
1781 test_config sendemail.aliasesfile ".mailrc" &&
1782 test_config sendemail.aliasfiletype mailrc &&
1783 git format-patch --stdout -1 --to=sbd >aliased.patch &&
1784 git send-email \
1785 --from="Example <nobody@example.com>" \
1786 --smtp-server="$(pwd)/fake.sendmail" \
1787 aliased.patch \
1788 2>errors >out &&
1789 grep "^!someone@example\.org!$" commandline1
1790'
1791
1792test_expect_success $PREREQ 'alias support in Cc header' '
1793 clean_fake_sendmail &&
1794 echo "alias sbd someone@example.org" >.mailrc &&
1795 test_config sendemail.aliasesfile ".mailrc" &&
1796 test_config sendemail.aliasfiletype mailrc &&
1797 git format-patch --stdout -1 --cc=sbd >aliased.patch &&
1798 git send-email \
1799 --from="Example <nobody@example.com>" \
1800 --smtp-server="$(pwd)/fake.sendmail" \
1801 aliased.patch \
1802 2>errors >out &&
1803 grep "^!someone@example\.org!$" commandline1
1804'
1805
1806test_expect_success $PREREQ 'tocmd works with aliases' '
1807 clean_fake_sendmail &&
1808 echo "alias sbd someone@example.org" >.mailrc &&
1809 test_config sendemail.aliasesfile ".mailrc" &&
1810 test_config sendemail.aliasfiletype mailrc &&
1811 git format-patch --stdout -1 >tocmd.patch &&
1812 echo tocmd--sbd >>tocmd.patch &&
1813 git send-email \
1814 --from="Example <nobody@example.com>" \
1815 --to-cmd=./tocmd-sed \
1816 --smtp-server="$(pwd)/fake.sendmail" \
1817 tocmd.patch \
1818 2>errors >out &&
1819 grep "^!someone@example\.org!$" commandline1
1820'
1821
1822test_expect_success $PREREQ 'cccmd works with aliases' '
1823 clean_fake_sendmail &&
1824 echo "alias sbd someone@example.org" >.mailrc &&
1825 test_config sendemail.aliasesfile ".mailrc" &&
1826 test_config sendemail.aliasfiletype mailrc &&
1827 git format-patch --stdout -1 >cccmd.patch &&
1828 echo cccmd--sbd >>cccmd.patch &&
1829 git send-email \
1830 --from="Example <nobody@example.com>" \
1831 --cc-cmd=./cccmd-sed \
1832 --smtp-server="$(pwd)/fake.sendmail" \
1833 cccmd.patch \
1834 2>errors >out &&
1835 grep "^!someone@example\.org!$" commandline1
1836'
1837
1838do_xmailer_test () {
1839 expected=$1 params=$2 &&
1840 git format-patch -1 &&
1841 git send-email \
1842 --from="Example <nobody@example.com>" \
1843 --to=someone@example.com \
1844 --smtp-server="$(pwd)/fake.sendmail" \
1845 $params \
1846 0001-*.patch \
1847 2>errors >out &&
1848 { grep '^X-Mailer:' out || :; } >mailer &&
1849 test_line_count = $expected mailer
1850}
1851
1852test_expect_success $PREREQ '--[no-]xmailer without any configuration' '
1853 do_xmailer_test 1 "--xmailer" &&
1854 do_xmailer_test 0 "--no-xmailer"
1855'
1856
1857test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=true' '
1858 test_config sendemail.xmailer true &&
1859 do_xmailer_test 1 "" &&
1860 do_xmailer_test 0 "--no-xmailer" &&
1861 do_xmailer_test 1 "--xmailer"
1862'
1863
1864test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=false' '
1865 test_config sendemail.xmailer false &&
1866 do_xmailer_test 0 "" &&
1867 do_xmailer_test 0 "--no-xmailer" &&
1868 do_xmailer_test 1 "--xmailer"
1869'
1870
1871test_expect_success $PREREQ 'setup expected-list' '
1872 git send-email \
1873 --dry-run \
1874 --from="Example <from@example.com>" \
1875 --to="To 1 <to1@example.com>" \
1876 --to="to2@example.com" \
1877 --to="to3@example.com" \
1878 --cc="Cc 1 <cc1@example.com>" \
1879 --cc="Cc2 <cc2@example.com>" \
1880 --bcc="bcc1@example.com" \
1881 --bcc="bcc2@example.com" \
1882 0001-add-master.patch | replace_variable_fields \
1883 >expected-list
1884'
1885
1886test_expect_success $PREREQ 'use email list in --cc --to and --bcc' '
1887 git send-email \
1888 --dry-run \
1889 --from="Example <from@example.com>" \
1890 --to="To 1 <to1@example.com>, to2@example.com" \
1891 --to="to3@example.com" \
1892 --cc="Cc 1 <cc1@example.com>, Cc2 <cc2@example.com>" \
1893 --bcc="bcc1@example.com, bcc2@example.com" \
1894 0001-add-master.patch | replace_variable_fields \
1895 >actual-list &&
1896 test_cmp expected-list actual-list
1897'
1898
1899test_expect_success $PREREQ 'aliases work with email list' '
1900 echo "alias to2 to2@example.com" >.mutt &&
1901 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt &&
1902 test_config sendemail.aliasesfile ".mutt" &&
1903 test_config sendemail.aliasfiletype mutt &&
1904 git send-email \
1905 --dry-run \
1906 --from="Example <from@example.com>" \
1907 --to="To 1 <to1@example.com>, to2, to3@example.com" \
1908 --cc="cc1, Cc2 <cc2@example.com>" \
1909 --bcc="bcc1@example.com, bcc2@example.com" \
1910 0001-add-master.patch | replace_variable_fields \
1911 >actual-list &&
1912 test_cmp expected-list actual-list
1913'
1914
1915test_expect_success $PREREQ 'leading and trailing whitespaces are removed' '
1916 echo "alias to2 to2@example.com" >.mutt &&
1917 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt &&
1918 test_config sendemail.aliasesfile ".mutt" &&
1919 test_config sendemail.aliasfiletype mutt &&
1920 TO1=$(echo "QTo 1 <to1@example.com>" | q_to_tab) &&
1921 TO2=$(echo "QZto2" | qz_to_tab_space) &&
1922 CC1=$(echo "cc1" | append_cr) &&
1923 BCC1=$(echo "Q bcc1@example.com Q" | q_to_nul) &&
1924 git send-email \
1925 --dry-run \
1926 --from=" Example <from@example.com>" \
1927 --to="$TO1" \
1928 --to="$TO2" \
1929 --to=" to3@example.com " \
1930 --cc="$CC1" \
1931 --cc="Cc2 <cc2@example.com>" \
1932 --bcc="$BCC1" \
1933 --bcc="bcc2@example.com" \
1934 0001-add-master.patch | replace_variable_fields \
1935 >actual-list &&
1936 test_cmp expected-list actual-list
1937'
1938
1939test_expect_success $PREREQ 'invoke hook' '
1940 mkdir -p .git/hooks &&
1941
1942 write_script .git/hooks/sendemail-validate <<-\EOF &&
1943 # test that we have the correct environment variable, pwd, and
1944 # argument
1945 case "$GIT_DIR" in
1946 *.git)
1947 true
1948 ;;
1949 *)
1950 false
1951 ;;
1952 esac &&
1953 test -f 0001-add-master.patch &&
1954 grep "add master" "$1"
1955 EOF
1956
1957 mkdir subdir &&
1958 (
1959 # Test that it works even if we are not at the root of the
1960 # working tree
1961 cd subdir &&
1962 git send-email \
1963 --from="Example <nobody@example.com>" \
1964 --to=nobody@example.com \
1965 --smtp-server="$(pwd)/../fake.sendmail" \
1966 ../0001-add-master.patch &&
1967
1968 # Verify error message when a patch is rejected by the hook
1969 sed -e "s/add master/x/" ../0001-add-master.patch >../another.patch &&
1970 git send-email \
1971 --from="Example <nobody@example.com>" \
1972 --to=nobody@example.com \
1973 --smtp-server="$(pwd)/../fake.sendmail" \
1974 ../another.patch 2>err
1975 test_i18ngrep "rejected by sendemail-validate hook" err
1976 )
1977'
1978
1979test_expect_success $PREREQ 'test that send-email works outside a repo' '
1980 nongit git send-email \
1981 --from="Example <nobody@example.com>" \
1982 --to=nobody@example.com \
1983 --smtp-server="$(pwd)/fake.sendmail" \
1984 "$(pwd)/0001-add-master.patch"
1985'
1986
1987test_done