blob: 5a771000c9ca0de56bf21e4d8212a6581727b189 [file] [log] [blame]
Ryan Andersonce903012006-05-29 12:30:15 -07001#!/bin/sh
2
Nanako Shiraishi47a528a2008-09-03 17:59:33 +09003test_description='git send-email'
Johannes Schindelina881baa2020-11-18 23:44:42 +00004GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
Johannes Schindelin334afbc2020-11-18 23:44:19 +00005export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
6
Jeff Kingcfa12092023-05-18 20:03:25 -04007TEST_PASSES_SANITIZE_LEAK=true
Ryan Andersonce903012006-05-29 12:30:15 -07008. ./test-lib.sh
9
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +000010# May be altered later in the test
11PREREQ="PERL"
Jeff King1b19ccd2009-04-03 15:33:59 -040012
Christian Ludwigec3b4b02018-01-12 11:37:24 +010013replace_variable_fields () {
14 sed -e "s/^\(Date:\).*/\1 DATE-STRING/" \
Junio C Hamanoba4324c2022-12-16 10:47:19 +090015 -e "s/^\(Message-ID:\).*/\1 MESSAGE-ID-STRING/" \
Christian Ludwigec3b4b02018-01-12 11:37:24 +010016 -e "s/^\(X-Mailer:\).*/\1 X-MAILER-STRING/"
17}
18
Junio C Hamanoaca56062014-11-25 14:11:39 -080019test_expect_success $PREREQ 'prepare reference tree' '
Junio C Hamano03335f22014-11-25 14:14:41 -080020 echo "1A quick brown fox jumps over the" >file &&
21 echo "lazy dog" >>file &&
22 git add file &&
23 GIT_AUTHOR_NAME="A" git commit -a -m "Initial."
Junio C Hamanoaca56062014-11-25 14:11:39 -080024'
Ryan Andersonce903012006-05-29 12:30:15 -070025
Junio C Hamanoaca56062014-11-25 14:11:39 -080026test_expect_success $PREREQ 'Setup helper tool' '
Junio C Hamanoacd72b52014-11-25 14:21:07 -080027 write_script fake.sendmail <<-\EOF &&
28 shift
29 output=1
30 while test -f commandline$output
31 do
32 output=$(($output+1))
33 done
34 for a
35 do
36 echo "!$a!"
37 done >commandline$output
38 cat >"msgtxt$output"
39 EOF
Junio C Hamano03335f22014-11-25 14:14:41 -080040 git add fake.sendmail &&
41 GIT_AUTHOR_NAME="A" git commit -a -m "Second."
Junio C Hamanoaca56062014-11-25 14:11:39 -080042'
Ryan Andersonce903012006-05-29 12:30:15 -070043
Junio C Hamanoee756a82014-11-25 14:52:42 -080044clean_fake_sendmail () {
Jeff King6d34a2b2008-02-24 16:03:52 -050045 rm -f commandline* msgtxt*
46}
47
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +000048test_expect_success $PREREQ 'Extract patches' '
Rafael Aquinif9f60d72020-06-29 10:11:04 -040049 patches=$(git format-patch -s --cc="One <one@example.com>" --cc=two@example.com -n HEAD^1) &&
Junio C Hamano3ece9bf2023-05-17 14:10:39 -070050 threaded_patches=$(git format-patch -o threaded --thread=shallow -s --in-reply-to="format" HEAD^1)
Junio C Hamano280242d2006-07-02 16:03:59 -070051'
52
Jay Soffianc1f2aa42009-03-02 23:52:18 -050053# Test no confirm early to ensure remaining tests will not hang
54test_no_confirm () {
55 rm -f no_confirm_okay
56 echo n | \
57 GIT_SEND_EMAIL_NOTTY=1 \
58 git send-email \
59 --from="Example <from@example.com>" \
60 --to=nobody@example.com \
61 --smtp-server="$(pwd)/fake.sendmail" \
62 $@ \
Junio C Hamanoee756a82014-11-25 14:52:42 -080063 $patches >stdout &&
Oswald Buddenhagenb46d8062023-08-13 12:46:49 +020064 ! grep "Send this email" stdout &&
65 >no_confirm_okay
Jay Soffianc1f2aa42009-03-02 23:52:18 -050066}
67
68# Exit immediately to prevent hang if a no-confirm test fails
69check_no_confirm () {
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +000070 if ! test -f no_confirm_okay
71 then
72 say 'confirm test failed; skipping remaining tests to prevent hanging'
73 PREREQ="$PREREQ,CHECK_NO_CONFIRM"
74 fi
75 return 0
Jay Soffianc1f2aa42009-03-02 23:52:18 -050076}
77
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +000078test_expect_success $PREREQ 'No confirm with --suppress-cc' '
79 test_no_confirm --suppress-cc=sob &&
80 check_no_confirm
Jay Soffianc1f2aa42009-03-02 23:52:18 -050081'
Jay Soffianc1f2aa42009-03-02 23:52:18 -050082
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +000083
84test_expect_success $PREREQ 'No confirm with --confirm=never' '
85 test_no_confirm --confirm=never &&
86 check_no_confirm
Jay Soffianc1f2aa42009-03-02 23:52:18 -050087'
Jay Soffianc1f2aa42009-03-02 23:52:18 -050088
89# leave sendemail.confirm set to never after this so that none of the
90# remaining tests prompt unintentionally.
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +000091test_expect_success $PREREQ 'No confirm with sendemail.confirm=never' '
Jay Soffianc1f2aa42009-03-02 23:52:18 -050092 git config sendemail.confirm never &&
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +000093 test_no_confirm --compose --subject=foo &&
94 check_no_confirm
Jay Soffianc1f2aa42009-03-02 23:52:18 -050095'
Jay Soffianc1f2aa42009-03-02 23:52:18 -050096
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +000097test_expect_success $PREREQ 'Send patches' '
Junio C Hamano03335f22014-11-25 14:14:41 -080098 git send-email --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
Junio C Hamano280242d2006-07-02 16:03:59 -070099'
Ryan Andersonce903012006-05-29 12:30:15 -0700100
Ævar Arnfjörð Bjarmasonf9444142010-08-13 20:40:10 +0000101test_expect_success $PREREQ 'setup expect' '
Junio C Hamano0720a512014-11-25 15:03:45 -0800102 cat >expected <<-\EOF
103 !nobody@example.com!
104 !author@example.com!
105 !one@example.com!
106 !two@example.com!
107 EOF
Ævar Arnfjörð Bjarmasonf9444142010-08-13 20:40:10 +0000108'
109
Junio C Hamanoaca56062014-11-25 14:11:39 -0800110test_expect_success $PREREQ 'Verify commandline' '
111 test_cmp expected commandline1
112'
Ryan Andersonce903012006-05-29 12:30:15 -0700113
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +0000114test_expect_success $PREREQ 'Send patches with --envelope-sender' '
Junio C Hamano03335f22014-11-25 14:14:41 -0800115 clean_fake_sendmail &&
116 git send-email --envelope-sender="Patch Contributor <patch@example.com>" --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
Junio C Hamano4f333bc2009-11-22 09:54:10 -0800117'
118
Ævar Arnfjörð Bjarmasonf9444142010-08-13 20:40:10 +0000119test_expect_success $PREREQ 'setup expect' '
Junio C Hamano0720a512014-11-25 15:03:45 -0800120 cat >expected <<-\EOF
121 !patch@example.com!
122 !-i!
123 !nobody@example.com!
124 !author@example.com!
125 !one@example.com!
126 !two@example.com!
127 EOF
Ævar Arnfjörð Bjarmasonf9444142010-08-13 20:40:10 +0000128'
129
Junio C Hamanoaca56062014-11-25 14:11:39 -0800130test_expect_success $PREREQ 'Verify commandline' '
131 test_cmp expected commandline1
132'
Junio C Hamano4f333bc2009-11-22 09:54:10 -0800133
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +0000134test_expect_success $PREREQ 'Send patches with --envelope-sender=auto' '
Junio C Hamano03335f22014-11-25 14:14:41 -0800135 clean_fake_sendmail &&
136 git send-email --envelope-sender=auto --suppress-cc=sob --from="Example <nobody@example.com>" --to=nobody@example.com --smtp-server="$(pwd)/fake.sendmail" $patches 2>errors
Felipe Contrerasc89e3242009-11-26 21:04:29 +0200137'
138
Ævar Arnfjörð Bjarmasonf9444142010-08-13 20:40:10 +0000139test_expect_success $PREREQ 'setup expect' '
Junio C Hamano0720a512014-11-25 15:03:45 -0800140 cat >expected <<-\EOF
141 !nobody@example.com!
142 !-i!
143 !nobody@example.com!
144 !author@example.com!
145 !one@example.com!
146 !two@example.com!
147 EOF
Ævar Arnfjörð Bjarmasonf9444142010-08-13 20:40:10 +0000148'
149
Junio C Hamanoaca56062014-11-25 14:11:39 -0800150test_expect_success $PREREQ 'Verify commandline' '
151 test_cmp expected commandline1
152'
Felipe Contrerasc89e3242009-11-26 21:04:29 +0200153
Matthieu Moye3fdbcc2016-10-13 07:47:27 +0200154test_expect_success $PREREQ 'setup expect for cc trailer' "
155cat >expected-cc <<\EOF
156!recipient@example.com!
157!author@example.com!
158!one@example.com!
159!two@example.com!
160!three@example.com!
161!four@example.com!
Matthieu Moycb2922f2017-08-23 12:21:01 +0200162!five@example.com!
163!six@example.com!
Matthieu Moye3fdbcc2016-10-13 07:47:27 +0200164EOF
165"
166
167test_expect_success $PREREQ 'cc trailer with various syntax' '
168 test_commit cc-trailer &&
169 test_when_finished "git reset --hard HEAD^" &&
170 git commit --amend -F - <<-EOF &&
171 Test Cc: trailers.
172
173 Cc: one@example.com
Johan Hovold9d334392017-02-20 12:44:06 +0100174 Cc: <two@example.com> # trailing comments are ignored
175 Cc: <three@example.com>, <not.four@example.com> one address per line
176 Cc: "Some # Body" <four@example.com> [ <also.a.comment> ]
Matthieu Moycb2922f2017-08-23 12:21:01 +0200177 Cc: five@example.com # not.six@example.com
178 Cc: six@example.com, not.seven@example.com
Matthieu Moye3fdbcc2016-10-13 07:47:27 +0200179 EOF
180 clean_fake_sendmail &&
181 git send-email -1 --to=recipient@example.com \
182 --smtp-server="$(pwd)/fake.sendmail" &&
183 test_cmp expected-cc commandline1
184'
185
Alex Bennéed60be8a2018-01-08 11:34:34 +0100186test_expect_success $PREREQ 'setup fake get_maintainer.pl script for cc trailer' "
187 write_script expected-cc-script.sh <<-EOF
188 echo 'One Person <one@example.com> (supporter:THIS (FOO/bar))'
189 echo 'Two Person <two@example.com> (maintainer:THIS THING)'
190 echo 'Third List <three@example.com> (moderated list:THIS THING (FOO/bar))'
191 echo '<four@example.com> (moderated list:FOR THING)'
192 echo 'five@example.com (open list:FOR THING (FOO/bar))'
193 echo 'six@example.com (open list)'
194 EOF
195"
196
197test_expect_success $PREREQ 'cc trailer with get_maintainer.pl output' '
198 clean_fake_sendmail &&
199 git send-email -1 --to=recipient@example.com \
200 --cc-cmd=./expected-cc-script.sh \
201 --smtp-server="$(pwd)/fake.sendmail" &&
202 test_cmp expected-cc commandline1
203'
204
Ævar Arnfjörð Bjarmasonf9444142010-08-13 20:40:10 +0000205test_expect_success $PREREQ 'setup expect' "
David D. Kilzerb7f30e02007-11-18 20:14:55 -0800206cat >expected-show-all-headers <<\EOF
2070001-Second.patch
208(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
Jay Soffian50126992009-02-14 23:32:14 -0500209(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
210(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
David D. Kilzerb7f30e02007-11-18 20:14:55 -0800211Dry-OK. Log says:
212Server: relay.example.com
213MAIL FROM:<from@example.com>
Joe Perches02461e02009-10-08 10:03:26 -0700214RCPT TO:<to@example.com>
215RCPT TO:<cc@example.com>
216RCPT TO:<author@example.com>
217RCPT TO:<one@example.com>
218RCPT TO:<two@example.com>
219RCPT TO:<bcc@example.com>
David D. Kilzerb7f30e02007-11-18 20:14:55 -0800220From: Example <from@example.com>
221To: to@example.com
Joe Perches02461e02009-10-08 10:03:26 -0700222Cc: cc@example.com,
223 A <author@example.com>,
224 One <one@example.com>,
225 two@example.com
David D. Kilzerb7f30e02007-11-18 20:14:55 -0800226Subject: [PATCH 1/1] Second.
227Date: DATE-STRING
Junio C Hamanoba4324c2022-12-16 10:47:19 +0900228Message-ID: MESSAGE-ID-STRING
David D. Kilzerb7f30e02007-11-18 20:14:55 -0800229X-Mailer: X-MAILER-STRING
230In-Reply-To: <unique-message-id@example.com>
231References: <unique-message-id@example.com>
Christian Ludwigd11c9432018-03-04 00:58:14 +0100232Reply-To: Reply <reply@example.com>
brian m. carlsone67a2282018-07-08 22:17:12 +0000233MIME-Version: 1.0
234Content-Transfer-Encoding: 8bit
David D. Kilzerb7f30e02007-11-18 20:14:55 -0800235
236Result: OK
237EOF
Ævar Arnfjörð Bjarmasonf9444142010-08-13 20:40:10 +0000238"
David D. Kilzerb7f30e02007-11-18 20:14:55 -0800239
Michael S. Tsirkin5adcf2c2013-05-30 10:11:13 +0300240test_suppress_self () {
241 test_commit $3 &&
242 test_when_finished "git reset --hard HEAD^" &&
243
244 write_script cccmd-sed <<-EOF &&
245 sed -n -e s/^cccmd--//p "\$1"
246 EOF
247
248 git commit --amend --author="$1 <$2>" -F - &&
249 clean_fake_sendmail &&
250 git format-patch --stdout -1 >"suppress-self-$3.patch" &&
251
252 git send-email --from="$1 <$2>" \
253 --to=nobody@example.com \
254 --cc-cmd=./cccmd-sed \
255 --suppress-cc=self \
256 --smtp-server="$(pwd)/fake.sendmail" \
257 suppress-self-$3.patch &&
258
259 mv msgtxt1 msgtxt1-$3 &&
260 sed -e '/^$/q' msgtxt1-$3 >"msghdr1-$3" &&
Michael S. Tsirkin5adcf2c2013-05-30 10:11:13 +0300261
262 (grep '^Cc:' msghdr1-$3 >"actual-no-cc-$3";
Ævar Arnfjörð Bjarmasond3c67512018-07-27 17:48:11 +0000263 test_must_be_empty actual-no-cc-$3)
Michael S. Tsirkin5adcf2c2013-05-30 10:11:13 +0300264}
265
266test_suppress_self_unquoted () {
267 test_suppress_self "$1" "$2" "unquoted-$3" <<-EOF
268 test suppress-cc.self unquoted-$3 with name $1 email $2
269
270 unquoted-$3
271
Michael S. Tsirkind6ee4452013-06-05 21:10:57 +0300272 cccmd--$1 <$2>
273
Michael S. Tsirkin5adcf2c2013-05-30 10:11:13 +0300274 Cc: $1 <$2>
275 Signed-off-by: $1 <$2>
276 EOF
277}
278
Michael S. Tsirkindd29f0b2013-06-05 21:11:02 +0300279test_suppress_self_quoted () {
280 test_suppress_self "$1" "$2" "quoted-$3" <<-EOF
281 test suppress-cc.self quoted-$3 with name $1 email $2
282
283 quoted-$3
284
285 cccmd--"$1" <$2>
286
287 Cc: $1 <$2>
288 Cc: "$1" <$2>
289 Signed-off-by: $1 <$2>
290 Signed-off-by: "$1" <$2>
291 EOF
292}
293
Michael S. Tsirkin5adcf2c2013-05-30 10:11:13 +0300294test_expect_success $PREREQ 'self name is suppressed' "
Michael S. Tsirkind6ee4452013-06-05 21:10:57 +0300295 test_suppress_self_unquoted 'A U Thor' 'author@example.com' \
Michael S. Tsirkin5adcf2c2013-05-30 10:11:13 +0300296 'self_name_suppressed'
297"
298
Michael S. Tsirkindd29f0b2013-06-05 21:11:02 +0300299test_expect_success $PREREQ 'self name with dot is suppressed' "
300 test_suppress_self_quoted 'A U. Thor' 'author@example.com' \
301 'self_name_dot_suppressed'
302"
303
Michael S. Tsirkin4b45bcf2013-06-05 21:11:04 +0300304test_expect_success $PREREQ 'non-ascii self name is suppressed' "
305 test_suppress_self_quoted 'Füñný Nâmé' 'odd_?=mail@example.com' \
306 'non_ascii_self_suppressed'
307"
308
Роман Донченкоab47e2a2014-12-14 18:59:47 +0300309# This name is long enough to force format-patch to split it into multiple
310# encoded-words, assuming it uses UTF-8 with the "Q" encoding.
311test_expect_success $PREREQ 'long non-ascii self name is suppressed' "
312 test_suppress_self_quoted 'Ƒüñníęř €. Nâṁé' 'odd_?=mail@example.com' \
313 'long_non_ascii_self_suppressed'
314"
315
Michael S. Tsirkin14952662013-06-05 21:11:08 +0300316test_expect_success $PREREQ 'sanitized self name is suppressed' "
317 test_suppress_self_unquoted '\"A U. Thor\"' 'author@example.com' \
318 'self_name_sanitized_suppressed'
319"
320
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +0000321test_expect_success $PREREQ 'Show all headers' '
David D. Kilzerb7f30e02007-11-18 20:14:55 -0800322 git send-email \
323 --dry-run \
Jay Soffian3531e272009-02-14 23:32:15 -0500324 --suppress-cc=sob \
David D. Kilzerb7f30e02007-11-18 20:14:55 -0800325 --from="Example <from@example.com>" \
Christian Ludwigd11c9432018-03-04 00:58:14 +0100326 --reply-to="Reply <reply@example.com>" \
David D. Kilzerb7f30e02007-11-18 20:14:55 -0800327 --to=to@example.com \
328 --cc=cc@example.com \
329 --bcc=bcc@example.com \
330 --in-reply-to="<unique-message-id@example.com>" \
331 --smtp-server relay.example.com \
Christian Ludwigec3b4b02018-01-12 11:37:24 +0100332 $patches | replace_variable_fields \
David D. Kilzerb7f30e02007-11-18 20:14:55 -0800333 >actual-show-all-headers &&
Jeff King82ebb0b2008-03-12 17:36:36 -0400334 test_cmp expected-show-all-headers actual-show-all-headers
David D. Kilzerb7f30e02007-11-18 20:14:55 -0800335'
336
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +0000337test_expect_success $PREREQ 'Prompting works' '
Jay Soffian0da43a62009-04-04 23:23:21 -0400338 clean_fake_sendmail &&
Eric Sunshinecff42432018-07-01 20:24:04 -0400339 (echo "to@example.com" &&
Jeff Kingc0167262023-08-08 14:15:31 -0400340 echo "my-message-id@example.com"
Jay Soffian0da43a62009-04-04 23:23:21 -0400341 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
342 --smtp-server="$(pwd)/fake.sendmail" \
343 $patches \
344 2>errors &&
Felipe Contreras8cac13d2012-11-24 12:16:19 +0100345 grep "^From: A U Thor <author@example.com>\$" msgtxt1 &&
Jeff Kingc0167262023-08-08 14:15:31 -0400346 grep "^To: to@example.com\$" msgtxt1 &&
347 grep "^In-Reply-To: <my-message-id@example.com>" msgtxt1
Jay Soffian0da43a62009-04-04 23:23:21 -0400348'
349
Jeff King59defcc2012-11-28 15:06:26 -0500350test_expect_success $PREREQ,AUTOIDENT 'implicit ident is allowed' '
351 clean_fake_sendmail &&
352 (sane_unset GIT_AUTHOR_NAME &&
353 sane_unset GIT_AUTHOR_EMAIL &&
354 sane_unset GIT_COMMITTER_NAME &&
355 sane_unset GIT_COMMITTER_EMAIL &&
356 GIT_SEND_EMAIL_NOTTY=1 git send-email \
357 --smtp-server="$(pwd)/fake.sendmail" \
358 --to=to@example.com \
359 $patches </dev/null 2>errors
360 )
361'
362
363test_expect_success $PREREQ,!AUTOIDENT 'broken implicit ident aborts send-email' '
364 clean_fake_sendmail &&
365 (sane_unset GIT_AUTHOR_NAME &&
366 sane_unset GIT_AUTHOR_EMAIL &&
367 sane_unset GIT_COMMITTER_NAME &&
368 sane_unset GIT_COMMITTER_EMAIL &&
369 GIT_SEND_EMAIL_NOTTY=1 && export GIT_SEND_EMAIL_NOTTY &&
370 test_must_fail git send-email \
371 --smtp-server="$(pwd)/fake.sendmail" \
372 --to=to@example.com \
373 $patches </dev/null 2>errors &&
Junio C Hamano67892752023-10-31 14:23:30 +0900374 test_grep "tell me who you are" errors
Jeff King59defcc2012-11-28 15:06:26 -0500375 )
376'
377
Maxim Cournoyerba921062023-05-01 10:38:47 -0400378test_expect_success $PREREQ 'setup cmd scripts' '
Remi Lespinet62089fb2015-06-30 14:16:42 +0200379 write_script tocmd-sed <<-\EOF &&
380 sed -n -e "s/^tocmd--//p" "$1"
381 EOF
Maxim Cournoyerba921062023-05-01 10:38:47 -0400382 write_script cccmd-sed <<-\EOF &&
Remi Lespinet62089fb2015-06-30 14:16:42 +0200383 sed -n -e "s/^cccmd--//p" "$1"
384 EOF
Maxim Cournoyerba921062023-05-01 10:38:47 -0400385 write_script headercmd-sed <<-\EOF
386 sed -n -e "s/^headercmd--//p" "$1"
387 EOF
Remi Lespinet62089fb2015-06-30 14:16:42 +0200388'
389
Joe Perches6e74e072010-09-24 10:03:00 -0700390test_expect_success $PREREQ 'tocmd works' '
391 clean_fake_sendmail &&
392 cp $patches tocmd.patch &&
393 echo tocmd--tocmd@example.com >>tocmd.patch &&
Joe Perches6e74e072010-09-24 10:03:00 -0700394 git send-email \
395 --from="Example <nobody@example.com>" \
396 --to-cmd=./tocmd-sed \
397 --smtp-server="$(pwd)/fake.sendmail" \
398 tocmd.patch \
399 &&
400 grep "^To: tocmd@example.com" msgtxt1
401'
402
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +0000403test_expect_success $PREREQ 'cccmd works' '
Paolo Bonzinicb8a9bd2009-06-18 14:31:32 +0200404 clean_fake_sendmail &&
405 cp $patches cccmd.patch &&
Ævar Arnfjörð Bjarmason41ae8f12010-09-30 13:43:09 +0000406 echo "cccmd-- cccmd@example.com" >>cccmd.patch &&
Paolo Bonzinicb8a9bd2009-06-18 14:31:32 +0200407 git send-email \
408 --from="Example <nobody@example.com>" \
409 --to=nobody@example.com \
410 --cc-cmd=./cccmd-sed \
411 --smtp-server="$(pwd)/fake.sendmail" \
412 cccmd.patch \
413 &&
Joe Perches02461e02009-10-08 10:03:26 -0700414 grep "^ cccmd@example.com" msgtxt1
Paolo Bonzinicb8a9bd2009-06-18 14:31:32 +0200415'
416
Maxim Cournoyerba921062023-05-01 10:38:47 -0400417test_expect_success $PREREQ 'headercmd works' '
418 clean_fake_sendmail &&
419 cp $patches headercmd.patch &&
420 echo "headercmd--X-Debbugs-CC: dummy@example.com" >>headercmd.patch &&
421 git send-email \
422 --from="Example <nobody@example.com>" \
423 --to=nobody@example.com \
424 --header-cmd=./headercmd-sed \
425 --smtp-server="$(pwd)/fake.sendmail" \
426 headercmd.patch \
427 &&
428 grep "^X-Debbugs-CC: dummy@example.com" msgtxt1
429'
430
431test_expect_success $PREREQ '--no-header-cmd works' '
432 clean_fake_sendmail &&
433 cp $patches headercmd.patch &&
434 echo "headercmd--X-Debbugs-CC: dummy@example.com" >>headercmd.patch &&
435 git send-email \
436 --from="Example <nobody@example.com>" \
437 --to=nobody@example.com \
438 --header-cmd=./headercmd-sed \
439 --no-header-cmd \
440 --smtp-server="$(pwd)/fake.sendmail" \
441 headercmd.patch \
442 &&
443 ! grep "^X-Debbugs-CC: dummy@example.com" msgtxt1
444'
445
446test_expect_success $PREREQ 'multiline fields are correctly unfolded' '
447 clean_fake_sendmail &&
448 cp $patches headercmd.patch &&
449 write_script headercmd-multiline <<-\EOF &&
450 echo "X-Debbugs-CC: someone@example.com
451FoldedField: This is a tale
452 best told using
453 multiple lines."
454 EOF
455 git send-email \
456 --from="Example <nobody@example.com>" \
457 --to=nobody@example.com \
458 --header-cmd=./headercmd-multiline \
459 --smtp-server="$(pwd)/fake.sendmail" \
460 headercmd.patch &&
461 grep "^FoldedField: This is a tale best told using multiple lines.$" msgtxt1
462'
463
Maxim Cournoyer3a7a18a2023-05-01 10:38:48 -0400464# Blank lines in the middle of the output of a command are invalid.
465test_expect_success $PREREQ 'malform output reported on blank lines in command output' '
466 clean_fake_sendmail &&
467 cp $patches headercmd.patch &&
468 write_script headercmd-malformed-output <<-\EOF &&
469 echo "X-Debbugs-CC: someone@example.com
470
471SomeOtherField: someone-else@example.com"
472 EOF
473 ! git send-email \
474 --from="Example <nobody@example.com>" \
475 --to=nobody@example.com \
476 --header-cmd=./headercmd-malformed-output \
477 --smtp-server="$(pwd)/fake.sendmail" \
478 headercmd.patch
479'
480
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +0000481test_expect_success $PREREQ 'reject long lines' '
Ævar Arnfjörð Bjarmasonf9444142010-08-13 20:40:10 +0000482 z8=zzzzzzzz &&
483 z64=$z8$z8$z8$z8$z8$z8$z8$z8 &&
484 z512=$z64$z64$z64$z64$z64$z64$z64$z64 &&
Jeff King6d34a2b2008-02-24 16:03:52 -0500485 clean_fake_sendmail &&
Jeff King747bbff2008-01-18 09:19:48 -0500486 cp $patches longline.patch &&
Ævar Arnfjörð Bjarmasonea7811b2021-04-06 16:00:37 +0200487 cat >>longline.patch <<-EOF &&
488 $z512$z512
489 not a long line
490 $z512$z512
491 EOF
Stephan Beyerd492b312008-07-12 17:47:52 +0200492 test_must_fail git send-email \
Jeff King747bbff2008-01-18 09:19:48 -0500493 --from="Example <nobody@example.com>" \
494 --to=nobody@example.com \
495 --smtp-server="$(pwd)/fake.sendmail" \
brian m. carlsone67a2282018-07-08 22:17:12 +0000496 --transfer-encoding=8bit \
Jeff King747bbff2008-01-18 09:19:48 -0500497 $patches longline.patch \
Ævar Arnfjörð Bjarmasone5852102021-04-06 16:00:35 +0200498 2>actual &&
499 cat >expect <<-\EOF &&
Ævar Arnfjörð Bjarmasonea7811b2021-04-06 16:00:37 +0200500 fatal: longline.patch:35 is longer than 998 characters
Ævar Arnfjörð Bjarmasone5852102021-04-06 16:00:35 +0200501 warning: no patches were sent
502 EOF
503 test_cmp expect actual
Jeff King747bbff2008-01-18 09:19:48 -0500504'
505
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +0000506test_expect_success $PREREQ 'no patch was sent' '
Jeff King6d34a2b2008-02-24 16:03:52 -0500507 ! test -e commandline1
Jeff King747bbff2008-01-18 09:19:48 -0500508'
509
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +0000510test_expect_success $PREREQ 'Author From: in message body' '
Jay Soffian50126992009-02-14 23:32:14 -0500511 clean_fake_sendmail &&
512 git send-email \
513 --from="Example <nobody@example.com>" \
514 --to=nobody@example.com \
515 --smtp-server="$(pwd)/fake.sendmail" \
516 $patches &&
Junio C Hamanoee756a82014-11-25 14:52:42 -0800517 sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
Jay Soffian50126992009-02-14 23:32:14 -0500518 grep "From: A <author@example.com>" msgbody1
519'
520
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +0000521test_expect_success $PREREQ 'Author From: not in message body' '
Jay Soffian50126992009-02-14 23:32:14 -0500522 clean_fake_sendmail &&
523 git send-email \
524 --from="A <author@example.com>" \
525 --to=nobody@example.com \
526 --smtp-server="$(pwd)/fake.sendmail" \
527 $patches &&
Junio C Hamanoee756a82014-11-25 14:52:42 -0800528 sed "1,/^\$/d" <msgtxt1 >msgbody1 &&
Jay Soffian50126992009-02-14 23:32:14 -0500529 ! grep "From: A <author@example.com>" msgbody1
530'
531
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +0000532test_expect_success $PREREQ 'allow long lines with --no-validate' '
Jeff Kingc764a0c2008-01-18 09:20:10 -0500533 git send-email \
534 --from="Example <nobody@example.com>" \
535 --to=nobody@example.com \
536 --smtp-server="$(pwd)/fake.sendmail" \
Kyle J. McKayf4714942015-01-30 18:40:17 -0800537 --no-validate \
Jeff Kingc764a0c2008-01-18 09:20:10 -0500538 $patches longline.patch \
539 2>errors
540'
541
brian m. carlson7a369872018-07-08 22:17:10 +0000542test_expect_success $PREREQ 'short lines with auto encoding are 8bit' '
543 clean_fake_sendmail &&
544 git send-email \
545 --from="A <author@example.com>" \
546 --to=nobody@example.com \
547 --smtp-server="$(pwd)/fake.sendmail" \
548 --transfer-encoding=auto \
549 $patches &&
550 grep "Content-Transfer-Encoding: 8bit" msgtxt1
551'
552
553test_expect_success $PREREQ 'long lines with auto encoding are quoted-printable' '
554 clean_fake_sendmail &&
555 git send-email \
556 --from="Example <nobody@example.com>" \
557 --to=nobody@example.com \
558 --smtp-server="$(pwd)/fake.sendmail" \
559 --transfer-encoding=auto \
560 --no-validate \
561 longline.patch &&
562 grep "Content-Transfer-Encoding: quoted-printable" msgtxt1
563'
564
brian m. carlson74d76a12019-04-13 22:45:51 +0000565test_expect_success $PREREQ 'carriage returns with auto encoding are quoted-printable' '
566 clean_fake_sendmail &&
567 cp $patches cr.patch &&
568 printf "this is a line\r\n" >>cr.patch &&
569 git send-email \
570 --from="Example <nobody@example.com>" \
571 --to=nobody@example.com \
572 --smtp-server="$(pwd)/fake.sendmail" \
573 --transfer-encoding=auto \
574 --no-validate \
575 cr.patch &&
576 grep "Content-Transfer-Encoding: quoted-printable" msgtxt1
577'
578
brian m. carlsonf2d06fb2018-07-08 22:17:11 +0000579for enc in auto quoted-printable base64
580do
581 test_expect_success $PREREQ "--validate passes with encoding $enc" '
582 git send-email \
583 --from="Example <nobody@example.com>" \
584 --to=nobody@example.com \
585 --smtp-server="$(pwd)/fake.sendmail" \
586 --transfer-encoding=$enc \
587 --validate \
588 $patches longline.patch
589 '
Aaron Lindsay3c88e462018-11-02 05:52:38 -0400590
591done
592
Robert Fossc8243932021-03-23 18:33:27 +0100593test_expect_success $PREREQ "--validate respects relative core.hooksPath path" '
594 clean_fake_sendmail &&
595 mkdir my-hooks &&
596 test_when_finished "rm my-hooks.ran" &&
597 write_script my-hooks/sendemail-validate <<-\EOF &&
598 >my-hooks.ran
599 exit 1
600 EOF
601 test_config core.hooksPath "my-hooks" &&
602 test_must_fail git send-email \
603 --from="Example <nobody@example.com>" \
604 --to=nobody@example.com \
605 --smtp-server="$(pwd)/fake.sendmail" \
606 --validate \
Ævar Arnfjörð Bjarmasone5852102021-04-06 16:00:35 +0200607 longline.patch 2>actual &&
Robert Fossc8243932021-03-23 18:33:27 +0100608 test_path_is_file my-hooks.ran &&
Ævar Arnfjörð Bjarmasonea7811b2021-04-06 16:00:37 +0200609 cat >expect <<-EOF &&
Ævar Arnfjörð Bjarmasone5852102021-04-06 16:00:35 +0200610 fatal: longline.patch: rejected by sendemail-validate hook
Michael Strawbridgea8022c52023-04-19 16:27:03 -0400611 fatal: command '"'"'git hook run --ignore-missing sendemail-validate -- <patch> <header>'"'"' died with exit code 1
Ævar Arnfjörð Bjarmasone5852102021-04-06 16:00:35 +0200612 warning: no patches were sent
613 EOF
614 test_cmp expect actual
Robert Fossc8243932021-03-23 18:33:27 +0100615'
616
617test_expect_success $PREREQ "--validate respects absolute core.hooksPath path" '
Ævar Arnfjörð Bjarmason28153262021-05-26 13:21:06 +0200618 hooks_path="$(pwd)/my-hooks" &&
619 test_config core.hooksPath "$hooks_path" &&
Robert Fossc8243932021-03-23 18:33:27 +0100620 test_when_finished "rm my-hooks.ran" &&
621 test_must_fail git send-email \
622 --from="Example <nobody@example.com>" \
623 --to=nobody@example.com \
624 --smtp-server="$(pwd)/fake.sendmail" \
625 --validate \
Ævar Arnfjörð Bjarmasone5852102021-04-06 16:00:35 +0200626 longline.patch 2>actual &&
Robert Fossc8243932021-03-23 18:33:27 +0100627 test_path_is_file my-hooks.ran &&
Ævar Arnfjörð Bjarmasonea7811b2021-04-06 16:00:37 +0200628 cat >expect <<-EOF &&
Ævar Arnfjörð Bjarmasone5852102021-04-06 16:00:35 +0200629 fatal: longline.patch: rejected by sendemail-validate hook
Michael Strawbridgea8022c52023-04-19 16:27:03 -0400630 fatal: command '"'"'git hook run --ignore-missing sendemail-validate -- <patch> <header>'"'"' died with exit code 1
Ævar Arnfjörð Bjarmasone5852102021-04-06 16:00:35 +0200631 warning: no patches were sent
632 EOF
633 test_cmp expect actual
Robert Fossc8243932021-03-23 18:33:27 +0100634'
635
Michael Strawbridge0d864702023-10-25 14:51:29 -0400636test_expect_success $PREREQ "--validate hook supports multiple addresses in arguments" '
637 hooks_path="$(pwd)/my-hooks" &&
638 test_config core.hooksPath "$hooks_path" &&
639 test_when_finished "rm my-hooks.ran" &&
640 test_must_fail git send-email \
641 --from="Example <nobody@example.com>" \
642 --to=nobody@example.com,abc@example.com \
643 --smtp-server="$(pwd)/fake.sendmail" \
644 --validate \
645 longline.patch 2>actual &&
646 test_path_is_file my-hooks.ran &&
647 cat >expect <<-EOF &&
648 fatal: longline.patch: rejected by sendemail-validate hook
649 fatal: command '"'"'git hook run --ignore-missing sendemail-validate -- <patch> <header>'"'"' died with exit code 1
650 warning: no patches were sent
651 EOF
652 test_cmp expect actual
653'
654
Michael Strawbridgea8022c52023-04-19 16:27:03 -0400655test_expect_success $PREREQ "--validate hook supports header argument" '
656 write_script my-hooks/sendemail-validate <<-\EOF &&
657 if test "$#" -ge 2
658 then
659 grep "X-test-header: v1.0" "$2"
660 else
661 echo "No header arg passed"
662 exit 1
663 fi
664 EOF
665 test_config core.hooksPath "my-hooks" &&
666 rm -fr outdir &&
667 git format-patch \
668 --add-header="X-test-header: v1.0" \
669 -n HEAD^1 -o outdir &&
670 git send-email \
671 --dry-run \
672 --to=nobody@example.com \
673 --smtp-server="$(pwd)/fake.sendmail" \
674 --validate \
675 outdir/000?-*.patch
676'
677
Junio C Hamano3ece9bf2023-05-17 14:10:39 -0700678test_expect_success $PREREQ 'clear message-id before parsing a new message' '
679 clean_fake_sendmail &&
680 echo true | write_script my-hooks/sendemail-validate &&
681 test_config core.hooksPath my-hooks &&
Junio C Hamano3ece9bf2023-05-17 14:10:39 -0700682 git send-email --validate --to=recipient@example.com \
683 --smtp-server="$(pwd)/fake.sendmail" \
684 $patches $threaded_patches &&
685 id0=$(grep "^Message-ID: " $threaded_patches) &&
686 id1=$(grep "^Message-ID: " msgtxt1) &&
687 id2=$(grep "^Message-ID: " msgtxt2) &&
688 test "z$id0" = "z$id2" &&
689 test "z$id1" != "z$id2"
690'
691
Aaron Lindsay3c88e462018-11-02 05:52:38 -0400692for enc in 7bit 8bit quoted-printable base64
693do
694 test_expect_success $PREREQ "--transfer-encoding=$enc produces correct header" '
695 clean_fake_sendmail &&
696 git send-email \
697 --from="Example <nobody@example.com>" \
698 --to=nobody@example.com \
699 --smtp-server="$(pwd)/fake.sendmail" \
700 --transfer-encoding=$enc \
701 $patches &&
702 grep "Content-Transfer-Encoding: $enc" msgtxt1
703 '
brian m. carlsonf2d06fb2018-07-08 22:17:11 +0000704done
705
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +0000706test_expect_success $PREREQ 'Invalid In-Reply-To' '
Jeff King6d34a2b2008-02-24 16:03:52 -0500707 clean_fake_sendmail &&
Jay Soffian0fb7fc72008-02-21 19:16:04 -0500708 git send-email \
709 --from="Example <nobody@example.com>" \
710 --to=nobody@example.com \
711 --in-reply-to=" " \
712 --smtp-server="$(pwd)/fake.sendmail" \
Antonio Ospite5b574132010-10-19 11:50:39 +0200713 $patches \
Antonio Ospitecc7e8162011-01-04 21:56:58 +0100714 2>errors &&
Jeff King6d34a2b2008-02-24 16:03:52 -0500715 ! grep "^In-Reply-To: < *>" msgtxt1
Jay Soffian0fb7fc72008-02-21 19:16:04 -0500716'
717
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +0000718test_expect_success $PREREQ 'Valid In-Reply-To when prompting' '
Jeff King6d34a2b2008-02-24 16:03:52 -0500719 clean_fake_sendmail &&
Eric Sunshinecff42432018-07-01 20:24:04 -0400720 (echo "From Example <from@example.com>" &&
721 echo "To Example <to@example.com>" &&
Jay Soffian0fb7fc72008-02-21 19:16:04 -0500722 echo ""
Junio C Hamano6eca18c2014-03-06 15:22:34 -0800723 ) | GIT_SEND_EMAIL_NOTTY=1 git send-email \
Jay Soffian0fb7fc72008-02-21 19:16:04 -0500724 --smtp-server="$(pwd)/fake.sendmail" \
725 $patches 2>errors &&
Jeff King6d34a2b2008-02-24 16:03:52 -0500726 ! grep "^In-Reply-To: < *>" msgtxt1
Jay Soffian0fb7fc72008-02-21 19:16:04 -0500727'
728
Junio C Hamano54aae5e2010-10-19 11:46:31 -0700729test_expect_success $PREREQ 'In-Reply-To without --chain-reply-to' '
730 clean_fake_sendmail &&
731 echo "<unique-message-id@example.com>" >expect &&
732 git send-email \
733 --from="Example <nobody@example.com>" \
734 --to=nobody@example.com \
Kyle J. McKayf4714942015-01-30 18:40:17 -0800735 --no-chain-reply-to \
Junio C Hamano54aae5e2010-10-19 11:46:31 -0700736 --in-reply-to="$(cat expect)" \
737 --smtp-server="$(pwd)/fake.sendmail" \
738 $patches $patches $patches \
739 2>errors &&
Antonio Ospitedb54c8e2010-11-12 15:55:08 +0100740 # The first message is a reply to --in-reply-to
Junio C Hamano54aae5e2010-10-19 11:46:31 -0700741 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
742 test_cmp expect actual &&
Antonio Ospitedb54c8e2010-11-12 15:55:08 +0100743 # Second and subsequent messages are replies to the first one
Junio C Hamanoba4324c2022-12-16 10:47:19 +0900744 sed -n -e "s/^Message-ID: *\(.*\)/\1/p" msgtxt1 >expect &&
Junio C Hamano54aae5e2010-10-19 11:46:31 -0700745 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
746 test_cmp expect actual &&
747 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
748 test_cmp expect actual
749'
750
751test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' '
752 clean_fake_sendmail &&
753 echo "<unique-message-id@example.com>" >expect &&
754 git send-email \
755 --from="Example <nobody@example.com>" \
756 --to=nobody@example.com \
757 --chain-reply-to \
758 --in-reply-to="$(cat expect)" \
759 --smtp-server="$(pwd)/fake.sendmail" \
760 $patches $patches $patches \
761 2>errors &&
762 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
763 test_cmp expect actual &&
Junio C Hamanoba4324c2022-12-16 10:47:19 +0900764 sed -n -e "s/^Message-ID: *\(.*\)/\1/p" msgtxt1 >expect &&
Junio C Hamano54aae5e2010-10-19 11:46:31 -0700765 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt2 >actual &&
766 test_cmp expect actual &&
Junio C Hamanoba4324c2022-12-16 10:47:19 +0900767 sed -n -e "s/^Message-ID: *\(.*\)/\1/p" msgtxt2 >expect &&
Junio C Hamano54aae5e2010-10-19 11:46:31 -0700768 sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt3 >actual &&
769 test_cmp expect actual
770'
771
Ævar Arnfjörð Bjarmason5b719b72021-05-25 01:14:24 +0200772test_set_editor "$(pwd)/fake-editor"
773
774test_expect_success $PREREQ 'setup erroring fake editor' '
775 write_script fake-editor <<-\EOF
776 echo >&2 "I am about to error"
777 exit 1
778 EOF
779'
780
781test_expect_success $PREREQ 'fake editor dies with error' '
782 clean_fake_sendmail &&
783 test_must_fail git send-email \
784 --compose --subject foo \
785 --from="Example <nobody@example.com>" \
786 --to=nobody@example.com \
787 --smtp-server="$(pwd)/fake.sendmail" \
788 $patches 2>err &&
789 grep "I am about to error" err &&
790 grep "the editor exited uncleanly, aborting everything" err
791'
792
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +0000793test_expect_success $PREREQ 'setup fake editor' '
Junio C Hamanoacd72b52014-11-25 14:21:07 -0800794 write_script fake-editor <<-\EOF
795 echo fake edit >>"$1"
796 EOF
Jeff King8a8bf462008-02-24 16:04:14 -0500797'
798
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +0000799test_expect_success $PREREQ '--compose works' '
Jeff King8a8bf462008-02-24 16:04:14 -0500800 clean_fake_sendmail &&
Jay Soffianc1f2aa42009-03-02 23:52:18 -0500801 git send-email \
802 --compose --subject foo \
803 --from="Example <nobody@example.com>" \
804 --to=nobody@example.com \
805 --smtp-server="$(pwd)/fake.sendmail" \
806 $patches \
807 2>errors
Jeff King8a8bf462008-02-24 16:04:14 -0500808'
809
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +0000810test_expect_success $PREREQ 'first message is compose text' '
Jeff King8a8bf462008-02-24 16:04:14 -0500811 grep "^fake edit" msgtxt1
812'
813
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +0000814test_expect_success $PREREQ 'second message is patch' '
Jeff King8a8bf462008-02-24 16:04:14 -0500815 grep "Subject:.*Second" msgtxt2
816'
817
Ævar Arnfjörð Bjarmasonf9444142010-08-13 20:40:10 +0000818test_expect_success $PREREQ 'setup expect' "
Jay Soffian3531e272009-02-14 23:32:15 -0500819cat >expected-suppress-sob <<\EOF
Miklos Vajna33c592d2008-04-29 12:56:47 +02008200001-Second.patch
821(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
Jay Soffian50126992009-02-14 23:32:14 -0500822(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
823(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
Miklos Vajna33c592d2008-04-29 12:56:47 +0200824Dry-OK. Log says:
825Server: relay.example.com
826MAIL FROM:<from@example.com>
Joe Perches02461e02009-10-08 10:03:26 -0700827RCPT TO:<to@example.com>
828RCPT TO:<cc@example.com>
829RCPT TO:<author@example.com>
830RCPT TO:<one@example.com>
831RCPT TO:<two@example.com>
Miklos Vajna33c592d2008-04-29 12:56:47 +0200832From: Example <from@example.com>
833To: to@example.com
Joe Perches02461e02009-10-08 10:03:26 -0700834Cc: cc@example.com,
835 A <author@example.com>,
836 One <one@example.com>,
837 two@example.com
Miklos Vajna33c592d2008-04-29 12:56:47 +0200838Subject: [PATCH 1/1] Second.
839Date: DATE-STRING
Junio C Hamanoba4324c2022-12-16 10:47:19 +0900840Message-ID: MESSAGE-ID-STRING
Miklos Vajna33c592d2008-04-29 12:56:47 +0200841X-Mailer: X-MAILER-STRING
brian m. carlsone67a2282018-07-08 22:17:12 +0000842MIME-Version: 1.0
843Content-Transfer-Encoding: 8bit
Miklos Vajna33c592d2008-04-29 12:56:47 +0200844
845Result: OK
846EOF
Ævar Arnfjörð Bjarmasonf9444142010-08-13 20:40:10 +0000847"
Miklos Vajna33c592d2008-04-29 12:56:47 +0200848
Jay Soffian3531e272009-02-14 23:32:15 -0500849test_suppression () {
Miklos Vajna33c592d2008-04-29 12:56:47 +0200850 git send-email \
851 --dry-run \
Paolo Bonzinicb8a9bd2009-06-18 14:31:32 +0200852 --suppress-cc=$1 ${2+"--suppress-cc=$2"} \
Miklos Vajna33c592d2008-04-29 12:56:47 +0200853 --from="Example <from@example.com>" \
854 --to=to@example.com \
855 --smtp-server relay.example.com \
Remi Lespinetd4cf11c2015-06-30 14:16:44 +0200856 $patches | replace_variable_fields \
Paolo Bonzinicb8a9bd2009-06-18 14:31:32 +0200857 >actual-suppress-$1${2+"-$2"} &&
858 test_cmp expected-suppress-$1${2+"-$2"} actual-suppress-$1${2+"-$2"}
Jay Soffian3531e272009-02-14 23:32:15 -0500859}
860
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +0000861test_expect_success $PREREQ 'sendemail.cc set' '
Jay Soffian3531e272009-02-14 23:32:15 -0500862 git config sendemail.cc cc@example.com &&
863 test_suppression sob
Miklos Vajna33c592d2008-04-29 12:56:47 +0200864'
865
Ævar Arnfjörð Bjarmasonf9444142010-08-13 20:40:10 +0000866test_expect_success $PREREQ 'setup expect' "
Jay Soffian3531e272009-02-14 23:32:15 -0500867cat >expected-suppress-sob <<\EOF
Miklos Vajna33c592d2008-04-29 12:56:47 +02008680001-Second.patch
869(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
Jay Soffian50126992009-02-14 23:32:14 -0500870(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
871(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
Miklos Vajna33c592d2008-04-29 12:56:47 +0200872Dry-OK. Log says:
873Server: relay.example.com
874MAIL FROM:<from@example.com>
Joe Perches02461e02009-10-08 10:03:26 -0700875RCPT TO:<to@example.com>
876RCPT TO:<author@example.com>
877RCPT TO:<one@example.com>
878RCPT TO:<two@example.com>
Miklos Vajna33c592d2008-04-29 12:56:47 +0200879From: Example <from@example.com>
880To: to@example.com
Joe Perches02461e02009-10-08 10:03:26 -0700881Cc: A <author@example.com>,
882 One <one@example.com>,
883 two@example.com
Miklos Vajna33c592d2008-04-29 12:56:47 +0200884Subject: [PATCH 1/1] Second.
885Date: DATE-STRING
Junio C Hamanoba4324c2022-12-16 10:47:19 +0900886Message-ID: MESSAGE-ID-STRING
Miklos Vajna33c592d2008-04-29 12:56:47 +0200887X-Mailer: X-MAILER-STRING
brian m. carlsone67a2282018-07-08 22:17:12 +0000888MIME-Version: 1.0
889Content-Transfer-Encoding: 8bit
Miklos Vajna33c592d2008-04-29 12:56:47 +0200890
891Result: OK
892EOF
Ævar Arnfjörð Bjarmasonf9444142010-08-13 20:40:10 +0000893"
Miklos Vajna33c592d2008-04-29 12:56:47 +0200894
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +0000895test_expect_success $PREREQ 'sendemail.cc unset' '
Miklos Vajna33c592d2008-04-29 12:56:47 +0200896 git config --unset sendemail.cc &&
Jay Soffian3531e272009-02-14 23:32:15 -0500897 test_suppression sob
898'
899
Ævar Arnfjörð Bjarmasonf9444142010-08-13 20:40:10 +0000900test_expect_success $PREREQ 'setup expect' "
Paolo Bonzinicb8a9bd2009-06-18 14:31:32 +0200901cat >expected-suppress-cccmd <<\EOF
9020001-Second.patch
903(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
904(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
905(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
906(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
907Dry-OK. Log says:
908Server: relay.example.com
909MAIL FROM:<from@example.com>
Joe Perches02461e02009-10-08 10:03:26 -0700910RCPT TO:<to@example.com>
911RCPT TO:<author@example.com>
912RCPT TO:<one@example.com>
913RCPT TO:<two@example.com>
914RCPT TO:<committer@example.com>
Paolo Bonzinicb8a9bd2009-06-18 14:31:32 +0200915From: Example <from@example.com>
916To: to@example.com
Joe Perches02461e02009-10-08 10:03:26 -0700917Cc: A <author@example.com>,
918 One <one@example.com>,
919 two@example.com,
920 C O Mitter <committer@example.com>
Paolo Bonzinicb8a9bd2009-06-18 14:31:32 +0200921Subject: [PATCH 1/1] Second.
922Date: DATE-STRING
Junio C Hamanoba4324c2022-12-16 10:47:19 +0900923Message-ID: MESSAGE-ID-STRING
Paolo Bonzinicb8a9bd2009-06-18 14:31:32 +0200924X-Mailer: X-MAILER-STRING
brian m. carlsone67a2282018-07-08 22:17:12 +0000925MIME-Version: 1.0
926Content-Transfer-Encoding: 8bit
Paolo Bonzinicb8a9bd2009-06-18 14:31:32 +0200927
928Result: OK
929EOF
Ævar Arnfjörð Bjarmasonf9444142010-08-13 20:40:10 +0000930"
Paolo Bonzinicb8a9bd2009-06-18 14:31:32 +0200931
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +0000932test_expect_success $PREREQ 'sendemail.cccmd' '
Junio C Hamanoacd72b52014-11-25 14:21:07 -0800933 write_script cccmd <<-\EOF &&
934 echo cc-cmd@example.com
935 EOF
Paolo Bonzinicb8a9bd2009-06-18 14:31:32 +0200936 git config sendemail.cccmd ./cccmd &&
937 test_suppression cccmd
938'
939
Ævar Arnfjörð Bjarmasonf9444142010-08-13 20:40:10 +0000940test_expect_success $PREREQ 'setup expect' '
Jay Soffian3531e272009-02-14 23:32:15 -0500941cat >expected-suppress-all <<\EOF
9420001-Second.patch
943Dry-OK. Log says:
944Server: relay.example.com
945MAIL FROM:<from@example.com>
946RCPT TO:<to@example.com>
947From: Example <from@example.com>
948To: to@example.com
949Subject: [PATCH 1/1] Second.
950Date: DATE-STRING
Junio C Hamanoba4324c2022-12-16 10:47:19 +0900951Message-ID: MESSAGE-ID-STRING
Jay Soffian3531e272009-02-14 23:32:15 -0500952X-Mailer: X-MAILER-STRING
brian m. carlsone67a2282018-07-08 22:17:12 +0000953MIME-Version: 1.0
954Content-Transfer-Encoding: 8bit
Jay Soffian3531e272009-02-14 23:32:15 -0500955
956Result: OK
957EOF
Ævar Arnfjörð Bjarmasonf9444142010-08-13 20:40:10 +0000958'
Jay Soffian3531e272009-02-14 23:32:15 -0500959
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +0000960test_expect_success $PREREQ '--suppress-cc=all' '
Jay Soffian3531e272009-02-14 23:32:15 -0500961 test_suppression all
962'
963
Ævar Arnfjörð Bjarmasonf9444142010-08-13 20:40:10 +0000964test_expect_success $PREREQ 'setup expect' "
Jay Soffian3531e272009-02-14 23:32:15 -0500965cat >expected-suppress-body <<\EOF
9660001-Second.patch
967(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
968(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
969(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
Paolo Bonzinicb8a9bd2009-06-18 14:31:32 +0200970(cc-cmd) Adding cc: cc-cmd@example.com from: './cccmd'
971Dry-OK. Log says:
972Server: relay.example.com
973MAIL FROM:<from@example.com>
Joe Perches02461e02009-10-08 10:03:26 -0700974RCPT TO:<to@example.com>
975RCPT TO:<author@example.com>
976RCPT TO:<one@example.com>
977RCPT TO:<two@example.com>
978RCPT TO:<cc-cmd@example.com>
Paolo Bonzinicb8a9bd2009-06-18 14:31:32 +0200979From: Example <from@example.com>
980To: to@example.com
Joe Perches02461e02009-10-08 10:03:26 -0700981Cc: A <author@example.com>,
982 One <one@example.com>,
983 two@example.com,
984 cc-cmd@example.com
Paolo Bonzinicb8a9bd2009-06-18 14:31:32 +0200985Subject: [PATCH 1/1] Second.
986Date: DATE-STRING
Junio C Hamanoba4324c2022-12-16 10:47:19 +0900987Message-ID: MESSAGE-ID-STRING
Paolo Bonzinicb8a9bd2009-06-18 14:31:32 +0200988X-Mailer: X-MAILER-STRING
brian m. carlsone67a2282018-07-08 22:17:12 +0000989MIME-Version: 1.0
990Content-Transfer-Encoding: 8bit
Paolo Bonzinicb8a9bd2009-06-18 14:31:32 +0200991
992Result: OK
993EOF
Ævar Arnfjörð Bjarmasonf9444142010-08-13 20:40:10 +0000994"
Paolo Bonzinicb8a9bd2009-06-18 14:31:32 +0200995
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +0000996test_expect_success $PREREQ '--suppress-cc=body' '
Paolo Bonzinicb8a9bd2009-06-18 14:31:32 +0200997 test_suppression body
998'
999
Ævar Arnfjörð Bjarmasonf9444142010-08-13 20:40:10 +00001000test_expect_success $PREREQ 'setup expect' "
Paolo Bonzinicb8a9bd2009-06-18 14:31:32 +02001001cat >expected-suppress-body-cccmd <<\EOF
10020001-Second.patch
1003(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
1004(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
1005(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
Jay Soffian3531e272009-02-14 23:32:15 -05001006Dry-OK. Log says:
1007Server: relay.example.com
1008MAIL FROM:<from@example.com>
Joe Perches02461e02009-10-08 10:03:26 -07001009RCPT TO:<to@example.com>
1010RCPT TO:<author@example.com>
1011RCPT TO:<one@example.com>
1012RCPT TO:<two@example.com>
Jay Soffian3531e272009-02-14 23:32:15 -05001013From: Example <from@example.com>
1014To: to@example.com
Joe Perches02461e02009-10-08 10:03:26 -07001015Cc: A <author@example.com>,
1016 One <one@example.com>,
1017 two@example.com
Jay Soffian3531e272009-02-14 23:32:15 -05001018Subject: [PATCH 1/1] Second.
1019Date: DATE-STRING
Junio C Hamanoba4324c2022-12-16 10:47:19 +09001020Message-ID: MESSAGE-ID-STRING
Jay Soffian3531e272009-02-14 23:32:15 -05001021X-Mailer: X-MAILER-STRING
brian m. carlsone67a2282018-07-08 22:17:12 +00001022MIME-Version: 1.0
1023Content-Transfer-Encoding: 8bit
Jay Soffian3531e272009-02-14 23:32:15 -05001024
1025Result: OK
1026EOF
Ævar Arnfjörð Bjarmasonf9444142010-08-13 20:40:10 +00001027"
Jay Soffian3531e272009-02-14 23:32:15 -05001028
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +00001029test_expect_success $PREREQ '--suppress-cc=body --suppress-cc=cccmd' '
Paolo Bonzinicb8a9bd2009-06-18 14:31:32 +02001030 test_suppression body cccmd
Jay Soffian3531e272009-02-14 23:32:15 -05001031'
1032
Ævar Arnfjörð Bjarmasonf9444142010-08-13 20:40:10 +00001033test_expect_success $PREREQ 'setup expect' "
Jay Soffian3531e272009-02-14 23:32:15 -05001034cat >expected-suppress-sob <<\EOF
10350001-Second.patch
1036(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
1037(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
1038(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
1039Dry-OK. Log says:
1040Server: relay.example.com
1041MAIL FROM:<from@example.com>
Joe Perches02461e02009-10-08 10:03:26 -07001042RCPT TO:<to@example.com>
1043RCPT TO:<author@example.com>
1044RCPT TO:<one@example.com>
1045RCPT TO:<two@example.com>
Jay Soffian3531e272009-02-14 23:32:15 -05001046From: Example <from@example.com>
1047To: to@example.com
Joe Perches02461e02009-10-08 10:03:26 -07001048Cc: A <author@example.com>,
1049 One <one@example.com>,
1050 two@example.com
Jay Soffian3531e272009-02-14 23:32:15 -05001051Subject: [PATCH 1/1] Second.
1052Date: DATE-STRING
Junio C Hamanoba4324c2022-12-16 10:47:19 +09001053Message-ID: MESSAGE-ID-STRING
Jay Soffian3531e272009-02-14 23:32:15 -05001054X-Mailer: X-MAILER-STRING
brian m. carlsone67a2282018-07-08 22:17:12 +00001055MIME-Version: 1.0
1056Content-Transfer-Encoding: 8bit
Jay Soffian3531e272009-02-14 23:32:15 -05001057
1058Result: OK
1059EOF
Ævar Arnfjörð Bjarmasonf9444142010-08-13 20:40:10 +00001060"
Jay Soffian3531e272009-02-14 23:32:15 -05001061
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +00001062test_expect_success $PREREQ '--suppress-cc=sob' '
Antonio Ospitecc7e8162011-01-04 21:56:58 +01001063 test_might_fail git config --unset sendemail.cccmd &&
Jay Soffian3531e272009-02-14 23:32:15 -05001064 test_suppression sob
1065'
1066
Ævar Arnfjörð Bjarmasonf9444142010-08-13 20:40:10 +00001067test_expect_success $PREREQ 'setup expect' "
Jay Soffian3531e272009-02-14 23:32:15 -05001068cat >expected-suppress-bodycc <<\EOF
10690001-Second.patch
1070(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
1071(mbox) Adding cc: One <one@example.com> from line 'Cc: One <one@example.com>, two@example.com'
1072(mbox) Adding cc: two@example.com from line 'Cc: One <one@example.com>, two@example.com'
1073(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
1074Dry-OK. Log says:
1075Server: relay.example.com
1076MAIL FROM:<from@example.com>
Joe Perches02461e02009-10-08 10:03:26 -07001077RCPT TO:<to@example.com>
1078RCPT TO:<author@example.com>
1079RCPT TO:<one@example.com>
1080RCPT TO:<two@example.com>
1081RCPT TO:<committer@example.com>
Jay Soffian3531e272009-02-14 23:32:15 -05001082From: Example <from@example.com>
1083To: to@example.com
Joe Perches02461e02009-10-08 10:03:26 -07001084Cc: A <author@example.com>,
1085 One <one@example.com>,
1086 two@example.com,
1087 C O Mitter <committer@example.com>
Jay Soffian3531e272009-02-14 23:32:15 -05001088Subject: [PATCH 1/1] Second.
1089Date: DATE-STRING
Junio C Hamanoba4324c2022-12-16 10:47:19 +09001090Message-ID: MESSAGE-ID-STRING
Jay Soffian3531e272009-02-14 23:32:15 -05001091X-Mailer: X-MAILER-STRING
brian m. carlsone67a2282018-07-08 22:17:12 +00001092MIME-Version: 1.0
1093Content-Transfer-Encoding: 8bit
Jay Soffian3531e272009-02-14 23:32:15 -05001094
1095Result: OK
1096EOF
Ævar Arnfjörð Bjarmasonf9444142010-08-13 20:40:10 +00001097"
Jay Soffian3531e272009-02-14 23:32:15 -05001098
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +00001099test_expect_success $PREREQ '--suppress-cc=bodycc' '
Jay Soffian3531e272009-02-14 23:32:15 -05001100 test_suppression bodycc
1101'
1102
Ævar Arnfjörð Bjarmasonf9444142010-08-13 20:40:10 +00001103test_expect_success $PREREQ 'setup expect' "
Jay Soffian3531e272009-02-14 23:32:15 -05001104cat >expected-suppress-cc <<\EOF
11050001-Second.patch
1106(mbox) Adding cc: A <author@example.com> from line 'From: A <author@example.com>'
1107(body) Adding cc: C O Mitter <committer@example.com> from line 'Signed-off-by: C O Mitter <committer@example.com>'
1108Dry-OK. Log says:
1109Server: relay.example.com
1110MAIL FROM:<from@example.com>
Joe Perches02461e02009-10-08 10:03:26 -07001111RCPT TO:<to@example.com>
1112RCPT TO:<author@example.com>
1113RCPT TO:<committer@example.com>
Jay Soffian3531e272009-02-14 23:32:15 -05001114From: Example <from@example.com>
1115To: to@example.com
Joe Perches02461e02009-10-08 10:03:26 -07001116Cc: A <author@example.com>,
1117 C O Mitter <committer@example.com>
Jay Soffian3531e272009-02-14 23:32:15 -05001118Subject: [PATCH 1/1] Second.
1119Date: DATE-STRING
Junio C Hamanoba4324c2022-12-16 10:47:19 +09001120Message-ID: MESSAGE-ID-STRING
Jay Soffian3531e272009-02-14 23:32:15 -05001121X-Mailer: X-MAILER-STRING
brian m. carlsone67a2282018-07-08 22:17:12 +00001122MIME-Version: 1.0
1123Content-Transfer-Encoding: 8bit
Jay Soffian3531e272009-02-14 23:32:15 -05001124
1125Result: OK
1126EOF
Ævar Arnfjörð Bjarmasonf9444142010-08-13 20:40:10 +00001127"
Jay Soffian3531e272009-02-14 23:32:15 -05001128
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +00001129test_expect_success $PREREQ '--suppress-cc=cc' '
Jay Soffian3531e272009-02-14 23:32:15 -05001130 test_suppression cc
Miklos Vajna33c592d2008-04-29 12:56:47 +02001131'
1132
Jay Soffianc1f2aa42009-03-02 23:52:18 -05001133test_confirm () {
1134 echo y | \
1135 GIT_SEND_EMAIL_NOTTY=1 \
1136 git send-email \
1137 --from="Example <nobody@example.com>" \
1138 --to=nobody@example.com \
1139 --smtp-server="$(pwd)/fake.sendmail" \
Junio C Hamanoee756a82014-11-25 14:52:42 -08001140 $@ $patches >stdout &&
Jay Soffianc18f75a2009-03-28 21:39:11 -04001141 grep "Send this email" stdout
Jay Soffianc1f2aa42009-03-02 23:52:18 -05001142}
1143
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +00001144test_expect_success $PREREQ '--confirm=always' '
Jay Soffianc1f2aa42009-03-02 23:52:18 -05001145 test_confirm --confirm=always --suppress-cc=all
1146'
1147
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +00001148test_expect_success $PREREQ '--confirm=auto' '
Jay Soffianc1f2aa42009-03-02 23:52:18 -05001149 test_confirm --confirm=auto
1150'
1151
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +00001152test_expect_success $PREREQ '--confirm=cc' '
Jay Soffianc1f2aa42009-03-02 23:52:18 -05001153 test_confirm --confirm=cc
1154'
1155
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +00001156test_expect_success $PREREQ '--confirm=compose' '
Jay Soffianc1f2aa42009-03-02 23:52:18 -05001157 test_confirm --confirm=compose --compose
1158'
1159
Jeff King545871b2015-03-20 06:13:22 -04001160test_expect_success $PREREQ 'confirm by default (due to cc)' '
Jeff Kingfc99da12015-03-25 01:32:20 -04001161 test_when_finished git config sendemail.confirm never &&
Jay Soffianc1f2aa42009-03-02 23:52:18 -05001162 git config --unset sendemail.confirm &&
Jay Soffianc18f75a2009-03-28 21:39:11 -04001163 test_confirm
Jay Soffianc1f2aa42009-03-02 23:52:18 -05001164'
1165
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +00001166test_expect_success $PREREQ 'confirm by default (due to --compose)' '
Jeff Kingfc99da12015-03-25 01:32:20 -04001167 test_when_finished git config sendemail.confirm never &&
Jay Soffianc1f2aa42009-03-02 23:52:18 -05001168 git config --unset sendemail.confirm &&
1169 test_confirm --suppress-cc=all --compose
Jay Soffianc1f2aa42009-03-02 23:52:18 -05001170'
1171
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +00001172test_expect_success $PREREQ 'confirm detects EOF (inform assumes y)' '
Jeff Kingfc99da12015-03-25 01:32:20 -04001173 test_when_finished git config sendemail.confirm never &&
Jay Soffianc18f75a2009-03-28 21:39:11 -04001174 git config --unset sendemail.confirm &&
Jay Soffiandc1460a2009-03-31 12:22:12 -04001175 rm -fr outdir &&
1176 git format-patch -2 -o outdir &&
Jay Soffianc18f75a2009-03-28 21:39:11 -04001177 GIT_SEND_EMAIL_NOTTY=1 \
1178 git send-email \
1179 --from="Example <nobody@example.com>" \
1180 --to=nobody@example.com \
1181 --smtp-server="$(pwd)/fake.sendmail" \
Junio C Hamanoee756a82014-11-25 14:52:42 -08001182 outdir/*.patch </dev/null
Jay Soffianc18f75a2009-03-28 21:39:11 -04001183'
1184
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +00001185test_expect_success $PREREQ 'confirm detects EOF (auto causes failure)' '
Jeff Kingfc99da12015-03-25 01:32:20 -04001186 test_when_finished git config sendemail.confirm never &&
Jay Soffianc18f75a2009-03-28 21:39:11 -04001187 git config sendemail.confirm auto &&
Jay Soffian3b3637c2009-03-31 12:22:13 -04001188 GIT_SEND_EMAIL_NOTTY=1 &&
1189 export GIT_SEND_EMAIL_NOTTY &&
Jay Soffianc18f75a2009-03-28 21:39:11 -04001190 test_must_fail git send-email \
1191 --from="Example <nobody@example.com>" \
1192 --to=nobody@example.com \
1193 --smtp-server="$(pwd)/fake.sendmail" \
Junio C Hamanoee756a82014-11-25 14:52:42 -08001194 $patches </dev/null
Jay Soffianc18f75a2009-03-28 21:39:11 -04001195'
1196
Stefano Lattarini41ccfdd2013-04-12 00:36:10 +02001197test_expect_success $PREREQ 'confirm does not loop forever' '
Jeff Kingfc99da12015-03-25 01:32:20 -04001198 test_when_finished git config sendemail.confirm never &&
Jay Soffianc18f75a2009-03-28 21:39:11 -04001199 git config sendemail.confirm auto &&
Jay Soffian3b3637c2009-03-31 12:22:13 -04001200 GIT_SEND_EMAIL_NOTTY=1 &&
1201 export GIT_SEND_EMAIL_NOTTY &&
1202 yes "bogus" | test_must_fail git send-email \
Jay Soffianc18f75a2009-03-28 21:39:11 -04001203 --from="Example <nobody@example.com>" \
1204 --to=nobody@example.com \
1205 --smtp-server="$(pwd)/fake.sendmail" \
1206 $patches
Jay Soffianc18f75a2009-03-28 21:39:11 -04001207'
1208
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +00001209test_expect_success $PREREQ 'utf8 Cc is rfc2047 encoded' '
Jay Soffiana61c0ff2009-03-31 12:22:14 -04001210 clean_fake_sendmail &&
1211 rm -fr outdir &&
1212 git format-patch -1 -o outdir --cc="àéìöú <utf8@example.com>" &&
1213 git send-email \
1214 --from="Example <nobody@example.com>" \
1215 --to=nobody@example.com \
1216 --smtp-server="$(pwd)/fake.sendmail" \
1217 outdir/*.patch &&
Joe Perches02461e02009-10-08 10:03:26 -07001218 grep "^ " msgtxt1 |
Brandon Caseyd1fff6f2009-06-06 20:12:31 -05001219 grep "=?UTF-8?q?=C3=A0=C3=A9=C3=AC=C3=B6=C3=BA?= <utf8@example.com>"
Jay Soffiana61c0ff2009-03-31 12:22:14 -04001220'
1221
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +00001222test_expect_success $PREREQ '--compose adds MIME for utf8 body' '
Jeff King0706bd12008-03-28 17:28:33 -04001223 clean_fake_sendmail &&
Junio C Hamanoacd72b52014-11-25 14:21:07 -08001224 write_script fake-editor-utf8 <<-\EOF &&
1225 echo "utf8 body: àéìöú" >>"$1"
1226 EOF
Junio C Hamano03335f22014-11-25 14:14:41 -08001227 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1228 git send-email \
1229 --compose --subject foo \
1230 --from="Example <nobody@example.com>" \
1231 --to=nobody@example.com \
1232 --smtp-server="$(pwd)/fake.sendmail" \
1233 $patches &&
Jeff King0706bd12008-03-28 17:28:33 -04001234 grep "^utf8 body" msgtxt1 &&
Brandon Caseyd1fff6f2009-06-06 20:12:31 -05001235 grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
Jeff King0706bd12008-03-28 17:28:33 -04001236'
1237
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +00001238test_expect_success $PREREQ '--compose respects user mime type' '
Jeff King0706bd12008-03-28 17:28:33 -04001239 clean_fake_sendmail &&
Junio C Hamanoacd72b52014-11-25 14:21:07 -08001240 write_script fake-editor-utf8-mime <<-\EOF &&
1241 cat >"$1" <<-\EOM
1242 MIME-Version: 1.0
1243 Content-Type: text/plain; charset=iso-8859-1
1244 Content-Transfer-Encoding: 8bit
1245 Subject: foo
1246
1247 utf8 body: àéìöú
1248 EOM
1249 EOF
Junio C Hamano03335f22014-11-25 14:14:41 -08001250 GIT_EDITOR="\"$(pwd)/fake-editor-utf8-mime\"" \
1251 git send-email \
1252 --compose --subject foo \
1253 --from="Example <nobody@example.com>" \
1254 --to=nobody@example.com \
1255 --smtp-server="$(pwd)/fake.sendmail" \
1256 $patches &&
Jeff King0706bd12008-03-28 17:28:33 -04001257 grep "^utf8 body" msgtxt1 &&
1258 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1 &&
Brandon Caseyd1fff6f2009-06-06 20:12:31 -05001259 ! grep "^Content-Type: text/plain; charset=UTF-8" msgtxt1
Jeff King0706bd12008-03-28 17:28:33 -04001260'
1261
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +00001262test_expect_success $PREREQ '--compose adds MIME for utf8 subject' '
Jeff Kingd54eaaa2008-03-28 17:29:01 -04001263 clean_fake_sendmail &&
Junio C Hamano03335f22014-11-25 14:14:41 -08001264 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
1265 git send-email \
1266 --compose --subject utf8-sübjëct \
1267 --from="Example <nobody@example.com>" \
1268 --to=nobody@example.com \
1269 --smtp-server="$(pwd)/fake.sendmail" \
1270 $patches &&
Jeff Kingd54eaaa2008-03-28 17:29:01 -04001271 grep "^fake edit" msgtxt1 &&
Brandon Caseyd1fff6f2009-06-06 20:12:31 -05001272 grep "^Subject: =?UTF-8?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
Jeff Kingd54eaaa2008-03-28 17:29:01 -04001273'
1274
Thomas Rastb622d4d2012-07-30 21:25:40 +02001275test_expect_success $PREREQ 'utf8 author is correctly passed on' '
1276 clean_fake_sendmail &&
1277 test_commit weird_author &&
1278 test_when_finished "git reset --hard HEAD^" &&
1279 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
1280 git format-patch --stdout -1 >funny_name.patch &&
1281 git send-email --from="Example <nobody@example.com>" \
Junio C Hamano03335f22014-11-25 14:14:41 -08001282 --to=nobody@example.com \
1283 --smtp-server="$(pwd)/fake.sendmail" \
1284 funny_name.patch &&
Thomas Rastb622d4d2012-07-30 21:25:40 +02001285 grep "^From: Füñný Nâmé <odd_?=mail@example.com>" msgtxt1
1286'
1287
Michael S. Tsirkin4cb46bd2013-06-18 15:49:26 +03001288test_expect_success $PREREQ 'utf8 sender is not duplicated' '
Michael S. Tsirkinf07075c2013-06-18 15:49:29 +03001289 clean_fake_sendmail &&
1290 test_commit weird_sender &&
1291 test_when_finished "git reset --hard HEAD^" &&
1292 git commit --amend --author "Füñný Nâmé <odd_?=mail@example.com>" &&
1293 git format-patch --stdout -1 >funny_name.patch &&
1294 git send-email --from="Füñný Nâmé <odd_?=mail@example.com>" \
Junio C Hamano03335f22014-11-25 14:14:41 -08001295 --to=nobody@example.com \
1296 --smtp-server="$(pwd)/fake.sendmail" \
1297 funny_name.patch &&
Michael S. Tsirkinf07075c2013-06-18 15:49:29 +03001298 grep "^From: " msgtxt1 >msgfrom &&
1299 test_line_count = 1 msgfrom
1300'
1301
Krzysztof Mazur62e00692012-10-10 01:02:56 +02001302test_expect_success $PREREQ 'sendemail.composeencoding works' '
1303 clean_fake_sendmail &&
1304 git config sendemail.composeencoding iso-8859-1 &&
Junio C Hamanoacd72b52014-11-25 14:21:07 -08001305 write_script fake-editor-utf8 <<-\EOF &&
1306 echo "utf8 body: àéìöú" >>"$1"
1307 EOF
Junio C Hamano03335f22014-11-25 14:14:41 -08001308 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1309 git send-email \
1310 --compose --subject foo \
1311 --from="Example <nobody@example.com>" \
1312 --to=nobody@example.com \
1313 --smtp-server="$(pwd)/fake.sendmail" \
1314 $patches &&
Krzysztof Mazur62e00692012-10-10 01:02:56 +02001315 grep "^utf8 body" msgtxt1 &&
1316 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1317'
1318
1319test_expect_success $PREREQ '--compose-encoding works' '
1320 clean_fake_sendmail &&
Junio C Hamanoacd72b52014-11-25 14:21:07 -08001321 write_script fake-editor-utf8 <<-\EOF &&
1322 echo "utf8 body: àéìöú" >>"$1"
1323 EOF
Junio C Hamano03335f22014-11-25 14:14:41 -08001324 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1325 git send-email \
1326 --compose-encoding iso-8859-1 \
1327 --compose --subject foo \
1328 --from="Example <nobody@example.com>" \
1329 --to=nobody@example.com \
1330 --smtp-server="$(pwd)/fake.sendmail" \
1331 $patches &&
Krzysztof Mazur62e00692012-10-10 01:02:56 +02001332 grep "^utf8 body" msgtxt1 &&
1333 grep "^Content-Type: text/plain; charset=iso-8859-1" msgtxt1
1334'
1335
1336test_expect_success $PREREQ '--compose-encoding overrides sendemail.composeencoding' '
1337 clean_fake_sendmail &&
1338 git config sendemail.composeencoding iso-8859-1 &&
Junio C Hamanoacd72b52014-11-25 14:21:07 -08001339 write_script fake-editor-utf8 <<-\EOF &&
1340 echo "utf8 body: àéìöú" >>"$1"
1341 EOF
Junio C Hamano03335f22014-11-25 14:14:41 -08001342 GIT_EDITOR="\"$(pwd)/fake-editor-utf8\"" \
1343 git send-email \
1344 --compose-encoding iso-8859-2 \
1345 --compose --subject foo \
1346 --from="Example <nobody@example.com>" \
1347 --to=nobody@example.com \
1348 --smtp-server="$(pwd)/fake.sendmail" \
1349 $patches &&
Krzysztof Mazur62e00692012-10-10 01:02:56 +02001350 grep "^utf8 body" msgtxt1 &&
1351 grep "^Content-Type: text/plain; charset=iso-8859-2" msgtxt1
1352'
1353
Krzysztof Mazur4a47a4d2012-10-22 14:41:48 +02001354test_expect_success $PREREQ '--compose-encoding adds correct MIME for subject' '
1355 clean_fake_sendmail &&
Junio C Hamano03335f22014-11-25 14:14:41 -08001356 GIT_EDITOR="\"$(pwd)/fake-editor\"" \
1357 git send-email \
1358 --compose-encoding iso-8859-2 \
1359 --compose --subject utf8-sübjëct \
1360 --from="Example <nobody@example.com>" \
1361 --to=nobody@example.com \
1362 --smtp-server="$(pwd)/fake.sendmail" \
1363 $patches &&
Krzysztof Mazur4a47a4d2012-10-22 14:41:48 +02001364 grep "^fake edit" msgtxt1 &&
1365 grep "^Subject: =?iso-8859-2?q?utf8-s=C3=BCbj=C3=ABct?=" msgtxt1
1366'
1367
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +00001368test_expect_success $PREREQ 'detects ambiguous reference/file conflict' '
Johannes Schindelina881baa2020-11-18 23:44:42 +00001369 echo main >main &&
1370 git add main &&
1371 git commit -m"add main" &&
1372 test_must_fail git send-email --dry-run main 2>errors &&
Pierre Habouzit5df9fcf2008-11-11 00:54:00 +01001373 grep disambiguate errors
1374'
1375
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +00001376test_expect_success $PREREQ 'feed two files' '
Junio C Hamano69f4ce52008-11-30 22:38:20 -08001377 rm -fr outdir &&
1378 git format-patch -2 -o outdir &&
Jay Soffianc1f2aa42009-03-02 23:52:18 -05001379 git send-email \
Junio C Hamano03335f22014-11-25 14:14:41 -08001380 --dry-run \
1381 --from="Example <nobody@example.com>" \
1382 --to=nobody@example.com \
1383 outdir/000?-*.patch 2>errors >out &&
Junio C Hamano69f4ce52008-11-30 22:38:20 -08001384 grep "^Subject: " out >subjects &&
1385 test "z$(sed -n -e 1p subjects)" = "zSubject: [PATCH 1/2] Second." &&
Johannes Schindelina881baa2020-11-18 23:44:42 +00001386 test "z$(sed -n -e 2p subjects)" = "zSubject: [PATCH 2/2] add main"
Junio C Hamano69f4ce52008-11-30 22:38:20 -08001387'
1388
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +00001389test_expect_success $PREREQ 'in-reply-to but no threading' '
Thomas Rastaaab4b92009-03-11 23:40:13 +01001390 git send-email \
1391 --dry-run \
1392 --from="Example <nobody@example.com>" \
1393 --to=nobody@example.com \
1394 --in-reply-to="<in-reply-id@example.com>" \
Kyle J. McKayf4714942015-01-30 18:40:17 -08001395 --no-thread \
Johannes Schindelinde26f022020-02-14 13:53:21 +00001396 $patches >out &&
1397 grep "In-Reply-To: <in-reply-id@example.com>" out
Thomas Rastaaab4b92009-03-11 23:40:13 +01001398'
1399
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +00001400test_expect_success $PREREQ 'no in-reply-to and no threading' '
Markus Heidelberg32ae8312009-06-12 12:51:37 +02001401 git send-email \
1402 --dry-run \
1403 --from="Example <nobody@example.com>" \
1404 --to=nobody@example.com \
Kyle J. McKayf4714942015-01-30 18:40:17 -08001405 --no-thread \
Ævar Arnfjörð Bjarmason2554dd12019-05-17 21:55:41 +02001406 $patches >stdout &&
Markus Heidelberg32ae8312009-06-12 12:51:37 +02001407 ! grep "In-Reply-To: " stdout
1408'
1409
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +00001410test_expect_success $PREREQ 'threading but no chain-reply-to' '
Markus Heidelbergd67114a2009-06-12 12:51:40 +02001411 git send-email \
1412 --dry-run \
1413 --from="Example <nobody@example.com>" \
1414 --to=nobody@example.com \
1415 --thread \
Kyle J. McKayf4714942015-01-30 18:40:17 -08001416 --no-chain-reply-to \
Markus Heidelbergd67114a2009-06-12 12:51:40 +02001417 $patches $patches >stdout &&
1418 grep "In-Reply-To: " stdout
1419'
1420
Rafael Aquinif9f60d72020-06-29 10:11:04 -04001421test_expect_success $PREREQ 'override in-reply-to if no threading' '
1422 git send-email \
1423 --dry-run \
1424 --from="Example <nobody@example.com>" \
1425 --to=nobody@example.com \
1426 --no-thread \
1427 --in-reply-to="override" \
1428 $threaded_patches >stdout &&
1429 grep "In-Reply-To: <override>" stdout
1430'
1431
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +00001432test_expect_success $PREREQ 'sendemail.to works' '
Stephen Boydf434c082010-03-07 14:46:48 -08001433 git config --replace-all sendemail.to "Somebody <somebody@ex.com>" &&
1434 git send-email \
1435 --dry-run \
1436 --from="Example <nobody@example.com>" \
Ævar Arnfjörð Bjarmason2554dd12019-05-17 21:55:41 +02001437 $patches >stdout &&
Stephen Boydf434c082010-03-07 14:46:48 -08001438 grep "To: Somebody <somebody@ex.com>" stdout
1439'
1440
Ævar Arnfjörð Bjarmason3ff15042019-05-17 21:55:44 +02001441test_expect_success $PREREQ 'setup sendemail.identity' '
1442 git config --replace-all sendemail.to "default@example.com" &&
1443 git config --replace-all sendemail.isp.to "isp@example.com" &&
1444 git config --replace-all sendemail.cloud.to "cloud@example.com"
1445'
1446
1447test_expect_success $PREREQ 'sendemail.identity: reads the correct identity config' '
1448 git -c sendemail.identity=cloud send-email \
1449 --dry-run \
1450 --from="nobody@example.com" \
1451 $patches >stdout &&
1452 grep "To: cloud@example.com" stdout
1453'
1454
1455test_expect_success $PREREQ 'sendemail.identity: identity overrides sendemail.identity' '
1456 git -c sendemail.identity=cloud send-email \
1457 --identity=isp \
1458 --dry-run \
1459 --from="nobody@example.com" \
1460 $patches >stdout &&
1461 grep "To: isp@example.com" stdout
1462'
1463
1464test_expect_success $PREREQ 'sendemail.identity: --no-identity clears previous identity' '
1465 git -c sendemail.identity=cloud send-email \
1466 --no-identity \
1467 --dry-run \
1468 --from="nobody@example.com" \
1469 $patches >stdout &&
1470 grep "To: default@example.com" stdout
1471'
1472
Elijah Newren4dc8b1c2019-11-05 17:07:25 +00001473test_expect_success $PREREQ 'sendemail.identity: bool identity variable existence overrides' '
Ævar Arnfjörð Bjarmason3ff15042019-05-17 21:55:44 +02001474 git -c sendemail.identity=cloud \
1475 -c sendemail.xmailer=true \
1476 -c sendemail.cloud.xmailer=false \
1477 send-email \
1478 --dry-run \
1479 --from="nobody@example.com" \
1480 $patches >stdout &&
1481 grep "To: cloud@example.com" stdout &&
1482 ! grep "X-Mailer" stdout
1483'
1484
1485test_expect_success $PREREQ 'sendemail.identity: bool variable fallback' '
1486 git -c sendemail.identity=cloud \
1487 -c sendemail.xmailer=false \
1488 send-email \
1489 --dry-run \
1490 --from="nobody@example.com" \
1491 $patches >stdout &&
1492 grep "To: cloud@example.com" stdout &&
1493 ! grep "X-Mailer" stdout
1494'
1495
Ævar Arnfjörð Bjarmason879be432021-05-28 11:23:41 +02001496test_expect_success $PREREQ 'sendemail.identity: bool variable without a value' '
1497 git -c sendemail.xmailer \
1498 send-email \
1499 --dry-run \
1500 --from="nobody@example.com" \
1501 $patches >stdout &&
1502 grep "To: default@example.com" stdout &&
1503 grep "X-Mailer" stdout
1504'
1505
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +00001506test_expect_success $PREREQ '--no-to overrides sendemail.to' '
Stephen Boydf434c082010-03-07 14:46:48 -08001507 git send-email \
1508 --dry-run \
1509 --from="Example <nobody@example.com>" \
1510 --no-to \
1511 --to=nobody@example.com \
Ævar Arnfjörð Bjarmason2554dd12019-05-17 21:55:41 +02001512 $patches >stdout &&
Stephen Boydf434c082010-03-07 14:46:48 -08001513 grep "To: nobody@example.com" stdout &&
1514 ! grep "To: Somebody <somebody@ex.com>" stdout
1515'
1516
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +00001517test_expect_success $PREREQ 'sendemail.cc works' '
Stephen Boydf434c082010-03-07 14:46:48 -08001518 git config --replace-all sendemail.cc "Somebody <somebody@ex.com>" &&
1519 git send-email \
1520 --dry-run \
1521 --from="Example <nobody@example.com>" \
1522 --to=nobody@example.com \
Ævar Arnfjörð Bjarmason2554dd12019-05-17 21:55:41 +02001523 $patches >stdout &&
Stephen Boydf434c082010-03-07 14:46:48 -08001524 grep "Cc: Somebody <somebody@ex.com>" stdout
1525'
1526
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +00001527test_expect_success $PREREQ '--no-cc overrides sendemail.cc' '
Stephen Boydf434c082010-03-07 14:46:48 -08001528 git send-email \
1529 --dry-run \
1530 --from="Example <nobody@example.com>" \
1531 --no-cc \
1532 --cc=bodies@example.com \
1533 --to=nobody@example.com \
Ævar Arnfjörð Bjarmason2554dd12019-05-17 21:55:41 +02001534 $patches >stdout &&
Stephen Boydf434c082010-03-07 14:46:48 -08001535 grep "Cc: bodies@example.com" stdout &&
1536 ! grep "Cc: Somebody <somebody@ex.com>" stdout
1537'
1538
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +00001539test_expect_success $PREREQ 'sendemail.bcc works' '
Stephen Boydf434c082010-03-07 14:46:48 -08001540 git config --replace-all sendemail.bcc "Other <other@ex.com>" &&
1541 git send-email \
1542 --dry-run \
1543 --from="Example <nobody@example.com>" \
1544 --to=nobody@example.com \
1545 --smtp-server relay.example.com \
Ævar Arnfjörð Bjarmason2554dd12019-05-17 21:55:41 +02001546 $patches >stdout &&
Stephen Boydf434c082010-03-07 14:46:48 -08001547 grep "RCPT TO:<other@ex.com>" stdout
1548'
1549
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +00001550test_expect_success $PREREQ '--no-bcc overrides sendemail.bcc' '
Stephen Boydf434c082010-03-07 14:46:48 -08001551 git send-email \
1552 --dry-run \
1553 --from="Example <nobody@example.com>" \
1554 --no-bcc \
1555 --bcc=bodies@example.com \
1556 --to=nobody@example.com \
1557 --smtp-server relay.example.com \
Ævar Arnfjörð Bjarmason2554dd12019-05-17 21:55:41 +02001558 $patches >stdout &&
Stephen Boydf434c082010-03-07 14:46:48 -08001559 grep "RCPT TO:<bodies@example.com>" stdout &&
1560 ! grep "RCPT TO:<other@ex.com>" stdout
1561'
1562
Stephen Boyd21802cd2010-09-29 00:26:44 -07001563test_expect_success $PREREQ 'patches To headers are used by default' '
Elia Pintobdf20f52016-01-11 14:34:09 +01001564 patch=$(git format-patch -1 --to="bodies@example.com") &&
Stephen Boyd21802cd2010-09-29 00:26:44 -07001565 test_when_finished "rm $patch" &&
1566 git send-email \
1567 --dry-run \
1568 --from="Example <nobody@example.com>" \
1569 --smtp-server relay.example.com \
1570 $patch >stdout &&
1571 grep "RCPT TO:<bodies@example.com>" stdout
1572'
1573
1574test_expect_success $PREREQ 'patches To headers are appended to' '
Elia Pintobdf20f52016-01-11 14:34:09 +01001575 patch=$(git format-patch -1 --to="bodies@example.com") &&
Stephen Boyd21802cd2010-09-29 00:26:44 -07001576 test_when_finished "rm $patch" &&
1577 git send-email \
1578 --dry-run \
1579 --from="Example <nobody@example.com>" \
1580 --to=nobody@example.com \
1581 --smtp-server relay.example.com \
1582 $patch >stdout &&
1583 grep "RCPT TO:<bodies@example.com>" stdout &&
1584 grep "RCPT TO:<nobody@example.com>" stdout
1585'
1586
Stephen Boyd3c3bb512010-10-04 00:05:24 -07001587test_expect_success $PREREQ 'To headers from files reset each patch' '
Elia Pintobdf20f52016-01-11 14:34:09 +01001588 patch1=$(git format-patch -1 --to="bodies@example.com") &&
1589 patch2=$(git format-patch -1 --to="other@example.com" HEAD~) &&
Stephen Boyd3c3bb512010-10-04 00:05:24 -07001590 test_when_finished "rm $patch1 && rm $patch2" &&
1591 git send-email \
1592 --dry-run \
1593 --from="Example <nobody@example.com>" \
1594 --to="nobody@example.com" \
1595 --smtp-server relay.example.com \
1596 $patch1 $patch2 >stdout &&
1597 test $(grep -c "RCPT TO:<bodies@example.com>" stdout) = 1 &&
1598 test $(grep -c "RCPT TO:<nobody@example.com>" stdout) = 2 &&
1599 test $(grep -c "RCPT TO:<other@example.com>" stdout) = 1
1600'
1601
Ævar Arnfjörð Bjarmasonf9444142010-08-13 20:40:10 +00001602test_expect_success $PREREQ 'setup expect' '
Junio C Hamano0720a512014-11-25 15:03:45 -08001603cat >email-using-8bit <<\EOF
Thomas Rast3cae7e52010-06-17 22:10:39 +02001604From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
Junio C Hamanoba4324c2022-12-16 10:47:19 +09001605Message-ID: <bogus-message-id@example.com>
Thomas Rast3cae7e52010-06-17 22:10:39 +02001606From: author@example.com
1607Date: Sat, 12 Jun 2010 15:53:58 +0200
1608Subject: subject goes here
1609
1610Dieser deutsche Text enthält einen Umlaut!
1611EOF
Ævar Arnfjörð Bjarmasonf9444142010-08-13 20:40:10 +00001612'
Thomas Rast3cae7e52010-06-17 22:10:39 +02001613
Ævar Arnfjörð Bjarmasonf9444142010-08-13 20:40:10 +00001614test_expect_success $PREREQ 'setup expect' '
Junio C Hamano0720a512014-11-25 15:03:45 -08001615 echo "Subject: subject goes here" >expected
Krzysztof Mazur5637d852012-10-24 10:03:35 +02001616'
1617
1618test_expect_success $PREREQ 'ASCII subject is not RFC2047 quoted' '
1619 clean_fake_sendmail &&
1620 echo bogus |
1621 git send-email --from=author@example.com --to=nobody@example.com \
1622 --smtp-server="$(pwd)/fake.sendmail" \
1623 --8bit-encoding=UTF-8 \
1624 email-using-8bit >stdout &&
1625 grep "Subject" msgtxt1 >actual &&
1626 test_cmp expected actual
1627'
1628
1629test_expect_success $PREREQ 'setup expect' '
Junio C Hamano0720a512014-11-25 15:03:45 -08001630 cat >content-type-decl <<-\EOF
1631 MIME-Version: 1.0
1632 Content-Type: text/plain; charset=UTF-8
1633 Content-Transfer-Encoding: 8bit
1634 EOF
Ævar Arnfjörð Bjarmasonf9444142010-08-13 20:40:10 +00001635'
Thomas Rast3cae7e52010-06-17 22:10:39 +02001636
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +00001637test_expect_success $PREREQ 'asks about and fixes 8bit encodings' '
Thomas Rast3cae7e52010-06-17 22:10:39 +02001638 clean_fake_sendmail &&
1639 echo |
1640 git send-email --from=author@example.com --to=nobody@example.com \
1641 --smtp-server="$(pwd)/fake.sendmail" \
1642 email-using-8bit >stdout &&
1643 grep "do not declare a Content-Transfer-Encoding" stdout &&
1644 grep email-using-8bit stdout &&
1645 grep "Which 8bit encoding" stdout &&
Đoàn Trần Công Danh81580fa2022-09-21 20:02:31 +07001646 grep -E "Content|MIME" msgtxt1 >actual &&
Stefan Beller9c5b2fa2017-10-06 12:00:06 -07001647 test_cmp content-type-decl actual
Thomas Rast3cae7e52010-06-17 22:10:39 +02001648'
1649
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +00001650test_expect_success $PREREQ 'sendemail.8bitEncoding works' '
Thomas Rast3cae7e52010-06-17 22:10:39 +02001651 clean_fake_sendmail &&
1652 git config sendemail.assume8bitEncoding UTF-8 &&
1653 echo bogus |
1654 git send-email --from=author@example.com --to=nobody@example.com \
1655 --smtp-server="$(pwd)/fake.sendmail" \
1656 email-using-8bit >stdout &&
Đoàn Trần Công Danh81580fa2022-09-21 20:02:31 +07001657 grep -E "Content|MIME" msgtxt1 >actual &&
Stefan Beller9c5b2fa2017-10-06 12:00:06 -07001658 test_cmp content-type-decl actual
Thomas Rast3cae7e52010-06-17 22:10:39 +02001659'
1660
Ævar Arnfjörð Bjarmasonb996f842021-09-06 09:33:29 +02001661test_expect_success $PREREQ 'sendemail.8bitEncoding in .git/config overrides --global .gitconfig' '
1662 clean_fake_sendmail &&
1663 git config sendemail.assume8bitEncoding UTF-8 &&
1664 test_when_finished "rm -rf home" &&
1665 mkdir home &&
1666 git config -f home/.gitconfig sendemail.assume8bitEncoding "bogus too" &&
1667 echo bogus |
1668 env HOME="$(pwd)/home" DEBUG=1 \
1669 git send-email --from=author@example.com --to=nobody@example.com \
1670 --smtp-server="$(pwd)/fake.sendmail" \
1671 email-using-8bit >stdout &&
Đoàn Trần Công Danh81580fa2022-09-21 20:02:31 +07001672 grep -E "Content|MIME" msgtxt1 >actual &&
Ævar Arnfjörð Bjarmasonb996f842021-09-06 09:33:29 +02001673 test_cmp content-type-decl actual
1674'
1675
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +00001676test_expect_success $PREREQ '--8bit-encoding overrides sendemail.8bitEncoding' '
Thomas Rast3cae7e52010-06-17 22:10:39 +02001677 clean_fake_sendmail &&
1678 git config sendemail.assume8bitEncoding "bogus too" &&
1679 echo bogus |
1680 git send-email --from=author@example.com --to=nobody@example.com \
1681 --smtp-server="$(pwd)/fake.sendmail" \
1682 --8bit-encoding=UTF-8 \
1683 email-using-8bit >stdout &&
Đoàn Trần Công Danh81580fa2022-09-21 20:02:31 +07001684 grep -E "Content|MIME" msgtxt1 >actual &&
Stefan Beller9c5b2fa2017-10-06 12:00:06 -07001685 test_cmp content-type-decl actual
Thomas Rast3cae7e52010-06-17 22:10:39 +02001686'
1687
Ævar Arnfjörð Bjarmasonf9444142010-08-13 20:40:10 +00001688test_expect_success $PREREQ 'setup expect' '
Junio C Hamano0720a512014-11-25 15:03:45 -08001689 cat >email-using-8bit <<-\EOF
1690 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
Junio C Hamanoba4324c2022-12-16 10:47:19 +09001691 Message-ID: <bogus-message-id@example.com>
Junio C Hamano0720a512014-11-25 15:03:45 -08001692 From: author@example.com
1693 Date: Sat, 12 Jun 2010 15:53:58 +0200
1694 Subject: Dieser Betreff enthält auch einen Umlaut!
Thomas Rast3cae7e52010-06-17 22:10:39 +02001695
Junio C Hamano0720a512014-11-25 15:03:45 -08001696 Nothing to see here.
1697 EOF
Ævar Arnfjörð Bjarmasonf9444142010-08-13 20:40:10 +00001698'
Thomas Rast3cae7e52010-06-17 22:10:39 +02001699
Ævar Arnfjörð Bjarmasonf9444142010-08-13 20:40:10 +00001700test_expect_success $PREREQ 'setup expect' '
Junio C Hamano0720a512014-11-25 15:03:45 -08001701 cat >expected <<-\EOF
1702 Subject: =?UTF-8?q?Dieser=20Betreff=20enth=C3=A4lt=20auch=20einen=20Umlaut!?=
1703 EOF
Ævar Arnfjörð Bjarmasonf9444142010-08-13 20:40:10 +00001704'
Thomas Rast3cae7e52010-06-17 22:10:39 +02001705
Ævar Arnfjörð Bjarmason57cd35e2010-08-13 20:40:09 +00001706test_expect_success $PREREQ '--8bit-encoding also treats subject' '
Thomas Rast3cae7e52010-06-17 22:10:39 +02001707 clean_fake_sendmail &&
1708 echo bogus |
1709 git send-email --from=author@example.com --to=nobody@example.com \
1710 --smtp-server="$(pwd)/fake.sendmail" \
1711 --8bit-encoding=UTF-8 \
1712 email-using-8bit >stdout &&
1713 grep "Subject" msgtxt1 >actual &&
1714 test_cmp expected actual
1715'
1716
Paolo Bonzini8d814082014-11-25 15:00:27 +01001717test_expect_success $PREREQ 'setup expect' '
Junio C Hamano0720a512014-11-25 15:03:45 -08001718 cat >email-using-8bit <<-\EOF
1719 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
Junio C Hamanoba4324c2022-12-16 10:47:19 +09001720 Message-ID: <bogus-message-id@example.com>
Junio C Hamano0720a512014-11-25 15:03:45 -08001721 From: A U Thor <author@example.com>
1722 Date: Sat, 12 Jun 2010 15:53:58 +0200
1723 Content-Type: text/plain; charset=UTF-8
1724 Subject: Nothing to see here.
Paolo Bonzini8d814082014-11-25 15:00:27 +01001725
Junio C Hamano0720a512014-11-25 15:03:45 -08001726 Dieser Betreff enthält auch einen Umlaut!
1727 EOF
Paolo Bonzini8d814082014-11-25 15:00:27 +01001728'
1729
Paolo Bonzini8d814082014-11-25 15:00:27 +01001730test_expect_success $PREREQ '--transfer-encoding overrides sendemail.transferEncoding' '
1731 clean_fake_sendmail &&
Ævar Arnfjörð Bjarmasona8aea5d2019-05-17 21:55:42 +02001732 test_must_fail git -c sendemail.transferEncoding=8bit \
1733 send-email \
Junio C Hamano03335f22014-11-25 14:14:41 -08001734 --transfer-encoding=7bit \
1735 --smtp-server="$(pwd)/fake.sendmail" \
1736 email-using-8bit \
1737 2>errors >out &&
Paolo Bonzini8d814082014-11-25 15:00:27 +01001738 grep "cannot send message as 7bit" errors &&
1739 test -z "$(ls msgtxt*)"
1740'
1741
Ævar Arnfjörð Bjarmasona8aea5d2019-05-17 21:55:42 +02001742test_expect_success $PREREQ 'sendemail.transferEncoding via config' '
Paolo Bonzini8d814082014-11-25 15:00:27 +01001743 clean_fake_sendmail &&
Ævar Arnfjörð Bjarmasona8aea5d2019-05-17 21:55:42 +02001744 test_must_fail git -c sendemail.transferEncoding=7bit \
1745 send-email \
Junio C Hamano03335f22014-11-25 14:14:41 -08001746 --smtp-server="$(pwd)/fake.sendmail" \
1747 email-using-8bit \
1748 2>errors >out &&
Ævar Arnfjörð Bjarmasona8aea5d2019-05-17 21:55:42 +02001749 grep "cannot send message as 7bit" errors &&
1750 test -z "$(ls msgtxt*)"
Ævar Arnfjörð Bjarmason3494dfd2019-05-09 13:48:30 +02001751'
1752
Ævar Arnfjörð Bjarmasona8aea5d2019-05-17 21:55:42 +02001753test_expect_success $PREREQ 'sendemail.transferEncoding via cli' '
Paolo Bonzini8d814082014-11-25 15:00:27 +01001754 clean_fake_sendmail &&
Ævar Arnfjörð Bjarmasona8aea5d2019-05-17 21:55:42 +02001755 test_must_fail git send-email \
1756 --transfer-encoding=7bit \
Paolo Bonzini8d814082014-11-25 15:00:27 +01001757 --smtp-server="$(pwd)/fake.sendmail" \
1758 email-using-8bit \
1759 2>errors >out &&
Ævar Arnfjörð Bjarmasona8aea5d2019-05-17 21:55:42 +02001760 grep "cannot send message as 7bit" errors &&
1761 test -z "$(ls msgtxt*)"
Paolo Bonzini8d814082014-11-25 15:00:27 +01001762'
1763
1764test_expect_success $PREREQ 'setup expect' '
Junio C Hamano0720a512014-11-25 15:03:45 -08001765 cat >expected <<-\EOF
1766 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1767 EOF
Paolo Bonzini8d814082014-11-25 15:00:27 +01001768'
1769
1770test_expect_success $PREREQ '8-bit and sendemail.transferencoding=quoted-printable' '
1771 clean_fake_sendmail &&
1772 git send-email \
Junio C Hamano03335f22014-11-25 14:14:41 -08001773 --transfer-encoding=quoted-printable \
1774 --smtp-server="$(pwd)/fake.sendmail" \
1775 email-using-8bit \
1776 2>errors >out &&
Martin Ågrenc76b84a2020-08-06 22:08:53 +02001777 sed "1,/^$/d" msgtxt1 >actual &&
Paolo Bonzini8d814082014-11-25 15:00:27 +01001778 test_cmp expected actual
1779'
1780
1781test_expect_success $PREREQ 'setup expect' '
Junio C Hamano0720a512014-11-25 15:03:45 -08001782 cat >expected <<-\EOF
1783 RGllc2VyIEJldHJlZmYgZW50aMOkbHQgYXVjaCBlaW5lbiBVbWxhdXQhCg==
1784 EOF
Paolo Bonzini8d814082014-11-25 15:00:27 +01001785'
1786
1787test_expect_success $PREREQ '8-bit and sendemail.transferencoding=base64' '
1788 clean_fake_sendmail &&
1789 git send-email \
Junio C Hamano03335f22014-11-25 14:14:41 -08001790 --transfer-encoding=base64 \
1791 --smtp-server="$(pwd)/fake.sendmail" \
1792 email-using-8bit \
1793 2>errors >out &&
Martin Ågrenc76b84a2020-08-06 22:08:53 +02001794 sed "1,/^$/d" msgtxt1 >actual &&
Paolo Bonzini8d814082014-11-25 15:00:27 +01001795 test_cmp expected actual
1796'
1797
1798test_expect_success $PREREQ 'setup expect' '
Junio C Hamano0720a512014-11-25 15:03:45 -08001799 cat >email-using-qp <<-\EOF
1800 From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
Junio C Hamanoba4324c2022-12-16 10:47:19 +09001801 Message-ID: <bogus-message-id@example.com>
Junio C Hamano0720a512014-11-25 15:03:45 -08001802 From: A U Thor <author@example.com>
1803 Date: Sat, 12 Jun 2010 15:53:58 +0200
1804 MIME-Version: 1.0
1805 Content-Transfer-Encoding: quoted-printable
1806 Content-Type: text/plain; charset=UTF-8
1807 Subject: Nothing to see here.
Paolo Bonzini8d814082014-11-25 15:00:27 +01001808
Junio C Hamano0720a512014-11-25 15:03:45 -08001809 Dieser Betreff enth=C3=A4lt auch einen Umlaut!
1810 EOF
Paolo Bonzini8d814082014-11-25 15:00:27 +01001811'
1812
1813test_expect_success $PREREQ 'convert from quoted-printable to base64' '
1814 clean_fake_sendmail &&
1815 git send-email \
Junio C Hamano03335f22014-11-25 14:14:41 -08001816 --transfer-encoding=base64 \
1817 --smtp-server="$(pwd)/fake.sendmail" \
1818 email-using-qp \
1819 2>errors >out &&
Martin Ågrenc76b84a2020-08-06 22:08:53 +02001820 sed "1,/^$/d" msgtxt1 >actual &&
Paolo Bonzini8d814082014-11-25 15:00:27 +01001821 test_cmp expected actual
1822'
1823
1824test_expect_success $PREREQ 'setup expect' "
Junio C Hamanoee756a82014-11-25 14:52:42 -08001825tr -d '\\015' | tr '%' '\\015' >email-using-crlf <<EOF
Paolo Bonzini8d814082014-11-25 15:00:27 +01001826From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001
Junio C Hamanoba4324c2022-12-16 10:47:19 +09001827Message-ID: <bogus-message-id@example.com>
Paolo Bonzini8d814082014-11-25 15:00:27 +01001828From: A U Thor <author@example.com>
1829Date: Sat, 12 Jun 2010 15:53:58 +0200
1830Content-Type: text/plain; charset=UTF-8
1831Subject: Nothing to see here.
1832
1833Look, I have a CRLF and an = sign!%
1834EOF
1835"
1836
1837test_expect_success $PREREQ 'setup expect' '
Junio C Hamano0720a512014-11-25 15:03:45 -08001838 cat >expected <<-\EOF
1839 Look, I have a CRLF and an =3D sign!=0D
1840 EOF
Paolo Bonzini8d814082014-11-25 15:00:27 +01001841'
1842
1843test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=quoted-printable' '
1844 clean_fake_sendmail &&
1845 git send-email \
Junio C Hamano03335f22014-11-25 14:14:41 -08001846 --transfer-encoding=quoted-printable \
1847 --smtp-server="$(pwd)/fake.sendmail" \
1848 email-using-crlf \
1849 2>errors >out &&
Martin Ågrenc76b84a2020-08-06 22:08:53 +02001850 sed "1,/^$/d" msgtxt1 >actual &&
Paolo Bonzini8d814082014-11-25 15:00:27 +01001851 test_cmp expected actual
1852'
1853
1854test_expect_success $PREREQ 'setup expect' '
Junio C Hamano0720a512014-11-25 15:03:45 -08001855 cat >expected <<-\EOF
1856 TG9vaywgSSBoYXZlIGEgQ1JMRiBhbmQgYW4gPSBzaWduIQ0K
1857 EOF
Paolo Bonzini8d814082014-11-25 15:00:27 +01001858'
1859
1860test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=base64' '
1861 clean_fake_sendmail &&
1862 git send-email \
Junio C Hamano03335f22014-11-25 14:14:41 -08001863 --transfer-encoding=base64 \
1864 --smtp-server="$(pwd)/fake.sendmail" \
1865 email-using-crlf \
1866 2>errors >out &&
Martin Ågrenc76b84a2020-08-06 22:08:53 +02001867 sed "1,/^$/d" msgtxt1 >actual &&
Paolo Bonzini8d814082014-11-25 15:00:27 +01001868 test_cmp expected actual
1869'
1870
1871
Thomas Rasta03bc5b2009-06-08 23:34:12 +02001872# Note that the patches in this test are deliberately out of order; we
1873# want to make sure it works even if the cover-letter is not in the
1874# first mail.
Robin H. Johnson57da2042010-12-29 21:02:31 +00001875test_expect_success $PREREQ 'refusing to send cover letter template' '
Thomas Rasta03bc5b2009-06-08 23:34:12 +02001876 clean_fake_sendmail &&
1877 rm -fr outdir &&
1878 git format-patch --cover-letter -2 -o outdir &&
1879 test_must_fail git send-email \
Junio C Hamano03335f22014-11-25 14:14:41 -08001880 --from="Example <nobody@example.com>" \
1881 --to=nobody@example.com \
1882 --smtp-server="$(pwd)/fake.sendmail" \
1883 outdir/0002-*.patch \
1884 outdir/0000-*.patch \
1885 outdir/0001-*.patch \
1886 2>errors >out &&
Thomas Rasta03bc5b2009-06-08 23:34:12 +02001887 grep "SUBJECT HERE" errors &&
1888 test -z "$(ls msgtxt*)"
1889'
1890
Robin H. Johnson57da2042010-12-29 21:02:31 +00001891test_expect_success $PREREQ '--force sends cover letter template anyway' '
Thomas Rasta03bc5b2009-06-08 23:34:12 +02001892 clean_fake_sendmail &&
1893 rm -fr outdir &&
1894 git format-patch --cover-letter -2 -o outdir &&
1895 git send-email \
Junio C Hamano03335f22014-11-25 14:14:41 -08001896 --force \
1897 --from="Example <nobody@example.com>" \
1898 --to=nobody@example.com \
1899 --smtp-server="$(pwd)/fake.sendmail" \
1900 outdir/0002-*.patch \
1901 outdir/0000-*.patch \
1902 outdir/0001-*.patch \
1903 2>errors >out &&
Thomas Rasta03bc5b2009-06-08 23:34:12 +02001904 ! grep "SUBJECT HERE" errors &&
1905 test -n "$(ls msgtxt*)"
1906'
1907
Michael S. Tsirkin8ccc4e42014-04-29 08:41:18 +03001908test_cover_addresses () {
1909 header="$1"
1910 shift
1911 clean_fake_sendmail &&
1912 rm -fr outdir &&
1913 git format-patch --cover-letter -2 -o outdir &&
Elia Pintobdf20f52016-01-11 14:34:09 +01001914 cover=$(echo outdir/0000-*.patch) &&
Michael S. Tsirkin8ccc4e42014-04-29 08:41:18 +03001915 mv $cover cover-to-edit.patch &&
Torsten Bögershausen35ec0022014-06-10 06:07:59 +02001916 perl -pe "s/^From:/$header: extra\@address.com\nFrom:/" cover-to-edit.patch >"$cover" &&
Michael S. Tsirkin8ccc4e42014-04-29 08:41:18 +03001917 git send-email \
Junio C Hamano03335f22014-11-25 14:14:41 -08001918 --force \
1919 --from="Example <nobody@example.com>" \
1920 --no-to --no-cc \
1921 "$@" \
1922 --smtp-server="$(pwd)/fake.sendmail" \
1923 outdir/0000-*.patch \
1924 outdir/0001-*.patch \
1925 outdir/0002-*.patch \
1926 2>errors >out &&
Michael S. Tsirkin8ccc4e42014-04-29 08:41:18 +03001927 grep "^$header: extra@address.com" msgtxt1 >to1 &&
1928 grep "^$header: extra@address.com" msgtxt2 >to2 &&
1929 grep "^$header: extra@address.com" msgtxt3 >to3 &&
1930 test_line_count = 1 to1 &&
1931 test_line_count = 1 to2 &&
1932 test_line_count = 1 to3
1933}
1934
1935test_expect_success $PREREQ 'to-cover adds To to all mail' '
1936 test_cover_addresses "To" --to-cover
1937'
1938
1939test_expect_success $PREREQ 'cc-cover adds Cc to all mail' '
1940 test_cover_addresses "Cc" --cc-cover
1941'
1942
1943test_expect_success $PREREQ 'tocover adds To to all mail' '
1944 test_config sendemail.tocover true &&
1945 test_cover_addresses "To"
1946'
1947
1948test_expect_success $PREREQ 'cccover adds Cc to all mail' '
1949 test_config sendemail.cccover true &&
1950 test_cover_addresses "Cc"
1951'
1952
Eric Wong2c510f22016-01-04 20:53:30 +00001953test_expect_success $PREREQ 'escaped quotes in sendemail.aliasfiletype=mutt' '
1954 clean_fake_sendmail &&
1955 echo "alias sbd \\\"Dot U. Sir\\\" <somebody@example.org>" >.mutt &&
1956 git config --replace-all sendemail.aliasesfile "$(pwd)/.mutt" &&
1957 git config sendemail.aliasfiletype mutt &&
1958 git send-email \
1959 --from="Example <nobody@example.com>" \
1960 --to=sbd \
1961 --smtp-server="$(pwd)/fake.sendmail" \
1962 outdir/0001-*.patch \
1963 2>errors >out &&
1964 grep "^!somebody@example\.org!$" commandline1 &&
1965 grep -F "To: \"Dot U. Sir\" <somebody@example.org>" out
1966'
1967
Cord Seele463b0ea2011-10-14 22:53:31 +02001968test_expect_success $PREREQ 'sendemail.aliasfiletype=mailrc' '
1969 clean_fake_sendmail &&
1970 echo "alias sbd somebody@example.org" >.mailrc &&
1971 git config --replace-all sendemail.aliasesfile "$(pwd)/.mailrc" &&
1972 git config sendemail.aliasfiletype mailrc &&
1973 git send-email \
Junio C Hamano03335f22014-11-25 14:14:41 -08001974 --from="Example <nobody@example.com>" \
1975 --to=sbd \
1976 --smtp-server="$(pwd)/fake.sendmail" \
1977 outdir/0001-*.patch \
1978 2>errors >out &&
Cord Seele463b0ea2011-10-14 22:53:31 +02001979 grep "^!somebody@example\.org!$" commandline1
1980'
1981
Andrei Rybak6fc53692021-06-25 21:38:50 +02001982test_expect_success $PREREQ 'sendemail.aliasesfile=~/.mailrc' '
Cord Seele463b0ea2011-10-14 22:53:31 +02001983 clean_fake_sendmail &&
Junio C Hamano587089c2015-05-23 11:07:50 -07001984 echo "alias sbd someone@example.org" >"$HOME/.mailrc" &&
Cord Seele463b0ea2011-10-14 22:53:31 +02001985 git config --replace-all sendemail.aliasesfile "~/.mailrc" &&
1986 git config sendemail.aliasfiletype mailrc &&
1987 git send-email \
Junio C Hamano03335f22014-11-25 14:14:41 -08001988 --from="Example <nobody@example.com>" \
1989 --to=sbd \
1990 --smtp-server="$(pwd)/fake.sendmail" \
1991 outdir/0001-*.patch \
1992 2>errors >out &&
Cord Seele463b0ea2011-10-14 22:53:31 +02001993 grep "^!someone@example\.org!$" commandline1
1994'
1995
Jacob Keller17b7a832015-11-19 14:52:11 -08001996test_dump_aliases () {
1997 msg="$1" && shift &&
1998 filetype="$1" && shift &&
1999 printf '%s\n' "$@" >expect &&
2000 cat >.tmp-email-aliases &&
2001
2002 test_expect_success $PREREQ "$msg" '
2003 clean_fake_sendmail && rm -fr outdir &&
2004 git config --replace-all sendemail.aliasesfile \
2005 "$(pwd)/.tmp-email-aliases" &&
2006 git config sendemail.aliasfiletype "$filetype" &&
2007 git send-email --dump-aliases 2>errors >actual &&
2008 test_cmp expect actual
2009 '
2010}
2011
2012test_dump_aliases '--dump-aliases sendmail format' \
2013 'sendmail' \
2014 'abgroup' \
2015 'alice' \
2016 'bcgrp' \
2017 'bob' \
2018 'chloe' <<-\EOF
2019 alice: Alice W Land <awol@example.com>
2020 bob: Robert Bobbyton <bob@example.com>
2021 chloe: chloe@example.com
2022 abgroup: alice, bob
2023 bcgrp: bob, chloe, Other <o@example.com>
2024 EOF
2025
2026test_dump_aliases '--dump-aliases mutt format' \
2027 'mutt' \
2028 'alice' \
2029 'bob' \
2030 'chloe' \
2031 'donald' <<-\EOF
2032 alias alice Alice W Land <awol@example.com>
2033 alias donald Donald C Carlton <donc@example.com>
2034 alias bob Robert Bobbyton <bob@example.com>
2035 alias chloe chloe@example.com
2036 EOF
2037
2038test_dump_aliases '--dump-aliases mailrc format' \
2039 'mailrc' \
2040 'alice' \
2041 'bob' \
2042 'chloe' \
2043 'eve' <<-\EOF
2044 alias alice Alice W Land <awol@example.com>
2045 alias eve Eve <eve@example.com>
2046 alias bob Robert Bobbyton <bob@example.com>
2047 alias chloe chloe@example.com
2048 EOF
2049
2050test_dump_aliases '--dump-aliases pine format' \
2051 'pine' \
2052 'alice' \
2053 'bob' \
2054 'chloe' \
2055 'eve' <<-\EOF
2056 alice Alice W Land <awol@example.com>
2057 eve Eve <eve@example.com>
2058 bob Robert Bobbyton <bob@example.com>
2059 chloe chloe@example.com
2060 EOF
2061
2062test_dump_aliases '--dump-aliases gnus format' \
2063 'gnus' \
2064 'alice' \
2065 'bob' \
2066 'chloe' \
2067 'eve' <<-\EOF
2068 (define-mail-alias "alice" "awol@example.com")
2069 (define-mail-alias "eve" "eve@example.com")
2070 (define-mail-alias "bob" "bob@example.com")
2071 (define-mail-alias "chloe" "chloe@example.com")
2072 EOF
2073
2074test_expect_success '--dump-aliases must be used alone' '
2075 test_must_fail git send-email --dump-aliases --to=janice@example.com -1 refs/heads/accounting
2076'
2077
Ævar Arnfjörð Bjarmason3ff15042019-05-17 21:55:44 +02002078test_expect_success $PREREQ 'aliases and sendemail.identity' '
2079 test_must_fail git \
2080 -c sendemail.identity=cloud \
2081 -c sendemail.aliasesfile=default-aliases \
2082 -c sendemail.cloud.aliasesfile=cloud-aliases \
2083 send-email -1 2>stderr &&
Junio C Hamano67892752023-10-31 14:23:30 +09002084 test_grep "cloud-aliases" stderr
Ævar Arnfjörð Bjarmason3ff15042019-05-17 21:55:44 +02002085'
2086
Eric Sunshine514554c2015-05-31 18:29:30 -04002087test_sendmail_aliases () {
2088 msg="$1" && shift &&
2089 expect="$@" &&
2090 cat >.tmp-email-aliases &&
2091
2092 test_expect_success $PREREQ "$msg" '
2093 clean_fake_sendmail && rm -fr outdir &&
2094 git format-patch -1 -o outdir &&
2095 git config --replace-all sendemail.aliasesfile \
2096 "$(pwd)/.tmp-email-aliases" &&
2097 git config sendemail.aliasfiletype sendmail &&
2098 git send-email \
2099 --from="Example <nobody@example.com>" \
2100 --to=alice --to=bcgrp \
2101 --smtp-server="$(pwd)/fake.sendmail" \
2102 outdir/0001-*.patch \
2103 2>errors >out &&
2104 for i in $expect
2105 do
2106 grep "^!$i!$" commandline1 || return 1
2107 done
2108 '
2109}
2110
2111test_sendmail_aliases 'sendemail.aliasfiletype=sendmail' \
2112 'awol@example\.com' \
2113 'bob@example\.com' \
2114 'chloe@example\.com' \
2115 'o@example\.com' <<-\EOF
Allen Hubbe3169e062015-05-26 17:32:03 -04002116 alice: Alice W Land <awol@example.com>
2117 bob: Robert Bobbyton <bob@example.com>
2118 # this is a comment
2119 # this is also a comment
2120 chloe: chloe@example.com
2121 abgroup: alice, bob
2122 bcgrp: bob, chloe, Other <o@example.com>
2123 EOF
Allen Hubbe3169e062015-05-26 17:32:03 -04002124
Eric Sunshine6be02642015-05-31 18:29:31 -04002125test_sendmail_aliases 'sendmail aliases line folding' \
2126 alice1 \
2127 bob1 bob2 \
2128 chuck1 chuck2 \
2129 darla1 darla2 darla3 \
2130 elton1 elton2 elton3 \
2131 fred1 fred2 \
2132 greg1 <<-\EOF
2133 alice: alice1
2134 bob: bob1,\
2135 bob2
2136 chuck: chuck1,
2137 chuck2
2138 darla: darla1,\
2139 darla2,
2140 darla3
2141 elton: elton1,
2142 elton2,\
2143 elton3
2144 fred: fred1,\
2145 fred2
2146 greg: greg1
2147 bcgrp: bob, chuck, darla, elton, fred, greg
2148 EOF
2149
2150test_sendmail_aliases 'sendmail aliases tolerate bogus line folding' \
2151 alice1 bob1 <<-\EOF
2152 alice: alice1
2153 bcgrp: bob1\
2154 EOF
2155
2156test_sendmail_aliases 'sendmail aliases empty' alice bcgrp <<-\EOF
2157 EOF
2158
Remi Lespinetf6f79e52015-06-30 14:16:43 +02002159test_expect_success $PREREQ 'alias support in To header' '
2160 clean_fake_sendmail &&
2161 echo "alias sbd someone@example.org" >.mailrc &&
2162 test_config sendemail.aliasesfile ".mailrc" &&
2163 test_config sendemail.aliasfiletype mailrc &&
2164 git format-patch --stdout -1 --to=sbd >aliased.patch &&
2165 git send-email \
2166 --from="Example <nobody@example.com>" \
2167 --smtp-server="$(pwd)/fake.sendmail" \
2168 aliased.patch \
2169 2>errors >out &&
2170 grep "^!someone@example\.org!$" commandline1
2171'
2172
2173test_expect_success $PREREQ 'alias support in Cc header' '
2174 clean_fake_sendmail &&
2175 echo "alias sbd someone@example.org" >.mailrc &&
2176 test_config sendemail.aliasesfile ".mailrc" &&
2177 test_config sendemail.aliasfiletype mailrc &&
2178 git format-patch --stdout -1 --cc=sbd >aliased.patch &&
2179 git send-email \
2180 --from="Example <nobody@example.com>" \
2181 --smtp-server="$(pwd)/fake.sendmail" \
2182 aliased.patch \
2183 2>errors >out &&
2184 grep "^!someone@example\.org!$" commandline1
2185'
2186
2187test_expect_success $PREREQ 'tocmd works with aliases' '
2188 clean_fake_sendmail &&
2189 echo "alias sbd someone@example.org" >.mailrc &&
2190 test_config sendemail.aliasesfile ".mailrc" &&
2191 test_config sendemail.aliasfiletype mailrc &&
2192 git format-patch --stdout -1 >tocmd.patch &&
2193 echo tocmd--sbd >>tocmd.patch &&
2194 git send-email \
2195 --from="Example <nobody@example.com>" \
2196 --to-cmd=./tocmd-sed \
2197 --smtp-server="$(pwd)/fake.sendmail" \
2198 tocmd.patch \
2199 2>errors >out &&
2200 grep "^!someone@example\.org!$" commandline1
2201'
2202
2203test_expect_success $PREREQ 'cccmd works with aliases' '
2204 clean_fake_sendmail &&
2205 echo "alias sbd someone@example.org" >.mailrc &&
2206 test_config sendemail.aliasesfile ".mailrc" &&
2207 test_config sendemail.aliasfiletype mailrc &&
2208 git format-patch --stdout -1 >cccmd.patch &&
2209 echo cccmd--sbd >>cccmd.patch &&
2210 git send-email \
2211 --from="Example <nobody@example.com>" \
2212 --cc-cmd=./cccmd-sed \
2213 --smtp-server="$(pwd)/fake.sendmail" \
2214 cccmd.patch \
2215 2>errors >out &&
2216 grep "^!someone@example\.org!$" commandline1
2217'
2218
Luis Henriques2cf770f2014-12-04 19:11:30 +00002219do_xmailer_test () {
2220 expected=$1 params=$2 &&
2221 git format-patch -1 &&
2222 git send-email \
2223 --from="Example <nobody@example.com>" \
2224 --to=someone@example.com \
2225 --smtp-server="$(pwd)/fake.sendmail" \
2226 $params \
2227 0001-*.patch \
2228 2>errors >out &&
2229 { grep '^X-Mailer:' out || :; } >mailer &&
2230 test_line_count = $expected mailer
2231}
2232
2233test_expect_success $PREREQ '--[no-]xmailer without any configuration' '
2234 do_xmailer_test 1 "--xmailer" &&
2235 do_xmailer_test 0 "--no-xmailer"
2236'
2237
2238test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=true' '
2239 test_config sendemail.xmailer true &&
2240 do_xmailer_test 1 "" &&
2241 do_xmailer_test 0 "--no-xmailer" &&
2242 do_xmailer_test 1 "--xmailer"
2243'
2244
Ævar Arnfjörð Bjarmason879be432021-05-28 11:23:41 +02002245test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer' '
2246 test_when_finished "test_unconfig sendemail.xmailer" &&
2247 cat >>.git/config <<-\EOF &&
2248 [sendemail]
2249 xmailer
2250 EOF
2251 test_config sendemail.xmailer true &&
2252 do_xmailer_test 1 "" &&
2253 do_xmailer_test 0 "--no-xmailer" &&
2254 do_xmailer_test 1 "--xmailer"
2255'
2256
Luis Henriques2cf770f2014-12-04 19:11:30 +00002257test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=false' '
2258 test_config sendemail.xmailer false &&
2259 do_xmailer_test 0 "" &&
2260 do_xmailer_test 0 "--no-xmailer" &&
2261 do_xmailer_test 1 "--xmailer"
2262'
2263
Ævar Arnfjörð Bjarmason879be432021-05-28 11:23:41 +02002264test_expect_success $PREREQ '--[no-]xmailer with sendemail.xmailer=' '
2265 test_config sendemail.xmailer "" &&
2266 do_xmailer_test 0 "" &&
2267 do_xmailer_test 0 "--no-xmailer" &&
2268 do_xmailer_test 1 "--xmailer"
2269'
2270
Remi Lespinetb1c8a112015-06-30 14:16:50 +02002271test_expect_success $PREREQ 'setup expected-list' '
2272 git send-email \
2273 --dry-run \
2274 --from="Example <from@example.com>" \
2275 --to="To 1 <to1@example.com>" \
2276 --to="to2@example.com" \
2277 --to="to3@example.com" \
2278 --cc="Cc 1 <cc1@example.com>" \
2279 --cc="Cc2 <cc2@example.com>" \
2280 --bcc="bcc1@example.com" \
2281 --bcc="bcc2@example.com" \
Johannes Schindelina881baa2020-11-18 23:44:42 +00002282 0001-add-main.patch | replace_variable_fields \
Remi Lespinetb1c8a112015-06-30 14:16:50 +02002283 >expected-list
2284'
2285
2286test_expect_success $PREREQ 'use email list in --cc --to and --bcc' '
2287 git send-email \
2288 --dry-run \
2289 --from="Example <from@example.com>" \
2290 --to="To 1 <to1@example.com>, to2@example.com" \
2291 --to="to3@example.com" \
2292 --cc="Cc 1 <cc1@example.com>, Cc2 <cc2@example.com>" \
2293 --bcc="bcc1@example.com, bcc2@example.com" \
Johannes Schindelina881baa2020-11-18 23:44:42 +00002294 0001-add-main.patch | replace_variable_fields \
Remi Lespinetb1c8a112015-06-30 14:16:50 +02002295 >actual-list &&
2296 test_cmp expected-list actual-list
2297'
2298
2299test_expect_success $PREREQ 'aliases work with email list' '
2300 echo "alias to2 to2@example.com" >.mutt &&
2301 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt &&
2302 test_config sendemail.aliasesfile ".mutt" &&
2303 test_config sendemail.aliasfiletype mutt &&
2304 git send-email \
2305 --dry-run \
2306 --from="Example <from@example.com>" \
2307 --to="To 1 <to1@example.com>, to2, to3@example.com" \
2308 --cc="cc1, Cc2 <cc2@example.com>" \
2309 --bcc="bcc1@example.com, bcc2@example.com" \
Johannes Schindelina881baa2020-11-18 23:44:42 +00002310 0001-add-main.patch | replace_variable_fields \
Remi Lespinetb1c8a112015-06-30 14:16:50 +02002311 >actual-list &&
2312 test_cmp expected-list actual-list
2313'
2314
Remi Lespinetfa5b1aa2015-06-30 14:16:51 +02002315test_expect_success $PREREQ 'leading and trailing whitespaces are removed' '
2316 echo "alias to2 to2@example.com" >.mutt &&
2317 echo "alias cc1 Cc 1 <cc1@example.com>" >>.mutt &&
2318 test_config sendemail.aliasesfile ".mutt" &&
2319 test_config sendemail.aliasfiletype mutt &&
2320 TO1=$(echo "QTo 1 <to1@example.com>" | q_to_tab) &&
2321 TO2=$(echo "QZto2" | qz_to_tab_space) &&
2322 CC1=$(echo "cc1" | append_cr) &&
brian m. carlsonc64368e2019-11-27 19:01:42 +00002323 BCC1=$(echo " bcc1@example.com Q" | q_to_nul) &&
Remi Lespinetfa5b1aa2015-06-30 14:16:51 +02002324 git send-email \
2325 --dry-run \
2326 --from=" Example <from@example.com>" \
2327 --to="$TO1" \
2328 --to="$TO2" \
2329 --to=" to3@example.com " \
2330 --cc="$CC1" \
2331 --cc="Cc2 <cc2@example.com>" \
2332 --bcc="$BCC1" \
2333 --bcc="bcc2@example.com" \
Johannes Schindelina881baa2020-11-18 23:44:42 +00002334 0001-add-main.patch | replace_variable_fields \
Remi Lespinetfa5b1aa2015-06-30 14:16:51 +02002335 >actual-list &&
2336 test_cmp expected-list actual-list
2337'
2338
Gregory Anderscd5b33f2021-05-14 09:15:53 -06002339test_expect_success $PREREQ 'test using command name with --sendmail-cmd' '
2340 clean_fake_sendmail &&
Johannes Sixtf6a5af02021-08-24 20:01:29 +02002341 PATH="$PWD:$PATH" \
Gregory Anderscd5b33f2021-05-14 09:15:53 -06002342 git send-email \
2343 --from="Example <nobody@example.com>" \
2344 --to=nobody@example.com \
2345 --sendmail-cmd="fake.sendmail" \
2346 HEAD^ &&
2347 test_path_is_file commandline1
2348'
2349
2350test_expect_success $PREREQ 'test using arguments with --sendmail-cmd' '
2351 clean_fake_sendmail &&
2352 git send-email \
2353 --from="Example <nobody@example.com>" \
2354 --to=nobody@example.com \
2355 --sendmail-cmd='\''"$(pwd)/fake.sendmail" -f nobody@example.com'\'' \
2356 HEAD^ &&
2357 test_path_is_file commandline1
2358'
2359
2360test_expect_success $PREREQ 'test shell expression with --sendmail-cmd' '
2361 clean_fake_sendmail &&
2362 git send-email \
2363 --from="Example <nobody@example.com>" \
2364 --to=nobody@example.com \
2365 --sendmail-cmd='\''f() { "$(pwd)/fake.sendmail" "$@"; };f'\'' \
2366 HEAD^ &&
2367 test_path_is_file commandline1
2368'
2369
Marvin Häusere0821132021-08-30 15:30:01 +00002370test_expect_success $PREREQ 'set up in-reply-to/references patches' '
2371 cat >has-reply.patch <<-\EOF &&
2372 From: A U Thor <author@example.com>
2373 Subject: patch with in-reply-to
2374 Message-ID: <patch.with.in.reply.to@example.com>
2375 In-Reply-To: <replied.to@example.com>
2376 References: <replied.to@example.com>
2377
2378 This is the body.
2379 EOF
2380 cat >no-reply.patch <<-\EOF
2381 From: A U Thor <author@example.com>
2382 Subject: patch without in-reply-to
2383 Message-ID: <patch.without.in.reply.to@example.com>
2384
2385 This is the body.
2386 EOF
2387'
2388
2389test_expect_success $PREREQ 'patch reply headers correct with --no-thread' '
2390 clean_fake_sendmail &&
2391 git send-email \
2392 --no-thread \
2393 --to=nobody@example.com \
2394 --smtp-server="$(pwd)/fake.sendmail" \
2395 has-reply.patch no-reply.patch &&
2396 grep "In-Reply-To: <replied.to@example.com>" msgtxt1 &&
2397 grep "References: <replied.to@example.com>" msgtxt1 &&
2398 ! grep replied.to@example.com msgtxt2
2399'
2400
2401test_expect_success $PREREQ 'cmdline in-reply-to used with --no-thread' '
2402 clean_fake_sendmail &&
2403 git send-email \
2404 --no-thread \
2405 --in-reply-to="<cmdline.reply@example.com>" \
2406 --to=nobody@example.com \
2407 --smtp-server="$(pwd)/fake.sendmail" \
2408 has-reply.patch no-reply.patch &&
2409 grep "In-Reply-To: <cmdline.reply@example.com>" msgtxt1 &&
2410 grep "References: <cmdline.reply@example.com>" msgtxt1 &&
2411 grep "In-Reply-To: <cmdline.reply@example.com>" msgtxt2 &&
2412 grep "References: <cmdline.reply@example.com>" msgtxt2
2413'
2414
Jonathan Tan64896602017-05-12 15:38:26 -07002415test_expect_success $PREREQ 'invoke hook' '
Ævar Arnfjörð Bjarmasonbef805b2022-03-17 11:13:14 +01002416 test_hook sendemail-validate <<-\EOF &&
Jonathan Tan64896602017-05-12 15:38:26 -07002417 # test that we have the correct environment variable, pwd, and
2418 # argument
2419 case "$GIT_DIR" in
2420 *.git)
2421 true
2422 ;;
2423 *)
2424 false
2425 ;;
2426 esac &&
Johannes Schindelina881baa2020-11-18 23:44:42 +00002427 test -f 0001-add-main.patch &&
2428 grep "add main" "$1"
Jonathan Tan64896602017-05-12 15:38:26 -07002429 EOF
2430
2431 mkdir subdir &&
2432 (
2433 # Test that it works even if we are not at the root of the
2434 # working tree
2435 cd subdir &&
2436 git send-email \
2437 --from="Example <nobody@example.com>" \
2438 --to=nobody@example.com \
2439 --smtp-server="$(pwd)/../fake.sendmail" \
Johannes Schindelina881baa2020-11-18 23:44:42 +00002440 ../0001-add-main.patch &&
Jonathan Tan64896602017-05-12 15:38:26 -07002441
2442 # Verify error message when a patch is rejected by the hook
Johannes Schindelina881baa2020-11-18 23:44:42 +00002443 sed -e "s/add main/x/" ../0001-add-main.patch >../another.patch &&
Eric Sunshinebe8c48d2018-07-01 20:23:53 -04002444 test_must_fail git send-email \
Jonathan Tan64896602017-05-12 15:38:26 -07002445 --from="Example <nobody@example.com>" \
2446 --to=nobody@example.com \
2447 --smtp-server="$(pwd)/../fake.sendmail" \
Eric Sunshinebe8c48d2018-07-01 20:23:53 -04002448 ../another.patch 2>err &&
Junio C Hamano67892752023-10-31 14:23:30 +09002449 test_grep "rejected by sendemail-validate hook" err
Jonathan Tan64896602017-05-12 15:38:26 -07002450 )
2451'
2452
Robin Jarry3c8d3ad2023-04-14 17:52:49 +02002453expected_file_counter_output () {
2454 total=$1
2455 count=0
2456 while test $count -ne $total
2457 do
2458 count=$((count + 1)) &&
2459 echo "$count/$total" || return
2460 done
2461}
2462
2463test_expect_success $PREREQ '--validate hook allows counting of messages' '
2464 test_when_finished "rm -rf my-hooks.log" &&
2465 test_config core.hooksPath "my-hooks" &&
2466 mkdir -p my-hooks &&
2467
2468 write_script my-hooks/sendemail-validate <<-\EOF &&
2469 num=$GIT_SENDEMAIL_FILE_COUNTER &&
2470 tot=$GIT_SENDEMAIL_FILE_TOTAL &&
2471 echo "$num/$tot" >>my-hooks.log || exit 1
2472 EOF
2473
2474 >my-hooks.log &&
2475 expected_file_counter_output 4 >expect &&
2476 git send-email \
2477 --from="Example <from@example.com>" \
2478 --to=nobody@example.com \
2479 --smtp-server="$(pwd)/fake.sendmail" \
2480 --validate -3 --cover-letter --force &&
2481 test_cmp expect my-hooks.log
2482'
2483
Jonathan Tan177409e2017-06-01 16:50:55 -07002484test_expect_success $PREREQ 'test that send-email works outside a repo' '
2485 nongit git send-email \
2486 --from="Example <nobody@example.com>" \
2487 --to=nobody@example.com \
2488 --smtp-server="$(pwd)/fake.sendmail" \
Johannes Schindelina881baa2020-11-18 23:44:42 +00002489 "$(pwd)/0001-add-main.patch"
Jonathan Tan177409e2017-06-01 16:50:55 -07002490'
2491
Kyle Meyer8774aa52022-11-26 15:21:23 -05002492test_expect_success $PREREQ 'send-email relays -v 3 to format-patch' '
2493 test_when_finished "rm -f out" &&
2494 git send-email --dry-run -v 3 -1 >out &&
2495 grep "PATCH v3" out
2496'
2497
Drew DeVaultdd84e522020-07-23 20:44:32 -04002498test_expect_success $PREREQ 'test that sendmail config is rejected' '
2499 test_config sendmail.program sendmail &&
2500 test_must_fail git send-email \
2501 --from="Example <nobody@example.com>" \
2502 --to=nobody@example.com \
2503 --smtp-server="$(pwd)/fake.sendmail" \
2504 HEAD^ 2>err &&
Junio C Hamano67892752023-10-31 14:23:30 +09002505 test_grep "found configuration options for '"'"sendmail"'"'" err
Drew DeVaultdd84e522020-07-23 20:44:32 -04002506'
2507
2508test_expect_success $PREREQ 'test that sendmail config rejection is specific' '
2509 test_config resendmail.program sendmail &&
2510 git send-email \
2511 --from="Example <nobody@example.com>" \
2512 --to=nobody@example.com \
2513 --smtp-server="$(pwd)/fake.sendmail" \
2514 HEAD^
2515'
2516
2517test_expect_success $PREREQ 'test forbidSendmailVariables behavior override' '
2518 test_config sendmail.program sendmail &&
2519 test_config sendemail.forbidSendmailVariables false &&
2520 git send-email \
2521 --from="Example <nobody@example.com>" \
2522 --to=nobody@example.com \
2523 --smtp-server="$(pwd)/fake.sendmail" \
2524 HEAD^
2525'
2526
Jeff King637e8942023-10-20 06:13:10 -04002527test_expect_success $PREREQ '--compose handles lowercase headers' '
2528 write_script fake-editor <<-\EOF &&
2529 sed "s/^From:.*/from: edited-from@example.com/i" "$1" >"$1.tmp" &&
2530 mv "$1.tmp" "$1"
2531 EOF
2532 clean_fake_sendmail &&
2533 git send-email \
2534 --compose \
2535 --from="Example <from@example.com>" \
2536 --to=nobody@example.com \
2537 --smtp-server="$(pwd)/fake.sendmail" \
2538 HEAD^ &&
2539 grep "From: edited-from@example.com" msgtxt1
2540'
2541
2542test_expect_success $PREREQ '--compose handles to headers' '
2543 write_script fake-editor <<-\EOF &&
Jeff King3ec61672023-10-20 06:15:24 -04002544 sed "s/^To: .*/&, edited-to@example.com/" <"$1" >"$1.tmp" &&
Jeff King637e8942023-10-20 06:13:10 -04002545 echo this is the body >>"$1.tmp" &&
2546 mv "$1.tmp" "$1"
2547 EOF
2548 clean_fake_sendmail &&
2549 GIT_SEND_EMAIL_NOTTY=1 \
2550 git send-email \
2551 --compose \
2552 --from="Example <from@example.com>" \
2553 --to=nobody@example.com \
2554 --smtp-server="$(pwd)/fake.sendmail" \
2555 HEAD^ &&
Jeff King3ec61672023-10-20 06:15:24 -04002556 # Check both that the cover letter used our modified "to" line,
2557 # but also that it was picked up for the patch.
2558 q_to_tab >expect <<-\EOF &&
2559 To: nobody@example.com,
2560 Qedited-to@example.com
2561 EOF
2562 grep -A1 "^To:" msgtxt1 >msgtxt1.to &&
2563 test_cmp expect msgtxt1.to &&
2564 grep -A1 "^To:" msgtxt2 >msgtxt2.to &&
2565 test_cmp expect msgtxt2.to
Jeff King637e8942023-10-20 06:13:10 -04002566'
2567
Ryan Andersonce903012006-05-29 12:30:15 -07002568test_done