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