Code

t9001: send-email interation with --in-reply-to and --chain-reply-to
[git.git] / t / t9001-send-email.sh
1 #!/bin/sh
3 test_description='git send-email'
4 . ./test-lib.sh
6 # May be altered later in the test
7 PREREQ="PERL"
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."'
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       echo "cat > msgtxt\$output"
27       ) >fake.sendmail &&
28      chmod +x ./fake.sendmail &&
29      git add fake.sendmail &&
30      GIT_AUTHOR_NAME="A" git commit -a -m "Second."'
32 clean_fake_sendmail() {
33         rm -f commandline* msgtxt*
34 }
36 test_expect_success $PREREQ 'Extract patches' '
37     patches=`git format-patch -s --cc="One <one@example.com>" --cc=two@example.com -n HEAD^1`
38 '
40 # Test no confirm early to ensure remaining tests will not hang
41 test_no_confirm () {
42         rm -f no_confirm_okay
43         echo n | \
44                 GIT_SEND_EMAIL_NOTTY=1 \
45                 git send-email \
46                 --from="Example <from@example.com>" \
47                 --to=nobody@example.com \
48                 --smtp-server="$(pwd)/fake.sendmail" \
49                 $@ \
50                 $patches > stdout &&
51                 test_must_fail grep "Send this email" stdout &&
52                 > no_confirm_okay
53 }
55 # Exit immediately to prevent hang if a no-confirm test fails
56 check_no_confirm () {
57         if ! test -f no_confirm_okay
58         then
59                 say 'confirm test failed; skipping remaining tests to prevent hanging'
60                 PREREQ="$PREREQ,CHECK_NO_CONFIRM"
61         fi
62         return 0
63 }
65 test_expect_success $PREREQ 'No confirm with --suppress-cc' '
66         test_no_confirm --suppress-cc=sob &&
67         check_no_confirm
68 '
71 test_expect_success $PREREQ 'No confirm with --confirm=never' '
72         test_no_confirm --confirm=never &&
73         check_no_confirm
74 '
76 # leave sendemail.confirm set to never after this so that none of the
77 # remaining tests prompt unintentionally.
78 test_expect_success $PREREQ 'No confirm with sendemail.confirm=never' '
79         git config sendemail.confirm never &&
80         test_no_confirm --compose --subject=foo &&
81         check_no_confirm
82 '
84 test_expect_success $PREREQ 'Send patches' '
85      git send-email --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
86 '
88 test_expect_success $PREREQ 'setup expect' '
89 cat >expected <<\EOF
90 !nobody@example.com!
91 !author@example.com!
92 !one@example.com!
93 !two@example.com!
94 EOF
95 '
97 test_expect_success $PREREQ \
98     'Verify commandline' \
99     'test_cmp expected commandline1'
101 test_expect_success $PREREQ 'Send patches with --envelope-sender' '
102     clean_fake_sendmail &&
103      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
106 test_expect_success $PREREQ 'setup expect' '
107 cat >expected <<\EOF
108 !patch@example.com!
109 !-i!
110 !nobody@example.com!
111 !author@example.com!
112 !one@example.com!
113 !two@example.com!
114 EOF
117 test_expect_success $PREREQ \
118     'Verify commandline' \
119     'test_cmp expected commandline1'
121 test_expect_success $PREREQ 'Send patches with --envelope-sender=auto' '
122     clean_fake_sendmail &&
123      git send-email --envelope-sender=auto --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
126 test_expect_success $PREREQ 'setup expect' '
127 cat >expected <<\EOF
128 !nobody@example.com!
129 !-i!
130 !nobody@example.com!
131 !author@example.com!
132 !one@example.com!
133 !two@example.com!
134 EOF
137 test_expect_success $PREREQ \
138     'Verify commandline' \
139     'test_cmp expected commandline1'
141 test_expect_success $PREREQ 'setup expect' "
142 cat >expected-show-all-headers <<\EOF
143 0001-Second.patch
144 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
145 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
146 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
147 Dry-OK. Log says:
148 Server: relay.example.com
149 MAIL FROM:<from@example.com>
150 RCPT TO:<to@example.com>
151 RCPT TO:<cc@example.com>
152 RCPT TO:<author@example.com>
153 RCPT TO:<one@example.com>
154 RCPT TO:<two@example.com>
155 RCPT TO:<bcc@example.com>
156 From: Example <from@example.com>
157 To: to@example.com
158 Cc: cc@example.com,
159         A <author@example.com>,
160         One <one@example.com>,
161         two@example.com
162 Subject: [PATCH 1/1] Second.
163 Date: DATE-STRING
164 Message-Id: MESSAGE-ID-STRING
165 X-Mailer: X-MAILER-STRING
166 In-Reply-To: <unique-message-id@example.com>
167 References: <unique-message-id@example.com>
169 Result: OK
170 EOF
173 test_expect_success $PREREQ 'Show all headers' '
174         git send-email \
175                 --dry-run \
176                 --suppress-cc=sob \
177                 --from="Example <from@example.com>" \
178                 --to=to@example.com \
179                 --cc=cc@example.com \
180                 --bcc=bcc@example.com \
181                 --in-reply-to="<unique-message-id@example.com>" \
182                 --smtp-server relay.example.com \
183                 $patches |
184         sed     -e "s/^\(Date:\).*/\1 DATE-STRING/" \
185                 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
186                 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
187                 >actual-show-all-headers &&
188         test_cmp expected-show-all-headers actual-show-all-headers
191 test_expect_success $PREREQ 'Prompting works' '
192         clean_fake_sendmail &&
193         (echo "Example <from@example.com>"
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: Example <from@example.com>\$" msgtxt1 &&
201                 grep "^To: to@example.com\$" msgtxt1
204 test_expect_success $PREREQ 'tocmd works' '
205         clean_fake_sendmail &&
206         cp $patches tocmd.patch &&
207         echo tocmd--tocmd@example.com >>tocmd.patch &&
208         {
209           echo "#!$SHELL_PATH"
210           echo sed -n -e s/^tocmd--//p \"\$1\"
211         } > tocmd-sed &&
212         chmod +x tocmd-sed &&
213         git send-email \
214                 --from="Example <nobody@example.com>" \
215                 --to-cmd=./tocmd-sed \
216                 --smtp-server="$(pwd)/fake.sendmail" \
217                 tocmd.patch \
218                 &&
219         grep "^To: tocmd@example.com" msgtxt1
222 test_expect_success $PREREQ 'cccmd works' '
223         clean_fake_sendmail &&
224         cp $patches cccmd.patch &&
225         echo "cccmd--  cccmd@example.com" >>cccmd.patch &&
226         {
227           echo "#!$SHELL_PATH"
228           echo sed -n -e s/^cccmd--//p \"\$1\"
229         } > cccmd-sed &&
230         chmod +x cccmd-sed &&
231         git send-email \
232                 --from="Example <nobody@example.com>" \
233                 --to=nobody@example.com \
234                 --cc-cmd=./cccmd-sed \
235                 --smtp-server="$(pwd)/fake.sendmail" \
236                 cccmd.patch \
237                 &&
238         grep "^ cccmd@example.com" msgtxt1
241 test_expect_success $PREREQ 'reject long lines' '
242         z8=zzzzzzzz &&
243         z64=$z8$z8$z8$z8$z8$z8$z8$z8 &&
244         z512=$z64$z64$z64$z64$z64$z64$z64$z64 &&
245         clean_fake_sendmail &&
246         cp $patches longline.patch &&
247         echo $z512$z512 >>longline.patch &&
248         test_must_fail git send-email \
249                 --from="Example <nobody@example.com>" \
250                 --to=nobody@example.com \
251                 --smtp-server="$(pwd)/fake.sendmail" \
252                 $patches longline.patch \
253                 2>errors &&
254         grep longline.patch errors
257 test_expect_success $PREREQ 'no patch was sent' '
258         ! test -e commandline1
261 test_expect_success $PREREQ 'Author From: in message body' '
262         clean_fake_sendmail &&
263         git send-email \
264                 --from="Example <nobody@example.com>" \
265                 --to=nobody@example.com \
266                 --smtp-server="$(pwd)/fake.sendmail" \
267                 $patches &&
268         sed "1,/^\$/d" < msgtxt1 > msgbody1
269         grep "From: A <author@example.com>" msgbody1
272 test_expect_success $PREREQ 'Author From: not in message body' '
273         clean_fake_sendmail &&
274         git send-email \
275                 --from="A <author@example.com>" \
276                 --to=nobody@example.com \
277                 --smtp-server="$(pwd)/fake.sendmail" \
278                 $patches &&
279         sed "1,/^\$/d" < msgtxt1 > msgbody1
280         ! grep "From: A <author@example.com>" msgbody1
283 test_expect_success $PREREQ 'allow long lines with --no-validate' '
284         git send-email \
285                 --from="Example <nobody@example.com>" \
286                 --to=nobody@example.com \
287                 --smtp-server="$(pwd)/fake.sendmail" \
288                 --novalidate \
289                 $patches longline.patch \
290                 2>errors
293 test_expect_success $PREREQ 'Invalid In-Reply-To' '
294         clean_fake_sendmail &&
295         git send-email \
296                 --from="Example <nobody@example.com>" \
297                 --to=nobody@example.com \
298                 --in-reply-to=" " \
299                 --smtp-server="$(pwd)/fake.sendmail" \
300                 $patches \
301                 2>errors
302         ! grep "^In-Reply-To: < *>" msgtxt1
305 test_expect_success $PREREQ 'Valid In-Reply-To when prompting' '
306         clean_fake_sendmail &&
307         (echo "From Example <from@example.com>"
308          echo "To Example <to@example.com>"
309          echo ""
310         ) | env GIT_SEND_EMAIL_NOTTY=1 git send-email \
311                 --smtp-server="$(pwd)/fake.sendmail" \
312                 $patches 2>errors &&
313         ! grep "^In-Reply-To: < *>" msgtxt1
316 test_expect_success $PREREQ 'In-Reply-To without --chain-reply-to' '
317         clean_fake_sendmail &&
318         echo "<unique-message-id@example.com>" >expect &&
319         git send-email \
320                 --from="Example <nobody@example.com>" \
321                 --to=nobody@example.com \
322                 --no-chain-reply-to \
323                 --in-reply-to="$(cat expect)" \
324                 --smtp-server="$(pwd)/fake.sendmail" \
325                 $patches $patches $patches \
326                 2>errors &&
327         # All the messages are replies to --in-reply-to
328         sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
329         test_cmp expect actual &&
330         sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
331         test_cmp expect actual &&
332         sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
333         test_cmp expect actual
336 test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' '
337         clean_fake_sendmail &&
338         echo "<unique-message-id@example.com>" >expect &&
339         git send-email \
340                 --from="Example <nobody@example.com>" \
341                 --to=nobody@example.com \
342                 --chain-reply-to \
343                 --in-reply-to="$(cat expect)" \
344                 --smtp-server="$(pwd)/fake.sendmail" \
345                 $patches $patches $patches \
346                 2>errors &&
347         sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
348         test_cmp expect actual &&
349         sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
350         sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
351         test_cmp expect actual &&
352         sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt2 >expect &&
353         sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
354         test_cmp expect actual
357 test_expect_success $PREREQ 'setup fake editor' '
358         (echo "#!$SHELL_PATH" &&
359          echo "echo fake edit >>\"\$1\""
360         ) >fake-editor &&
361         chmod +x fake-editor
364 test_set_editor "$(pwd)/fake-editor"
366 test_expect_success $PREREQ '--compose works' '
367         clean_fake_sendmail &&
368         git send-email \
369         --compose --subject foo \
370         --from="Example <nobody@example.com>" \
371         --to=nobody@example.com \
372         --smtp-server="$(pwd)/fake.sendmail" \
373         $patches \
374         2>errors
377 test_expect_success $PREREQ 'first message is compose text' '
378         grep "^fake edit" msgtxt1
381 test_expect_success $PREREQ 'second message is patch' '
382         grep "Subject:.*Second" msgtxt2
385 test_expect_success $PREREQ 'setup expect' "
386 cat >expected-suppress-sob <<\EOF
387 0001-Second.patch
388 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
389 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
390 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
391 Dry-OK. Log says:
392 Server: relay.example.com
393 MAIL FROM:<from@example.com>
394 RCPT TO:<to@example.com>
395 RCPT TO:<cc@example.com>
396 RCPT TO:<author@example.com>
397 RCPT TO:<one@example.com>
398 RCPT TO:<two@example.com>
399 From: Example <from@example.com>
400 To: to@example.com
401 Cc: cc@example.com,
402         A <author@example.com>,
403         One <one@example.com>,
404         two@example.com
405 Subject: [PATCH 1/1] Second.
406 Date: DATE-STRING
407 Message-Id: MESSAGE-ID-STRING
408 X-Mailer: X-MAILER-STRING
410 Result: OK
411 EOF
414 test_suppression () {
415         git send-email \
416                 --dry-run \
417                 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
418                 --from="Example <from@example.com>" \
419                 --to=to@example.com \
420                 --smtp-server relay.example.com \
421                 $patches |
422         sed     -e "s/^\(Date:\).*/\1 DATE-STRING/" \
423                 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
424                 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
425                 >actual-suppress-$1${2+"-$2"} &&
426         test_cmp expected-suppress-$1${2+"-$2"} actual-suppress-$1${2+"-$2"}
429 test_expect_success $PREREQ 'sendemail.cc set' '
430         git config sendemail.cc cc@example.com &&
431         test_suppression sob
434 test_expect_success $PREREQ 'setup expect' "
435 cat >expected-suppress-sob <<\EOF
436 0001-Second.patch
437 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
438 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
439 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
440 Dry-OK. Log says:
441 Server: relay.example.com
442 MAIL FROM:<from@example.com>
443 RCPT TO:<to@example.com>
444 RCPT TO:<author@example.com>
445 RCPT TO:<one@example.com>
446 RCPT TO:<two@example.com>
447 From: Example <from@example.com>
448 To: to@example.com
449 Cc: A <author@example.com>,
450         One <one@example.com>,
451         two@example.com
452 Subject: [PATCH 1/1] Second.
453 Date: DATE-STRING
454 Message-Id: MESSAGE-ID-STRING
455 X-Mailer: X-MAILER-STRING
457 Result: OK
458 EOF
461 test_expect_success $PREREQ 'sendemail.cc unset' '
462         git config --unset sendemail.cc &&
463         test_suppression sob
466 test_expect_success $PREREQ 'setup expect' "
467 cat >expected-suppress-cccmd <<\EOF
468 0001-Second.patch
469 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
470 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
471 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
472 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
473 Dry-OK. Log says:
474 Server: relay.example.com
475 MAIL FROM:<from@example.com>
476 RCPT TO:<to@example.com>
477 RCPT TO:<author@example.com>
478 RCPT TO:<one@example.com>
479 RCPT TO:<two@example.com>
480 RCPT TO:<committer@example.com>
481 From: Example <from@example.com>
482 To: to@example.com
483 Cc: A <author@example.com>,
484         One <one@example.com>,
485         two@example.com,
486         C O Mitter <committer@example.com>
487 Subject: [PATCH 1/1] Second.
488 Date: DATE-STRING
489 Message-Id: MESSAGE-ID-STRING
490 X-Mailer: X-MAILER-STRING
492 Result: OK
493 EOF
496 test_expect_success $PREREQ 'sendemail.cccmd' '
497         echo echo cc-cmd@example.com > cccmd &&
498         chmod +x cccmd &&
499         git config sendemail.cccmd ./cccmd &&
500         test_suppression cccmd
503 test_expect_success $PREREQ 'setup expect' '
504 cat >expected-suppress-all <<\EOF
505 0001-Second.patch
506 Dry-OK. Log says:
507 Server: relay.example.com
508 MAIL FROM:<from@example.com>
509 RCPT TO:<to@example.com>
510 From: Example <from@example.com>
511 To: to@example.com
512 Subject: [PATCH 1/1] Second.
513 Date: DATE-STRING
514 Message-Id: MESSAGE-ID-STRING
515 X-Mailer: X-MAILER-STRING
517 Result: OK
518 EOF
521 test_expect_success $PREREQ '--suppress-cc=all' '
522         test_suppression all
525 test_expect_success $PREREQ 'setup expect' "
526 cat >expected-suppress-body <<\EOF
527 0001-Second.patch
528 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
529 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
530 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
531 (cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
532 Dry-OK. Log says:
533 Server: relay.example.com
534 MAIL FROM:<from@example.com>
535 RCPT TO:<to@example.com>
536 RCPT TO:<author@example.com>
537 RCPT TO:<one@example.com>
538 RCPT TO:<two@example.com>
539 RCPT TO:<cc-cmd@example.com>
540 From: Example <from@example.com>
541 To: to@example.com
542 Cc: A <author@example.com>,
543         One <one@example.com>,
544         two@example.com,
545         cc-cmd@example.com
546 Subject: [PATCH 1/1] Second.
547 Date: DATE-STRING
548 Message-Id: MESSAGE-ID-STRING
549 X-Mailer: X-MAILER-STRING
551 Result: OK
552 EOF
555 test_expect_success $PREREQ '--suppress-cc=body' '
556         test_suppression body
559 test_expect_success $PREREQ 'setup expect' "
560 cat >expected-suppress-body-cccmd <<\EOF
561 0001-Second.patch
562 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
563 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
564 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
565 Dry-OK. Log says:
566 Server: relay.example.com
567 MAIL FROM:<from@example.com>
568 RCPT TO:<to@example.com>
569 RCPT TO:<author@example.com>
570 RCPT TO:<one@example.com>
571 RCPT TO:<two@example.com>
572 From: Example <from@example.com>
573 To: to@example.com
574 Cc: A <author@example.com>,
575         One <one@example.com>,
576         two@example.com
577 Subject: [PATCH 1/1] Second.
578 Date: DATE-STRING
579 Message-Id: MESSAGE-ID-STRING
580 X-Mailer: X-MAILER-STRING
582 Result: OK
583 EOF
586 test_expect_success $PREREQ '--suppress-cc=body --suppress-cc=cccmd' '
587         test_suppression body cccmd
590 test_expect_success $PREREQ 'setup expect' "
591 cat >expected-suppress-sob <<\EOF
592 0001-Second.patch
593 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
594 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
595 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
596 Dry-OK. Log says:
597 Server: relay.example.com
598 MAIL FROM:<from@example.com>
599 RCPT TO:<to@example.com>
600 RCPT TO:<author@example.com>
601 RCPT TO:<one@example.com>
602 RCPT TO:<two@example.com>
603 From: Example <from@example.com>
604 To: to@example.com
605 Cc: A <author@example.com>,
606         One <one@example.com>,
607         two@example.com
608 Subject: [PATCH 1/1] Second.
609 Date: DATE-STRING
610 Message-Id: MESSAGE-ID-STRING
611 X-Mailer: X-MAILER-STRING
613 Result: OK
614 EOF
617 test_expect_success $PREREQ '--suppress-cc=sob' '
618         git config --unset sendemail.cccmd
619         test_suppression sob
622 test_expect_success $PREREQ 'setup expect' "
623 cat >expected-suppress-bodycc <<\EOF
624 0001-Second.patch
625 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
626 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
627 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
628 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
629 Dry-OK. Log says:
630 Server: relay.example.com
631 MAIL FROM:<from@example.com>
632 RCPT TO:<to@example.com>
633 RCPT TO:<author@example.com>
634 RCPT TO:<one@example.com>
635 RCPT TO:<two@example.com>
636 RCPT TO:<committer@example.com>
637 From: Example <from@example.com>
638 To: to@example.com
639 Cc: A <author@example.com>,
640         One <one@example.com>,
641         two@example.com,
642         C O Mitter <committer@example.com>
643 Subject: [PATCH 1/1] Second.
644 Date: DATE-STRING
645 Message-Id: MESSAGE-ID-STRING
646 X-Mailer: X-MAILER-STRING
648 Result: OK
649 EOF
652 test_expect_success $PREREQ '--suppress-cc=bodycc' '
653         test_suppression bodycc
656 test_expect_success $PREREQ 'setup expect' "
657 cat >expected-suppress-cc <<\EOF
658 0001-Second.patch
659 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
660 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
661 Dry-OK. Log says:
662 Server: relay.example.com
663 MAIL FROM:<from@example.com>
664 RCPT TO:<to@example.com>
665 RCPT TO:<author@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         C O Mitter <committer@example.com>
671 Subject: [PATCH 1/1] Second.
672 Date: DATE-STRING
673 Message-Id: MESSAGE-ID-STRING
674 X-Mailer: X-MAILER-STRING
676 Result: OK
677 EOF
680 test_expect_success $PREREQ '--suppress-cc=cc' '
681         test_suppression cc
684 test_confirm () {
685         echo y | \
686                 GIT_SEND_EMAIL_NOTTY=1 \
687                 git send-email \
688                 --from="Example <nobody@example.com>" \
689                 --to=nobody@example.com \
690                 --smtp-server="$(pwd)/fake.sendmail" \
691                 $@ $patches > stdout &&
692         grep "Send this email" stdout
695 test_expect_success $PREREQ '--confirm=always' '
696         test_confirm --confirm=always --suppress-cc=all
699 test_expect_success $PREREQ '--confirm=auto' '
700         test_confirm --confirm=auto
703 test_expect_success $PREREQ '--confirm=cc' '
704         test_confirm --confirm=cc
707 test_expect_success $PREREQ '--confirm=compose' '
708         test_confirm --confirm=compose --compose
711 test_expect_success $PREREQ 'confirm by default (due to cc)' '
712         CONFIRM=$(git config --get sendemail.confirm) &&
713         git config --unset sendemail.confirm &&
714         test_confirm
715         ret="$?"
716         git config sendemail.confirm ${CONFIRM:-never}
717         test $ret = "0"
720 test_expect_success $PREREQ 'confirm by default (due to --compose)' '
721         CONFIRM=$(git config --get sendemail.confirm) &&
722         git config --unset sendemail.confirm &&
723         test_confirm --suppress-cc=all --compose
724         ret="$?"
725         git config sendemail.confirm ${CONFIRM:-never}
726         test $ret = "0"
729 test_expect_success $PREREQ 'confirm detects EOF (inform assumes y)' '
730         CONFIRM=$(git config --get sendemail.confirm) &&
731         git config --unset sendemail.confirm &&
732         rm -fr outdir &&
733         git format-patch -2 -o outdir &&
734         GIT_SEND_EMAIL_NOTTY=1 \
735                 git send-email \
736                         --from="Example <nobody@example.com>" \
737                         --to=nobody@example.com \
738                         --smtp-server="$(pwd)/fake.sendmail" \
739                         outdir/*.patch < /dev/null
740         ret="$?"
741         git config sendemail.confirm ${CONFIRM:-never}
742         test $ret = "0"
745 test_expect_success $PREREQ 'confirm detects EOF (auto causes failure)' '
746         CONFIRM=$(git config --get sendemail.confirm) &&
747         git config sendemail.confirm auto &&
748         GIT_SEND_EMAIL_NOTTY=1 &&
749         export GIT_SEND_EMAIL_NOTTY &&
750                 test_must_fail git send-email \
751                         --from="Example <nobody@example.com>" \
752                         --to=nobody@example.com \
753                         --smtp-server="$(pwd)/fake.sendmail" \
754                         $patches < /dev/null
755         ret="$?"
756         git config sendemail.confirm ${CONFIRM:-never}
757         test $ret = "0"
760 test_expect_success $PREREQ 'confirm doesnt loop forever' '
761         CONFIRM=$(git config --get sendemail.confirm) &&
762         git config sendemail.confirm auto &&
763         GIT_SEND_EMAIL_NOTTY=1 &&
764         export GIT_SEND_EMAIL_NOTTY &&
765                 yes "bogus" | test_must_fail git send-email \
766                         --from="Example <nobody@example.com>" \
767                         --to=nobody@example.com \
768                         --smtp-server="$(pwd)/fake.sendmail" \
769                         $patches
770         ret="$?"
771         git config sendemail.confirm ${CONFIRM:-never}
772         test $ret = "0"
775 test_expect_success $PREREQ 'utf8 Cc is rfc2047 encoded' '
776         clean_fake_sendmail &&
777         rm -fr outdir &&
778         git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
779         git send-email \
780         --from="Example <nobody@example.com>" \
781         --to=nobody@example.com \
782         --smtp-server="$(pwd)/fake.sendmail" \
783         outdir/*.patch &&
784         grep "^ " msgtxt1 |
785         grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
788 test_expect_success $PREREQ '--compose adds MIME for utf8 body' '
789         clean_fake_sendmail &&
790         (echo "#!$SHELL_PATH" &&
791          echo "echo utf8 body: àéìöú >>\"\$1\""
792         ) >fake-editor-utf8 &&
793         chmod +x fake-editor-utf8 &&
794           GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
795           git send-email \
796           --compose --subject foo \
797           --from="Example <nobody@example.com>" \
798           --to=nobody@example.com \
799           --smtp-server="$(pwd)/fake.sendmail" \
800           $patches &&
801         grep "^utf8 body" msgtxt1 &&
802         grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
805 test_expect_success $PREREQ '--compose respects user mime type' '
806         clean_fake_sendmail &&
807         (echo "#!$SHELL_PATH" &&
808          echo "(echo MIME-Version: 1.0"
809          echo " echo Content-Type: text/plain\\; charset=iso-8859-1"
810          echo " echo Content-Transfer-Encoding: 8bit"
811          echo " echo Subject: foo"
812          echo " echo "
813          echo " echo utf8 body: àéìöú) >\"\$1\""
814         ) >fake-editor-utf8-mime &&
815         chmod +x fake-editor-utf8-mime &&
816           GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
817           git send-email \
818           --compose --subject foo \
819           --from="Example <nobody@example.com>" \
820           --to=nobody@example.com \
821           --smtp-server="$(pwd)/fake.sendmail" \
822           $patches &&
823         grep "^utf8 body" msgtxt1 &&
824         grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
825         ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
828 test_expect_success $PREREQ '--compose adds MIME for utf8 subject' '
829         clean_fake_sendmail &&
830           GIT_EDITOR="\"$(pwd)/fake-editor\"" \
831           git send-email \
832           --compose --subject utf8-sübjëct \
833           --from="Example <nobody@example.com>" \
834           --to=nobody@example.com \
835           --smtp-server="$(pwd)/fake.sendmail" \
836           $patches &&
837         grep "^fake edit" msgtxt1 &&
838         grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
841 test_expect_success $PREREQ 'detects ambiguous reference/file conflict' '
842         echo master > master &&
843         git add master &&
844         git commit -m"add master" &&
845         test_must_fail git send-email --dry-run master 2>errors &&
846         grep disambiguate errors
849 test_expect_success $PREREQ 'feed two files' '
850         rm -fr outdir &&
851         git format-patch -2 -o outdir &&
852         git send-email \
853         --dry-run \
854         --from="Example <nobody@example.com>" \
855         --to=nobody@example.com \
856         outdir/000?-*.patch 2>errors >out &&
857         grep "^Subject: " out >subjects &&
858         test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
859         test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"
862 test_expect_success $PREREQ 'in-reply-to but no threading' '
863         git send-email \
864                 --dry-run \
865                 --from="Example <nobody@example.com>" \
866                 --to=nobody@example.com \
867                 --in-reply-to="<in-reply-id@example.com>" \
868                 --nothread \
869                 $patches |
870         grep "In-Reply-To: <in-reply-id@example.com>"
873 test_expect_success $PREREQ 'no in-reply-to and no threading' '
874         git send-email \
875                 --dry-run \
876                 --from="Example <nobody@example.com>" \
877                 --to=nobody@example.com \
878                 --nothread \
879                 $patches $patches >stdout &&
880         ! grep "In-Reply-To: " stdout
883 test_expect_success $PREREQ 'threading but no chain-reply-to' '
884         git send-email \
885                 --dry-run \
886                 --from="Example <nobody@example.com>" \
887                 --to=nobody@example.com \
888                 --thread \
889                 --nochain-reply-to \
890                 $patches $patches >stdout &&
891         grep "In-Reply-To: " stdout
894 test_expect_success $PREREQ 'warning with an implicit --chain-reply-to' '
895         git send-email \
896         --dry-run \
897         --from="Example <nobody@example.com>" \
898         --to=nobody@example.com \
899         outdir/000?-*.patch 2>errors >out &&
900         grep "no-chain-reply-to" errors
903 test_expect_success $PREREQ 'no warning with an explicit --chain-reply-to' '
904         git send-email \
905         --dry-run \
906         --from="Example <nobody@example.com>" \
907         --to=nobody@example.com \
908         --chain-reply-to \
909         outdir/000?-*.patch 2>errors >out &&
910         ! grep "no-chain-reply-to" errors
913 test_expect_success $PREREQ 'no warning with an explicit --no-chain-reply-to' '
914         git send-email \
915         --dry-run \
916         --from="Example <nobody@example.com>" \
917         --to=nobody@example.com \
918         --nochain-reply-to \
919         outdir/000?-*.patch 2>errors >out &&
920         ! grep "no-chain-reply-to" errors
923 test_expect_success $PREREQ 'no warning with sendemail.chainreplyto = false' '
924         git config sendemail.chainreplyto false &&
925         git send-email \
926         --dry-run \
927         --from="Example <nobody@example.com>" \
928         --to=nobody@example.com \
929         outdir/000?-*.patch 2>errors >out &&
930         ! grep "no-chain-reply-to" errors
933 test_expect_success $PREREQ 'no warning with sendemail.chainreplyto = true' '
934         git config sendemail.chainreplyto true &&
935         git send-email \
936         --dry-run \
937         --from="Example <nobody@example.com>" \
938         --to=nobody@example.com \
939         outdir/000?-*.patch 2>errors >out &&
940         ! grep "no-chain-reply-to" errors
943 test_expect_success $PREREQ 'sendemail.to works' '
944         git config --replace-all sendemail.to "Somebody <somebody@ex.com>" &&
945         git send-email \
946                 --dry-run \
947                 --from="Example <nobody@example.com>" \
948                 $patches $patches >stdout &&
949         grep "To: Somebody <somebody@ex.com>" stdout
952 test_expect_success $PREREQ '--no-to overrides sendemail.to' '
953         git send-email \
954                 --dry-run \
955                 --from="Example <nobody@example.com>" \
956                 --no-to \
957                 --to=nobody@example.com \
958                 $patches $patches >stdout &&
959         grep "To: nobody@example.com" stdout &&
960         ! grep "To: Somebody <somebody@ex.com>" stdout
963 test_expect_success $PREREQ 'sendemail.cc works' '
964         git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" &&
965         git send-email \
966                 --dry-run \
967                 --from="Example <nobody@example.com>" \
968                 --to=nobody@example.com \
969                 $patches $patches >stdout &&
970         grep "Cc: Somebody <somebody@ex.com>" stdout
973 test_expect_success $PREREQ '--no-cc overrides sendemail.cc' '
974         git send-email \
975                 --dry-run \
976                 --from="Example <nobody@example.com>" \
977                 --no-cc \
978                 --cc=bodies@example.com \
979                 --to=nobody@example.com \
980                 $patches $patches >stdout &&
981         grep "Cc: bodies@example.com" stdout &&
982         ! grep "Cc: Somebody <somebody@ex.com>" stdout
985 test_expect_success $PREREQ 'sendemail.bcc works' '
986         git config --replace-all sendemail.bcc "Other <other@ex.com>" &&
987         git send-email \
988                 --dry-run \
989                 --from="Example <nobody@example.com>" \
990                 --to=nobody@example.com \
991                 --smtp-server relay.example.com \
992                 $patches $patches >stdout &&
993         grep "RCPT TO:<other@ex.com>" stdout
996 test_expect_success $PREREQ '--no-bcc overrides sendemail.bcc' '
997         git send-email \
998                 --dry-run \
999                 --from="Example <nobody@example.com>" \
1000                 --no-bcc \
1001                 --bcc=bodies@example.com \
1002                 --to=nobody@example.com \
1003                 --smtp-server relay.example.com \
1004                 $patches $patches >stdout &&
1005         grep "RCPT TO:<bodies@example.com>" stdout &&
1006         ! grep "RCPT TO:<other@ex.com>" stdout
1009 test_expect_success $PREREQ 'patches To headers are used by default' '
1010         patch=`git format-patch -1 --to="bodies@example.com"` &&
1011         test_when_finished "rm $patch" &&
1012         git send-email \
1013                 --dry-run \
1014                 --from="Example <nobody@example.com>" \
1015                 --smtp-server relay.example.com \
1016                 $patch >stdout &&
1017         grep "RCPT TO:<bodies@example.com>" stdout
1020 test_expect_success $PREREQ 'patches To headers are appended to' '
1021         patch=`git format-patch -1 --to="bodies@example.com"` &&
1022         test_when_finished "rm $patch" &&
1023         git send-email \
1024                 --dry-run \
1025                 --from="Example <nobody@example.com>" \
1026                 --to=nobody@example.com \
1027                 --smtp-server relay.example.com \
1028                 $patch >stdout &&
1029         grep "RCPT TO:<bodies@example.com>" stdout &&
1030         grep "RCPT TO:<nobody@example.com>" stdout
1033 test_expect_success $PREREQ 'To headers from files reset each patch' '
1034         patch1=`git format-patch -1 --to="bodies@example.com"` &&
1035         patch2=`git format-patch -1 --to="other@example.com" HEAD~` &&
1036         test_when_finished "rm $patch1 && rm $patch2" &&
1037         git send-email \
1038                 --dry-run \
1039                 --from="Example <nobody@example.com>" \
1040                 --to="nobody@example.com" \
1041                 --smtp-server relay.example.com \
1042                 $patch1 $patch2 >stdout &&
1043         test $(grep -c "RCPT TO:<bodies@example.com>" stdout) = 1 &&
1044         test $(grep -c "RCPT TO:<nobody@example.com>" stdout) = 2 &&
1045         test $(grep -c "RCPT TO:<other@example.com>" stdout) = 1
1048 test_expect_success $PREREQ 'setup expect' '
1049 cat >email-using-8bit <<EOF
1050 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1051 Message-Id: <bogus-message-id@example.com>
1052 From: author@example.com
1053 Date: Sat, 12 Jun 2010 15:53:58 +0200
1054 Subject: subject goes here
1056 Dieser deutsche Text enthält einen Umlaut!
1057 EOF
1060 test_expect_success $PREREQ 'setup expect' '
1061 cat >content-type-decl <<EOF
1062 MIME-Version: 1.0
1063 Content-Type: text/plain; charset=UTF-8
1064 Content-Transfer-Encoding: 8bit
1065 EOF
1068 test_expect_success $PREREQ 'asks about and fixes 8bit encodings' '
1069         clean_fake_sendmail &&
1070         echo |
1071         git send-email --from=author@example.com --to=nobody@example.com \
1072                         --smtp-server="$(pwd)/fake.sendmail" \
1073                         email-using-8bit >stdout &&
1074         grep "do not declare a Content-Transfer-Encoding" stdout &&
1075         grep email-using-8bit stdout &&
1076         grep "Which 8bit encoding" stdout &&
1077         egrep "Content|MIME" msgtxt1 >actual &&
1078         test_cmp actual content-type-decl
1081 test_expect_success $PREREQ 'sendemail.8bitEncoding works' '
1082         clean_fake_sendmail &&
1083         git config sendemail.assume8bitEncoding UTF-8 &&
1084         echo bogus |
1085         git send-email --from=author@example.com --to=nobody@example.com \
1086                         --smtp-server="$(pwd)/fake.sendmail" \
1087                         email-using-8bit >stdout &&
1088         egrep "Content|MIME" msgtxt1 >actual &&
1089         test_cmp actual content-type-decl
1092 test_expect_success $PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
1093         clean_fake_sendmail &&
1094         git config sendemail.assume8bitEncoding "bogus too" &&
1095         echo bogus |
1096         git send-email --from=author@example.com --to=nobody@example.com \
1097                         --smtp-server="$(pwd)/fake.sendmail" \
1098                         --8bit-encoding=UTF-8 \
1099                         email-using-8bit >stdout &&
1100         egrep "Content|MIME" msgtxt1 >actual &&
1101         test_cmp actual content-type-decl
1104 test_expect_success $PREREQ 'setup expect' '
1105 cat >email-using-8bit <<EOF
1106 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1107 Message-Id: <bogus-message-id@example.com>
1108 From: author@example.com
1109 Date: Sat, 12 Jun 2010 15:53:58 +0200
1110 Subject: Dieser Betreff enthält auch einen Umlaut!
1112 Nothing to see here.
1113 EOF
1116 test_expect_success $PREREQ 'setup expect' '
1117 cat >expected <<EOF
1118 Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
1119 EOF
1122 test_expect_success $PREREQ '--8bit-encoding also treats subject' '
1123         clean_fake_sendmail &&
1124         echo bogus |
1125         git send-email --from=author@example.com --to=nobody@example.com \
1126                         --smtp-server="$(pwd)/fake.sendmail" \
1127                         --8bit-encoding=UTF-8 \
1128                         email-using-8bit >stdout &&
1129         grep "Subject" msgtxt1 >actual &&
1130         test_cmp expected actual
1133 # Note that the patches in this test are deliberately out of order; we
1134 # want to make sure it works even if the cover-letter is not in the
1135 # first mail.
1136 test_expect_success 'refusing to send cover letter template' '
1137         clean_fake_sendmail &&
1138         rm -fr outdir &&
1139         git format-patch --cover-letter -2 -o outdir &&
1140         test_must_fail git send-email \
1141           --from="Example <nobody@example.com>" \
1142           --to=nobody@example.com \
1143           --smtp-server="$(pwd)/fake.sendmail" \
1144           outdir/0002-*.patch \
1145           outdir/0000-*.patch \
1146           outdir/0001-*.patch \
1147           2>errors >out &&
1148         grep "SUBJECT HERE" errors &&
1149         test -z "$(ls msgtxt*)"
1152 test_expect_success '--force sends cover letter template anyway' '
1153         clean_fake_sendmail &&
1154         rm -fr outdir &&
1155         git format-patch --cover-letter -2 -o outdir &&
1156         git send-email \
1157           --force \
1158           --from="Example <nobody@example.com>" \
1159           --to=nobody@example.com \
1160           --smtp-server="$(pwd)/fake.sendmail" \
1161           outdir/0002-*.patch \
1162           outdir/0000-*.patch \
1163           outdir/0001-*.patch \
1164           2>errors >out &&
1165         ! grep "SUBJECT HERE" errors &&
1166         test -n "$(ls msgtxt*)"
1169 test_done