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