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