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
9test_expect_success $PREREQ 'prepare reference tree' '
10 echo "1A quick brown fox jumps over the" >file &&
11 echo "lazy dog" >>file &&
12 git add file &&
13 GIT_AUTHOR_NAME="A" git commit -a -m "Initial."
14'
15
16test_expect_success $PREREQ 'Setup helper tool' '
17 write_script fake.sendmail <<-\EOF &&
18 shift
19 output=1
20 while test -f commandline$output
21 do
22 output=$(($output+1))
23 done
24 for a
25 do
26 echo "!$a!"
27 done >commandline$output
28 cat >"msgtxt$output"
29 EOF
30 git add fake.sendmail &&
31 GIT_AUTHOR_NAME="A" git commit -a -m "Second."
32'
33
34clean_fake_sendmail () {
35 rm -f commandline* msgtxt*
36}
37
38test_expect_success $PREREQ 'Extract patches' '
39 patches=`git format-patch -s --cc="One <one@example.com>" --cc=two@example.com -n HEAD^1`
40'
41
42# Test no confirm early to ensure remaining tests will not hang
43test_no_confirm () {
44 rm -f no_confirm_okay
45 echo n | \
46 GIT_SEND_EMAIL_NOTTY=1 \
47 git send-email \
48 --from="Example <from@example.com>" \
49 --to=nobody@example.com \
50 --smtp-server="$(pwd)/fake.sendmail" \
51 $@ \
52 $patches >stdout &&
53 test_must_fail grep "Send this email" stdout &&
54 >no_confirm_okay
55}
56
57# Exit immediately to prevent hang if a no-confirm test fails
58check_no_confirm () {
59 if ! test -f no_confirm_okay
60 then
61 say 'confirm test failed; skipping remaining tests to prevent hanging'
62 PREREQ="$PREREQ,CHECK_NO_CONFIRM"
63 fi
64 return 0
65}
66
67test_expect_success $PREREQ 'No confirm with --suppress-cc' '
68 test_no_confirm --suppress-cc=sob &&
69 check_no_confirm
70'
71
72
73test_expect_success $PREREQ 'No confirm with --confirm=never' '
74 test_no_confirm --confirm=never &&
75 check_no_confirm
76'
77
78# leave sendemail.confirm set to never after this so that none of the
79# remaining tests prompt unintentionally.
80test_expect_success $PREREQ 'No confirm with sendemail.confirm=never' '
81 git config sendemail.confirm never &&
82 test_no_confirm --compose --subject=foo &&
83 check_no_confirm
84'
85
86test_expect_success $PREREQ 'Send patches' '
87 git send-email --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
88'
89
90test_expect_success $PREREQ 'setup expect' '
91 cat >expected <<-\EOF
92 !nobody@example.com!
93 !author@example.com!
94 !one@example.com!
95 !two@example.com!
96 EOF
97'
98
99test_expect_success $PREREQ 'Verify commandline' '
100 test_cmp expected commandline1
101'
102
103test_expect_success $PREREQ 'Send patches with --envelope-sender' '
104 clean_fake_sendmail &&
105 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
106'
107
108test_expect_success $PREREQ 'setup expect' '
109 cat >expected <<-\EOF
110 !patch@example.com!
111 !-i!
112 !nobody@example.com!
113 !author@example.com!
114 !one@example.com!
115 !two@example.com!
116 EOF
117'
118
119test_expect_success $PREREQ 'Verify commandline' '
120 test_cmp expected commandline1
121'
122
123test_expect_success $PREREQ 'Send patches with --envelope-sender=auto' '
124 clean_fake_sendmail &&
125 git send-email --envelope-sender=auto --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
126'
127
128test_expect_success $PREREQ 'setup expect' '
129 cat >expected <<-\EOF
130 !nobody@example.com!
131 !-i!
132 !nobody@example.com!
133 !author@example.com!
134 !one@example.com!
135 !two@example.com!
136 EOF
137'
138
139test_expect_success $PREREQ 'Verify commandline' '
140 test_cmp expected commandline1
141'
142
143test_expect_success $PREREQ 'setup expect' "
144cat >expected-show-all-headers <<\EOF
1450001-Second.patch
146(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
147(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
148(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
149Dry-OK. Log says:
150Server: relay.example.com
151MAIL FROM:<from@example.com>
152RCPT TO:<to@example.com>
153RCPT TO:<cc@example.com>
154RCPT TO:<author@example.com>
155RCPT TO:<one@example.com>
156RCPT TO:<two@example.com>
157RCPT TO:<bcc@example.com>
158From: Example <from@example.com>
159To: to@example.com
160Cc: cc@example.com,
161 A <author@example.com>,
162 One <one@example.com>,
163 two@example.com
164Subject: [PATCH 1/1] Second.
165Date: DATE-STRING
166Message-Id: MESSAGE-ID-STRING
167X-Mailer: X-MAILER-STRING
168In-Reply-To: <unique-message-id@example.com>
169References: <unique-message-id@example.com>
170
171Result: OK
172EOF
173"
174
175test_suppress_self () {
176 test_commit $3 &&
177 test_when_finished "git reset --hard HEAD^" &&
178
179 write_script cccmd-sed <<-EOF &&
180 sed -n -e s/^cccmd--//p "\$1"
181 EOF
182
183 git commit --amend --author="$1 <$2>" -F - &&
184 clean_fake_sendmail &&
185 git format-patch --stdout -1 >"suppress-self-$3.patch" &&
186
187 git send-email --from="$1 <$2>" \
188 --to=nobody@example.com \
189 --cc-cmd=./cccmd-sed \
190 --suppress-cc=self \
191 --smtp-server="$(pwd)/fake.sendmail" \
192 suppress-self-$3.patch &&
193
194 mv msgtxt1 msgtxt1-$3 &&
195 sed -e '/^$/q' msgtxt1-$3 >"msghdr1-$3" &&
196 >"expected-no-cc-$3" &&
197
198 (grep '^Cc:' msghdr1-$3 >"actual-no-cc-$3";
199 test_cmp expected-no-cc-$3 actual-no-cc-$3)
200}
201
202test_suppress_self_unquoted () {
203 test_suppress_self "$1" "$2" "unquoted-$3" <<-EOF
204 test suppress-cc.self unquoted-$3 with name $1 email $2
205
206 unquoted-$3
207
208 cccmd--$1 <$2>
209
210 Cc: $1 <$2>
211 Signed-off-by: $1 <$2>
212 EOF
213}
214
215test_suppress_self_quoted () {
216 test_suppress_self "$1" "$2" "quoted-$3" <<-EOF
217 test suppress-cc.self quoted-$3 with name $1 email $2
218
219 quoted-$3
220
221 cccmd--"$1" <$2>
222
223 Cc: $1 <$2>
224 Cc: "$1" <$2>
225 Signed-off-by: $1 <$2>
226 Signed-off-by: "$1" <$2>
227 EOF
228}
229
230test_expect_success $PREREQ 'self name is suppressed' "
231 test_suppress_self_unquoted 'A U Thor' 'author@example.com' \
232 'self_name_suppressed'
233"
234
235test_expect_success $PREREQ 'self name with dot is suppressed' "
236 test_suppress_self_quoted 'A U. Thor' 'author@example.com' \
237 'self_name_dot_suppressed'
238"
239
240test_expect_success $PREREQ 'non-ascii self name is suppressed' "
241 test_suppress_self_quoted 'Füñný Nâmé' 'odd_?=mail@example.com' \
242 'non_ascii_self_suppressed'
243"
244
245# This name is long enough to force format-patch to split it into multiple
246# encoded-words, assuming it uses UTF-8 with the "Q" encoding.
247test_expect_success $PREREQ 'long non-ascii self name is suppressed' "
248 test_suppress_self_quoted 'Ƒüñníęř €. Nâṁé' 'odd_?=mail@example.com' \
249 'long_non_ascii_self_suppressed'
250"
251
252test_expect_success $PREREQ 'sanitized self name is suppressed' "
253 test_suppress_self_unquoted '\"A U. Thor\"' 'author@example.com' \
254 'self_name_sanitized_suppressed'
255"
256
257test_expect_success $PREREQ 'Show all headers' '
258 git send-email \
259 --dry-run \
260 --suppress-cc=sob \
261 --from="Example <from@example.com>" \
262 --to=to@example.com \
263 --cc=cc@example.com \
264 --bcc=bcc@example.com \
265 --in-reply-to="<unique-message-id@example.com>" \
266 --smtp-server relay.example.com \
267 $patches |
268 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
269 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
270 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
271 >actual-show-all-headers &&
272 test_cmp expected-show-all-headers actual-show-all-headers
273'
274
275test_expect_success $PREREQ 'Prompting works' '
276 clean_fake_sendmail &&
277 (echo "to@example.com"
278 echo ""
279 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
280 --smtp-server="$(pwd)/fake.sendmail" \
281 $patches \
282 2>errors &&
283 grep "^From: A U Thor <author@example.com>\$" msgtxt1 &&
284 grep "^To: to@example.com\$" msgtxt1
285'
286
287test_expect_success $PREREQ,AUTOIDENT 'implicit ident is allowed' '
288 clean_fake_sendmail &&
289 (sane_unset GIT_AUTHOR_NAME &&
290 sane_unset GIT_AUTHOR_EMAIL &&
291 sane_unset GIT_COMMITTER_NAME &&
292 sane_unset GIT_COMMITTER_EMAIL &&
293 GIT_SEND_EMAIL_NOTTY=1 git send-email \
294 --smtp-server="$(pwd)/fake.sendmail" \
295 --to=to@example.com \
296 $patches </dev/null 2>errors
297 )
298'
299
300test_expect_success $PREREQ,!AUTOIDENT 'broken implicit ident aborts send-email' '
301 clean_fake_sendmail &&
302 (sane_unset GIT_AUTHOR_NAME &&
303 sane_unset GIT_AUTHOR_EMAIL &&
304 sane_unset GIT_COMMITTER_NAME &&
305 sane_unset GIT_COMMITTER_EMAIL &&
306 GIT_SEND_EMAIL_NOTTY=1 && export GIT_SEND_EMAIL_NOTTY &&
307 test_must_fail git send-email \
308 --smtp-server="$(pwd)/fake.sendmail" \
309 --to=to@example.com \
310 $patches </dev/null 2>errors &&
311 test_i18ngrep "tell me who you are" errors
312 )
313'
314
315test_expect_success $PREREQ 'setup tocmd and cccmd scripts' '
316 write_script tocmd-sed <<-\EOF &&
317 sed -n -e "s/^tocmd--//p" "$1"
318 EOF
319 write_script cccmd-sed <<-\EOF
320 sed -n -e "s/^cccmd--//p" "$1"
321 EOF
322'
323
324test_expect_success $PREREQ 'tocmd works' '
325 clean_fake_sendmail &&
326 cp $patches tocmd.patch &&
327 echo tocmd--tocmd@example.com >>tocmd.patch &&
328 git send-email \
329 --from="Example <nobody@example.com>" \
330 --to-cmd=./tocmd-sed \
331 --smtp-server="$(pwd)/fake.sendmail" \
332 tocmd.patch \
333 &&
334 grep "^To: tocmd@example.com" msgtxt1
335'
336
337test_expect_success $PREREQ 'cccmd works' '
338 clean_fake_sendmail &&
339 cp $patches cccmd.patch &&
340 echo "cccmd-- cccmd@example.com" >>cccmd.patch &&
341 git send-email \
342 --from="Example <nobody@example.com>" \
343 --to=nobody@example.com \
344 --cc-cmd=./cccmd-sed \
345 --smtp-server="$(pwd)/fake.sendmail" \
346 cccmd.patch \
347 &&
348 grep "^ cccmd@example.com" msgtxt1
349'
350
351test_expect_success $PREREQ 'reject long lines' '
352 z8=zzzzzzzz &&
353 z64=$z8$z8$z8$z8$z8$z8$z8$z8 &&
354 z512=$z64$z64$z64$z64$z64$z64$z64$z64 &&
355 clean_fake_sendmail &&
356 cp $patches longline.patch &&
357 echo $z512$z512 >>longline.patch &&
358 test_must_fail git send-email \
359 --from="Example <nobody@example.com>" \
360 --to=nobody@example.com \
361 --smtp-server="$(pwd)/fake.sendmail" \
362 $patches longline.patch \
363 2>errors &&
364 grep longline.patch errors
365'
366
367test_expect_success $PREREQ 'no patch was sent' '
368 ! test -e commandline1
369'
370
371test_expect_success $PREREQ 'Author From: in message body' '
372 clean_fake_sendmail &&
373 git send-email \
374 --from="Example <nobody@example.com>" \
375 --to=nobody@example.com \
376 --smtp-server="$(pwd)/fake.sendmail" \
377 $patches &&
378 sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
379 grep "From: A <author@example.com>" msgbody1
380'
381
382test_expect_success $PREREQ 'Author From: not in message body' '
383 clean_fake_sendmail &&
384 git send-email \
385 --from="A <author@example.com>" \
386 --to=nobody@example.com \
387 --smtp-server="$(pwd)/fake.sendmail" \
388 $patches &&
389 sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
390 ! grep "From: A <author@example.com>" msgbody1
391'
392
393test_expect_success $PREREQ 'allow long lines with --no-validate' '
394 git send-email \
395 --from="Example <nobody@example.com>" \
396 --to=nobody@example.com \
397 --smtp-server="$(pwd)/fake.sendmail" \
398 --no-validate \
399 $patches longline.patch \
400 2>errors
401'
402
403test_expect_success $PREREQ 'Invalid In-Reply-To' '
404 clean_fake_sendmail &&
405 git send-email \
406 --from="Example <nobody@example.com>" \
407 --to=nobody@example.com \
408 --in-reply-to=" " \
409 --smtp-server="$(pwd)/fake.sendmail" \
410 $patches \
411 2>errors &&
412 ! grep "^In-Reply-To: < *>" msgtxt1
413'
414
415test_expect_success $PREREQ 'Valid In-Reply-To when prompting' '
416 clean_fake_sendmail &&
417 (echo "From Example <from@example.com>"
418 echo "To Example <to@example.com>"
419 echo ""
420 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
421 --smtp-server="$(pwd)/fake.sendmail" \
422 $patches 2>errors &&
423 ! grep "^In-Reply-To: < *>" msgtxt1
424'
425
426test_expect_success $PREREQ 'In-Reply-To without --chain-reply-to' '
427 clean_fake_sendmail &&
428 echo "<unique-message-id@example.com>" >expect &&
429 git send-email \
430 --from="Example <nobody@example.com>" \
431 --to=nobody@example.com \
432 --no-chain-reply-to \
433 --in-reply-to="$(cat expect)" \
434 --smtp-server="$(pwd)/fake.sendmail" \
435 $patches $patches $patches \
436 2>errors &&
437 # The first message is a reply to --in-reply-to
438 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
439 test_cmp expect actual &&
440 # Second and subsequent messages are replies to the first one
441 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
442 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
443 test_cmp expect actual &&
444 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
445 test_cmp expect actual
446'
447
448test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' '
449 clean_fake_sendmail &&
450 echo "<unique-message-id@example.com>" >expect &&
451 git send-email \
452 --from="Example <nobody@example.com>" \
453 --to=nobody@example.com \
454 --chain-reply-to \
455 --in-reply-to="$(cat expect)" \
456 --smtp-server="$(pwd)/fake.sendmail" \
457 $patches $patches $patches \
458 2>errors &&
459 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
460 test_cmp expect actual &&
461 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt1 >expect &&
462 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
463 test_cmp expect actual &&
464 sed -n -e "s/^Message-Id: *\(.*\)/\1/p" msgtxt2 >expect &&
465 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
466 test_cmp expect actual
467'
468
469test_expect_success $PREREQ 'setup fake editor' '
470 write_script fake-editor <<-\EOF
471 echo fake edit >>"$1"
472 EOF
473'
474
475test_set_editor "$(pwd)/fake-editor"
476
477test_expect_success $PREREQ '--compose works' '
478 clean_fake_sendmail &&
479 git send-email \
480 --compose --subject foo \
481 --from="Example <nobody@example.com>" \
482 --to=nobody@example.com \
483 --smtp-server="$(pwd)/fake.sendmail" \
484 $patches \
485 2>errors
486'
487
488test_expect_success $PREREQ 'first message is compose text' '
489 grep "^fake edit" msgtxt1
490'
491
492test_expect_success $PREREQ 'second message is patch' '
493 grep "Subject:.*Second" msgtxt2
494'
495
496test_expect_success $PREREQ 'setup expect' "
497cat >expected-suppress-sob <<\EOF
4980001-Second.patch
499(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
500(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
501(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
502Dry-OK. Log says:
503Server: relay.example.com
504MAIL FROM:<from@example.com>
505RCPT TO:<to@example.com>
506RCPT TO:<cc@example.com>
507RCPT TO:<author@example.com>
508RCPT TO:<one@example.com>
509RCPT TO:<two@example.com>
510From: Example <from@example.com>
511To: to@example.com
512Cc: cc@example.com,
513 A <author@example.com>,
514 One <one@example.com>,
515 two@example.com
516Subject: [PATCH 1/1] Second.
517Date: DATE-STRING
518Message-Id: MESSAGE-ID-STRING
519X-Mailer: X-MAILER-STRING
520
521Result: OK
522EOF
523"
524
525test_suppression () {
526 git send-email \
527 --dry-run \
528 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
529 --from="Example <from@example.com>" \
530 --to=to@example.com \
531 --smtp-server relay.example.com \
532 $patches |
533 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
534 -e "s/^\(Message-Id:\).*/\1 MESSAGE-ID-STRING/" \
535 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/" \
536 >actual-suppress-$1${2+"-$2"} &&
537 test_cmp expected-suppress-$1${2+"-$2"} actual-suppress-$1${2+"-$2"}
538}
539
540test_expect_success $PREREQ 'sendemail.cc set' '
541 git config sendemail.cc cc@example.com &&
542 test_suppression sob
543'
544
545test_expect_success $PREREQ 'setup expect' "
546cat >expected-suppress-sob <<\EOF
5470001-Second.patch
548(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
549(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
550(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
551Dry-OK. Log says:
552Server: relay.example.com
553MAIL FROM:<from@example.com>
554RCPT TO:<to@example.com>
555RCPT TO:<author@example.com>
556RCPT TO:<one@example.com>
557RCPT TO:<two@example.com>
558From: Example <from@example.com>
559To: to@example.com
560Cc: A <author@example.com>,
561 One <one@example.com>,
562 two@example.com
563Subject: [PATCH 1/1] Second.
564Date: DATE-STRING
565Message-Id: MESSAGE-ID-STRING
566X-Mailer: X-MAILER-STRING
567
568Result: OK
569EOF
570"
571
572test_expect_success $PREREQ 'sendemail.cc unset' '
573 git config --unset sendemail.cc &&
574 test_suppression sob
575'
576
577test_expect_success $PREREQ 'setup expect' "
578cat >expected-suppress-cccmd <<\EOF
5790001-Second.patch
580(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
581(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
582(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
583(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
584Dry-OK. Log says:
585Server: relay.example.com
586MAIL FROM:<from@example.com>
587RCPT TO:<to@example.com>
588RCPT TO:<author@example.com>
589RCPT TO:<one@example.com>
590RCPT TO:<two@example.com>
591RCPT TO:<committer@example.com>
592From: Example <from@example.com>
593To: to@example.com
594Cc: A <author@example.com>,
595 One <one@example.com>,
596 two@example.com,
597 C O Mitter <committer@example.com>
598Subject: [PATCH 1/1] Second.
599Date: DATE-STRING
600Message-Id: MESSAGE-ID-STRING
601X-Mailer: X-MAILER-STRING
602
603Result: OK
604EOF
605"
606
607test_expect_success $PREREQ 'sendemail.cccmd' '
608 write_script cccmd <<-\EOF &&
609 echo cc-cmd@example.com
610 EOF
611 git config sendemail.cccmd ./cccmd &&
612 test_suppression cccmd
613'
614
615test_expect_success $PREREQ 'setup expect' '
616cat >expected-suppress-all <<\EOF
6170001-Second.patch
618Dry-OK. Log says:
619Server: relay.example.com
620MAIL FROM:<from@example.com>
621RCPT TO:<to@example.com>
622From: Example <from@example.com>
623To: to@example.com
624Subject: [PATCH 1/1] Second.
625Date: DATE-STRING
626Message-Id: MESSAGE-ID-STRING
627X-Mailer: X-MAILER-STRING
628
629Result: OK
630EOF
631'
632
633test_expect_success $PREREQ '--suppress-cc=all' '
634 test_suppression all
635'
636
637test_expect_success $PREREQ 'setup expect' "
638cat >expected-suppress-body <<\EOF
6390001-Second.patch
640(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
641(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
642(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
643(cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
644Dry-OK. Log says:
645Server: relay.example.com
646MAIL FROM:<from@example.com>
647RCPT TO:<to@example.com>
648RCPT TO:<author@example.com>
649RCPT TO:<one@example.com>
650RCPT TO:<two@example.com>
651RCPT TO:<cc-cmd@example.com>
652From: Example <from@example.com>
653To: to@example.com
654Cc: A <author@example.com>,
655 One <one@example.com>,
656 two@example.com,
657 cc-cmd@example.com
658Subject: [PATCH 1/1] Second.
659Date: DATE-STRING
660Message-Id: MESSAGE-ID-STRING
661X-Mailer: X-MAILER-STRING
662
663Result: OK
664EOF
665"
666
667test_expect_success $PREREQ '--suppress-cc=body' '
668 test_suppression body
669'
670
671test_expect_success $PREREQ 'setup expect' "
672cat >expected-suppress-body-cccmd <<\EOF
6730001-Second.patch
674(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
675(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
676(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
677Dry-OK. Log says:
678Server: relay.example.com
679MAIL FROM:<from@example.com>
680RCPT TO:<to@example.com>
681RCPT TO:<author@example.com>
682RCPT TO:<one@example.com>
683RCPT TO:<two@example.com>
684From: Example <from@example.com>
685To: to@example.com
686Cc: A <author@example.com>,
687 One <one@example.com>,
688 two@example.com
689Subject: [PATCH 1/1] Second.
690Date: DATE-STRING
691Message-Id: MESSAGE-ID-STRING
692X-Mailer: X-MAILER-STRING
693
694Result: OK
695EOF
696"
697
698test_expect_success $PREREQ '--suppress-cc=body --suppress-cc=cccmd' '
699 test_suppression body cccmd
700'
701
702test_expect_success $PREREQ 'setup expect' "
703cat >expected-suppress-sob <<\EOF
7040001-Second.patch
705(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
706(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
707(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
708Dry-OK. Log says:
709Server: relay.example.com
710MAIL FROM:<from@example.com>
711RCPT TO:<to@example.com>
712RCPT TO:<author@example.com>
713RCPT TO:<one@example.com>
714RCPT TO:<two@example.com>
715From: Example <from@example.com>
716To: to@example.com
717Cc: A <author@example.com>,
718 One <one@example.com>,
719 two@example.com
720Subject: [PATCH 1/1] Second.
721Date: DATE-STRING
722Message-Id: MESSAGE-ID-STRING
723X-Mailer: X-MAILER-STRING
724
725Result: OK
726EOF
727"
728
729test_expect_success $PREREQ '--suppress-cc=sob' '
730 test_might_fail git config --unset sendemail.cccmd &&
731 test_suppression sob
732'
733
734test_expect_success $PREREQ 'setup expect' "
735cat >expected-suppress-bodycc <<\EOF
7360001-Second.patch
737(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
738(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
739(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
740(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
741Dry-OK. Log says:
742Server: relay.example.com
743MAIL FROM:<from@example.com>
744RCPT TO:<to@example.com>
745RCPT TO:<author@example.com>
746RCPT TO:<one@example.com>
747RCPT TO:<two@example.com>
748RCPT TO:<committer@example.com>
749From: Example <from@example.com>
750To: to@example.com
751Cc: A <author@example.com>,
752 One <one@example.com>,
753 two@example.com,
754 C O Mitter <committer@example.com>
755Subject: [PATCH 1/1] Second.
756Date: DATE-STRING
757Message-Id: MESSAGE-ID-STRING
758X-Mailer: X-MAILER-STRING
759
760Result: OK
761EOF
762"
763
764test_expect_success $PREREQ '--suppress-cc=bodycc' '
765 test_suppression bodycc
766'
767
768test_expect_success $PREREQ 'setup expect' "
769cat >expected-suppress-cc <<\EOF
7700001-Second.patch
771(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
772(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
773Dry-OK. Log says:
774Server: relay.example.com
775MAIL FROM:<from@example.com>
776RCPT TO:<to@example.com>
777RCPT TO:<author@example.com>
778RCPT TO:<committer@example.com>
779From: Example <from@example.com>
780To: to@example.com
781Cc: A <author@example.com>,
782 C O Mitter <committer@example.com>
783Subject: [PATCH 1/1] Second.
784Date: DATE-STRING
785Message-Id: MESSAGE-ID-STRING
786X-Mailer: X-MAILER-STRING
787
788Result: OK
789EOF
790"
791
792test_expect_success $PREREQ '--suppress-cc=cc' '
793 test_suppression cc
794'
795
796test_confirm () {
797 echo y | \
798 GIT_SEND_EMAIL_NOTTY=1 \
799 git send-email \
800 --from="Example <nobody@example.com>" \
801 --to=nobody@example.com \
802 --smtp-server="$(pwd)/fake.sendmail" \
803 $@ $patches >stdout &&
804 grep "Send this email" stdout
805}
806
807test_expect_success $PREREQ '--confirm=always' '
808 test_confirm --confirm=always --suppress-cc=all
809'
810
811test_expect_success $PREREQ '--confirm=auto' '
812 test_confirm --confirm=auto
813'
814
815test_expect_success $PREREQ '--confirm=cc' '
816 test_confirm --confirm=cc
817'
818
819test_expect_success $PREREQ '--confirm=compose' '
820 test_confirm --confirm=compose --compose
821'
822
823test_expect_success $PREREQ 'confirm by default (due to cc)' '
824 test_when_finished git config sendemail.confirm never &&
825 git config --unset sendemail.confirm &&
826 test_confirm
827'
828
829test_expect_success $PREREQ 'confirm by default (due to --compose)' '
830 test_when_finished git config sendemail.confirm never &&
831 git config --unset sendemail.confirm &&
832 test_confirm --suppress-cc=all --compose
833'
834
835test_expect_success $PREREQ 'confirm detects EOF (inform assumes y)' '
836 test_when_finished git config sendemail.confirm never &&
837 git config --unset sendemail.confirm &&
838 rm -fr outdir &&
839 git format-patch -2 -o outdir &&
840 GIT_SEND_EMAIL_NOTTY=1 \
841 git send-email \
842 --from="Example <nobody@example.com>" \
843 --to=nobody@example.com \
844 --smtp-server="$(pwd)/fake.sendmail" \
845 outdir/*.patch </dev/null
846'
847
848test_expect_success $PREREQ 'confirm detects EOF (auto causes failure)' '
849 test_when_finished git config sendemail.confirm never &&
850 git config sendemail.confirm auto &&
851 GIT_SEND_EMAIL_NOTTY=1 &&
852 export GIT_SEND_EMAIL_NOTTY &&
853 test_must_fail git send-email \
854 --from="Example <nobody@example.com>" \
855 --to=nobody@example.com \
856 --smtp-server="$(pwd)/fake.sendmail" \
857 $patches </dev/null
858'
859
860test_expect_success $PREREQ 'confirm does not loop forever' '
861 test_when_finished git config sendemail.confirm never &&
862 git config sendemail.confirm auto &&
863 GIT_SEND_EMAIL_NOTTY=1 &&
864 export GIT_SEND_EMAIL_NOTTY &&
865 yes "bogus" | test_must_fail git send-email \
866 --from="Example <nobody@example.com>" \
867 --to=nobody@example.com \
868 --smtp-server="$(pwd)/fake.sendmail" \
869 $patches
870'
871
872test_expect_success $PREREQ 'utf8 Cc is rfc2047 encoded' '
873 clean_fake_sendmail &&
874 rm -fr outdir &&
875 git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
876 git send-email \
877 --from="Example <nobody@example.com>" \
878 --to=nobody@example.com \
879 --smtp-server="$(pwd)/fake.sendmail" \
880 outdir/*.patch &&
881 grep "^ " msgtxt1 |
882 grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
883'
884
885test_expect_success $PREREQ '--compose adds MIME for utf8 body' '
886 clean_fake_sendmail &&
887 write_script fake-editor-utf8 <<-\EOF &&
888 echo "utf8 body: àéìöú" >>"$1"
889 EOF
890 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
891 git send-email \
892 --compose --subject foo \
893 --from="Example <nobody@example.com>" \
894 --to=nobody@example.com \
895 --smtp-server="$(pwd)/fake.sendmail" \
896 $patches &&
897 grep "^utf8 body" msgtxt1 &&
898 grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
899'
900
901test_expect_success $PREREQ '--compose respects user mime type' '
902 clean_fake_sendmail &&
903 write_script fake-editor-utf8-mime <<-\EOF &&
904 cat >"$1" <<-\EOM
905 MIME-Version: 1.0
906 Content-Type: text/plain; charset=iso-8859-1
907 Content-Transfer-Encoding: 8bit
908 Subject: foo
909
910 utf8 body: àéìöú
911 EOM
912 EOF
913 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
914 git send-email \
915 --compose --subject foo \
916 --from="Example <nobody@example.com>" \
917 --to=nobody@example.com \
918 --smtp-server="$(pwd)/fake.sendmail" \
919 $patches &&
920 grep "^utf8 body" msgtxt1 &&
921 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
922 ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
923'
924
925test_expect_success $PREREQ '--compose adds MIME for utf8 subject' '
926 clean_fake_sendmail &&
927 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
928 git send-email \
929 --compose --subject utf8-sübjëct \
930 --from="Example <nobody@example.com>" \
931 --to=nobody@example.com \
932 --smtp-server="$(pwd)/fake.sendmail" \
933 $patches &&
934 grep "^fake edit" msgtxt1 &&
935 grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
936'
937
938test_expect_success $PREREQ 'utf8 author is correctly passed on' '
939 clean_fake_sendmail &&
940 test_commit weird_author &&
941 test_when_finished "git reset --hard HEAD^" &&
942 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
943 git format-patch --stdout -1 >funny_name.patch &&
944 git send-email --from="Example <nobody@example.com>" \
945 --to=nobody@example.com \
946 --smtp-server="$(pwd)/fake.sendmail" \
947 funny_name.patch &&
948 grep "^From: Füñný Nâmé <odd_?=mail@example.com>" msgtxt1
949'
950
951test_expect_success $PREREQ 'utf8 sender is not duplicated' '
952 clean_fake_sendmail &&
953 test_commit weird_sender &&
954 test_when_finished "git reset --hard HEAD^" &&
955 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
956 git format-patch --stdout -1 >funny_name.patch &&
957 git send-email --from="Füñný Nâmé <odd_?=mail@example.com>" \
958 --to=nobody@example.com \
959 --smtp-server="$(pwd)/fake.sendmail" \
960 funny_name.patch &&
961 grep "^From: " msgtxt1 >msgfrom &&
962 test_line_count = 1 msgfrom
963'
964
965test_expect_success $PREREQ 'sendemail.composeencoding works' '
966 clean_fake_sendmail &&
967 git config sendemail.composeencoding iso-8859-1 &&
968 write_script fake-editor-utf8 <<-\EOF &&
969 echo "utf8 body: àéìöú" >>"$1"
970 EOF
971 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
972 git send-email \
973 --compose --subject foo \
974 --from="Example <nobody@example.com>" \
975 --to=nobody@example.com \
976 --smtp-server="$(pwd)/fake.sendmail" \
977 $patches &&
978 grep "^utf8 body" msgtxt1 &&
979 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
980'
981
982test_expect_success $PREREQ '--compose-encoding works' '
983 clean_fake_sendmail &&
984 write_script fake-editor-utf8 <<-\EOF &&
985 echo "utf8 body: àéìöú" >>"$1"
986 EOF
987 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
988 git send-email \
989 --compose-encoding iso-8859-1 \
990 --compose --subject foo \
991 --from="Example <nobody@example.com>" \
992 --to=nobody@example.com \
993 --smtp-server="$(pwd)/fake.sendmail" \
994 $patches &&
995 grep "^utf8 body" msgtxt1 &&
996 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
997'
998
999test_expect_success $PREREQ '--compose-encoding overrides sendemail.composeencoding' '
1000 clean_fake_sendmail &&
1001 git config sendemail.composeencoding iso-8859-1 &&
1002 write_script fake-editor-utf8 <<-\EOF &&
1003 echo "utf8 body: àéìöú" >>"$1"
1004 EOF
1005 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1006 git send-email \
1007 --compose-encoding iso-8859-2 \
1008 --compose --subject foo \
1009 --from="Example <nobody@example.com>" \
1010 --to=nobody@example.com \
1011 --smtp-server="$(pwd)/fake.sendmail" \
1012 $patches &&
1013 grep "^utf8 body" msgtxt1 &&
1014 grep "^Content-Type: text/plain; charset=iso-8859-2" msgtxt1
1015'
1016
1017test_expect_success $PREREQ '--compose-encoding adds correct MIME for subject' '
1018 clean_fake_sendmail &&
1019 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
1020 git send-email \
1021 --compose-encoding iso-8859-2 \
1022 --compose --subject utf8-sübjëct \
1023 --from="Example <nobody@example.com>" \
1024 --to=nobody@example.com \
1025 --smtp-server="$(pwd)/fake.sendmail" \
1026 $patches &&
1027 grep "^fake edit" msgtxt1 &&
1028 grep "^Subject: =?iso-8859-2?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
1029'
1030
1031test_expect_success $PREREQ 'detects ambiguous reference/file conflict' '
1032 echo master >master &&
1033 git add master &&
1034 git commit -m"add master" &&
1035 test_must_fail git send-email --dry-run master 2>errors &&
1036 grep disambiguate errors
1037'
1038
1039test_expect_success $PREREQ 'feed two files' '
1040 rm -fr outdir &&
1041 git format-patch -2 -o outdir &&
1042 git send-email \
1043 --dry-run \
1044 --from="Example <nobody@example.com>" \
1045 --to=nobody@example.com \
1046 outdir/000?-*.patch 2>errors >out &&
1047 grep "^Subject: " out >subjects &&
1048 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
1049 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add master"
1050'
1051
1052test_expect_success $PREREQ 'in-reply-to but no threading' '
1053 git send-email \
1054 --dry-run \
1055 --from="Example <nobody@example.com>" \
1056 --to=nobody@example.com \
1057 --in-reply-to="<in-reply-id@example.com>" \
1058 --no-thread \
1059 $patches |
1060 grep "In-Reply-To: <in-reply-id@example.com>"
1061'
1062
1063test_expect_success $PREREQ 'no in-reply-to and no threading' '
1064 git send-email \
1065 --dry-run \
1066 --from="Example <nobody@example.com>" \
1067 --to=nobody@example.com \
1068 --no-thread \
1069 $patches $patches >stdout &&
1070 ! grep "In-Reply-To: " stdout
1071'
1072
1073test_expect_success $PREREQ 'threading but no chain-reply-to' '
1074 git send-email \
1075 --dry-run \
1076 --from="Example <nobody@example.com>" \
1077 --to=nobody@example.com \
1078 --thread \
1079 --no-chain-reply-to \
1080 $patches $patches >stdout &&
1081 grep "In-Reply-To: " stdout
1082'
1083
1084test_expect_success $PREREQ 'sendemail.to works' '
1085 git config --replace-all sendemail.to "Somebody <somebody@ex.com>" &&
1086 git send-email \
1087 --dry-run \
1088 --from="Example <nobody@example.com>" \
1089 $patches $patches >stdout &&
1090 grep "To: Somebody <somebody@ex.com>" stdout
1091'
1092
1093test_expect_success $PREREQ '--no-to overrides sendemail.to' '
1094 git send-email \
1095 --dry-run \
1096 --from="Example <nobody@example.com>" \
1097 --no-to \
1098 --to=nobody@example.com \
1099 $patches $patches >stdout &&
1100 grep "To: nobody@example.com" stdout &&
1101 ! grep "To: Somebody <somebody@ex.com>" stdout
1102'
1103
1104test_expect_success $PREREQ 'sendemail.cc works' '
1105 git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" &&
1106 git send-email \
1107 --dry-run \
1108 --from="Example <nobody@example.com>" \
1109 --to=nobody@example.com \
1110 $patches $patches >stdout &&
1111 grep "Cc: Somebody <somebody@ex.com>" stdout
1112'
1113
1114test_expect_success $PREREQ '--no-cc overrides sendemail.cc' '
1115 git send-email \
1116 --dry-run \
1117 --from="Example <nobody@example.com>" \
1118 --no-cc \
1119 --cc=bodies@example.com \
1120 --to=nobody@example.com \
1121 $patches $patches >stdout &&
1122 grep "Cc: bodies@example.com" stdout &&
1123 ! grep "Cc: Somebody <somebody@ex.com>" stdout
1124'
1125
1126test_expect_success $PREREQ 'sendemail.bcc works' '
1127 git config --replace-all sendemail.bcc "Other <other@ex.com>" &&
1128 git send-email \
1129 --dry-run \
1130 --from="Example <nobody@example.com>" \
1131 --to=nobody@example.com \
1132 --smtp-server relay.example.com \
1133 $patches $patches >stdout &&
1134 grep "RCPT TO:<other@ex.com>" stdout
1135'
1136
1137test_expect_success $PREREQ '--no-bcc overrides sendemail.bcc' '
1138 git send-email \
1139 --dry-run \
1140 --from="Example <nobody@example.com>" \
1141 --no-bcc \
1142 --bcc=bodies@example.com \
1143 --to=nobody@example.com \
1144 --smtp-server relay.example.com \
1145 $patches $patches >stdout &&
1146 grep "RCPT TO:<bodies@example.com>" stdout &&
1147 ! grep "RCPT TO:<other@ex.com>" stdout
1148'
1149
1150test_expect_success $PREREQ 'patches To headers are used by default' '
1151 patch=`git format-patch -1 --to="bodies@example.com"` &&
1152 test_when_finished "rm $patch" &&
1153 git send-email \
1154 --dry-run \
1155 --from="Example <nobody@example.com>" \
1156 --smtp-server relay.example.com \
1157 $patch >stdout &&
1158 grep "RCPT TO:<bodies@example.com>" stdout
1159'
1160
1161test_expect_success $PREREQ 'patches To headers are appended to' '
1162 patch=`git format-patch -1 --to="bodies@example.com"` &&
1163 test_when_finished "rm $patch" &&
1164 git send-email \
1165 --dry-run \
1166 --from="Example <nobody@example.com>" \
1167 --to=nobody@example.com \
1168 --smtp-server relay.example.com \
1169 $patch >stdout &&
1170 grep "RCPT TO:<bodies@example.com>" stdout &&
1171 grep "RCPT TO:<nobody@example.com>" stdout
1172'
1173
1174test_expect_success $PREREQ 'To headers from files reset each patch' '
1175 patch1=`git format-patch -1 --to="bodies@example.com"` &&
1176 patch2=`git format-patch -1 --to="other@example.com" HEAD~` &&
1177 test_when_finished "rm $patch1 && rm $patch2" &&
1178 git send-email \
1179 --dry-run \
1180 --from="Example <nobody@example.com>" \
1181 --to="nobody@example.com" \
1182 --smtp-server relay.example.com \
1183 $patch1 $patch2 >stdout &&
1184 test $(grep -c "RCPT TO:<bodies@example.com>" stdout) = 1 &&
1185 test $(grep -c "RCPT TO:<nobody@example.com>" stdout) = 2 &&
1186 test $(grep -c "RCPT TO:<other@example.com>" stdout) = 1
1187'
1188
1189test_expect_success $PREREQ 'setup expect' '
1190cat >email-using-8bit <<\EOF
1191From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1192Message-Id: <bogus-message-id@example.com>
1193From: author@example.com
1194Date: Sat, 12 Jun 2010 15:53:58 +0200
1195Subject: subject goes here
1196
1197Dieser deutsche Text enthält einen Umlaut!
1198EOF
1199'
1200
1201test_expect_success $PREREQ 'setup expect' '
1202 echo "Subject: subject goes here" >expected
1203'
1204
1205test_expect_success $PREREQ 'ASCII subject is not RFC2047 quoted' '
1206 clean_fake_sendmail &&
1207 echo bogus |
1208 git send-email --from=author@example.com --to=nobody@example.com \
1209 --smtp-server="$(pwd)/fake.sendmail" \
1210 --8bit-encoding=UTF-8 \
1211 email-using-8bit >stdout &&
1212 grep "Subject" msgtxt1 >actual &&
1213 test_cmp expected actual
1214'
1215
1216test_expect_success $PREREQ 'setup expect' '
1217 cat >content-type-decl <<-\EOF
1218 MIME-Version: 1.0
1219 Content-Type: text/plain; charset=UTF-8
1220 Content-Transfer-Encoding: 8bit
1221 EOF
1222'
1223
1224test_expect_success $PREREQ 'asks about and fixes 8bit encodings' '
1225 clean_fake_sendmail &&
1226 echo |
1227 git send-email --from=author@example.com --to=nobody@example.com \
1228 --smtp-server="$(pwd)/fake.sendmail" \
1229 email-using-8bit >stdout &&
1230 grep "do not declare a Content-Transfer-Encoding" stdout &&
1231 grep email-using-8bit stdout &&
1232 grep "Which 8bit encoding" stdout &&
1233 egrep "Content|MIME" msgtxt1 >actual &&
1234 test_cmp actual content-type-decl
1235'
1236
1237test_expect_success $PREREQ 'sendemail.8bitEncoding works' '
1238 clean_fake_sendmail &&
1239 git config sendemail.assume8bitEncoding UTF-8 &&
1240 echo bogus |
1241 git send-email --from=author@example.com --to=nobody@example.com \
1242 --smtp-server="$(pwd)/fake.sendmail" \
1243 email-using-8bit >stdout &&
1244 egrep "Content|MIME" msgtxt1 >actual &&
1245 test_cmp actual content-type-decl
1246'
1247
1248test_expect_success $PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
1249 clean_fake_sendmail &&
1250 git config sendemail.assume8bitEncoding "bogus too" &&
1251 echo bogus |
1252 git send-email --from=author@example.com --to=nobody@example.com \
1253 --smtp-server="$(pwd)/fake.sendmail" \
1254 --8bit-encoding=UTF-8 \
1255 email-using-8bit >stdout &&
1256 egrep "Content|MIME" msgtxt1 >actual &&
1257 test_cmp actual content-type-decl
1258'
1259
1260test_expect_success $PREREQ 'setup expect' '
1261 cat >email-using-8bit <<-\EOF
1262 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1263 Message-Id: <bogus-message-id@example.com>
1264 From: author@example.com
1265 Date: Sat, 12 Jun 2010 15:53:58 +0200
1266 Subject: Dieser Betreff enthält auch einen Umlaut!
1267
1268 Nothing to see here.
1269 EOF
1270'
1271
1272test_expect_success $PREREQ 'setup expect' '
1273 cat >expected <<-\EOF
1274 Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
1275 EOF
1276'
1277
1278test_expect_success $PREREQ '--8bit-encoding also treats subject' '
1279 clean_fake_sendmail &&
1280 echo bogus |
1281 git send-email --from=author@example.com --to=nobody@example.com \
1282 --smtp-server="$(pwd)/fake.sendmail" \
1283 --8bit-encoding=UTF-8 \
1284 email-using-8bit >stdout &&
1285 grep "Subject" msgtxt1 >actual &&
1286 test_cmp expected actual
1287'
1288
1289test_expect_success $PREREQ 'setup expect' '
1290 cat >email-using-8bit <<-\EOF
1291 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1292 Message-Id: <bogus-message-id@example.com>
1293 From: A U Thor <author@example.com>
1294 Date: Sat, 12 Jun 2010 15:53:58 +0200
1295 Content-Type: text/plain; charset=UTF-8
1296 Subject: Nothing to see here.
1297
1298 Dieser Betreff enthält auch einen Umlaut!
1299 EOF
1300'
1301
1302test_expect_success $PREREQ 'sendemail.transferencoding=7bit fails on 8bit data' '
1303 clean_fake_sendmail &&
1304 git config sendemail.transferEncoding 7bit &&
1305 test_must_fail git send-email \
1306 --transfer-encoding=7bit \
1307 --smtp-server="$(pwd)/fake.sendmail" \
1308 email-using-8bit \
1309 2>errors >out &&
1310 grep "cannot send message as 7bit" errors &&
1311 test -z "$(ls msgtxt*)"
1312'
1313
1314test_expect_success $PREREQ '--transfer-encoding overrides sendemail.transferEncoding' '
1315 clean_fake_sendmail &&
1316 git config sendemail.transferEncoding 8bit &&
1317 test_must_fail git send-email \
1318 --transfer-encoding=7bit \
1319 --smtp-server="$(pwd)/fake.sendmail" \
1320 email-using-8bit \
1321 2>errors >out &&
1322 grep "cannot send message as 7bit" errors &&
1323 test -z "$(ls msgtxt*)"
1324'
1325
1326test_expect_success $PREREQ 'sendemail.transferencoding=8bit' '
1327 clean_fake_sendmail &&
1328 git send-email \
1329 --transfer-encoding=8bit \
1330 --smtp-server="$(pwd)/fake.sendmail" \
1331 email-using-8bit \
1332 2>errors >out &&
1333 sed '1,/^$/d' msgtxt1 >actual &&
1334 sed '1,/^$/d' email-using-8bit >expected &&
1335 test_cmp expected actual
1336'
1337
1338test_expect_success $PREREQ 'setup expect' '
1339 cat >expected <<-\EOF
1340 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1341 EOF
1342'
1343
1344test_expect_success $PREREQ '8-bit and sendemail.transferencoding=quoted-printable' '
1345 clean_fake_sendmail &&
1346 git send-email \
1347 --transfer-encoding=quoted-printable \
1348 --smtp-server="$(pwd)/fake.sendmail" \
1349 email-using-8bit \
1350 2>errors >out &&
1351 sed '1,/^$/d' msgtxt1 >actual &&
1352 test_cmp expected actual
1353'
1354
1355test_expect_success $PREREQ 'setup expect' '
1356 cat >expected <<-\EOF
1357 RGllc2VyIEJldHJlZmYgZW50aMOkbHQgYXVjaCBlaW5lbiBVbWxhdXQhCg==
1358 EOF
1359'
1360
1361test_expect_success $PREREQ '8-bit and sendemail.transferencoding=base64' '
1362 clean_fake_sendmail &&
1363 git send-email \
1364 --transfer-encoding=base64 \
1365 --smtp-server="$(pwd)/fake.sendmail" \
1366 email-using-8bit \
1367 2>errors >out &&
1368 sed '1,/^$/d' msgtxt1 >actual &&
1369 test_cmp expected actual
1370'
1371
1372test_expect_success $PREREQ 'setup expect' '
1373 cat >email-using-qp <<-\EOF
1374 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1375 Message-Id: <bogus-message-id@example.com>
1376 From: A U Thor <author@example.com>
1377 Date: Sat, 12 Jun 2010 15:53:58 +0200
1378 MIME-Version: 1.0
1379 Content-Transfer-Encoding: quoted-printable
1380 Content-Type: text/plain; charset=UTF-8
1381 Subject: Nothing to see here.
1382
1383 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1384 EOF
1385'
1386
1387test_expect_success $PREREQ 'convert from quoted-printable to base64' '
1388 clean_fake_sendmail &&
1389 git send-email \
1390 --transfer-encoding=base64 \
1391 --smtp-server="$(pwd)/fake.sendmail" \
1392 email-using-qp \
1393 2>errors >out &&
1394 sed '1,/^$/d' msgtxt1 >actual &&
1395 test_cmp expected actual
1396'
1397
1398test_expect_success $PREREQ 'setup expect' "
1399tr -d '\\015' | tr '%' '\\015' >email-using-crlf <<EOF
1400From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
1401Message-Id: <bogus-message-id@example.com>
1402From: A U Thor <author@example.com>
1403Date: Sat, 12 Jun 2010 15:53:58 +0200
1404Content-Type: text/plain; charset=UTF-8
1405Subject: Nothing to see here.
1406
1407Look, I have a CRLF and an = sign!%
1408EOF
1409"
1410
1411test_expect_success $PREREQ 'setup expect' '
1412 cat >expected <<-\EOF
1413 Look, I have a CRLF and an =3D sign!=0D
1414 EOF
1415'
1416
1417test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=quoted-printable' '
1418 clean_fake_sendmail &&
1419 git send-email \
1420 --transfer-encoding=quoted-printable \
1421 --smtp-server="$(pwd)/fake.sendmail" \
1422 email-using-crlf \
1423 2>errors >out &&
1424 sed '1,/^$/d' msgtxt1 >actual &&
1425 test_cmp expected actual
1426'
1427
1428test_expect_success $PREREQ 'setup expect' '
1429 cat >expected <<-\EOF
1430 TG9vaywgSSBoYXZlIGEgQ1JMRiBhbmQgYW4gPSBzaWduIQ0K
1431 EOF
1432'
1433
1434test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=base64' '
1435 clean_fake_sendmail &&
1436 git send-email \
1437 --transfer-encoding=base64 \
1438 --smtp-server="$(pwd)/fake.sendmail" \
1439 email-using-crlf \
1440 2>errors >out &&
1441 sed '1,/^$/d' msgtxt1 >actual &&
1442 test_cmp expected actual
1443'
1444
1445
1446# Note that the patches in this test are deliberately out of order; we
1447# want to make sure it works even if the cover-letter is not in the
1448# first mail.
1449test_expect_success $PREREQ 'refusing to send cover letter template' '
1450 clean_fake_sendmail &&
1451 rm -fr outdir &&
1452 git format-patch --cover-letter -2 -o outdir &&
1453 test_must_fail git send-email \
1454 --from="Example <nobody@example.com>" \
1455 --to=nobody@example.com \
1456 --smtp-server="$(pwd)/fake.sendmail" \
1457 outdir/0002-*.patch \
1458 outdir/0000-*.patch \
1459 outdir/0001-*.patch \
1460 2>errors >out &&
1461 grep "SUBJECT HERE" errors &&
1462 test -z "$(ls msgtxt*)"
1463'
1464
1465test_expect_success $PREREQ '--force sends cover letter template anyway' '
1466 clean_fake_sendmail &&
1467 rm -fr outdir &&
1468 git format-patch --cover-letter -2 -o outdir &&
1469 git send-email \
1470 --force \
1471 --from="Example <nobody@example.com>" \
1472 --to=nobody@example.com \
1473 --smtp-server="$(pwd)/fake.sendmail" \
1474 outdir/0002-*.patch \
1475 outdir/0000-*.patch \
1476 outdir/0001-*.patch \
1477 2>errors >out &&
1478 ! grep "SUBJECT HERE" errors &&
1479 test -n "$(ls msgtxt*)"
1480'
1481
1482test_cover_addresses () {
1483 header="$1"
1484 shift
1485 clean_fake_sendmail &&
1486 rm -fr outdir &&
1487 git format-patch --cover-letter -2 -o outdir &&
1488 cover=`echo outdir/0000-*.patch` &&
1489 mv $cover cover-to-edit.patch &&
1490 perl -pe "s/^From:/$header: extra\@address.com\nFrom:/" cover-to-edit.patch >"$cover" &&
1491 git send-email \
1492 --force \
1493 --from="Example <nobody@example.com>" \
1494 --no-to --no-cc \
1495 "$@" \
1496 --smtp-server="$(pwd)/fake.sendmail" \
1497 outdir/0000-*.patch \
1498 outdir/0001-*.patch \
1499 outdir/0002-*.patch \
1500 2>errors >out &&
1501 grep "^$header: extra@address.com" msgtxt1 >to1 &&
1502 grep "^$header: extra@address.com" msgtxt2 >to2 &&
1503 grep "^$header: extra@address.com" msgtxt3 >to3 &&
1504 test_line_count = 1 to1 &&
1505 test_line_count = 1 to2 &&
1506 test_line_count = 1 to3
1507}
1508
1509test_expect_success $PREREQ 'to-cover adds To to all mail' '
1510 test_cover_addresses "To" --to-cover
1511'
1512
1513test_expect_success $PREREQ 'cc-cover adds Cc to all mail' '
1514 test_cover_addresses "Cc" --cc-cover
1515'
1516
1517test_expect_success $PREREQ 'tocover adds To to all mail' '
1518 test_config sendemail.tocover true &&
1519 test_cover_addresses "To"
1520'
1521
1522test_expect_success $PREREQ 'cccover adds Cc to all mail' '
1523 test_config sendemail.cccover true &&
1524 test_cover_addresses "Cc"
1525'
1526
1527test_expect_success $PREREQ 'sendemail.aliasfiletype=mailrc' '
1528 clean_fake_sendmail &&
1529 echo "alias sbd somebody@example.org" >.mailrc &&
1530 git config --replace-all sendemail.aliasesfile "$(pwd)/.mailrc" &&
1531 git config sendemail.aliasfiletype mailrc &&
1532 git send-email \
1533 --from="Example <nobody@example.com>" \
1534 --to=sbd \
1535 --smtp-server="$(pwd)/fake.sendmail" \
1536 outdir/0001-*.patch \
1537 2>errors >out &&
1538 grep "^!somebody@example\.org!$" commandline1
1539'
1540
1541test_expect_success $PREREQ 'sendemail.aliasfile=~/.mailrc' '
1542 clean_fake_sendmail &&
1543 echo "alias sbd someone@example.org" >~/.mailrc &&
1544 git config --replace-all sendemail.aliasesfile "~/.mailrc" &&
1545 git config sendemail.aliasfiletype mailrc &&
1546 git send-email \
1547 --from="Example <nobody@example.com>" \
1548 --to=sbd \
1549 --smtp-server="$(pwd)/fake.sendmail" \
1550 outdir/0001-*.patch \
1551 2>errors >out &&
1552 grep "^!someone@example\.org!$" commandline1
1553'
1554
1555test_expect_success $PREREQ 'alias support in To header' '
1556 clean_fake_sendmail &&
1557 echo "alias sbd someone@example.org" >.mailrc &&
1558 test_config sendemail.aliasesfile ".mailrc" &&
1559 test_config sendemail.aliasfiletype mailrc &&
1560 git format-patch --stdout -1 --to=sbd >aliased.patch &&
1561 git send-email \
1562 --from="Example <nobody@example.com>" \
1563 --smtp-server="$(pwd)/fake.sendmail" \
1564 aliased.patch \
1565 2>errors >out &&
1566 grep "^!someone@example\.org!$" commandline1
1567'
1568
1569test_expect_success $PREREQ 'alias support in Cc header' '
1570 clean_fake_sendmail &&
1571 echo "alias sbd someone@example.org" >.mailrc &&
1572 test_config sendemail.aliasesfile ".mailrc" &&
1573 test_config sendemail.aliasfiletype mailrc &&
1574 git format-patch --stdout -1 --cc=sbd >aliased.patch &&
1575 git send-email \
1576 --from="Example <nobody@example.com>" \
1577 --smtp-server="$(pwd)/fake.sendmail" \
1578 aliased.patch \
1579 2>errors >out &&
1580 grep "^!someone@example\.org!$" commandline1
1581'
1582
1583test_expect_success $PREREQ 'tocmd works with aliases' '
1584 clean_fake_sendmail &&
1585 echo "alias sbd someone@example.org" >.mailrc &&
1586 test_config sendemail.aliasesfile ".mailrc" &&
1587 test_config sendemail.aliasfiletype mailrc &&
1588 git format-patch --stdout -1 >tocmd.patch &&
1589 echo tocmd--sbd >>tocmd.patch &&
1590 git send-email \
1591 --from="Example <nobody@example.com>" \
1592 --to-cmd=./tocmd-sed \
1593 --smtp-server="$(pwd)/fake.sendmail" \
1594 tocmd.patch \
1595 2>errors >out &&
1596 grep "^!someone@example\.org!$" commandline1
1597'
1598
1599test_expect_success $PREREQ 'cccmd works with aliases' '
1600 clean_fake_sendmail &&
1601 echo "alias sbd someone@example.org" >.mailrc &&
1602 test_config sendemail.aliasesfile ".mailrc" &&
1603 test_config sendemail.aliasfiletype mailrc &&
1604 git format-patch --stdout -1 >cccmd.patch &&
1605 echo cccmd--sbd >>cccmd.patch &&
1606 git send-email \
1607 --from="Example <nobody@example.com>" \
1608 --cc-cmd=./cccmd-sed \
1609 --smtp-server="$(pwd)/fake.sendmail" \
1610 cccmd.patch \
1611 2>errors >out &&
1612 grep "^!someone@example\.org!$" commandline1
1613'
1614
1615do_xmailer_test () {
1616 expected=$1 params=$2 &&
1617 git format-patch -1 &&
1618 git send-email \
1619 --from="Example <nobody@example.com>" \
1620 --to=someone@example.com \
1621 --smtp-server="$(pwd)/fake.sendmail" \
1622 $params \
1623 0001-*.patch \
1624 2>errors >out &&
1625 { grep '^X-Mailer:' out || :; } >mailer &&
1626 test_line_count = $expected mailer
1627}
1628
1629test_expect_success $PREREQ '--[no-]xmailer without any configuration' '
1630 do_xmailer_test 1 "--xmailer" &&
1631 do_xmailer_test 0 "--no-xmailer"
1632'
1633
1634test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=true' '
1635 test_config sendemail.xmailer true &&
1636 do_xmailer_test 1 "" &&
1637 do_xmailer_test 0 "--no-xmailer" &&
1638 do_xmailer_test 1 "--xmailer"
1639'
1640
1641test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=false' '
1642 test_config sendemail.xmailer false &&
1643 do_xmailer_test 0 "" &&
1644 do_xmailer_test 0 "--no-xmailer" &&
1645 do_xmailer_test 1 "--xmailer"
1646'
1647
1648test_done