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