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