]> git.ipfire.org Git - thirdparty/git.git/blob - t/t9001-send-email.sh
Merge branch 'jc/send-email-pre-process-fix'
[thirdparty/git.git] / t / t9001-send-email.sh
1 #!/bin/sh
2
3 test_description='git send-email'
4 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
5 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
6
7 TEST_PASSES_SANITIZE_LEAK=true
8 . ./test-lib.sh
9
10 # May be altered later in the test
11 PREREQ="PERL"
12
13 replace_variable_fields () {
14 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
15 -e "s/^\(Message-ID:\).*/\1 MESSAGE-ID-STRING/" \
16 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/"
17 }
18
19 test_expect_success $PREREQ 'prepare reference tree' '
20 echo "1A quick brown fox jumps over the" >file &&
21 echo "lazy dog" >>file &&
22 git add file &&
23 GIT_AUTHOR_NAME="A" git commit -a -m "Initial."
24 '
25
26 test_expect_success $PREREQ 'Setup helper tool' '
27 write_script fake.sendmail <<-\EOF &&
28 shift
29 output=1
30 while test -f commandline$output
31 do
32 output=$(($output+1))
33 done
34 for a
35 do
36 echo "!$a!"
37 done >commandline$output
38 cat >"msgtxt$output"
39 EOF
40 git add fake.sendmail &&
41 GIT_AUTHOR_NAME="A" git commit -a -m "Second."
42 '
43
44 clean_fake_sendmail () {
45 rm -f commandline* msgtxt*
46 }
47
48 test_expect_success $PREREQ 'Extract patches' '
49 patches=$(git format-patch -s --cc="One <one@example.com>" --cc=two@example.com -n HEAD^1) &&
50 threaded_patches=$(git format-patch -o threaded --thread=shallow -s --in-reply-to="format" HEAD^1)
51 '
52
53 # Test no confirm early to ensure remaining tests will not hang
54 test_no_confirm () {
55 rm -f no_confirm_okay
56 echo n | \
57 GIT_SEND_EMAIL_NOTTY=1 \
58 git send-email \
59 --from="Example <from@example.com>" \
60 --to=nobody@example.com \
61 --smtp-server="$(pwd)/fake.sendmail" \
62 $@ \
63 $patches >stdout &&
64 ! grep "Send this email" stdout &&
65 >no_confirm_okay
66 }
67
68 # Exit immediately to prevent hang if a no-confirm test fails
69 check_no_confirm () {
70 if ! test -f no_confirm_okay
71 then
72 say 'confirm test failed; skipping remaining tests to prevent hanging'
73 PREREQ="$PREREQ,CHECK_NO_CONFIRM"
74 fi
75 return 0
76 }
77
78 test_expect_success $PREREQ 'No confirm with --suppress-cc' '
79 test_no_confirm --suppress-cc=sob &&
80 check_no_confirm
81 '
82
83
84 test_expect_success $PREREQ 'No confirm with --confirm=never' '
85 test_no_confirm --confirm=never &&
86 check_no_confirm
87 '
88
89 # leave sendemail.confirm set to never after this so that none of the
90 # remaining tests prompt unintentionally.
91 test_expect_success $PREREQ 'No confirm with sendemail.confirm=never' '
92 git config sendemail.confirm never &&
93 test_no_confirm --compose --subject=foo &&
94 check_no_confirm
95 '
96
97 test_expect_success $PREREQ 'Send patches' '
98 git send-email --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
99 '
100
101 test_expect_success $PREREQ 'setup expect' '
102 cat >expected <<-\EOF
103 !nobody@example.com!
104 !author@example.com!
105 !one@example.com!
106 !two@example.com!
107 EOF
108 '
109
110 test_expect_success $PREREQ 'Verify commandline' '
111 test_cmp expected commandline1
112 '
113
114 test_expect_success $PREREQ 'Send patches with --envelope-sender' '
115 clean_fake_sendmail &&
116 git send-email --envelope-sender="Patch Contributor <patch@example.com>" --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
117 '
118
119 test_expect_success $PREREQ 'setup expect' '
120 cat >expected <<-\EOF
121 !patch@example.com!
122 !-i!
123 !nobody@example.com!
124 !author@example.com!
125 !one@example.com!
126 !two@example.com!
127 EOF
128 '
129
130 test_expect_success $PREREQ 'Verify commandline' '
131 test_cmp expected commandline1
132 '
133
134 test_expect_success $PREREQ 'Send patches with --envelope-sender=auto' '
135 clean_fake_sendmail &&
136 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
137 '
138
139 test_expect_success $PREREQ 'setup expect' '
140 cat >expected <<-\EOF
141 !nobody@example.com!
142 !-i!
143 !nobody@example.com!
144 !author@example.com!
145 !one@example.com!
146 !two@example.com!
147 EOF
148 '
149
150 test_expect_success $PREREQ 'Verify commandline' '
151 test_cmp expected commandline1
152 '
153
154 test_expect_success $PREREQ 'setup expect for cc trailer' "
155 cat >expected-cc <<\EOF
156 !recipient@example.com!
157 !author@example.com!
158 !one@example.com!
159 !two@example.com!
160 !three@example.com!
161 !four@example.com!
162 !five@example.com!
163 !six@example.com!
164 EOF
165 "
166
167 test_expect_success $PREREQ 'cc trailer with various syntax' '
168 test_commit cc-trailer &&
169 test_when_finished "git reset --hard HEAD^" &&
170 git commit --amend -F - <<-EOF &&
171 Test Cc: trailers.
172
173 Cc: one@example.com
174 Cc: <two@example.com> # trailing comments are ignored
175 Cc: <three@example.com>, <not.four@example.com> one address per line
176 Cc: "Some # Body" <four@example.com> [ <also.a.comment> ]
177 Cc: five@example.com # not.six@example.com
178 Cc: six@example.com, not.seven@example.com
179 EOF
180 clean_fake_sendmail &&
181 git send-email -1 --to=recipient@example.com \
182 --smtp-server="$(pwd)/fake.sendmail" &&
183 test_cmp expected-cc commandline1
184 '
185
186 test_expect_success $PREREQ 'setup fake get_maintainer.pl script for cc trailer' "
187 write_script expected-cc-script.sh <<-EOF
188 echo 'One Person <one@example.com> (supporter:THIS (FOO/bar))'
189 echo 'Two Person <two@example.com> (maintainer:THIS THING)'
190 echo 'Third List <three@example.com> (moderated list:THIS THING (FOO/bar))'
191 echo '<four@example.com> (moderated list:FOR THING)'
192 echo 'five@example.com (open list:FOR THING (FOO/bar))'
193 echo 'six@example.com (open list)'
194 EOF
195 "
196
197 test_expect_success $PREREQ 'cc trailer with get_maintainer.pl output' '
198 clean_fake_sendmail &&
199 git send-email -1 --to=recipient@example.com \
200 --cc-cmd=./expected-cc-script.sh \
201 --smtp-server="$(pwd)/fake.sendmail" &&
202 test_cmp expected-cc commandline1
203 '
204
205 test_expect_success $PREREQ 'setup expect' "
206 cat >expected-show-all-headers <<\EOF
207 0001-Second.patch
208 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
209 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
210 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
211 Dry-OK. Log says:
212 Server: relay.example.com
213 MAIL FROM:<from@example.com>
214 RCPT TO:<to@example.com>
215 RCPT TO:<cc@example.com>
216 RCPT TO:<author@example.com>
217 RCPT TO:<one@example.com>
218 RCPT TO:<two@example.com>
219 RCPT TO:<bcc@example.com>
220 From: Example <from@example.com>
221 To: to@example.com
222 Cc: cc@example.com,
223 A <author@example.com>,
224 One <one@example.com>,
225 two@example.com
226 Subject: [PATCH 1/1] Second.
227 Date: DATE-STRING
228 Message-ID: MESSAGE-ID-STRING
229 X-Mailer: X-MAILER-STRING
230 In-Reply-To: <unique-message-id@example.com>
231 References: <unique-message-id@example.com>
232 Reply-To: Reply <reply@example.com>
233 MIME-Version: 1.0
234 Content-Transfer-Encoding: 8bit
235
236 Result: OK
237 EOF
238 "
239
240 test_suppress_self () {
241 test_commit $3 &&
242 test_when_finished "git reset --hard HEAD^" &&
243
244 write_script cccmd-sed <<-EOF &&
245 sed -n -e s/^cccmd--//p "\$1"
246 EOF
247
248 git commit --amend --author="$1 <$2>" -F - &&
249 clean_fake_sendmail &&
250 git format-patch --stdout -1 >"suppress-self-$3.patch" &&
251
252 git send-email --from="$1 <$2>" \
253 --to=nobody@example.com \
254 --cc-cmd=./cccmd-sed \
255 --suppress-cc=self \
256 --smtp-server="$(pwd)/fake.sendmail" \
257 suppress-self-$3.patch &&
258
259 mv msgtxt1 msgtxt1-$3 &&
260 sed -e '/^$/q' msgtxt1-$3 >"msghdr1-$3" &&
261
262 (grep '^Cc:' msghdr1-$3 >"actual-no-cc-$3";
263 test_must_be_empty actual-no-cc-$3)
264 }
265
266 test_suppress_self_unquoted () {
267 test_suppress_self "$1" "$2" "unquoted-$3" <<-EOF
268 test suppress-cc.self unquoted-$3 with name $1 email $2
269
270 unquoted-$3
271
272 cccmd--$1 <$2>
273
274 Cc: $1 <$2>
275 Signed-off-by: $1 <$2>
276 EOF
277 }
278
279 test_suppress_self_quoted () {
280 test_suppress_self "$1" "$2" "quoted-$3" <<-EOF
281 test suppress-cc.self quoted-$3 with name $1 email $2
282
283 quoted-$3
284
285 cccmd--"$1" <$2>
286
287 Cc: $1 <$2>
288 Cc: "$1" <$2>
289 Signed-off-by: $1 <$2>
290 Signed-off-by: "$1" <$2>
291 EOF
292 }
293
294 test_expect_success $PREREQ 'self name is suppressed' "
295 test_suppress_self_unquoted 'A U Thor' 'author@example.com' \
296 'self_name_suppressed'
297 "
298
299 test_expect_success $PREREQ 'self name with dot is suppressed' "
300 test_suppress_self_quoted 'A U. Thor' 'author@example.com' \
301 'self_name_dot_suppressed'
302 "
303
304 test_expect_success $PREREQ 'non-ascii self name is suppressed' "
305 test_suppress_self_quoted 'Füñný Nâmé' 'odd_?=mail@example.com' \
306 'non_ascii_self_suppressed'
307 "
308
309 # This name is long enough to force format-patch to split it into multiple
310 # encoded-words, assuming it uses UTF-8 with the "Q" encoding.
311 test_expect_success $PREREQ 'long non-ascii self name is suppressed' "
312 test_suppress_self_quoted 'Ƒüñníęř €. Nâṁé' 'odd_?=mail@example.com' \
313 'long_non_ascii_self_suppressed'
314 "
315
316 test_expect_success $PREREQ 'sanitized self name is suppressed' "
317 test_suppress_self_unquoted '\"A U. Thor\"' 'author@example.com' \
318 'self_name_sanitized_suppressed'
319 "
320
321 test_expect_success $PREREQ 'Show all headers' '
322 git send-email \
323 --dry-run \
324 --suppress-cc=sob \
325 --from="Example <from@example.com>" \
326 --reply-to="Reply <reply@example.com>" \
327 --to=to@example.com \
328 --cc=cc@example.com \
329 --bcc=bcc@example.com \
330 --in-reply-to="<unique-message-id@example.com>" \
331 --smtp-server relay.example.com \
332 $patches | replace_variable_fields \
333 >actual-show-all-headers &&
334 test_cmp expected-show-all-headers actual-show-all-headers
335 '
336
337 test_expect_success $PREREQ 'Prompting works' '
338 clean_fake_sendmail &&
339 (echo "to@example.com" &&
340 echo "my-message-id@example.com"
341 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
342 --smtp-server="$(pwd)/fake.sendmail" \
343 $patches \
344 2>errors &&
345 grep "^From: A U Thor <author@example.com>\$" msgtxt1 &&
346 grep "^To: to@example.com\$" msgtxt1 &&
347 grep "^In-Reply-To: <my-message-id@example.com>" msgtxt1
348 '
349
350 test_expect_success $PREREQ,AUTOIDENT 'implicit ident is allowed' '
351 clean_fake_sendmail &&
352 (sane_unset GIT_AUTHOR_NAME &&
353 sane_unset GIT_AUTHOR_EMAIL &&
354 sane_unset GIT_COMMITTER_NAME &&
355 sane_unset GIT_COMMITTER_EMAIL &&
356 GIT_SEND_EMAIL_NOTTY=1 git send-email \
357 --smtp-server="$(pwd)/fake.sendmail" \
358 --to=to@example.com \
359 $patches </dev/null 2>errors
360 )
361 '
362
363 test_expect_success $PREREQ,!AUTOIDENT 'broken implicit ident aborts send-email' '
364 clean_fake_sendmail &&
365 (sane_unset GIT_AUTHOR_NAME &&
366 sane_unset GIT_AUTHOR_EMAIL &&
367 sane_unset GIT_COMMITTER_NAME &&
368 sane_unset GIT_COMMITTER_EMAIL &&
369 GIT_SEND_EMAIL_NOTTY=1 && export GIT_SEND_EMAIL_NOTTY &&
370 test_must_fail git send-email \
371 --smtp-server="$(pwd)/fake.sendmail" \
372 --to=to@example.com \
373 $patches </dev/null 2>errors &&
374 test_i18ngrep "tell me who you are" errors
375 )
376 '
377
378 test_expect_success $PREREQ 'setup cmd scripts' '
379 write_script tocmd-sed <<-\EOF &&
380 sed -n -e "s/^tocmd--//p" "$1"
381 EOF
382 write_script cccmd-sed <<-\EOF &&
383 sed -n -e "s/^cccmd--//p" "$1"
384 EOF
385 write_script headercmd-sed <<-\EOF
386 sed -n -e "s/^headercmd--//p" "$1"
387 EOF
388 '
389
390 test_expect_success $PREREQ 'tocmd works' '
391 clean_fake_sendmail &&
392 cp $patches tocmd.patch &&
393 echo tocmd--tocmd@example.com >>tocmd.patch &&
394 git send-email \
395 --from="Example <nobody@example.com>" \
396 --to-cmd=./tocmd-sed \
397 --smtp-server="$(pwd)/fake.sendmail" \
398 tocmd.patch \
399 &&
400 grep "^To: tocmd@example.com" msgtxt1
401 '
402
403 test_expect_success $PREREQ 'cccmd works' '
404 clean_fake_sendmail &&
405 cp $patches cccmd.patch &&
406 echo "cccmd-- cccmd@example.com" >>cccmd.patch &&
407 git send-email \
408 --from="Example <nobody@example.com>" \
409 --to=nobody@example.com \
410 --cc-cmd=./cccmd-sed \
411 --smtp-server="$(pwd)/fake.sendmail" \
412 cccmd.patch \
413 &&
414 grep "^ cccmd@example.com" msgtxt1
415 '
416
417 test_expect_success $PREREQ 'headercmd works' '
418 clean_fake_sendmail &&
419 cp $patches headercmd.patch &&
420 echo "headercmd--X-Debbugs-CC: dummy@example.com" >>headercmd.patch &&
421 git send-email \
422 --from="Example <nobody@example.com>" \
423 --to=nobody@example.com \
424 --header-cmd=./headercmd-sed \
425 --smtp-server="$(pwd)/fake.sendmail" \
426 headercmd.patch \
427 &&
428 grep "^X-Debbugs-CC: dummy@example.com" msgtxt1
429 '
430
431 test_expect_success $PREREQ '--no-header-cmd works' '
432 clean_fake_sendmail &&
433 cp $patches headercmd.patch &&
434 echo "headercmd--X-Debbugs-CC: dummy@example.com" >>headercmd.patch &&
435 git send-email \
436 --from="Example <nobody@example.com>" \
437 --to=nobody@example.com \
438 --header-cmd=./headercmd-sed \
439 --no-header-cmd \
440 --smtp-server="$(pwd)/fake.sendmail" \
441 headercmd.patch \
442 &&
443 ! grep "^X-Debbugs-CC: dummy@example.com" msgtxt1
444 '
445
446 test_expect_success $PREREQ 'multiline fields are correctly unfolded' '
447 clean_fake_sendmail &&
448 cp $patches headercmd.patch &&
449 write_script headercmd-multiline <<-\EOF &&
450 echo "X-Debbugs-CC: someone@example.com
451 FoldedField: This is a tale
452 best told using
453 multiple lines."
454 EOF
455 git send-email \
456 --from="Example <nobody@example.com>" \
457 --to=nobody@example.com \
458 --header-cmd=./headercmd-multiline \
459 --smtp-server="$(pwd)/fake.sendmail" \
460 headercmd.patch &&
461 grep "^FoldedField: This is a tale best told using multiple lines.$" msgtxt1
462 '
463
464 # Blank lines in the middle of the output of a command are invalid.
465 test_expect_success $PREREQ 'malform output reported on blank lines in command output' '
466 clean_fake_sendmail &&
467 cp $patches headercmd.patch &&
468 write_script headercmd-malformed-output <<-\EOF &&
469 echo "X-Debbugs-CC: someone@example.com
470
471 SomeOtherField: someone-else@example.com"
472 EOF
473 ! git send-email \
474 --from="Example <nobody@example.com>" \
475 --to=nobody@example.com \
476 --header-cmd=./headercmd-malformed-output \
477 --smtp-server="$(pwd)/fake.sendmail" \
478 headercmd.patch
479 '
480
481 test_expect_success $PREREQ 'reject long lines' '
482 z8=zzzzzzzz &&
483 z64=$z8$z8$z8$z8$z8$z8$z8$z8 &&
484 z512=$z64$z64$z64$z64$z64$z64$z64$z64 &&
485 clean_fake_sendmail &&
486 cp $patches longline.patch &&
487 cat >>longline.patch <<-EOF &&
488 $z512$z512
489 not a long line
490 $z512$z512
491 EOF
492 test_must_fail git send-email \
493 --from="Example <nobody@example.com>" \
494 --to=nobody@example.com \
495 --smtp-server="$(pwd)/fake.sendmail" \
496 --transfer-encoding=8bit \
497 $patches longline.patch \
498 2>actual &&
499 cat >expect <<-\EOF &&
500 fatal: longline.patch:35 is longer than 998 characters
501 warning: no patches were sent
502 EOF
503 test_cmp expect actual
504 '
505
506 test_expect_success $PREREQ 'no patch was sent' '
507 ! test -e commandline1
508 '
509
510 test_expect_success $PREREQ 'Author From: in message body' '
511 clean_fake_sendmail &&
512 git send-email \
513 --from="Example <nobody@example.com>" \
514 --to=nobody@example.com \
515 --smtp-server="$(pwd)/fake.sendmail" \
516 $patches &&
517 sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
518 grep "From: A <author@example.com>" msgbody1
519 '
520
521 test_expect_success $PREREQ 'Author From: not in message body' '
522 clean_fake_sendmail &&
523 git send-email \
524 --from="A <author@example.com>" \
525 --to=nobody@example.com \
526 --smtp-server="$(pwd)/fake.sendmail" \
527 $patches &&
528 sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
529 ! grep "From: A <author@example.com>" msgbody1
530 '
531
532 test_expect_success $PREREQ 'allow long lines with --no-validate' '
533 git send-email \
534 --from="Example <nobody@example.com>" \
535 --to=nobody@example.com \
536 --smtp-server="$(pwd)/fake.sendmail" \
537 --no-validate \
538 $patches longline.patch \
539 2>errors
540 '
541
542 test_expect_success $PREREQ 'short lines with auto encoding are 8bit' '
543 clean_fake_sendmail &&
544 git send-email \
545 --from="A <author@example.com>" \
546 --to=nobody@example.com \
547 --smtp-server="$(pwd)/fake.sendmail" \
548 --transfer-encoding=auto \
549 $patches &&
550 grep "Content-Transfer-Encoding: 8bit" msgtxt1
551 '
552
553 test_expect_success $PREREQ 'long lines with auto encoding are quoted-printable' '
554 clean_fake_sendmail &&
555 git send-email \
556 --from="Example <nobody@example.com>" \
557 --to=nobody@example.com \
558 --smtp-server="$(pwd)/fake.sendmail" \
559 --transfer-encoding=auto \
560 --no-validate \
561 longline.patch &&
562 grep "Content-Transfer-Encoding: quoted-printable" msgtxt1
563 '
564
565 test_expect_success $PREREQ 'carriage returns with auto encoding are quoted-printable' '
566 clean_fake_sendmail &&
567 cp $patches cr.patch &&
568 printf "this is a line\r\n" >>cr.patch &&
569 git send-email \
570 --from="Example <nobody@example.com>" \
571 --to=nobody@example.com \
572 --smtp-server="$(pwd)/fake.sendmail" \
573 --transfer-encoding=auto \
574 --no-validate \
575 cr.patch &&
576 grep "Content-Transfer-Encoding: quoted-printable" msgtxt1
577 '
578
579 for enc in auto quoted-printable base64
580 do
581 test_expect_success $PREREQ "--validate passes with encoding $enc" '
582 git send-email \
583 --from="Example <nobody@example.com>" \
584 --to=nobody@example.com \
585 --smtp-server="$(pwd)/fake.sendmail" \
586 --transfer-encoding=$enc \
587 --validate \
588 $patches longline.patch
589 '
590
591 done
592
593 test_expect_success $PREREQ "--validate respects relative core.hooksPath path" '
594 clean_fake_sendmail &&
595 mkdir my-hooks &&
596 test_when_finished "rm my-hooks.ran" &&
597 write_script my-hooks/sendemail-validate <<-\EOF &&
598 >my-hooks.ran
599 exit 1
600 EOF
601 test_config core.hooksPath "my-hooks" &&
602 test_must_fail git send-email \
603 --from="Example <nobody@example.com>" \
604 --to=nobody@example.com \
605 --smtp-server="$(pwd)/fake.sendmail" \
606 --validate \
607 longline.patch 2>actual &&
608 test_path_is_file my-hooks.ran &&
609 cat >expect <<-EOF &&
610 fatal: longline.patch: rejected by sendemail-validate hook
611 fatal: command '"'"'git hook run --ignore-missing sendemail-validate -- <patch> <header>'"'"' died with exit code 1
612 warning: no patches were sent
613 EOF
614 test_cmp expect actual
615 '
616
617 test_expect_success $PREREQ "--validate respects absolute core.hooksPath path" '
618 hooks_path="$(pwd)/my-hooks" &&
619 test_config core.hooksPath "$hooks_path" &&
620 test_when_finished "rm my-hooks.ran" &&
621 test_must_fail git send-email \
622 --from="Example <nobody@example.com>" \
623 --to=nobody@example.com \
624 --smtp-server="$(pwd)/fake.sendmail" \
625 --validate \
626 longline.patch 2>actual &&
627 test_path_is_file my-hooks.ran &&
628 cat >expect <<-EOF &&
629 fatal: longline.patch: rejected by sendemail-validate hook
630 fatal: command '"'"'git hook run --ignore-missing sendemail-validate -- <patch> <header>'"'"' died with exit code 1
631 warning: no patches were sent
632 EOF
633 test_cmp expect actual
634 '
635
636 test_expect_success $PREREQ "--validate hook supports header argument" '
637 write_script my-hooks/sendemail-validate <<-\EOF &&
638 if test "$#" -ge 2
639 then
640 grep "X-test-header: v1.0" "$2"
641 else
642 echo "No header arg passed"
643 exit 1
644 fi
645 EOF
646 test_config core.hooksPath "my-hooks" &&
647 rm -fr outdir &&
648 git format-patch \
649 --add-header="X-test-header: v1.0" \
650 -n HEAD^1 -o outdir &&
651 git send-email \
652 --dry-run \
653 --to=nobody@example.com \
654 --smtp-server="$(pwd)/fake.sendmail" \
655 --validate \
656 outdir/000?-*.patch
657 '
658
659 test_expect_success $PREREQ 'clear message-id before parsing a new message' '
660 clean_fake_sendmail &&
661 echo true | write_script my-hooks/sendemail-validate &&
662 test_config core.hooksPath my-hooks &&
663 git send-email --validate --to=recipient@example.com \
664 --smtp-server="$(pwd)/fake.sendmail" \
665 $patches $threaded_patches &&
666 id0=$(grep "^Message-ID: " $threaded_patches) &&
667 id1=$(grep "^Message-ID: " msgtxt1) &&
668 id2=$(grep "^Message-ID: " msgtxt2) &&
669 test "z$id0" = "z$id2" &&
670 test "z$id1" != "z$id2"
671 '
672
673 for enc in 7bit 8bit quoted-printable base64
674 do
675 test_expect_success $PREREQ "--transfer-encoding=$enc produces correct header" '
676 clean_fake_sendmail &&
677 git send-email \
678 --from="Example <nobody@example.com>" \
679 --to=nobody@example.com \
680 --smtp-server="$(pwd)/fake.sendmail" \
681 --transfer-encoding=$enc \
682 $patches &&
683 grep "Content-Transfer-Encoding: $enc" msgtxt1
684 '
685 done
686
687 test_expect_success $PREREQ 'Invalid In-Reply-To' '
688 clean_fake_sendmail &&
689 git send-email \
690 --from="Example <nobody@example.com>" \
691 --to=nobody@example.com \
692 --in-reply-to=" " \
693 --smtp-server="$(pwd)/fake.sendmail" \
694 $patches \
695 2>errors &&
696 ! grep "^In-Reply-To: < *>" msgtxt1
697 '
698
699 test_expect_success $PREREQ 'Valid In-Reply-To when prompting' '
700 clean_fake_sendmail &&
701 (echo "From Example <from@example.com>" &&
702 echo "To Example <to@example.com>" &&
703 echo ""
704 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
705 --smtp-server="$(pwd)/fake.sendmail" \
706 $patches 2>errors &&
707 ! grep "^In-Reply-To: < *>" msgtxt1
708 '
709
710 test_expect_success $PREREQ 'In-Reply-To without --chain-reply-to' '
711 clean_fake_sendmail &&
712 echo "<unique-message-id@example.com>" >expect &&
713 git send-email \
714 --from="Example <nobody@example.com>" \
715 --to=nobody@example.com \
716 --no-chain-reply-to \
717 --in-reply-to="$(cat expect)" \
718 --smtp-server="$(pwd)/fake.sendmail" \
719 $patches $patches $patches \
720 2>errors &&
721 # The first message is a reply to --in-reply-to
722 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
723 test_cmp expect actual &&
724 # Second and subsequent messages are replies to the first one
725 sed -n -e "s/^Message-ID: *\(.*\)/\1/p" msgtxt1 >expect &&
726 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
727 test_cmp expect actual &&
728 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
729 test_cmp expect actual
730 '
731
732 test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' '
733 clean_fake_sendmail &&
734 echo "<unique-message-id@example.com>" >expect &&
735 git send-email \
736 --from="Example <nobody@example.com>" \
737 --to=nobody@example.com \
738 --chain-reply-to \
739 --in-reply-to="$(cat expect)" \
740 --smtp-server="$(pwd)/fake.sendmail" \
741 $patches $patches $patches \
742 2>errors &&
743 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
744 test_cmp expect actual &&
745 sed -n -e "s/^Message-ID: *\(.*\)/\1/p" msgtxt1 >expect &&
746 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
747 test_cmp expect actual &&
748 sed -n -e "s/^Message-ID: *\(.*\)/\1/p" msgtxt2 >expect &&
749 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
750 test_cmp expect actual
751 '
752
753 test_set_editor "$(pwd)/fake-editor"
754
755 test_expect_success $PREREQ 'setup erroring fake editor' '
756 write_script fake-editor <<-\EOF
757 echo >&2 "I am about to error"
758 exit 1
759 EOF
760 '
761
762 test_expect_success $PREREQ 'fake editor dies with error' '
763 clean_fake_sendmail &&
764 test_must_fail git send-email \
765 --compose --subject foo \
766 --from="Example <nobody@example.com>" \
767 --to=nobody@example.com \
768 --smtp-server="$(pwd)/fake.sendmail" \
769 $patches 2>err &&
770 grep "I am about to error" err &&
771 grep "the editor exited uncleanly, aborting everything" err
772 '
773
774 test_expect_success $PREREQ 'setup fake editor' '
775 write_script fake-editor <<-\EOF
776 echo fake edit >>"$1"
777 EOF
778 '
779
780 test_expect_success $PREREQ '--compose works' '
781 clean_fake_sendmail &&
782 git send-email \
783 --compose --subject foo \
784 --from="Example <nobody@example.com>" \
785 --to=nobody@example.com \
786 --smtp-server="$(pwd)/fake.sendmail" \
787 $patches \
788 2>errors
789 '
790
791 test_expect_success $PREREQ 'first message is compose text' '
792 grep "^fake edit" msgtxt1
793 '
794
795 test_expect_success $PREREQ 'second message is patch' '
796 grep "Subject:.*Second" msgtxt2
797 '
798
799 test_expect_success $PREREQ 'setup expect' "
800 cat >expected-suppress-sob <<\EOF
801 0001-Second.patch
802 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
803 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
804 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
805 Dry-OK. Log says:
806 Server: relay.example.com
807 MAIL FROM:<from@example.com>
808 RCPT TO:<to@example.com>
809 RCPT TO:<cc@example.com>
810 RCPT TO:<author@example.com>
811 RCPT TO:<one@example.com>
812 RCPT TO:<two@example.com>
813 From: Example <from@example.com>
814 To: to@example.com
815 Cc: cc@example.com,
816 A <author@example.com>,
817 One <one@example.com>,
818 two@example.com
819 Subject: [PATCH 1/1] Second.
820 Date: DATE-STRING
821 Message-ID: MESSAGE-ID-STRING
822 X-Mailer: X-MAILER-STRING
823 MIME-Version: 1.0
824 Content-Transfer-Encoding: 8bit
825
826 Result: OK
827 EOF
828 "
829
830 test_suppression () {
831 git send-email \
832 --dry-run \
833 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
834 --from="Example <from@example.com>" \
835 --to=to@example.com \
836 --smtp-server relay.example.com \
837 $patches | replace_variable_fields \
838 >actual-suppress-$1${2+"-$2"} &&
839 test_cmp expected-suppress-$1${2+"-$2"} actual-suppress-$1${2+"-$2"}
840 }
841
842 test_expect_success $PREREQ 'sendemail.cc set' '
843 git config sendemail.cc cc@example.com &&
844 test_suppression sob
845 '
846
847 test_expect_success $PREREQ 'setup expect' "
848 cat >expected-suppress-sob <<\EOF
849 0001-Second.patch
850 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
851 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
852 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
853 Dry-OK. Log says:
854 Server: relay.example.com
855 MAIL FROM:<from@example.com>
856 RCPT TO:<to@example.com>
857 RCPT TO:<author@example.com>
858 RCPT TO:<one@example.com>
859 RCPT TO:<two@example.com>
860 From: Example <from@example.com>
861 To: to@example.com
862 Cc: A <author@example.com>,
863 One <one@example.com>,
864 two@example.com
865 Subject: [PATCH 1/1] Second.
866 Date: DATE-STRING
867 Message-ID: MESSAGE-ID-STRING
868 X-Mailer: X-MAILER-STRING
869 MIME-Version: 1.0
870 Content-Transfer-Encoding: 8bit
871
872 Result: OK
873 EOF
874 "
875
876 test_expect_success $PREREQ 'sendemail.cc unset' '
877 git config --unset sendemail.cc &&
878 test_suppression sob
879 '
880
881 test_expect_success $PREREQ 'setup expect' "
882 cat >expected-suppress-cccmd <<\EOF
883 0001-Second.patch
884 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
885 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
886 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
887 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
888 Dry-OK. Log says:
889 Server: relay.example.com
890 MAIL FROM:<from@example.com>
891 RCPT TO:<to@example.com>
892 RCPT TO:<author@example.com>
893 RCPT TO:<one@example.com>
894 RCPT TO:<two@example.com>
895 RCPT TO:<committer@example.com>
896 From: Example <from@example.com>
897 To: to@example.com
898 Cc: A <author@example.com>,
899 One <one@example.com>,
900 two@example.com,
901 C O Mitter <committer@example.com>
902 Subject: [PATCH 1/1] Second.
903 Date: DATE-STRING
904 Message-ID: MESSAGE-ID-STRING
905 X-Mailer: X-MAILER-STRING
906 MIME-Version: 1.0
907 Content-Transfer-Encoding: 8bit
908
909 Result: OK
910 EOF
911 "
912
913 test_expect_success $PREREQ 'sendemail.cccmd' '
914 write_script cccmd <<-\EOF &&
915 echo cc-cmd@example.com
916 EOF
917 git config sendemail.cccmd ./cccmd &&
918 test_suppression cccmd
919 '
920
921 test_expect_success $PREREQ 'setup expect' '
922 cat >expected-suppress-all <<\EOF
923 0001-Second.patch
924 Dry-OK. Log says:
925 Server: relay.example.com
926 MAIL FROM:<from@example.com>
927 RCPT TO:<to@example.com>
928 From: Example <from@example.com>
929 To: to@example.com
930 Subject: [PATCH 1/1] Second.
931 Date: DATE-STRING
932 Message-ID: MESSAGE-ID-STRING
933 X-Mailer: X-MAILER-STRING
934 MIME-Version: 1.0
935 Content-Transfer-Encoding: 8bit
936
937 Result: OK
938 EOF
939 '
940
941 test_expect_success $PREREQ '--suppress-cc=all' '
942 test_suppression all
943 '
944
945 test_expect_success $PREREQ 'setup expect' "
946 cat >expected-suppress-body <<\EOF
947 0001-Second.patch
948 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
949 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
950 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
951 (cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
952 Dry-OK. Log says:
953 Server: relay.example.com
954 MAIL FROM:<from@example.com>
955 RCPT TO:<to@example.com>
956 RCPT TO:<author@example.com>
957 RCPT TO:<one@example.com>
958 RCPT TO:<two@example.com>
959 RCPT TO:<cc-cmd@example.com>
960 From: Example <from@example.com>
961 To: to@example.com
962 Cc: A <author@example.com>,
963 One <one@example.com>,
964 two@example.com,
965 cc-cmd@example.com
966 Subject: [PATCH 1/1] Second.
967 Date: DATE-STRING
968 Message-ID: MESSAGE-ID-STRING
969 X-Mailer: X-MAILER-STRING
970 MIME-Version: 1.0
971 Content-Transfer-Encoding: 8bit
972
973 Result: OK
974 EOF
975 "
976
977 test_expect_success $PREREQ '--suppress-cc=body' '
978 test_suppression body
979 '
980
981 test_expect_success $PREREQ 'setup expect' "
982 cat >expected-suppress-body-cccmd <<\EOF
983 0001-Second.patch
984 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
985 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
986 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
987 Dry-OK. Log says:
988 Server: relay.example.com
989 MAIL FROM:<from@example.com>
990 RCPT TO:<to@example.com>
991 RCPT TO:<author@example.com>
992 RCPT TO:<one@example.com>
993 RCPT TO:<two@example.com>
994 From: Example <from@example.com>
995 To: to@example.com
996 Cc: A <author@example.com>,
997 One <one@example.com>,
998 two@example.com
999 Subject: [PATCH 1/1] Second.
1000 Date: DATE-STRING
1001 Message-ID: MESSAGE-ID-STRING
1002 X-Mailer: X-MAILER-STRING
1003 MIME-Version: 1.0
1004 Content-Transfer-Encoding: 8bit
1005
1006 Result: OK
1007 EOF
1008 "
1009
1010 test_expect_success $PREREQ '--suppress-cc=body --suppress-cc=cccmd' '
1011 test_suppression body cccmd
1012 '
1013
1014 test_expect_success $PREREQ 'setup expect' "
1015 cat >expected-suppress-sob <<\EOF
1016 0001-Second.patch
1017 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
1018 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
1019 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
1020 Dry-OK. Log says:
1021 Server: relay.example.com
1022 MAIL FROM:<from@example.com>
1023 RCPT TO:<to@example.com>
1024 RCPT TO:<author@example.com>
1025 RCPT TO:<one@example.com>
1026 RCPT TO:<two@example.com>
1027 From: Example <from@example.com>
1028 To: to@example.com
1029 Cc: A <author@example.com>,
1030 One <one@example.com>,
1031 two@example.com
1032 Subject: [PATCH 1/1] Second.
1033 Date: DATE-STRING
1034 Message-ID: MESSAGE-ID-STRING
1035 X-Mailer: X-MAILER-STRING
1036 MIME-Version: 1.0
1037 Content-Transfer-Encoding: 8bit
1038
1039 Result: OK
1040 EOF
1041 "
1042
1043 test_expect_success $PREREQ '--suppress-cc=sob' '
1044 test_might_fail git config --unset sendemail.cccmd &&
1045 test_suppression sob
1046 '
1047
1048 test_expect_success $PREREQ 'setup expect' "
1049 cat >expected-suppress-bodycc <<\EOF
1050 0001-Second.patch
1051 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
1052 (mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
1053 (mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
1054 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
1055 Dry-OK. Log says:
1056 Server: relay.example.com
1057 MAIL FROM:<from@example.com>
1058 RCPT TO:<to@example.com>
1059 RCPT TO:<author@example.com>
1060 RCPT TO:<one@example.com>
1061 RCPT TO:<two@example.com>
1062 RCPT TO:<committer@example.com>
1063 From: Example <from@example.com>
1064 To: to@example.com
1065 Cc: A <author@example.com>,
1066 One <one@example.com>,
1067 two@example.com,
1068 C O Mitter <committer@example.com>
1069 Subject: [PATCH 1/1] Second.
1070 Date: DATE-STRING
1071 Message-ID: MESSAGE-ID-STRING
1072 X-Mailer: X-MAILER-STRING
1073 MIME-Version: 1.0
1074 Content-Transfer-Encoding: 8bit
1075
1076 Result: OK
1077 EOF
1078 "
1079
1080 test_expect_success $PREREQ '--suppress-cc=bodycc' '
1081 test_suppression bodycc
1082 '
1083
1084 test_expect_success $PREREQ 'setup expect' "
1085 cat >expected-suppress-cc <<\EOF
1086 0001-Second.patch
1087 (mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
1088 (body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
1089 Dry-OK. Log says:
1090 Server: relay.example.com
1091 MAIL FROM:<from@example.com>
1092 RCPT TO:<to@example.com>
1093 RCPT TO:<author@example.com>
1094 RCPT TO:<committer@example.com>
1095 From: Example <from@example.com>
1096 To: to@example.com
1097 Cc: A <author@example.com>,
1098 C O Mitter <committer@example.com>
1099 Subject: [PATCH 1/1] Second.
1100 Date: DATE-STRING
1101 Message-ID: MESSAGE-ID-STRING
1102 X-Mailer: X-MAILER-STRING
1103 MIME-Version: 1.0
1104 Content-Transfer-Encoding: 8bit
1105
1106 Result: OK
1107 EOF
1108 "
1109
1110 test_expect_success $PREREQ '--suppress-cc=cc' '
1111 test_suppression cc
1112 '
1113
1114 test_confirm () {
1115 echo y | \
1116 GIT_SEND_EMAIL_NOTTY=1 \
1117 git send-email \
1118 --from="Example <nobody@example.com>" \
1119 --to=nobody@example.com \
1120 --smtp-server="$(pwd)/fake.sendmail" \
1121 $@ $patches >stdout &&
1122 grep "Send this email" stdout
1123 }
1124
1125 test_expect_success $PREREQ '--confirm=always' '
1126 test_confirm --confirm=always --suppress-cc=all
1127 '
1128
1129 test_expect_success $PREREQ '--confirm=auto' '
1130 test_confirm --confirm=auto
1131 '
1132
1133 test_expect_success $PREREQ '--confirm=cc' '
1134 test_confirm --confirm=cc
1135 '
1136
1137 test_expect_success $PREREQ '--confirm=compose' '
1138 test_confirm --confirm=compose --compose
1139 '
1140
1141 test_expect_success $PREREQ 'confirm by default (due to cc)' '
1142 test_when_finished git config sendemail.confirm never &&
1143 git config --unset sendemail.confirm &&
1144 test_confirm
1145 '
1146
1147 test_expect_success $PREREQ 'confirm by default (due to --compose)' '
1148 test_when_finished git config sendemail.confirm never &&
1149 git config --unset sendemail.confirm &&
1150 test_confirm --suppress-cc=all --compose
1151 '
1152
1153 test_expect_success $PREREQ 'confirm detects EOF (inform assumes y)' '
1154 test_when_finished git config sendemail.confirm never &&
1155 git config --unset sendemail.confirm &&
1156 rm -fr outdir &&
1157 git format-patch -2 -o outdir &&
1158 GIT_SEND_EMAIL_NOTTY=1 \
1159 git send-email \
1160 --from="Example <nobody@example.com>" \
1161 --to=nobody@example.com \
1162 --smtp-server="$(pwd)/fake.sendmail" \
1163 outdir/*.patch </dev/null
1164 '
1165
1166 test_expect_success $PREREQ 'confirm detects EOF (auto causes failure)' '
1167 test_when_finished git config sendemail.confirm never &&
1168 git config sendemail.confirm auto &&
1169 GIT_SEND_EMAIL_NOTTY=1 &&
1170 export GIT_SEND_EMAIL_NOTTY &&
1171 test_must_fail git send-email \
1172 --from="Example <nobody@example.com>" \
1173 --to=nobody@example.com \
1174 --smtp-server="$(pwd)/fake.sendmail" \
1175 $patches </dev/null
1176 '
1177
1178 test_expect_success $PREREQ 'confirm does not loop forever' '
1179 test_when_finished git config sendemail.confirm never &&
1180 git config sendemail.confirm auto &&
1181 GIT_SEND_EMAIL_NOTTY=1 &&
1182 export GIT_SEND_EMAIL_NOTTY &&
1183 yes "bogus" | test_must_fail git send-email \
1184 --from="Example <nobody@example.com>" \
1185 --to=nobody@example.com \
1186 --smtp-server="$(pwd)/fake.sendmail" \
1187 $patches
1188 '
1189
1190 test_expect_success $PREREQ 'utf8 Cc is rfc2047 encoded' '
1191 clean_fake_sendmail &&
1192 rm -fr outdir &&
1193 git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
1194 git send-email \
1195 --from="Example <nobody@example.com>" \
1196 --to=nobody@example.com \
1197 --smtp-server="$(pwd)/fake.sendmail" \
1198 outdir/*.patch &&
1199 grep "^ " msgtxt1 |
1200 grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
1201 '
1202
1203 test_expect_success $PREREQ '--compose adds MIME for utf8 body' '
1204 clean_fake_sendmail &&
1205 write_script fake-editor-utf8 <<-\EOF &&
1206 echo "utf8 body: àéìöú" >>"$1"
1207 EOF
1208 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1209 git send-email \
1210 --compose --subject foo \
1211 --from="Example <nobody@example.com>" \
1212 --to=nobody@example.com \
1213 --smtp-server="$(pwd)/fake.sendmail" \
1214 $patches &&
1215 grep "^utf8 body" msgtxt1 &&
1216 grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
1217 '
1218
1219 test_expect_success $PREREQ '--compose respects user mime type' '
1220 clean_fake_sendmail &&
1221 write_script fake-editor-utf8-mime <<-\EOF &&
1222 cat >"$1" <<-\EOM
1223 MIME-Version: 1.0
1224 Content-Type: text/plain; charset=iso-8859-1
1225 Content-Transfer-Encoding: 8bit
1226 Subject: foo
1227
1228 utf8 body: àéìöú
1229 EOM
1230 EOF
1231 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
1232 git send-email \
1233 --compose --subject foo \
1234 --from="Example <nobody@example.com>" \
1235 --to=nobody@example.com \
1236 --smtp-server="$(pwd)/fake.sendmail" \
1237 $patches &&
1238 grep "^utf8 body" msgtxt1 &&
1239 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
1240 ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
1241 '
1242
1243 test_expect_success $PREREQ '--compose adds MIME for utf8 subject' '
1244 clean_fake_sendmail &&
1245 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
1246 git send-email \
1247 --compose --subject utf8-sübjëct \
1248 --from="Example <nobody@example.com>" \
1249 --to=nobody@example.com \
1250 --smtp-server="$(pwd)/fake.sendmail" \
1251 $patches &&
1252 grep "^fake edit" msgtxt1 &&
1253 grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
1254 '
1255
1256 test_expect_success $PREREQ 'utf8 author is correctly passed on' '
1257 clean_fake_sendmail &&
1258 test_commit weird_author &&
1259 test_when_finished "git reset --hard HEAD^" &&
1260 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
1261 git format-patch --stdout -1 >funny_name.patch &&
1262 git send-email --from="Example <nobody@example.com>" \
1263 --to=nobody@example.com \
1264 --smtp-server="$(pwd)/fake.sendmail" \
1265 funny_name.patch &&
1266 grep "^From: Füñný Nâmé <odd_?=mail@example.com>" msgtxt1
1267 '
1268
1269 test_expect_success $PREREQ 'utf8 sender is not duplicated' '
1270 clean_fake_sendmail &&
1271 test_commit weird_sender &&
1272 test_when_finished "git reset --hard HEAD^" &&
1273 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
1274 git format-patch --stdout -1 >funny_name.patch &&
1275 git send-email --from="Füñný Nâmé <odd_?=mail@example.com>" \
1276 --to=nobody@example.com \
1277 --smtp-server="$(pwd)/fake.sendmail" \
1278 funny_name.patch &&
1279 grep "^From: " msgtxt1 >msgfrom &&
1280 test_line_count = 1 msgfrom
1281 '
1282
1283 test_expect_success $PREREQ 'sendemail.composeencoding works' '
1284 clean_fake_sendmail &&
1285 git config sendemail.composeencoding iso-8859-1 &&
1286 write_script fake-editor-utf8 <<-\EOF &&
1287 echo "utf8 body: àéìöú" >>"$1"
1288 EOF
1289 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1290 git send-email \
1291 --compose --subject foo \
1292 --from="Example <nobody@example.com>" \
1293 --to=nobody@example.com \
1294 --smtp-server="$(pwd)/fake.sendmail" \
1295 $patches &&
1296 grep "^utf8 body" msgtxt1 &&
1297 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1298 '
1299
1300 test_expect_success $PREREQ '--compose-encoding works' '
1301 clean_fake_sendmail &&
1302 write_script fake-editor-utf8 <<-\EOF &&
1303 echo "utf8 body: àéìöú" >>"$1"
1304 EOF
1305 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1306 git send-email \
1307 --compose-encoding iso-8859-1 \
1308 --compose --subject foo \
1309 --from="Example <nobody@example.com>" \
1310 --to=nobody@example.com \
1311 --smtp-server="$(pwd)/fake.sendmail" \
1312 $patches &&
1313 grep "^utf8 body" msgtxt1 &&
1314 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1315 '
1316
1317 test_expect_success $PREREQ '--compose-encoding overrides sendemail.composeencoding' '
1318 clean_fake_sendmail &&
1319 git config sendemail.composeencoding iso-8859-1 &&
1320 write_script fake-editor-utf8 <<-\EOF &&
1321 echo "utf8 body: àéìöú" >>"$1"
1322 EOF
1323 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1324 git send-email \
1325 --compose-encoding iso-8859-2 \
1326 --compose --subject foo \
1327 --from="Example <nobody@example.com>" \
1328 --to=nobody@example.com \
1329 --smtp-server="$(pwd)/fake.sendmail" \
1330 $patches &&
1331 grep "^utf8 body" msgtxt1 &&
1332 grep "^Content-Type: text/plain; charset=iso-8859-2" msgtxt1
1333 '
1334
1335 test_expect_success $PREREQ '--compose-encoding adds correct MIME for subject' '
1336 clean_fake_sendmail &&
1337 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
1338 git send-email \
1339 --compose-encoding iso-8859-2 \
1340 --compose --subject utf8-sübjëct \
1341 --from="Example <nobody@example.com>" \
1342 --to=nobody@example.com \
1343 --smtp-server="$(pwd)/fake.sendmail" \
1344 $patches &&
1345 grep "^fake edit" msgtxt1 &&
1346 grep "^Subject: =?iso-8859-2?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
1347 '
1348
1349 test_expect_success $PREREQ 'detects ambiguous reference/file conflict' '
1350 echo main >main &&
1351 git add main &&
1352 git commit -m"add main" &&
1353 test_must_fail git send-email --dry-run main 2>errors &&
1354 grep disambiguate errors
1355 '
1356
1357 test_expect_success $PREREQ 'feed two files' '
1358 rm -fr outdir &&
1359 git format-patch -2 -o outdir &&
1360 git send-email \
1361 --dry-run \
1362 --from="Example <nobody@example.com>" \
1363 --to=nobody@example.com \
1364 outdir/000?-*.patch 2>errors >out &&
1365 grep "^Subject: " out >subjects &&
1366 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
1367 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add main"
1368 '
1369
1370 test_expect_success $PREREQ 'in-reply-to but no threading' '
1371 git send-email \
1372 --dry-run \
1373 --from="Example <nobody@example.com>" \
1374 --to=nobody@example.com \
1375 --in-reply-to="<in-reply-id@example.com>" \
1376 --no-thread \
1377 $patches >out &&
1378 grep "In-Reply-To: <in-reply-id@example.com>" out
1379 '
1380
1381 test_expect_success $PREREQ 'no in-reply-to and no threading' '
1382 git send-email \
1383 --dry-run \
1384 --from="Example <nobody@example.com>" \
1385 --to=nobody@example.com \
1386 --no-thread \
1387 $patches >stdout &&
1388 ! grep "In-Reply-To: " stdout
1389 '
1390
1391 test_expect_success $PREREQ 'threading but no chain-reply-to' '
1392 git send-email \
1393 --dry-run \
1394 --from="Example <nobody@example.com>" \
1395 --to=nobody@example.com \
1396 --thread \
1397 --no-chain-reply-to \
1398 $patches $patches >stdout &&
1399 grep "In-Reply-To: " stdout
1400 '
1401
1402 test_expect_success $PREREQ 'override in-reply-to if no threading' '
1403 git send-email \
1404 --dry-run \
1405 --from="Example <nobody@example.com>" \
1406 --to=nobody@example.com \
1407 --no-thread \
1408 --in-reply-to="override" \
1409 $threaded_patches >stdout &&
1410 grep "In-Reply-To: <override>" stdout
1411 '
1412
1413 test_expect_success $PREREQ 'sendemail.to works' '
1414 git config --replace-all sendemail.to "Somebody <somebody@ex.com>" &&
1415 git send-email \
1416 --dry-run \
1417 --from="Example <nobody@example.com>" \
1418 $patches >stdout &&
1419 grep "To: Somebody <somebody@ex.com>" stdout
1420 '
1421
1422 test_expect_success $PREREQ 'setup sendemail.identity' '
1423 git config --replace-all sendemail.to "default@example.com" &&
1424 git config --replace-all sendemail.isp.to "isp@example.com" &&
1425 git config --replace-all sendemail.cloud.to "cloud@example.com"
1426 '
1427
1428 test_expect_success $PREREQ 'sendemail.identity: reads the correct identity config' '
1429 git -c sendemail.identity=cloud send-email \
1430 --dry-run \
1431 --from="nobody@example.com" \
1432 $patches >stdout &&
1433 grep "To: cloud@example.com" stdout
1434 '
1435
1436 test_expect_success $PREREQ 'sendemail.identity: identity overrides sendemail.identity' '
1437 git -c sendemail.identity=cloud send-email \
1438 --identity=isp \
1439 --dry-run \
1440 --from="nobody@example.com" \
1441 $patches >stdout &&
1442 grep "To: isp@example.com" stdout
1443 '
1444
1445 test_expect_success $PREREQ 'sendemail.identity: --no-identity clears previous identity' '
1446 git -c sendemail.identity=cloud send-email \
1447 --no-identity \
1448 --dry-run \
1449 --from="nobody@example.com" \
1450 $patches >stdout &&
1451 grep "To: default@example.com" stdout
1452 '
1453
1454 test_expect_success $PREREQ 'sendemail.identity: bool identity variable existence overrides' '
1455 git -c sendemail.identity=cloud \
1456 -c sendemail.xmailer=true \
1457 -c sendemail.cloud.xmailer=false \
1458 send-email \
1459 --dry-run \
1460 --from="nobody@example.com" \
1461 $patches >stdout &&
1462 grep "To: cloud@example.com" stdout &&
1463 ! grep "X-Mailer" stdout
1464 '
1465
1466 test_expect_success $PREREQ 'sendemail.identity: bool variable fallback' '
1467 git -c sendemail.identity=cloud \
1468 -c sendemail.xmailer=false \
1469 send-email \
1470 --dry-run \
1471 --from="nobody@example.com" \
1472 $patches >stdout &&
1473 grep "To: cloud@example.com" stdout &&
1474 ! grep "X-Mailer" stdout
1475 '
1476
1477 test_expect_success $PREREQ 'sendemail.identity: bool variable without a value' '
1478 git -c sendemail.xmailer \
1479 send-email \
1480 --dry-run \
1481 --from="nobody@example.com" \
1482 $patches >stdout &&
1483 grep "To: default@example.com" stdout &&
1484 grep "X-Mailer" stdout
1485 '
1486
1487 test_expect_success $PREREQ '--no-to overrides sendemail.to' '
1488 git send-email \
1489 --dry-run \
1490 --from="Example <nobody@example.com>" \
1491 --no-to \
1492 --to=nobody@example.com \
1493 $patches >stdout &&
1494 grep "To: nobody@example.com" stdout &&
1495 ! grep "To: Somebody <somebody@ex.com>" stdout
1496 '
1497
1498 test_expect_success $PREREQ 'sendemail.cc works' '
1499 git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" &&
1500 git send-email \
1501 --dry-run \
1502 --from="Example <nobody@example.com>" \
1503 --to=nobody@example.com \
1504 $patches >stdout &&
1505 grep "Cc: Somebody <somebody@ex.com>" stdout
1506 '
1507
1508 test_expect_success $PREREQ '--no-cc overrides sendemail.cc' '
1509 git send-email \
1510 --dry-run \
1511 --from="Example <nobody@example.com>" \
1512 --no-cc \
1513 --cc=bodies@example.com \
1514 --to=nobody@example.com \
1515 $patches >stdout &&
1516 grep "Cc: bodies@example.com" stdout &&
1517 ! grep "Cc: Somebody <somebody@ex.com>" stdout
1518 '
1519
1520 test_expect_success $PREREQ 'sendemail.bcc works' '
1521 git config --replace-all sendemail.bcc "Other <other@ex.com>" &&
1522 git send-email \
1523 --dry-run \
1524 --from="Example <nobody@example.com>" \
1525 --to=nobody@example.com \
1526 --smtp-server relay.example.com \
1527 $patches >stdout &&
1528 grep "RCPT TO:<other@ex.com>" stdout
1529 '
1530
1531 test_expect_success $PREREQ '--no-bcc overrides sendemail.bcc' '
1532 git send-email \
1533 --dry-run \
1534 --from="Example <nobody@example.com>" \
1535 --no-bcc \
1536 --bcc=bodies@example.com \
1537 --to=nobody@example.com \
1538 --smtp-server relay.example.com \
1539 $patches >stdout &&
1540 grep "RCPT TO:<bodies@example.com>" stdout &&
1541 ! grep "RCPT TO:<other@ex.com>" stdout
1542 '
1543
1544 test_expect_success $PREREQ 'patches To headers are used by default' '
1545 patch=$(git format-patch -1 --to="bodies@example.com") &&
1546 test_when_finished "rm $patch" &&
1547 git send-email \
1548 --dry-run \
1549 --from="Example <nobody@example.com>" \
1550 --smtp-server relay.example.com \
1551 $patch >stdout &&
1552 grep "RCPT TO:<bodies@example.com>" stdout
1553 '
1554
1555 test_expect_success $PREREQ 'patches To headers are appended to' '
1556 patch=$(git format-patch -1 --to="bodies@example.com") &&
1557 test_when_finished "rm $patch" &&
1558 git send-email \
1559 --dry-run \
1560 --from="Example <nobody@example.com>" \
1561 --to=nobody@example.com \
1562 --smtp-server relay.example.com \
1563 $patch >stdout &&
1564 grep "RCPT TO:<bodies@example.com>" stdout &&
1565 grep "RCPT TO:<nobody@example.com>" stdout
1566 '
1567
1568 test_expect_success $PREREQ 'To headers from files reset each patch' '
1569 patch1=$(git format-patch -1 --to="bodies@example.com") &&
1570 patch2=$(git format-patch -1 --to="other@example.com" HEAD~) &&
1571 test_when_finished "rm $patch1 && rm $patch2" &&
1572 git send-email \
1573 --dry-run \
1574 --from="Example <nobody@example.com>" \
1575 --to="nobody@example.com" \
1576 --smtp-server relay.example.com \
1577 $patch1 $patch2 >stdout &&
1578 test $(grep -c "RCPT TO:<bodies@example.com>" stdout) = 1 &&
1579 test $(grep -c "RCPT TO:<nobody@example.com>" stdout) = 2 &&
1580 test $(grep -c "RCPT TO:<other@example.com>" stdout) = 1
1581 '
1582
1583 test_expect_success $PREREQ 'setup expect' '
1584 cat >email-using-8bit <<\EOF
1585 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1586 Message-ID: <bogus-message-id@example.com>
1587 From: author@example.com
1588 Date: Sat, 12 Jun 2010 15:53:58 +0200
1589 Subject: subject goes here
1590
1591 Dieser deutsche Text enthält einen Umlaut!
1592 EOF
1593 '
1594
1595 test_expect_success $PREREQ 'setup expect' '
1596 echo "Subject: subject goes here" >expected
1597 '
1598
1599 test_expect_success $PREREQ 'ASCII subject is not RFC2047 quoted' '
1600 clean_fake_sendmail &&
1601 echo bogus |
1602 git send-email --from=author@example.com --to=nobody@example.com \
1603 --smtp-server="$(pwd)/fake.sendmail" \
1604 --8bit-encoding=UTF-8 \
1605 email-using-8bit >stdout &&
1606 grep "Subject" msgtxt1 >actual &&
1607 test_cmp expected actual
1608 '
1609
1610 test_expect_success $PREREQ 'setup expect' '
1611 cat >content-type-decl <<-\EOF
1612 MIME-Version: 1.0
1613 Content-Type: text/plain; charset=UTF-8
1614 Content-Transfer-Encoding: 8bit
1615 EOF
1616 '
1617
1618 test_expect_success $PREREQ 'asks about and fixes 8bit encodings' '
1619 clean_fake_sendmail &&
1620 echo |
1621 git send-email --from=author@example.com --to=nobody@example.com \
1622 --smtp-server="$(pwd)/fake.sendmail" \
1623 email-using-8bit >stdout &&
1624 grep "do not declare a Content-Transfer-Encoding" stdout &&
1625 grep email-using-8bit stdout &&
1626 grep "Which 8bit encoding" stdout &&
1627 grep -E "Content|MIME" msgtxt1 >actual &&
1628 test_cmp content-type-decl actual
1629 '
1630
1631 test_expect_success $PREREQ 'sendemail.8bitEncoding works' '
1632 clean_fake_sendmail &&
1633 git config sendemail.assume8bitEncoding UTF-8 &&
1634 echo bogus |
1635 git send-email --from=author@example.com --to=nobody@example.com \
1636 --smtp-server="$(pwd)/fake.sendmail" \
1637 email-using-8bit >stdout &&
1638 grep -E "Content|MIME" msgtxt1 >actual &&
1639 test_cmp content-type-decl actual
1640 '
1641
1642 test_expect_success $PREREQ 'sendemail.8bitEncoding in .git/config overrides --global .gitconfig' '
1643 clean_fake_sendmail &&
1644 git config sendemail.assume8bitEncoding UTF-8 &&
1645 test_when_finished "rm -rf home" &&
1646 mkdir home &&
1647 git config -f home/.gitconfig sendemail.assume8bitEncoding "bogus too" &&
1648 echo bogus |
1649 env HOME="$(pwd)/home" DEBUG=1 \
1650 git send-email --from=author@example.com --to=nobody@example.com \
1651 --smtp-server="$(pwd)/fake.sendmail" \
1652 email-using-8bit >stdout &&
1653 grep -E "Content|MIME" msgtxt1 >actual &&
1654 test_cmp content-type-decl actual
1655 '
1656
1657 test_expect_success $PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
1658 clean_fake_sendmail &&
1659 git config sendemail.assume8bitEncoding "bogus too" &&
1660 echo bogus |
1661 git send-email --from=author@example.com --to=nobody@example.com \
1662 --smtp-server="$(pwd)/fake.sendmail" \
1663 --8bit-encoding=UTF-8 \
1664 email-using-8bit >stdout &&
1665 grep -E "Content|MIME" msgtxt1 >actual &&
1666 test_cmp content-type-decl actual
1667 '
1668
1669 test_expect_success $PREREQ 'setup expect' '
1670 cat >email-using-8bit <<-\EOF
1671 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1672 Message-ID: <bogus-message-id@example.com>
1673 From: author@example.com
1674 Date: Sat, 12 Jun 2010 15:53:58 +0200
1675 Subject: Dieser Betreff enthält auch einen Umlaut!
1676
1677 Nothing to see here.
1678 EOF
1679 '
1680
1681 test_expect_success $PREREQ 'setup expect' '
1682 cat >expected <<-\EOF
1683 Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
1684 EOF
1685 '
1686
1687 test_expect_success $PREREQ '--8bit-encoding also treats subject' '
1688 clean_fake_sendmail &&
1689 echo bogus |
1690 git send-email --from=author@example.com --to=nobody@example.com \
1691 --smtp-server="$(pwd)/fake.sendmail" \
1692 --8bit-encoding=UTF-8 \
1693 email-using-8bit >stdout &&
1694 grep "Subject" msgtxt1 >actual &&
1695 test_cmp expected actual
1696 '
1697
1698 test_expect_success $PREREQ 'setup expect' '
1699 cat >email-using-8bit <<-\EOF
1700 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1701 Message-ID: <bogus-message-id@example.com>
1702 From: A U Thor <author@example.com>
1703 Date: Sat, 12 Jun 2010 15:53:58 +0200
1704 Content-Type: text/plain; charset=UTF-8
1705 Subject: Nothing to see here.
1706
1707 Dieser Betreff enthält auch einen Umlaut!
1708 EOF
1709 '
1710
1711 test_expect_success $PREREQ '--transfer-encoding overrides sendemail.transferEncoding' '
1712 clean_fake_sendmail &&
1713 test_must_fail git -c sendemail.transferEncoding=8bit \
1714 send-email \
1715 --transfer-encoding=7bit \
1716 --smtp-server="$(pwd)/fake.sendmail" \
1717 email-using-8bit \
1718 2>errors >out &&
1719 grep "cannot send message as 7bit" errors &&
1720 test -z "$(ls msgtxt*)"
1721 '
1722
1723 test_expect_success $PREREQ 'sendemail.transferEncoding via config' '
1724 clean_fake_sendmail &&
1725 test_must_fail git -c sendemail.transferEncoding=7bit \
1726 send-email \
1727 --smtp-server="$(pwd)/fake.sendmail" \
1728 email-using-8bit \
1729 2>errors >out &&
1730 grep "cannot send message as 7bit" errors &&
1731 test -z "$(ls msgtxt*)"
1732 '
1733
1734 test_expect_success $PREREQ 'sendemail.transferEncoding via cli' '
1735 clean_fake_sendmail &&
1736 test_must_fail git send-email \
1737 --transfer-encoding=7bit \
1738 --smtp-server="$(pwd)/fake.sendmail" \
1739 email-using-8bit \
1740 2>errors >out &&
1741 grep "cannot send message as 7bit" errors &&
1742 test -z "$(ls msgtxt*)"
1743 '
1744
1745 test_expect_success $PREREQ 'setup expect' '
1746 cat >expected <<-\EOF
1747 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1748 EOF
1749 '
1750
1751 test_expect_success $PREREQ '8-bit and sendemail.transferencoding=quoted-printable' '
1752 clean_fake_sendmail &&
1753 git send-email \
1754 --transfer-encoding=quoted-printable \
1755 --smtp-server="$(pwd)/fake.sendmail" \
1756 email-using-8bit \
1757 2>errors >out &&
1758 sed "1,/^$/d" msgtxt1 >actual &&
1759 test_cmp expected actual
1760 '
1761
1762 test_expect_success $PREREQ 'setup expect' '
1763 cat >expected <<-\EOF
1764 RGllc2VyIEJldHJlZmYgZW50aMOkbHQgYXVjaCBlaW5lbiBVbWxhdXQhCg==
1765 EOF
1766 '
1767
1768 test_expect_success $PREREQ '8-bit and sendemail.transferencoding=base64' '
1769 clean_fake_sendmail &&
1770 git send-email \
1771 --transfer-encoding=base64 \
1772 --smtp-server="$(pwd)/fake.sendmail" \
1773 email-using-8bit \
1774 2>errors >out &&
1775 sed "1,/^$/d" msgtxt1 >actual &&
1776 test_cmp expected actual
1777 '
1778
1779 test_expect_success $PREREQ 'setup expect' '
1780 cat >email-using-qp <<-\EOF
1781 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1782 Message-ID: <bogus-message-id@example.com>
1783 From: A U Thor <author@example.com>
1784 Date: Sat, 12 Jun 2010 15:53:58 +0200
1785 MIME-Version: 1.0
1786 Content-Transfer-Encoding: quoted-printable
1787 Content-Type: text/plain; charset=UTF-8
1788 Subject: Nothing to see here.
1789
1790 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1791 EOF
1792 '
1793
1794 test_expect_success $PREREQ 'convert from quoted-printable to base64' '
1795 clean_fake_sendmail &&
1796 git send-email \
1797 --transfer-encoding=base64 \
1798 --smtp-server="$(pwd)/fake.sendmail" \
1799 email-using-qp \
1800 2>errors >out &&
1801 sed "1,/^$/d" msgtxt1 >actual &&
1802 test_cmp expected actual
1803 '
1804
1805 test_expect_success $PREREQ 'setup expect' "
1806 tr -d '\\015' | tr '%' '\\015' >email-using-crlf <<EOF
1807 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1808 Message-ID: <bogus-message-id@example.com>
1809 From: A U Thor <author@example.com>
1810 Date: Sat, 12 Jun 2010 15:53:58 +0200
1811 Content-Type: text/plain; charset=UTF-8
1812 Subject: Nothing to see here.
1813
1814 Look, I have a CRLF and an = sign!%
1815 EOF
1816 "
1817
1818 test_expect_success $PREREQ 'setup expect' '
1819 cat >expected <<-\EOF
1820 Look, I have a CRLF and an =3D sign!=0D
1821 EOF
1822 '
1823
1824 test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=quoted-printable' '
1825 clean_fake_sendmail &&
1826 git send-email \
1827 --transfer-encoding=quoted-printable \
1828 --smtp-server="$(pwd)/fake.sendmail" \
1829 email-using-crlf \
1830 2>errors >out &&
1831 sed "1,/^$/d" msgtxt1 >actual &&
1832 test_cmp expected actual
1833 '
1834
1835 test_expect_success $PREREQ 'setup expect' '
1836 cat >expected <<-\EOF
1837 TG9vaywgSSBoYXZlIGEgQ1JMRiBhbmQgYW4gPSBzaWduIQ0K
1838 EOF
1839 '
1840
1841 test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=base64' '
1842 clean_fake_sendmail &&
1843 git send-email \
1844 --transfer-encoding=base64 \
1845 --smtp-server="$(pwd)/fake.sendmail" \
1846 email-using-crlf \
1847 2>errors >out &&
1848 sed "1,/^$/d" msgtxt1 >actual &&
1849 test_cmp expected actual
1850 '
1851
1852
1853 # Note that the patches in this test are deliberately out of order; we
1854 # want to make sure it works even if the cover-letter is not in the
1855 # first mail.
1856 test_expect_success $PREREQ 'refusing to send cover letter template' '
1857 clean_fake_sendmail &&
1858 rm -fr outdir &&
1859 git format-patch --cover-letter -2 -o outdir &&
1860 test_must_fail git send-email \
1861 --from="Example <nobody@example.com>" \
1862 --to=nobody@example.com \
1863 --smtp-server="$(pwd)/fake.sendmail" \
1864 outdir/0002-*.patch \
1865 outdir/0000-*.patch \
1866 outdir/0001-*.patch \
1867 2>errors >out &&
1868 grep "SUBJECT HERE" errors &&
1869 test -z "$(ls msgtxt*)"
1870 '
1871
1872 test_expect_success $PREREQ '--force sends cover letter template anyway' '
1873 clean_fake_sendmail &&
1874 rm -fr outdir &&
1875 git format-patch --cover-letter -2 -o outdir &&
1876 git send-email \
1877 --force \
1878 --from="Example <nobody@example.com>" \
1879 --to=nobody@example.com \
1880 --smtp-server="$(pwd)/fake.sendmail" \
1881 outdir/0002-*.patch \
1882 outdir/0000-*.patch \
1883 outdir/0001-*.patch \
1884 2>errors >out &&
1885 ! grep "SUBJECT HERE" errors &&
1886 test -n "$(ls msgtxt*)"
1887 '
1888
1889 test_cover_addresses () {
1890 header="$1"
1891 shift
1892 clean_fake_sendmail &&
1893 rm -fr outdir &&
1894 git format-patch --cover-letter -2 -o outdir &&
1895 cover=$(echo outdir/0000-*.patch) &&
1896 mv $cover cover-to-edit.patch &&
1897 perl -pe "s/^From:/$header: extra\@address.com\nFrom:/" cover-to-edit.patch >"$cover" &&
1898 git send-email \
1899 --force \
1900 --from="Example <nobody@example.com>" \
1901 --no-to --no-cc \
1902 "$@" \
1903 --smtp-server="$(pwd)/fake.sendmail" \
1904 outdir/0000-*.patch \
1905 outdir/0001-*.patch \
1906 outdir/0002-*.patch \
1907 2>errors >out &&
1908 grep "^$header: extra@address.com" msgtxt1 >to1 &&
1909 grep "^$header: extra@address.com" msgtxt2 >to2 &&
1910 grep "^$header: extra@address.com" msgtxt3 >to3 &&
1911 test_line_count = 1 to1 &&
1912 test_line_count = 1 to2 &&
1913 test_line_count = 1 to3
1914 }
1915
1916 test_expect_success $PREREQ 'to-cover adds To to all mail' '
1917 test_cover_addresses "To" --to-cover
1918 '
1919
1920 test_expect_success $PREREQ 'cc-cover adds Cc to all mail' '
1921 test_cover_addresses "Cc" --cc-cover
1922 '
1923
1924 test_expect_success $PREREQ 'tocover adds To to all mail' '
1925 test_config sendemail.tocover true &&
1926 test_cover_addresses "To"
1927 '
1928
1929 test_expect_success $PREREQ 'cccover adds Cc to all mail' '
1930 test_config sendemail.cccover true &&
1931 test_cover_addresses "Cc"
1932 '
1933
1934 test_expect_success $PREREQ 'escaped quotes in sendemail.aliasfiletype=mutt' '
1935 clean_fake_sendmail &&
1936 echo "alias sbd \\\"Dot U. Sir\\\" <somebody@example.org>" >.mutt &&
1937 git config --replace-all sendemail.aliasesfile "$(pwd)/.mutt" &&
1938 git config sendemail.aliasfiletype mutt &&
1939 git send-email \
1940 --from="Example <nobody@example.com>" \
1941 --to=sbd \
1942 --smtp-server="$(pwd)/fake.sendmail" \
1943 outdir/0001-*.patch \
1944 2>errors >out &&
1945 grep "^!somebody@example\.org!$" commandline1 &&
1946 grep -F "To: \"Dot U. Sir\" <somebody@example.org>" out
1947 '
1948
1949 test_expect_success $PREREQ 'sendemail.aliasfiletype=mailrc' '
1950 clean_fake_sendmail &&
1951 echo "alias sbd somebody@example.org" >.mailrc &&
1952 git config --replace-all sendemail.aliasesfile "$(pwd)/.mailrc" &&
1953 git config sendemail.aliasfiletype mailrc &&
1954 git send-email \
1955 --from="Example <nobody@example.com>" \
1956 --to=sbd \
1957 --smtp-server="$(pwd)/fake.sendmail" \
1958 outdir/0001-*.patch \
1959 2>errors >out &&
1960 grep "^!somebody@example\.org!$" commandline1
1961 '
1962
1963 test_expect_success $PREREQ 'sendemail.aliasesfile=~/.mailrc' '
1964 clean_fake_sendmail &&
1965 echo "alias sbd someone@example.org" >"$HOME/.mailrc" &&
1966 git config --replace-all sendemail.aliasesfile "~/.mailrc" &&
1967 git config sendemail.aliasfiletype mailrc &&
1968 git send-email \
1969 --from="Example <nobody@example.com>" \
1970 --to=sbd \
1971 --smtp-server="$(pwd)/fake.sendmail" \
1972 outdir/0001-*.patch \
1973 2>errors >out &&
1974 grep "^!someone@example\.org!$" commandline1
1975 '
1976
1977 test_dump_aliases () {
1978 msg="$1" && shift &&
1979 filetype="$1" && shift &&
1980 printf '%s\n' "$@" >expect &&
1981 cat >.tmp-email-aliases &&
1982
1983 test_expect_success $PREREQ "$msg" '
1984 clean_fake_sendmail && rm -fr outdir &&
1985 git config --replace-all sendemail.aliasesfile \
1986 "$(pwd)/.tmp-email-aliases" &&
1987 git config sendemail.aliasfiletype "$filetype" &&
1988 git send-email --dump-aliases 2>errors >actual &&
1989 test_cmp expect actual
1990 '
1991 }
1992
1993 test_dump_aliases '--dump-aliases sendmail format' \
1994 'sendmail' \
1995 'abgroup' \
1996 'alice' \
1997 'bcgrp' \
1998 'bob' \
1999 'chloe' <<-\EOF
2000 alice: Alice W Land <awol@example.com>
2001 bob: Robert Bobbyton <bob@example.com>
2002 chloe: chloe@example.com
2003 abgroup: alice, bob
2004 bcgrp: bob, chloe, Other <o@example.com>
2005 EOF
2006
2007 test_dump_aliases '--dump-aliases mutt format' \
2008 'mutt' \
2009 'alice' \
2010 'bob' \
2011 'chloe' \
2012 'donald' <<-\EOF
2013 alias alice Alice W Land <awol@example.com>
2014 alias donald Donald C Carlton <donc@example.com>
2015 alias bob Robert Bobbyton <bob@example.com>
2016 alias chloe chloe@example.com
2017 EOF
2018
2019 test_dump_aliases '--dump-aliases mailrc format' \
2020 'mailrc' \
2021 'alice' \
2022 'bob' \
2023 'chloe' \
2024 'eve' <<-\EOF
2025 alias alice Alice W Land <awol@example.com>
2026 alias eve Eve <eve@example.com>
2027 alias bob Robert Bobbyton <bob@example.com>
2028 alias chloe chloe@example.com
2029 EOF
2030
2031 test_dump_aliases '--dump-aliases pine format' \
2032 'pine' \
2033 'alice' \
2034 'bob' \
2035 'chloe' \
2036 'eve' <<-\EOF
2037 alice Alice W Land <awol@example.com>
2038 eve Eve <eve@example.com>
2039 bob Robert Bobbyton <bob@example.com>
2040 chloe chloe@example.com
2041 EOF
2042
2043 test_dump_aliases '--dump-aliases gnus format' \
2044 'gnus' \
2045 'alice' \
2046 'bob' \
2047 'chloe' \
2048 'eve' <<-\EOF
2049 (define-mail-alias "alice" "awol@example.com")
2050 (define-mail-alias "eve" "eve@example.com")
2051 (define-mail-alias "bob" "bob@example.com")
2052 (define-mail-alias "chloe" "chloe@example.com")
2053 EOF
2054
2055 test_expect_success '--dump-aliases must be used alone' '
2056 test_must_fail git send-email --dump-aliases --to=janice@example.com -1 refs/heads/accounting
2057 '
2058
2059 test_expect_success $PREREQ 'aliases and sendemail.identity' '
2060 test_must_fail git \
2061 -c sendemail.identity=cloud \
2062 -c sendemail.aliasesfile=default-aliases \
2063 -c sendemail.cloud.aliasesfile=cloud-aliases \
2064 send-email -1 2>stderr &&
2065 test_i18ngrep "cloud-aliases" stderr
2066 '
2067
2068 test_sendmail_aliases () {
2069 msg="$1" && shift &&
2070 expect="$@" &&
2071 cat >.tmp-email-aliases &&
2072
2073 test_expect_success $PREREQ "$msg" '
2074 clean_fake_sendmail && rm -fr outdir &&
2075 git format-patch -1 -o outdir &&
2076 git config --replace-all sendemail.aliasesfile \
2077 "$(pwd)/.tmp-email-aliases" &&
2078 git config sendemail.aliasfiletype sendmail &&
2079 git send-email \
2080 --from="Example <nobody@example.com>" \
2081 --to=alice --to=bcgrp \
2082 --smtp-server="$(pwd)/fake.sendmail" \
2083 outdir/0001-*.patch \
2084 2>errors >out &&
2085 for i in $expect
2086 do
2087 grep "^!$i!$" commandline1 || return 1
2088 done
2089 '
2090 }
2091
2092 test_sendmail_aliases 'sendemail.aliasfiletype=sendmail' \
2093 'awol@example\.com' \
2094 'bob@example\.com' \
2095 'chloe@example\.com' \
2096 'o@example\.com' <<-\EOF
2097 alice: Alice W Land <awol@example.com>
2098 bob: Robert Bobbyton <bob@example.com>
2099 # this is a comment
2100 # this is also a comment
2101 chloe: chloe@example.com
2102 abgroup: alice, bob
2103 bcgrp: bob, chloe, Other <o@example.com>
2104 EOF
2105
2106 test_sendmail_aliases 'sendmail aliases line folding' \
2107 alice1 \
2108 bob1 bob2 \
2109 chuck1 chuck2 \
2110 darla1 darla2 darla3 \
2111 elton1 elton2 elton3 \
2112 fred1 fred2 \
2113 greg1 <<-\EOF
2114 alice: alice1
2115 bob: bob1,\
2116 bob2
2117 chuck: chuck1,
2118 chuck2
2119 darla: darla1,\
2120 darla2,
2121 darla3
2122 elton: elton1,
2123 elton2,\
2124 elton3
2125 fred: fred1,\
2126 fred2
2127 greg: greg1
2128 bcgrp: bob, chuck, darla, elton, fred, greg
2129 EOF
2130
2131 test_sendmail_aliases 'sendmail aliases tolerate bogus line folding' \
2132 alice1 bob1 <<-\EOF
2133 alice: alice1
2134 bcgrp: bob1\
2135 EOF
2136
2137 test_sendmail_aliases 'sendmail aliases empty' alice bcgrp <<-\EOF
2138 EOF
2139
2140 test_expect_success $PREREQ 'alias support in To header' '
2141 clean_fake_sendmail &&
2142 echo "alias sbd someone@example.org" >.mailrc &&
2143 test_config sendemail.aliasesfile ".mailrc" &&
2144 test_config sendemail.aliasfiletype mailrc &&
2145 git format-patch --stdout -1 --to=sbd >aliased.patch &&
2146 git send-email \
2147 --from="Example <nobody@example.com>" \
2148 --smtp-server="$(pwd)/fake.sendmail" \
2149 aliased.patch \
2150 2>errors >out &&
2151 grep "^!someone@example\.org!$" commandline1
2152 '
2153
2154 test_expect_success $PREREQ 'alias support in Cc header' '
2155 clean_fake_sendmail &&
2156 echo "alias sbd someone@example.org" >.mailrc &&
2157 test_config sendemail.aliasesfile ".mailrc" &&
2158 test_config sendemail.aliasfiletype mailrc &&
2159 git format-patch --stdout -1 --cc=sbd >aliased.patch &&
2160 git send-email \
2161 --from="Example <nobody@example.com>" \
2162 --smtp-server="$(pwd)/fake.sendmail" \
2163 aliased.patch \
2164 2>errors >out &&
2165 grep "^!someone@example\.org!$" commandline1
2166 '
2167
2168 test_expect_success $PREREQ 'tocmd works with aliases' '
2169 clean_fake_sendmail &&
2170 echo "alias sbd someone@example.org" >.mailrc &&
2171 test_config sendemail.aliasesfile ".mailrc" &&
2172 test_config sendemail.aliasfiletype mailrc &&
2173 git format-patch --stdout -1 >tocmd.patch &&
2174 echo tocmd--sbd >>tocmd.patch &&
2175 git send-email \
2176 --from="Example <nobody@example.com>" \
2177 --to-cmd=./tocmd-sed \
2178 --smtp-server="$(pwd)/fake.sendmail" \
2179 tocmd.patch \
2180 2>errors >out &&
2181 grep "^!someone@example\.org!$" commandline1
2182 '
2183
2184 test_expect_success $PREREQ 'cccmd works with aliases' '
2185 clean_fake_sendmail &&
2186 echo "alias sbd someone@example.org" >.mailrc &&
2187 test_config sendemail.aliasesfile ".mailrc" &&
2188 test_config sendemail.aliasfiletype mailrc &&
2189 git format-patch --stdout -1 >cccmd.patch &&
2190 echo cccmd--sbd >>cccmd.patch &&
2191 git send-email \
2192 --from="Example <nobody@example.com>" \
2193 --cc-cmd=./cccmd-sed \
2194 --smtp-server="$(pwd)/fake.sendmail" \
2195 cccmd.patch \
2196 2>errors >out &&
2197 grep "^!someone@example\.org!$" commandline1
2198 '
2199
2200 do_xmailer_test () {
2201 expected=$1 params=$2 &&
2202 git format-patch -1 &&
2203 git send-email \
2204 --from="Example <nobody@example.com>" \
2205 --to=someone@example.com \
2206 --smtp-server="$(pwd)/fake.sendmail" \
2207 $params \
2208 0001-*.patch \
2209 2>errors >out &&
2210 { grep '^X-Mailer:' out || :; } >mailer &&
2211 test_line_count = $expected mailer
2212 }
2213
2214 test_expect_success $PREREQ '--[no-]xmailer without any configuration' '
2215 do_xmailer_test 1 "--xmailer" &&
2216 do_xmailer_test 0 "--no-xmailer"
2217 '
2218
2219 test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=true' '
2220 test_config sendemail.xmailer true &&
2221 do_xmailer_test 1 "" &&
2222 do_xmailer_test 0 "--no-xmailer" &&
2223 do_xmailer_test 1 "--xmailer"
2224 '
2225
2226 test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer' '
2227 test_when_finished "test_unconfig sendemail.xmailer" &&
2228 cat >>.git/config <<-\EOF &&
2229 [sendemail]
2230 xmailer
2231 EOF
2232 test_config sendemail.xmailer true &&
2233 do_xmailer_test 1 "" &&
2234 do_xmailer_test 0 "--no-xmailer" &&
2235 do_xmailer_test 1 "--xmailer"
2236 '
2237
2238 test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=false' '
2239 test_config sendemail.xmailer false &&
2240 do_xmailer_test 0 "" &&
2241 do_xmailer_test 0 "--no-xmailer" &&
2242 do_xmailer_test 1 "--xmailer"
2243 '
2244
2245 test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=' '
2246 test_config sendemail.xmailer "" &&
2247 do_xmailer_test 0 "" &&
2248 do_xmailer_test 0 "--no-xmailer" &&
2249 do_xmailer_test 1 "--xmailer"
2250 '
2251
2252 test_expect_success $PREREQ 'setup expected-list' '
2253 git send-email \
2254 --dry-run \
2255 --from="Example <from@example.com>" \
2256 --to="To 1 <to1@example.com>" \
2257 --to="to2@example.com" \
2258 --to="to3@example.com" \
2259 --cc="Cc 1 <cc1@example.com>" \
2260 --cc="Cc2 <cc2@example.com>" \
2261 --bcc="bcc1@example.com" \
2262 --bcc="bcc2@example.com" \
2263 0001-add-main.patch | replace_variable_fields \
2264 >expected-list
2265 '
2266
2267 test_expect_success $PREREQ 'use email list in --cc --to and --bcc' '
2268 git send-email \
2269 --dry-run \
2270 --from="Example <from@example.com>" \
2271 --to="To 1 <to1@example.com>, to2@example.com" \
2272 --to="to3@example.com" \
2273 --cc="Cc 1 <cc1@example.com>, Cc2 <cc2@example.com>" \
2274 --bcc="bcc1@example.com, bcc2@example.com" \
2275 0001-add-main.patch | replace_variable_fields \
2276 >actual-list &&
2277 test_cmp expected-list actual-list
2278 '
2279
2280 test_expect_success $PREREQ 'aliases work with email list' '
2281 echo "alias to2 to2@example.com" >.mutt &&
2282 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt &&
2283 test_config sendemail.aliasesfile ".mutt" &&
2284 test_config sendemail.aliasfiletype mutt &&
2285 git send-email \
2286 --dry-run \
2287 --from="Example <from@example.com>" \
2288 --to="To 1 <to1@example.com>, to2, to3@example.com" \
2289 --cc="cc1, Cc2 <cc2@example.com>" \
2290 --bcc="bcc1@example.com, bcc2@example.com" \
2291 0001-add-main.patch | replace_variable_fields \
2292 >actual-list &&
2293 test_cmp expected-list actual-list
2294 '
2295
2296 test_expect_success $PREREQ 'leading and trailing whitespaces are removed' '
2297 echo "alias to2 to2@example.com" >.mutt &&
2298 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt &&
2299 test_config sendemail.aliasesfile ".mutt" &&
2300 test_config sendemail.aliasfiletype mutt &&
2301 TO1=$(echo "QTo 1 <to1@example.com>" | q_to_tab) &&
2302 TO2=$(echo "QZto2" | qz_to_tab_space) &&
2303 CC1=$(echo "cc1" | append_cr) &&
2304 BCC1=$(echo " bcc1@example.com Q" | q_to_nul) &&
2305 git send-email \
2306 --dry-run \
2307 --from=" Example <from@example.com>" \
2308 --to="$TO1" \
2309 --to="$TO2" \
2310 --to=" to3@example.com " \
2311 --cc="$CC1" \
2312 --cc="Cc2 <cc2@example.com>" \
2313 --bcc="$BCC1" \
2314 --bcc="bcc2@example.com" \
2315 0001-add-main.patch | replace_variable_fields \
2316 >actual-list &&
2317 test_cmp expected-list actual-list
2318 '
2319
2320 test_expect_success $PREREQ 'test using command name with --sendmail-cmd' '
2321 clean_fake_sendmail &&
2322 PATH="$PWD:$PATH" \
2323 git send-email \
2324 --from="Example <nobody@example.com>" \
2325 --to=nobody@example.com \
2326 --sendmail-cmd="fake.sendmail" \
2327 HEAD^ &&
2328 test_path_is_file commandline1
2329 '
2330
2331 test_expect_success $PREREQ 'test using arguments with --sendmail-cmd' '
2332 clean_fake_sendmail &&
2333 git send-email \
2334 --from="Example <nobody@example.com>" \
2335 --to=nobody@example.com \
2336 --sendmail-cmd='\''"$(pwd)/fake.sendmail" -f nobody@example.com'\'' \
2337 HEAD^ &&
2338 test_path_is_file commandline1
2339 '
2340
2341 test_expect_success $PREREQ 'test shell expression with --sendmail-cmd' '
2342 clean_fake_sendmail &&
2343 git send-email \
2344 --from="Example <nobody@example.com>" \
2345 --to=nobody@example.com \
2346 --sendmail-cmd='\''f() { "$(pwd)/fake.sendmail" "$@"; };f'\'' \
2347 HEAD^ &&
2348 test_path_is_file commandline1
2349 '
2350
2351 test_expect_success $PREREQ 'set up in-reply-to/references patches' '
2352 cat >has-reply.patch <<-\EOF &&
2353 From: A U Thor <author@example.com>
2354 Subject: patch with in-reply-to
2355 Message-ID: <patch.with.in.reply.to@example.com>
2356 In-Reply-To: <replied.to@example.com>
2357 References: <replied.to@example.com>
2358
2359 This is the body.
2360 EOF
2361 cat >no-reply.patch <<-\EOF
2362 From: A U Thor <author@example.com>
2363 Subject: patch without in-reply-to
2364 Message-ID: <patch.without.in.reply.to@example.com>
2365
2366 This is the body.
2367 EOF
2368 '
2369
2370 test_expect_success $PREREQ 'patch reply headers correct with --no-thread' '
2371 clean_fake_sendmail &&
2372 git send-email \
2373 --no-thread \
2374 --to=nobody@example.com \
2375 --smtp-server="$(pwd)/fake.sendmail" \
2376 has-reply.patch no-reply.patch &&
2377 grep "In-Reply-To: <replied.to@example.com>" msgtxt1 &&
2378 grep "References: <replied.to@example.com>" msgtxt1 &&
2379 ! grep replied.to@example.com msgtxt2
2380 '
2381
2382 test_expect_success $PREREQ 'cmdline in-reply-to used with --no-thread' '
2383 clean_fake_sendmail &&
2384 git send-email \
2385 --no-thread \
2386 --in-reply-to="<cmdline.reply@example.com>" \
2387 --to=nobody@example.com \
2388 --smtp-server="$(pwd)/fake.sendmail" \
2389 has-reply.patch no-reply.patch &&
2390 grep "In-Reply-To: <cmdline.reply@example.com>" msgtxt1 &&
2391 grep "References: <cmdline.reply@example.com>" msgtxt1 &&
2392 grep "In-Reply-To: <cmdline.reply@example.com>" msgtxt2 &&
2393 grep "References: <cmdline.reply@example.com>" msgtxt2
2394 '
2395
2396 test_expect_success $PREREQ 'invoke hook' '
2397 test_hook sendemail-validate <<-\EOF &&
2398 # test that we have the correct environment variable, pwd, and
2399 # argument
2400 case "$GIT_DIR" in
2401 *.git)
2402 true
2403 ;;
2404 *)
2405 false
2406 ;;
2407 esac &&
2408 test -f 0001-add-main.patch &&
2409 grep "add main" "$1"
2410 EOF
2411
2412 mkdir subdir &&
2413 (
2414 # Test that it works even if we are not at the root of the
2415 # working tree
2416 cd subdir &&
2417 git send-email \
2418 --from="Example <nobody@example.com>" \
2419 --to=nobody@example.com \
2420 --smtp-server="$(pwd)/../fake.sendmail" \
2421 ../0001-add-main.patch &&
2422
2423 # Verify error message when a patch is rejected by the hook
2424 sed -e "s/add main/x/" ../0001-add-main.patch >../another.patch &&
2425 test_must_fail git send-email \
2426 --from="Example <nobody@example.com>" \
2427 --to=nobody@example.com \
2428 --smtp-server="$(pwd)/../fake.sendmail" \
2429 ../another.patch 2>err &&
2430 test_i18ngrep "rejected by sendemail-validate hook" err
2431 )
2432 '
2433
2434 expected_file_counter_output () {
2435 total=$1
2436 count=0
2437 while test $count -ne $total
2438 do
2439 count=$((count + 1)) &&
2440 echo "$count/$total" || return
2441 done
2442 }
2443
2444 test_expect_success $PREREQ '--validate hook allows counting of messages' '
2445 test_when_finished "rm -rf my-hooks.log" &&
2446 test_config core.hooksPath "my-hooks" &&
2447 mkdir -p my-hooks &&
2448
2449 write_script my-hooks/sendemail-validate <<-\EOF &&
2450 num=$GIT_SENDEMAIL_FILE_COUNTER &&
2451 tot=$GIT_SENDEMAIL_FILE_TOTAL &&
2452 echo "$num/$tot" >>my-hooks.log || exit 1
2453 EOF
2454
2455 >my-hooks.log &&
2456 expected_file_counter_output 4 >expect &&
2457 git send-email \
2458 --from="Example <from@example.com>" \
2459 --to=nobody@example.com \
2460 --smtp-server="$(pwd)/fake.sendmail" \
2461 --validate -3 --cover-letter --force &&
2462 test_cmp expect my-hooks.log
2463 '
2464
2465 test_expect_success $PREREQ 'test that send-email works outside a repo' '
2466 nongit git send-email \
2467 --from="Example <nobody@example.com>" \
2468 --to=nobody@example.com \
2469 --smtp-server="$(pwd)/fake.sendmail" \
2470 "$(pwd)/0001-add-main.patch"
2471 '
2472
2473 test_expect_success $PREREQ 'send-email relays -v 3 to format-patch' '
2474 test_when_finished "rm -f out" &&
2475 git send-email --dry-run -v 3 -1 >out &&
2476 grep "PATCH v3" out
2477 '
2478
2479 test_expect_success $PREREQ 'test that sendmail config is rejected' '
2480 test_config sendmail.program sendmail &&
2481 test_must_fail git send-email \
2482 --from="Example <nobody@example.com>" \
2483 --to=nobody@example.com \
2484 --smtp-server="$(pwd)/fake.sendmail" \
2485 HEAD^ 2>err &&
2486 test_i18ngrep "found configuration options for '"'"sendmail"'"'" err
2487 '
2488
2489 test_expect_success $PREREQ 'test that sendmail config rejection is specific' '
2490 test_config resendmail.program sendmail &&
2491 git send-email \
2492 --from="Example <nobody@example.com>" \
2493 --to=nobody@example.com \
2494 --smtp-server="$(pwd)/fake.sendmail" \
2495 HEAD^
2496 '
2497
2498 test_expect_success $PREREQ 'test forbidSendmailVariables behavior override' '
2499 test_config sendmail.program sendmail &&
2500 test_config sendemail.forbidSendmailVariables false &&
2501 git send-email \
2502 --from="Example <nobody@example.com>" \
2503 --to=nobody@example.com \
2504 --smtp-server="$(pwd)/fake.sendmail" \
2505 HEAD^
2506 '
2507
2508 test_done