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