Merge branch 'jk/add-i-read-error'
[git] / t / t9001-send-email.sh
1 #!/bin/sh
2
3 test_description='git send-email'
4 . ./test-lib.sh
5
6 # May be altered later in the test
7 PREREQ="PERL"
8
9 test_expect_success $PREREQ 'prepare reference tree' '
10         echo "1A quick brown fox jumps over the" >file &&
11         echo "lazy dog" >>file &&
12         git add file &&
13         GIT_AUTHOR_NAME="A" git commit -a -m "Initial."
14 '
15
16 test_expect_success $PREREQ 'Setup helper tool' '
17         write_script fake.sendmail <<-\EOF &&
18         shift
19         output=1
20         while test -f commandline$output
21         do
22                 output=$(($output+1))
23         done
24         for a
25         do
26                 echo "!$a!"
27         done >commandline$output
28         cat >"msgtxt$output"
29         EOF
30         git add fake.sendmail &&
31         GIT_AUTHOR_NAME="A" git commit -a -m "Second."
32 '
33
34 clean_fake_sendmail () {
35         rm -f commandline* msgtxt*
36 }
37
38 test_expect_success $PREREQ 'Extract patches' '
39         patches=`git format-patch -s --cc="One <one@example.com>" --cc=two@example.com -n HEAD^1`
40 '
41
42 # Test no confirm early to ensure remaining tests will not hang
43 test_no_confirm () {
44         rm -f no_confirm_okay
45         echo n | \
46                 GIT_SEND_EMAIL_NOTTY=1 \
47                 git send-email \
48                 --from="Example <from@example.com>" \
49                 --to=nobody@example.com \
50                 --smtp-server="$(pwd)/fake.sendmail" \
51                 $@ \
52                 $patches >stdout &&
53                 test_must_fail grep "Send this email" stdout &&
54                 >no_confirm_okay
55 }
56
57 # Exit immediately to prevent hang if a no-confirm test fails
58 check_no_confirm () {
59         if ! test -f no_confirm_okay
60         then
61                 say 'confirm test failed; skipping remaining tests to prevent hanging'
62                 PREREQ="$PREREQ,CHECK_NO_CONFIRM"
63         fi
64         return 0
65 }
66
67 test_expect_success $PREREQ 'No confirm with --suppress-cc' '
68         test_no_confirm --suppress-cc=sob &&
69         check_no_confirm
70 '
71
72
73 test_expect_success $PREREQ 'No confirm with --confirm=never' '
74         test_no_confirm --confirm=never &&
75         check_no_confirm
76 '
77
78 # leave sendemail.confirm set to never after this so that none of the
79 # remaining tests prompt unintentionally.
80 test_expect_success $PREREQ 'No confirm with sendemail.confirm=never' '
81         git config sendemail.confirm never &&
82         test_no_confirm --compose --subject=foo &&
83         check_no_confirm
84 '
85
86 test_expect_success $PREREQ 'Send patches' '
87         git send-email --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
88 '
89
90 test_expect_success $PREREQ 'setup expect' '
91         cat >expected <<-\EOF
92         !nobody@example.com!
93         !author@example.com!
94         !one@example.com!
95         !two@example.com!
96         EOF
97 '
98
99 test_expect_success $PREREQ 'Verify commandline' '
100         test_cmp expected commandline1
101 '
102
103 test_expect_success $PREREQ 'Send patches with --envelope-sender' '
104         clean_fake_sendmail &&
105         git send-email --envelope-sender="Patch Contributor <patch@example.com>" --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
106 '
107
108 test_expect_success $PREREQ 'setup expect' '
109         cat >expected <<-\EOF
110         !patch@example.com!
111         !-i!
112         !nobody@example.com!
113         !author@example.com!
114         !one@example.com!
115         !two@example.com!
116         EOF
117 '
118
119 test_expect_success $PREREQ 'Verify commandline' '
120         test_cmp expected commandline1
121 '
122
123 test_expect_success $PREREQ 'Send patches with --envelope-sender=auto' '
124         clean_fake_sendmail &&
125         git send-email --envelope-sender=auto --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
126 '
127
128 test_expect_success $PREREQ 'setup expect' '
129         cat >expected <<-\EOF
130         !nobody@example.com!
131         !-i!
132         !nobody@example.com!
133         !author@example.com!
134         !one@example.com!
135         !two@example.com!
136         EOF
137 '
138
139 test_expect_success $PREREQ 'Verify commandline' '
140         test_cmp expected commandline1
141 '
142
143 test_expect_success $PREREQ 'setup expect' "
144 cat >expected-show-all-headers <<\EOF
145 0001-Second.patch
146 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
147 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
148 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
149 Dry-OK. Log says:
150 Server: relay.example.com
151 MAIL FROM:<from@example.com>
152 RCPT TO:<to@example.com>
153 RCPT TO:<cc@example.com>
154 RCPT TO:<author@example.com>
155 RCPT TO:<one@example.com>
156 RCPT TO:<two@example.com>
157 RCPT TO:<bcc@example.com>
158 From: Example <from@example.com>
159 To: to@example.com
160 Cc: cc@example.com,
161         A <author@example.com>,
162         One <one@example.com>,
163         two@example.com
164 Subject: [PATCH 1/1] Second.
165 Date: DATE-STRING
166 Message-Id: MESSAGE-ID-STRING
167 X-Mailer: X-MAILER-STRING
168 In-Reply-To: <unique-message-id@example.com>
169 References: <unique-message-id@example.com>
170
171 Result: OK
172 EOF
173 "
174
175 test_suppress_self () {
176         test_commit $3 &&
177         test_when_finished "git reset --hard HEAD^" &&
178
179         write_script cccmd-sed <<-EOF &&
180                 sed -n -e s/^cccmd--//p "\$1"
181         EOF
182
183         git commit --amend --author="$1 <$2>" -F - &&
184         clean_fake_sendmail &&
185         git format-patch --stdout -1 >"suppress-self-$3.patch" &&
186
187         git send-email --from="$1 <$2>" \
188                 --to=nobody@example.com \
189                 --cc-cmd=./cccmd-sed \
190                 --suppress-cc=self \
191                 --smtp-server="$(pwd)/fake.sendmail" \
192                 suppress-self-$3.patch &&
193
194         mv msgtxt1 msgtxt1-$3 &&
195         sed -e '/^$/q' msgtxt1-$3 >"msghdr1-$3" &&
196         >"expected-no-cc-$3" &&
197
198         (grep '^Cc:' msghdr1-$3 >"actual-no-cc-$3";
199          test_cmp expected-no-cc-$3 actual-no-cc-$3)
200 }
201
202 test_suppress_self_unquoted () {
203         test_suppress_self "$1" "$2" "unquoted-$3" <<-EOF
204                 test suppress-cc.self unquoted-$3 with name $1 email $2
205
206                 unquoted-$3
207
208                 cccmd--$1 <$2>
209
210                 Cc: $1 <$2>
211                 Signed-off-by: $1 <$2>
212         EOF
213 }
214
215 test_suppress_self_quoted () {
216         test_suppress_self "$1" "$2" "quoted-$3" <<-EOF
217                 test suppress-cc.self quoted-$3 with name $1 email $2
218
219                 quoted-$3
220
221                 cccmd--"$1" <$2>
222
223                 Cc: $1 <$2>
224                 Cc: "$1" <$2>
225                 Signed-off-by: $1 <$2>
226                 Signed-off-by: "$1" <$2>
227         EOF
228 }
229
230 test_expect_success $PREREQ 'self name is suppressed' "
231         test_suppress_self_unquoted 'A U Thor' 'author@example.com' \
232                 'self_name_suppressed'
233 "
234
235 test_expect_success $PREREQ 'self name with dot is suppressed' "
236         test_suppress_self_quoted 'A U. Thor' 'author@example.com' \
237                 'self_name_dot_suppressed'
238 "
239
240 test_expect_success $PREREQ 'non-ascii self name is suppressed' "
241         test_suppress_self_quoted 'Füñný Nâmé' 'odd_?=mail@example.com' \
242                 'non_ascii_self_suppressed'
243 "
244
245 test_expect_success $PREREQ 'sanitized self name is suppressed' "
246         test_suppress_self_unquoted '\"A U. Thor\"' 'author@example.com' \
247                 'self_name_sanitized_suppressed'
248 "
249
250 test_expect_success $PREREQ 'Show all headers' '
251         git send-email \
252                 --dry-run \
253                 --suppress-cc=sob \
254                 --from="Example <from@example.com>" \
255                 --to=to@example.com \
256                 --cc=cc@example.com \
257                 --bcc=bcc@example.com \
258                 --in-reply-to="<unique-message-id@example.com>" \
259                 --smtp-server relay.example.com \
260                 $patches |
261         sed     -e "s/^\(Date:\).*/\1 DATE-STRING/" \
262                 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
263                 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
264                 >actual-show-all-headers &&
265         test_cmp expected-show-all-headers actual-show-all-headers
266 '
267
268 test_expect_success $PREREQ 'Prompting works' '
269         clean_fake_sendmail &&
270         (echo "to@example.com"
271          echo ""
272         ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
273                 --smtp-server="$(pwd)/fake.sendmail" \
274                 $patches \
275                 2>errors &&
276                 grep "^From: A U Thor <author@example.com>\$" msgtxt1 &&
277                 grep "^To: to@example.com\$" msgtxt1
278 '
279
280 test_expect_success $PREREQ,AUTOIDENT 'implicit ident is allowed' '
281         clean_fake_sendmail &&
282         (sane_unset GIT_AUTHOR_NAME &&
283         sane_unset GIT_AUTHOR_EMAIL &&
284         sane_unset GIT_COMMITTER_NAME &&
285         sane_unset GIT_COMMITTER_EMAIL &&
286         GIT_SEND_EMAIL_NOTTY=1 git send-email \
287                 --smtp-server="$(pwd)/fake.sendmail" \
288                 --to=to@example.com \
289                 $patches </dev/null 2>errors
290         )
291 '
292
293 test_expect_success $PREREQ,!AUTOIDENT 'broken implicit ident aborts send-email' '
294         clean_fake_sendmail &&
295         (sane_unset GIT_AUTHOR_NAME &&
296         sane_unset GIT_AUTHOR_EMAIL &&
297         sane_unset GIT_COMMITTER_NAME &&
298         sane_unset GIT_COMMITTER_EMAIL &&
299         GIT_SEND_EMAIL_NOTTY=1 && export GIT_SEND_EMAIL_NOTTY &&
300         test_must_fail git send-email \
301                 --smtp-server="$(pwd)/fake.sendmail" \
302                 --to=to@example.com \
303                 $patches </dev/null 2>errors &&
304         test_i18ngrep "tell me who you are" errors
305         )
306 '
307
308 test_expect_success $PREREQ 'tocmd works' '
309         clean_fake_sendmail &&
310         cp $patches tocmd.patch &&
311         echo tocmd--tocmd@example.com >>tocmd.patch &&
312         write_script tocmd-sed <<-\EOF &&
313         sed -n -e "s/^tocmd--//p" "$1"
314         EOF
315         git send-email \
316                 --from="Example <nobody@example.com>" \
317                 --to-cmd=./tocmd-sed \
318                 --smtp-server="$(pwd)/fake.sendmail" \
319                 tocmd.patch \
320                 &&
321         grep "^To: tocmd@example.com" msgtxt1
322 '
323
324 test_expect_success $PREREQ 'cccmd works' '
325         clean_fake_sendmail &&
326         cp $patches cccmd.patch &&
327         echo "cccmd--  cccmd@example.com" >>cccmd.patch &&
328         write_script cccmd-sed <<-\EOF &&
329         sed -n -e "s/^cccmd--//p" "$1"
330         EOF
331         git send-email \
332                 --from="Example <nobody@example.com>" \
333                 --to=nobody@example.com \
334                 --cc-cmd=./cccmd-sed \
335                 --smtp-server="$(pwd)/fake.sendmail" \
336                 cccmd.patch \
337                 &&
338         grep "^ cccmd@example.com" msgtxt1
339 '
340
341 test_expect_success $PREREQ 'reject long lines' '
342         z8=zzzzzzzz &&
343         z64=$z8$z8$z8$z8$z8$z8$z8$z8 &&
344         z512=$z64$z64$z64$z64$z64$z64$z64$z64 &&
345         clean_fake_sendmail &&
346         cp $patches longline.patch &&
347         echo $z512$z512 >>longline.patch &&
348         test_must_fail git send-email \
349                 --from="Example <nobody@example.com>" \
350                 --to=nobody@example.com \
351                 --smtp-server="$(pwd)/fake.sendmail" \
352                 $patches longline.patch \
353                 2>errors &&
354         grep longline.patch errors
355 '
356
357 test_expect_success $PREREQ 'no patch was sent' '
358         ! test -e commandline1
359 '
360
361 test_expect_success $PREREQ 'Author From: in message body' '
362         clean_fake_sendmail &&
363         git send-email \
364                 --from="Example <nobody@example.com>" \
365                 --to=nobody@example.com \
366                 --smtp-server="$(pwd)/fake.sendmail" \
367                 $patches &&
368         sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
369         grep "From: A <author@example.com>" msgbody1
370 '
371
372 test_expect_success $PREREQ 'Author From: not in message body' '
373         clean_fake_sendmail &&
374         git send-email \
375                 --from="A <author@example.com>" \
376                 --to=nobody@example.com \
377                 --smtp-server="$(pwd)/fake.sendmail" \
378                 $patches &&
379         sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
380         ! grep "From: A <author@example.com>" msgbody1
381 '
382
383 test_expect_success $PREREQ 'allow long lines with --no-validate' '
384         git send-email \
385                 --from="Example <nobody@example.com>" \
386                 --to=nobody@example.com \
387                 --smtp-server="$(pwd)/fake.sendmail" \
388                 --novalidate \
389                 $patches longline.patch \
390                 2>errors
391 '
392
393 test_expect_success $PREREQ 'Invalid In-Reply-To' '
394         clean_fake_sendmail &&
395         git send-email \
396                 --from="Example <nobody@example.com>" \
397                 --to=nobody@example.com \
398                 --in-reply-to=" " \
399                 --smtp-server="$(pwd)/fake.sendmail" \
400                 $patches \
401                 2>errors &&
402         ! grep "^In-Reply-To: < *>" msgtxt1
403 '
404
405 test_expect_success $PREREQ 'Valid In-Reply-To when prompting' '
406         clean_fake_sendmail &&
407         (echo "From Example <from@example.com>"
408          echo "To Example <to@example.com>"
409          echo ""
410         ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
411                 --smtp-server="$(pwd)/fake.sendmail" \
412                 $patches 2>errors &&
413         ! grep "^In-Reply-To: < *>" msgtxt1
414 '
415
416 test_expect_success $PREREQ 'In-Reply-To without --chain-reply-to' '
417         clean_fake_sendmail &&
418         echo "<unique-message-id@example.com>" >expect &&
419         git send-email \
420                 --from="Example <nobody@example.com>" \
421                 --to=nobody@example.com \
422                 --nochain-reply-to \
423                 --in-reply-to="$(cat expect)" \
424                 --smtp-server="$(pwd)/fake.sendmail" \
425                 $patches $patches $patches \
426                 2>errors &&
427         # The first message is a reply to --in-reply-to
428         sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
429         test_cmp expect actual &&
430         # Second and subsequent messages are replies to the first one
431         sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
432         sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
433         test_cmp expect actual &&
434         sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
435         test_cmp expect actual
436 '
437
438 test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' '
439         clean_fake_sendmail &&
440         echo "<unique-message-id@example.com>" >expect &&
441         git send-email \
442                 --from="Example <nobody@example.com>" \
443                 --to=nobody@example.com \
444                 --chain-reply-to \
445                 --in-reply-to="$(cat expect)" \
446                 --smtp-server="$(pwd)/fake.sendmail" \
447                 $patches $patches $patches \
448                 2>errors &&
449         sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
450         test_cmp expect actual &&
451         sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
452         sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
453         test_cmp expect actual &&
454         sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt2 >expect &&
455         sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
456         test_cmp expect actual
457 '
458
459 test_expect_success $PREREQ 'setup fake editor' '
460         write_script fake-editor <<-\EOF
461         echo fake edit >>"$1"
462         EOF
463 '
464
465 test_set_editor "$(pwd)/fake-editor"
466
467 test_expect_success $PREREQ '--compose works' '
468         clean_fake_sendmail &&
469         git send-email \
470         --compose --subject foo \
471         --from="Example <nobody@example.com>" \
472         --to=nobody@example.com \
473         --smtp-server="$(pwd)/fake.sendmail" \
474         $patches \
475         2>errors
476 '
477
478 test_expect_success $PREREQ 'first message is compose text' '
479         grep "^fake edit" msgtxt1
480 '
481
482 test_expect_success $PREREQ 'second message is patch' '
483         grep "Subject:.*Second" msgtxt2
484 '
485
486 test_expect_success $PREREQ 'setup expect' "
487 cat >expected-suppress-sob <<\EOF
488 0001-Second.patch
489 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
490 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
491 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
492 Dry-OK. Log says:
493 Server: relay.example.com
494 MAIL FROM:<from@example.com>
495 RCPT TO:<to@example.com>
496 RCPT TO:<cc@example.com>
497 RCPT TO:<author@example.com>
498 RCPT TO:<one@example.com>
499 RCPT TO:<two@example.com>
500 From: Example <from@example.com>
501 To: to@example.com
502 Cc: cc@example.com,
503         A <author@example.com>,
504         One <one@example.com>,
505         two@example.com
506 Subject: [PATCH 1/1] Second.
507 Date: DATE-STRING
508 Message-Id: MESSAGE-ID-STRING
509 X-Mailer: X-MAILER-STRING
510
511 Result: OK
512 EOF
513 "
514
515 test_suppression () {
516         git send-email \
517                 --dry-run \
518                 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
519                 --from="Example <from@example.com>" \
520                 --to=to@example.com \
521                 --smtp-server relay.example.com \
522                 $patches |
523         sed     -e "s/^\(Date:\).*/\1 DATE-STRING/" \
524                 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
525                 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
526                 >actual-suppress-$1${2+"-$2"} &&
527         test_cmp expected-suppress-$1${2+"-$2"} actual-suppress-$1${2+"-$2"}
528 }
529
530 test_expect_success $PREREQ 'sendemail.cc set' '
531         git config sendemail.cc cc@example.com &&
532         test_suppression sob
533 '
534
535 test_expect_success $PREREQ 'setup expect' "
536 cat >expected-suppress-sob <<\EOF
537 0001-Second.patch
538 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
539 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
540 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
541 Dry-OK. Log says:
542 Server: relay.example.com
543 MAIL FROM:<from@example.com>
544 RCPT TO:<to@example.com>
545 RCPT TO:<author@example.com>
546 RCPT TO:<one@example.com>
547 RCPT TO:<two@example.com>
548 From: Example <from@example.com>
549 To: to@example.com
550 Cc: A <author@example.com>,
551         One <one@example.com>,
552         two@example.com
553 Subject: [PATCH 1/1] Second.
554 Date: DATE-STRING
555 Message-Id: MESSAGE-ID-STRING
556 X-Mailer: X-MAILER-STRING
557
558 Result: OK
559 EOF
560 "
561
562 test_expect_success $PREREQ 'sendemail.cc unset' '
563         git config --unset sendemail.cc &&
564         test_suppression sob
565 '
566
567 test_expect_success $PREREQ 'setup expect' "
568 cat >expected-suppress-cccmd <<\EOF
569 0001-Second.patch
570 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
571 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
572 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
573 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
574 Dry-OK. Log says:
575 Server: relay.example.com
576 MAIL FROM:<from@example.com>
577 RCPT TO:<to@example.com>
578 RCPT TO:<author@example.com>
579 RCPT TO:<one@example.com>
580 RCPT TO:<two@example.com>
581 RCPT TO:<committer@example.com>
582 From: Example <from@example.com>
583 To: to@example.com
584 Cc: A <author@example.com>,
585         One <one@example.com>,
586         two@example.com,
587         C O Mitter <committer@example.com>
588 Subject: [PATCH 1/1] Second.
589 Date: DATE-STRING
590 Message-Id: MESSAGE-ID-STRING
591 X-Mailer: X-MAILER-STRING
592
593 Result: OK
594 EOF
595 "
596
597 test_expect_success $PREREQ 'sendemail.cccmd' '
598         write_script cccmd <<-\EOF &&
599         echo cc-cmd@example.com
600         EOF
601         git config sendemail.cccmd ./cccmd &&
602         test_suppression cccmd
603 '
604
605 test_expect_success $PREREQ 'setup expect' '
606 cat >expected-suppress-all <<\EOF
607 0001-Second.patch
608 Dry-OK. Log says:
609 Server: relay.example.com
610 MAIL FROM:<from@example.com>
611 RCPT TO:<to@example.com>
612 From: Example <from@example.com>
613 To: to@example.com
614 Subject: [PATCH 1/1] Second.
615 Date: DATE-STRING
616 Message-Id: MESSAGE-ID-STRING
617 X-Mailer: X-MAILER-STRING
618
619 Result: OK
620 EOF
621 '
622
623 test_expect_success $PREREQ '--suppress-cc=all' '
624         test_suppression all
625 '
626
627 test_expect_success $PREREQ 'setup expect' "
628 cat >expected-suppress-body <<\EOF
629 0001-Second.patch
630 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
631 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
632 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
633 (cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
634 Dry-OK. Log says:
635 Server: relay.example.com
636 MAIL FROM:<from@example.com>
637 RCPT TO:<to@example.com>
638 RCPT TO:<author@example.com>
639 RCPT TO:<one@example.com>
640 RCPT TO:<two@example.com>
641 RCPT TO:<cc-cmd@example.com>
642 From: Example <from@example.com>
643 To: to@example.com
644 Cc: A <author@example.com>,
645         One <one@example.com>,
646         two@example.com,
647         cc-cmd@example.com
648 Subject: [PATCH 1/1] Second.
649 Date: DATE-STRING
650 Message-Id: MESSAGE-ID-STRING
651 X-Mailer: X-MAILER-STRING
652
653 Result: OK
654 EOF
655 "
656
657 test_expect_success $PREREQ '--suppress-cc=body' '
658         test_suppression body
659 '
660
661 test_expect_success $PREREQ 'setup expect' "
662 cat >expected-suppress-body-cccmd <<\EOF
663 0001-Second.patch
664 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
665 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
666 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
667 Dry-OK. Log says:
668 Server: relay.example.com
669 MAIL FROM:<from@example.com>
670 RCPT TO:<to@example.com>
671 RCPT TO:<author@example.com>
672 RCPT TO:<one@example.com>
673 RCPT TO:<two@example.com>
674 From: Example <from@example.com>
675 To: to@example.com
676 Cc: A <author@example.com>,
677         One <one@example.com>,
678         two@example.com
679 Subject: [PATCH 1/1] Second.
680 Date: DATE-STRING
681 Message-Id: MESSAGE-ID-STRING
682 X-Mailer: X-MAILER-STRING
683
684 Result: OK
685 EOF
686 "
687
688 test_expect_success $PREREQ '--suppress-cc=body --suppress-cc=cccmd' '
689         test_suppression body cccmd
690 '
691
692 test_expect_success $PREREQ 'setup expect' "
693 cat >expected-suppress-sob <<\EOF
694 0001-Second.patch
695 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
696 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
697 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
698 Dry-OK. Log says:
699 Server: relay.example.com
700 MAIL FROM:<from@example.com>
701 RCPT TO:<to@example.com>
702 RCPT TO:<author@example.com>
703 RCPT TO:<one@example.com>
704 RCPT TO:<two@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 Subject: [PATCH 1/1] Second.
711 Date: DATE-STRING
712 Message-Id: MESSAGE-ID-STRING
713 X-Mailer: X-MAILER-STRING
714
715 Result: OK
716 EOF
717 "
718
719 test_expect_success $PREREQ '--suppress-cc=sob' '
720         test_might_fail git config --unset sendemail.cccmd &&
721         test_suppression sob
722 '
723
724 test_expect_success $PREREQ 'setup expect' "
725 cat >expected-suppress-bodycc <<\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 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
731 Dry-OK. Log says:
732 Server: relay.example.com
733 MAIL FROM:<from@example.com>
734 RCPT TO:<to@example.com>
735 RCPT TO:<author@example.com>
736 RCPT TO:<one@example.com>
737 RCPT TO:<two@example.com>
738 RCPT TO:<committer@example.com>
739 From: Example <from@example.com>
740 To: to@example.com
741 Cc: A <author@example.com>,
742         One <one@example.com>,
743         two@example.com,
744         C O Mitter <committer@example.com>
745 Subject: [PATCH 1/1] Second.
746 Date: DATE-STRING
747 Message-Id: MESSAGE-ID-STRING
748 X-Mailer: X-MAILER-STRING
749
750 Result: OK
751 EOF
752 "
753
754 test_expect_success $PREREQ '--suppress-cc=bodycc' '
755         test_suppression bodycc
756 '
757
758 test_expect_success $PREREQ 'setup expect' "
759 cat >expected-suppress-cc <<\EOF
760 0001-Second.patch
761 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
762 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
763 Dry-OK. Log says:
764 Server: relay.example.com
765 MAIL FROM:<from@example.com>
766 RCPT TO:<to@example.com>
767 RCPT TO:<author@example.com>
768 RCPT TO:<committer@example.com>
769 From: Example <from@example.com>
770 To: to@example.com
771 Cc: A <author@example.com>,
772         C O Mitter <committer@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=cc' '
783         test_suppression cc
784 '
785
786 test_confirm () {
787         echo y | \
788                 GIT_SEND_EMAIL_NOTTY=1 \
789                 git send-email \
790                 --from="Example <nobody@example.com>" \
791                 --to=nobody@example.com \
792                 --smtp-server="$(pwd)/fake.sendmail" \
793                 $@ $patches >stdout &&
794         grep "Send this email" stdout
795 }
796
797 test_expect_success $PREREQ '--confirm=always' '
798         test_confirm --confirm=always --suppress-cc=all
799 '
800
801 test_expect_success $PREREQ '--confirm=auto' '
802         test_confirm --confirm=auto
803 '
804
805 test_expect_success $PREREQ '--confirm=cc' '
806         test_confirm --confirm=cc
807 '
808
809 test_expect_success $PREREQ '--confirm=compose' '
810         test_confirm --confirm=compose --compose
811 '
812
813 test_expect_success $PREREQ 'confirm by default (due to cc)' '
814         CONFIRM=$(git config --get sendemail.confirm) &&
815         git config --unset sendemail.confirm &&
816         test_confirm
817         ret="$?"
818         git config sendemail.confirm ${CONFIRM:-never}
819         test $ret = "0"
820 '
821
822 test_expect_success $PREREQ 'confirm by default (due to --compose)' '
823         CONFIRM=$(git config --get sendemail.confirm) &&
824         git config --unset sendemail.confirm &&
825         test_confirm --suppress-cc=all --compose
826         ret="$?"
827         git config sendemail.confirm ${CONFIRM:-never}
828         test $ret = "0"
829 '
830
831 test_expect_success $PREREQ 'confirm detects EOF (inform assumes y)' '
832         CONFIRM=$(git config --get sendemail.confirm) &&
833         git config --unset sendemail.confirm &&
834         rm -fr outdir &&
835         git format-patch -2 -o outdir &&
836         GIT_SEND_EMAIL_NOTTY=1 \
837                 git send-email \
838                         --from="Example <nobody@example.com>" \
839                         --to=nobody@example.com \
840                         --smtp-server="$(pwd)/fake.sendmail" \
841                         outdir/*.patch </dev/null
842         ret="$?"
843         git config sendemail.confirm ${CONFIRM:-never}
844         test $ret = "0"
845 '
846
847 test_expect_success $PREREQ 'confirm detects EOF (auto causes failure)' '
848         CONFIRM=$(git config --get sendemail.confirm) &&
849         git config sendemail.confirm auto &&
850         GIT_SEND_EMAIL_NOTTY=1 &&
851         export GIT_SEND_EMAIL_NOTTY &&
852                 test_must_fail git send-email \
853                         --from="Example <nobody@example.com>" \
854                         --to=nobody@example.com \
855                         --smtp-server="$(pwd)/fake.sendmail" \
856                         $patches </dev/null
857         ret="$?"
858         git config sendemail.confirm ${CONFIRM:-never}
859         test $ret = "0"
860 '
861
862 test_expect_success $PREREQ 'confirm does not loop forever' '
863         CONFIRM=$(git config --get sendemail.confirm) &&
864         git config sendemail.confirm auto &&
865         GIT_SEND_EMAIL_NOTTY=1 &&
866         export GIT_SEND_EMAIL_NOTTY &&
867                 yes "bogus" | test_must_fail git send-email \
868                         --from="Example <nobody@example.com>" \
869                         --to=nobody@example.com \
870                         --smtp-server="$(pwd)/fake.sendmail" \
871                         $patches
872         ret="$?"
873         git config sendemail.confirm ${CONFIRM:-never}
874         test $ret = "0"
875 '
876
877 test_expect_success $PREREQ 'utf8 Cc is rfc2047 encoded' '
878         clean_fake_sendmail &&
879         rm -fr outdir &&
880         git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
881         git send-email \
882         --from="Example <nobody@example.com>" \
883         --to=nobody@example.com \
884         --smtp-server="$(pwd)/fake.sendmail" \
885         outdir/*.patch &&
886         grep "^ " msgtxt1 |
887         grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
888 '
889
890 test_expect_success $PREREQ '--compose adds MIME for utf8 body' '
891         clean_fake_sendmail &&
892         write_script fake-editor-utf8 <<-\EOF &&
893         echo "utf8 body: àéìöú" >>"$1"
894         EOF
895         GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
896         git send-email \
897                 --compose --subject foo \
898                 --from="Example <nobody@example.com>" \
899                 --to=nobody@example.com \
900                 --smtp-server="$(pwd)/fake.sendmail" \
901                 $patches &&
902         grep "^utf8 body" msgtxt1 &&
903         grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
904 '
905
906 test_expect_success $PREREQ '--compose respects user mime type' '
907         clean_fake_sendmail &&
908         write_script fake-editor-utf8-mime <<-\EOF &&
909         cat >"$1" <<-\EOM
910         MIME-Version: 1.0
911         Content-Type: text/plain; charset=iso-8859-1
912         Content-Transfer-Encoding: 8bit
913         Subject: foo
914
915         utf8 body: àéìöú
916         EOM
917         EOF
918         GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
919         git send-email \
920                 --compose --subject foo \
921                 --from="Example <nobody@example.com>" \
922                 --to=nobody@example.com \
923                 --smtp-server="$(pwd)/fake.sendmail" \
924                 $patches &&
925         grep "^utf8 body" msgtxt1 &&
926         grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
927         ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
928 '
929
930 test_expect_success $PREREQ '--compose adds MIME for utf8 subject' '
931         clean_fake_sendmail &&
932         GIT_EDITOR="\"$(pwd)/fake-editor\"" \
933         git send-email \
934                 --compose --subject utf8-sübjëct \
935                 --from="Example <nobody@example.com>" \
936                 --to=nobody@example.com \
937                 --smtp-server="$(pwd)/fake.sendmail" \
938                 $patches &&
939         grep "^fake edit" msgtxt1 &&
940         grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
941 '
942
943 test_expect_success $PREREQ 'utf8 author is correctly passed on' '
944         clean_fake_sendmail &&
945         test_commit weird_author &&
946         test_when_finished "git reset --hard HEAD^" &&
947         git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
948         git format-patch --stdout -1 >funny_name.patch &&
949         git send-email --from="Example <nobody@example.com>" \
950                 --to=nobody@example.com \
951                 --smtp-server="$(pwd)/fake.sendmail" \
952                 funny_name.patch &&
953         grep "^From: Füñný Nâmé <odd_?=mail@example.com>" msgtxt1
954 '
955
956 test_expect_success $PREREQ 'utf8 sender is not duplicated' '
957         clean_fake_sendmail &&
958         test_commit weird_sender &&
959         test_when_finished "git reset --hard HEAD^" &&
960         git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
961         git format-patch --stdout -1 >funny_name.patch &&
962         git send-email --from="Füñný Nâmé <odd_?=mail@example.com>" \
963                 --to=nobody@example.com \
964                 --smtp-server="$(pwd)/fake.sendmail" \
965                 funny_name.patch &&
966         grep "^From: " msgtxt1 >msgfrom &&
967         test_line_count = 1 msgfrom
968 '
969
970 test_expect_success $PREREQ 'sendemail.composeencoding works' '
971         clean_fake_sendmail &&
972         git config sendemail.composeencoding iso-8859-1 &&
973         write_script fake-editor-utf8 <<-\EOF &&
974         echo "utf8 body: àéìöú" >>"$1"
975         EOF
976         GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
977         git send-email \
978                 --compose --subject foo \
979                 --from="Example <nobody@example.com>" \
980                 --to=nobody@example.com \
981                 --smtp-server="$(pwd)/fake.sendmail" \
982                 $patches &&
983         grep "^utf8 body" msgtxt1 &&
984         grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
985 '
986
987 test_expect_success $PREREQ '--compose-encoding works' '
988         clean_fake_sendmail &&
989         write_script fake-editor-utf8 <<-\EOF &&
990         echo "utf8 body: àéìöú" >>"$1"
991         EOF
992         GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
993         git send-email \
994                 --compose-encoding iso-8859-1 \
995                 --compose --subject foo \
996                 --from="Example <nobody@example.com>" \
997                 --to=nobody@example.com \
998                 --smtp-server="$(pwd)/fake.sendmail" \
999                 $patches &&
1000         grep "^utf8 body" msgtxt1 &&
1001         grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1002 '
1003
1004 test_expect_success $PREREQ '--compose-encoding overrides sendemail.composeencoding' '
1005         clean_fake_sendmail &&
1006         git config sendemail.composeencoding iso-8859-1 &&
1007         write_script fake-editor-utf8 <<-\EOF &&
1008         echo "utf8 body: àéìöú" >>"$1"
1009         EOF
1010         GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1011         git send-email \
1012                 --compose-encoding iso-8859-2 \
1013                 --compose --subject foo \
1014                 --from="Example <nobody@example.com>" \
1015                 --to=nobody@example.com \
1016                 --smtp-server="$(pwd)/fake.sendmail" \
1017                 $patches &&
1018         grep "^utf8 body" msgtxt1 &&
1019         grep "^Content-Type: text/plain; charset=iso-8859-2" msgtxt1
1020 '
1021
1022 test_expect_success $PREREQ '--compose-encoding adds correct MIME for subject' '
1023         clean_fake_sendmail &&
1024         GIT_EDITOR="\"$(pwd)/fake-editor\"" \
1025         git send-email \
1026                 --compose-encoding iso-8859-2 \
1027                 --compose --subject utf8-sübjëct \
1028                 --from="Example <nobody@example.com>" \
1029                 --to=nobody@example.com \
1030                 --smtp-server="$(pwd)/fake.sendmail" \
1031                 $patches &&
1032         grep "^fake edit" msgtxt1 &&
1033         grep "^Subject: =?iso-8859-2?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
1034 '
1035
1036 test_expect_success $PREREQ 'detects ambiguous reference/file conflict' '
1037         echo master >master &&
1038         git add master &&
1039         git commit -m"add master" &&
1040         test_must_fail git send-email --dry-run master 2>errors &&
1041         grep disambiguate errors
1042 '
1043
1044 test_expect_success $PREREQ 'feed two files' '
1045         rm -fr outdir &&
1046         git format-patch -2 -o outdir &&
1047         git send-email \
1048                 --dry-run \
1049                 --from="Example <nobody@example.com>" \
1050                 --to=nobody@example.com \
1051                 outdir/000?-*.patch 2>errors >out &&
1052         grep "^Subject: " out >subjects &&
1053         test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
1054         test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"
1055 '
1056
1057 test_expect_success $PREREQ 'in-reply-to but no threading' '
1058         git send-email \
1059                 --dry-run \
1060                 --from="Example <nobody@example.com>" \
1061                 --to=nobody@example.com \
1062                 --in-reply-to="<in-reply-id@example.com>" \
1063                 --nothread \
1064                 $patches |
1065         grep "In-Reply-To: <in-reply-id@example.com>"
1066 '
1067
1068 test_expect_success $PREREQ 'no in-reply-to and no threading' '
1069         git send-email \
1070                 --dry-run \
1071                 --from="Example <nobody@example.com>" \
1072                 --to=nobody@example.com \
1073                 --nothread \
1074                 $patches $patches >stdout &&
1075         ! grep "In-Reply-To: " stdout
1076 '
1077
1078 test_expect_success $PREREQ 'threading but no chain-reply-to' '
1079         git send-email \
1080                 --dry-run \
1081                 --from="Example <nobody@example.com>" \
1082                 --to=nobody@example.com \
1083                 --thread \
1084                 --nochain-reply-to \
1085                 $patches $patches >stdout &&
1086         grep "In-Reply-To: " stdout
1087 '
1088
1089 test_expect_success $PREREQ 'sendemail.to works' '
1090         git config --replace-all sendemail.to "Somebody <somebody@ex.com>" &&
1091         git send-email \
1092                 --dry-run \
1093                 --from="Example <nobody@example.com>" \
1094                 $patches $patches >stdout &&
1095         grep "To: Somebody <somebody@ex.com>" stdout
1096 '
1097
1098 test_expect_success $PREREQ '--no-to overrides sendemail.to' '
1099         git send-email \
1100                 --dry-run \
1101                 --from="Example <nobody@example.com>" \
1102                 --no-to \
1103                 --to=nobody@example.com \
1104                 $patches $patches >stdout &&
1105         grep "To: nobody@example.com" stdout &&
1106         ! grep "To: Somebody <somebody@ex.com>" stdout
1107 '
1108
1109 test_expect_success $PREREQ 'sendemail.cc works' '
1110         git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" &&
1111         git send-email \
1112                 --dry-run \
1113                 --from="Example <nobody@example.com>" \
1114                 --to=nobody@example.com \
1115                 $patches $patches >stdout &&
1116         grep "Cc: Somebody <somebody@ex.com>" stdout
1117 '
1118
1119 test_expect_success $PREREQ '--no-cc overrides sendemail.cc' '
1120         git send-email \
1121                 --dry-run \
1122                 --from="Example <nobody@example.com>" \
1123                 --no-cc \
1124                 --cc=bodies@example.com \
1125                 --to=nobody@example.com \
1126                 $patches $patches >stdout &&
1127         grep "Cc: bodies@example.com" stdout &&
1128         ! grep "Cc: Somebody <somebody@ex.com>" stdout
1129 '
1130
1131 test_expect_success $PREREQ 'sendemail.bcc works' '
1132         git config --replace-all sendemail.bcc "Other <other@ex.com>" &&
1133         git send-email \
1134                 --dry-run \
1135                 --from="Example <nobody@example.com>" \
1136                 --to=nobody@example.com \
1137                 --smtp-server relay.example.com \
1138                 $patches $patches >stdout &&
1139         grep "RCPT TO:<other@ex.com>" stdout
1140 '
1141
1142 test_expect_success $PREREQ '--no-bcc overrides sendemail.bcc' '
1143         git send-email \
1144                 --dry-run \
1145                 --from="Example <nobody@example.com>" \
1146                 --no-bcc \
1147                 --bcc=bodies@example.com \
1148                 --to=nobody@example.com \
1149                 --smtp-server relay.example.com \
1150                 $patches $patches >stdout &&
1151         grep "RCPT TO:<bodies@example.com>" stdout &&
1152         ! grep "RCPT TO:<other@ex.com>" stdout
1153 '
1154
1155 test_expect_success $PREREQ 'patches To headers are used by default' '
1156         patch=`git format-patch -1 --to="bodies@example.com"` &&
1157         test_when_finished "rm $patch" &&
1158         git send-email \
1159                 --dry-run \
1160                 --from="Example <nobody@example.com>" \
1161                 --smtp-server relay.example.com \
1162                 $patch >stdout &&
1163         grep "RCPT TO:<bodies@example.com>" stdout
1164 '
1165
1166 test_expect_success $PREREQ 'patches To headers are appended to' '
1167         patch=`git format-patch -1 --to="bodies@example.com"` &&
1168         test_when_finished "rm $patch" &&
1169         git send-email \
1170                 --dry-run \
1171                 --from="Example <nobody@example.com>" \
1172                 --to=nobody@example.com \
1173                 --smtp-server relay.example.com \
1174                 $patch >stdout &&
1175         grep "RCPT TO:<bodies@example.com>" stdout &&
1176         grep "RCPT TO:<nobody@example.com>" stdout
1177 '
1178
1179 test_expect_success $PREREQ 'To headers from files reset each patch' '
1180         patch1=`git format-patch -1 --to="bodies@example.com"` &&
1181         patch2=`git format-patch -1 --to="other@example.com" HEAD~` &&
1182         test_when_finished "rm $patch1 && rm $patch2" &&
1183         git send-email \
1184                 --dry-run \
1185                 --from="Example <nobody@example.com>" \
1186                 --to="nobody@example.com" \
1187                 --smtp-server relay.example.com \
1188                 $patch1 $patch2 >stdout &&
1189         test $(grep -c "RCPT TO:<bodies@example.com>" stdout) = 1 &&
1190         test $(grep -c "RCPT TO:<nobody@example.com>" stdout) = 2 &&
1191         test $(grep -c "RCPT TO:<other@example.com>" stdout) = 1
1192 '
1193
1194 test_expect_success $PREREQ 'setup expect' '
1195 cat >email-using-8bit <<\EOF
1196 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1197 Message-Id: <bogus-message-id@example.com>
1198 From: author@example.com
1199 Date: Sat, 12 Jun 2010 15:53:58 +0200
1200 Subject: subject goes here
1201
1202 Dieser deutsche Text enthält einen Umlaut!
1203 EOF
1204 '
1205
1206 test_expect_success $PREREQ 'setup expect' '
1207         echo "Subject: subject goes here" >expected
1208 '
1209
1210 test_expect_success $PREREQ 'ASCII subject is not RFC2047 quoted' '
1211         clean_fake_sendmail &&
1212         echo bogus |
1213         git send-email --from=author@example.com --to=nobody@example.com \
1214                         --smtp-server="$(pwd)/fake.sendmail" \
1215                         --8bit-encoding=UTF-8 \
1216                         email-using-8bit >stdout &&
1217         grep "Subject" msgtxt1 >actual &&
1218         test_cmp expected actual
1219 '
1220
1221 test_expect_success $PREREQ 'setup expect' '
1222         cat >content-type-decl <<-\EOF
1223         MIME-Version: 1.0
1224         Content-Type: text/plain; charset=UTF-8
1225         Content-Transfer-Encoding: 8bit
1226         EOF
1227 '
1228
1229 test_expect_success $PREREQ 'asks about and fixes 8bit encodings' '
1230         clean_fake_sendmail &&
1231         echo |
1232         git send-email --from=author@example.com --to=nobody@example.com \
1233                         --smtp-server="$(pwd)/fake.sendmail" \
1234                         email-using-8bit >stdout &&
1235         grep "do not declare a Content-Transfer-Encoding" stdout &&
1236         grep email-using-8bit stdout &&
1237         grep "Which 8bit encoding" stdout &&
1238         egrep "Content|MIME" msgtxt1 >actual &&
1239         test_cmp actual content-type-decl
1240 '
1241
1242 test_expect_success $PREREQ 'sendemail.8bitEncoding works' '
1243         clean_fake_sendmail &&
1244         git config sendemail.assume8bitEncoding UTF-8 &&
1245         echo bogus |
1246         git send-email --from=author@example.com --to=nobody@example.com \
1247                         --smtp-server="$(pwd)/fake.sendmail" \
1248                         email-using-8bit >stdout &&
1249         egrep "Content|MIME" msgtxt1 >actual &&
1250         test_cmp actual content-type-decl
1251 '
1252
1253 test_expect_success $PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
1254         clean_fake_sendmail &&
1255         git config sendemail.assume8bitEncoding "bogus too" &&
1256         echo bogus |
1257         git send-email --from=author@example.com --to=nobody@example.com \
1258                         --smtp-server="$(pwd)/fake.sendmail" \
1259                         --8bit-encoding=UTF-8 \
1260                         email-using-8bit >stdout &&
1261         egrep "Content|MIME" msgtxt1 >actual &&
1262         test_cmp actual content-type-decl
1263 '
1264
1265 test_expect_success $PREREQ 'setup expect' '
1266         cat >email-using-8bit <<-\EOF
1267         From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1268         Message-Id: <bogus-message-id@example.com>
1269         From: author@example.com
1270         Date: Sat, 12 Jun 2010 15:53:58 +0200
1271         Subject: Dieser Betreff enthält auch einen Umlaut!
1272
1273         Nothing to see here.
1274         EOF
1275 '
1276
1277 test_expect_success $PREREQ 'setup expect' '
1278         cat >expected <<-\EOF
1279         Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
1280         EOF
1281 '
1282
1283 test_expect_success $PREREQ '--8bit-encoding also treats subject' '
1284         clean_fake_sendmail &&
1285         echo bogus |
1286         git send-email --from=author@example.com --to=nobody@example.com \
1287                         --smtp-server="$(pwd)/fake.sendmail" \
1288                         --8bit-encoding=UTF-8 \
1289                         email-using-8bit >stdout &&
1290         grep "Subject" msgtxt1 >actual &&
1291         test_cmp expected actual
1292 '
1293
1294 test_expect_success $PREREQ 'setup expect' '
1295         cat >email-using-8bit <<-\EOF
1296         From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1297         Message-Id: <bogus-message-id@example.com>
1298         From: A U Thor <author@example.com>
1299         Date: Sat, 12 Jun 2010 15:53:58 +0200
1300         Content-Type: text/plain; charset=UTF-8
1301         Subject: Nothing to see here.
1302
1303         Dieser Betreff enthält auch einen Umlaut!
1304         EOF
1305 '
1306
1307 test_expect_success $PREREQ 'sendemail.transferencoding=7bit fails on 8bit data' '
1308         clean_fake_sendmail &&
1309         git config sendemail.transferEncoding 7bit &&
1310         test_must_fail git send-email \
1311                 --transfer-encoding=7bit \
1312                 --smtp-server="$(pwd)/fake.sendmail" \
1313                 email-using-8bit \
1314                 2>errors >out &&
1315         grep "cannot send message as 7bit" errors &&
1316         test -z "$(ls msgtxt*)"
1317 '
1318
1319 test_expect_success $PREREQ '--transfer-encoding overrides sendemail.transferEncoding' '
1320         clean_fake_sendmail &&
1321         git config sendemail.transferEncoding 8bit
1322         test_must_fail git send-email \
1323                 --transfer-encoding=7bit \
1324                 --smtp-server="$(pwd)/fake.sendmail" \
1325                 email-using-8bit \
1326                 2>errors >out &&
1327         grep "cannot send message as 7bit" errors &&
1328         test -z "$(ls msgtxt*)"
1329 '
1330
1331 test_expect_success $PREREQ 'sendemail.transferencoding=8bit' '
1332         clean_fake_sendmail &&
1333         git send-email \
1334                 --transfer-encoding=8bit \
1335                 --smtp-server="$(pwd)/fake.sendmail" \
1336                 email-using-8bit \
1337                 2>errors >out &&
1338         sed '1,/^$/d' msgtxt1 >actual &&
1339         sed '1,/^$/d' email-using-8bit >expected &&
1340         test_cmp expected actual
1341 '
1342
1343 test_expect_success $PREREQ 'setup expect' '
1344         cat >expected <<-\EOF
1345         Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1346         EOF
1347 '
1348
1349 test_expect_success $PREREQ '8-bit and sendemail.transferencoding=quoted-printable' '
1350         clean_fake_sendmail &&
1351         git send-email \
1352                 --transfer-encoding=quoted-printable \
1353                 --smtp-server="$(pwd)/fake.sendmail" \
1354                 email-using-8bit \
1355                 2>errors >out &&
1356         sed '1,/^$/d' msgtxt1 >actual &&
1357         test_cmp expected actual
1358 '
1359
1360 test_expect_success $PREREQ 'setup expect' '
1361         cat >expected <<-\EOF
1362         RGllc2VyIEJldHJlZmYgZW50aMOkbHQgYXVjaCBlaW5lbiBVbWxhdXQhCg==
1363         EOF
1364 '
1365
1366 test_expect_success $PREREQ '8-bit and sendemail.transferencoding=base64' '
1367         clean_fake_sendmail &&
1368         git send-email \
1369                 --transfer-encoding=base64 \
1370                 --smtp-server="$(pwd)/fake.sendmail" \
1371                 email-using-8bit \
1372                 2>errors >out &&
1373         sed '1,/^$/d' msgtxt1 >actual &&
1374         test_cmp expected actual
1375 '
1376
1377 test_expect_success $PREREQ 'setup expect' '
1378         cat >email-using-qp <<-\EOF
1379         From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1380         Message-Id: <bogus-message-id@example.com>
1381         From: A U Thor <author@example.com>
1382         Date: Sat, 12 Jun 2010 15:53:58 +0200
1383         MIME-Version: 1.0
1384         Content-Transfer-Encoding: quoted-printable
1385         Content-Type: text/plain; charset=UTF-8
1386         Subject: Nothing to see here.
1387
1388         Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1389         EOF
1390 '
1391
1392 test_expect_success $PREREQ 'convert from quoted-printable to base64' '
1393         clean_fake_sendmail &&
1394         git send-email \
1395                 --transfer-encoding=base64 \
1396                 --smtp-server="$(pwd)/fake.sendmail" \
1397                 email-using-qp \
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 tr -d '\\015' | tr '%' '\\015' >email-using-crlf <<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 Content-Type: text/plain; charset=UTF-8
1410 Subject: Nothing to see here.
1411
1412 Look, I have a CRLF and an = sign!%
1413 EOF
1414 "
1415
1416 test_expect_success $PREREQ 'setup expect' '
1417         cat >expected <<-\EOF
1418         Look, I have a CRLF and an =3D sign!=0D
1419         EOF
1420 '
1421
1422 test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=quoted-printable' '
1423         clean_fake_sendmail &&
1424         git send-email \
1425                 --transfer-encoding=quoted-printable \
1426                 --smtp-server="$(pwd)/fake.sendmail" \
1427                 email-using-crlf \
1428                 2>errors >out &&
1429         sed '1,/^$/d' msgtxt1 >actual &&
1430         test_cmp expected actual
1431 '
1432
1433 test_expect_success $PREREQ 'setup expect' '
1434         cat >expected <<-\EOF
1435         TG9vaywgSSBoYXZlIGEgQ1JMRiBhbmQgYW4gPSBzaWduIQ0K
1436         EOF
1437 '
1438
1439 test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=base64' '
1440         clean_fake_sendmail &&
1441         git send-email \
1442                 --transfer-encoding=base64 \
1443                 --smtp-server="$(pwd)/fake.sendmail" \
1444                 email-using-crlf \
1445                 2>errors >out &&
1446         sed '1,/^$/d' msgtxt1 >actual &&
1447         test_cmp expected actual
1448 '
1449
1450
1451 # Note that the patches in this test are deliberately out of order; we
1452 # want to make sure it works even if the cover-letter is not in the
1453 # first mail.
1454 test_expect_success $PREREQ 'refusing to send cover letter template' '
1455         clean_fake_sendmail &&
1456         rm -fr outdir &&
1457         git format-patch --cover-letter -2 -o outdir &&
1458         test_must_fail git send-email \
1459                 --from="Example <nobody@example.com>" \
1460                 --to=nobody@example.com \
1461                 --smtp-server="$(pwd)/fake.sendmail" \
1462                 outdir/0002-*.patch \
1463                 outdir/0000-*.patch \
1464                 outdir/0001-*.patch \
1465                 2>errors >out &&
1466         grep "SUBJECT HERE" errors &&
1467         test -z "$(ls msgtxt*)"
1468 '
1469
1470 test_expect_success $PREREQ '--force sends cover letter template anyway' '
1471         clean_fake_sendmail &&
1472         rm -fr outdir &&
1473         git format-patch --cover-letter -2 -o outdir &&
1474         git send-email \
1475                 --force \
1476                 --from="Example <nobody@example.com>" \
1477                 --to=nobody@example.com \
1478                 --smtp-server="$(pwd)/fake.sendmail" \
1479                 outdir/0002-*.patch \
1480                 outdir/0000-*.patch \
1481                 outdir/0001-*.patch \
1482                 2>errors >out &&
1483         ! grep "SUBJECT HERE" errors &&
1484         test -n "$(ls msgtxt*)"
1485 '
1486
1487 test_cover_addresses () {
1488         header="$1"
1489         shift
1490         clean_fake_sendmail &&
1491         rm -fr outdir &&
1492         git format-patch --cover-letter -2 -o outdir &&
1493         cover=`echo outdir/0000-*.patch` &&
1494         mv $cover cover-to-edit.patch &&
1495         perl -pe "s/^From:/$header: extra\@address.com\nFrom:/" cover-to-edit.patch >"$cover" &&
1496         git send-email \
1497                 --force \
1498                 --from="Example <nobody@example.com>" \
1499                 --no-to --no-cc \
1500                 "$@" \
1501                 --smtp-server="$(pwd)/fake.sendmail" \
1502                 outdir/0000-*.patch \
1503                 outdir/0001-*.patch \
1504                 outdir/0002-*.patch \
1505                 2>errors >out &&
1506         grep "^$header: extra@address.com" msgtxt1 >to1 &&
1507         grep "^$header: extra@address.com" msgtxt2 >to2 &&
1508         grep "^$header: extra@address.com" msgtxt3 >to3 &&
1509         test_line_count = 1 to1 &&
1510         test_line_count = 1 to2 &&
1511         test_line_count = 1 to3
1512 }
1513
1514 test_expect_success $PREREQ 'to-cover adds To to all mail' '
1515         test_cover_addresses "To" --to-cover
1516 '
1517
1518 test_expect_success $PREREQ 'cc-cover adds Cc to all mail' '
1519         test_cover_addresses "Cc" --cc-cover
1520 '
1521
1522 test_expect_success $PREREQ 'tocover adds To to all mail' '
1523         test_config sendemail.tocover true &&
1524         test_cover_addresses "To"
1525 '
1526
1527 test_expect_success $PREREQ 'cccover adds Cc to all mail' '
1528         test_config sendemail.cccover true &&
1529         test_cover_addresses "Cc"
1530 '
1531
1532 test_expect_success $PREREQ 'sendemail.aliasfiletype=mailrc' '
1533         clean_fake_sendmail &&
1534         echo "alias sbd  somebody@example.org" >.mailrc &&
1535         git config --replace-all sendemail.aliasesfile "$(pwd)/.mailrc" &&
1536         git config sendemail.aliasfiletype mailrc &&
1537         git send-email \
1538                 --from="Example <nobody@example.com>" \
1539                 --to=sbd \
1540                 --smtp-server="$(pwd)/fake.sendmail" \
1541                 outdir/0001-*.patch \
1542                 2>errors >out &&
1543         grep "^!somebody@example\.org!$" commandline1
1544 '
1545
1546 test_expect_success $PREREQ 'sendemail.aliasfile=~/.mailrc' '
1547         clean_fake_sendmail &&
1548         echo "alias sbd  someone@example.org" >~/.mailrc &&
1549         git config --replace-all sendemail.aliasesfile "~/.mailrc" &&
1550         git config sendemail.aliasfiletype mailrc &&
1551         git send-email \
1552                 --from="Example <nobody@example.com>" \
1553                 --to=sbd \
1554                 --smtp-server="$(pwd)/fake.sendmail" \
1555                 outdir/0001-*.patch \
1556                 2>errors >out &&
1557         grep "^!someone@example\.org!$" commandline1
1558 '
1559
1560 test_done