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