The 20th batch
[git.git] / t / t5100-mailinfo.sh
blob065156c1f39b1493ab7b2cb6fcb94adafe19748a
1 #!/bin/sh
3 # Copyright (c) 2005 Junio C Hamano
6 test_description='git mailinfo and git mailsplit test'
8 TEST_PASSES_SANITIZE_LEAK=true
9 . ./test-lib.sh
11 DATA="$TEST_DIRECTORY/t5100"
13 test_expect_success 'split sample box' \
14 'git mailsplit -o. "$DATA/sample.mbox" >last &&
15 last=$(cat last) &&
16 echo total is $last &&
17 test $(cat last) = 18'
19 check_mailinfo () {
20 mail=$1 opt=$2
21 mo="$mail$opt"
22 git mailinfo -u $opt "msg$mo" "patch$mo" <"$mail" >"info$mo" &&
23 test_cmp "$DATA/msg$mo" "msg$mo" &&
24 test_cmp "$DATA/patch$mo" "patch$mo" &&
25 test_cmp "$DATA/info$mo" "info$mo"
29 for mail in 00*
31 test_expect_success "mailinfo $mail" '
32 check_mailinfo "$mail" "" &&
33 if test -f "$DATA/msg$mail--scissors"
34 then
35 check_mailinfo "$mail" --scissors
36 fi &&
37 if test -f "$DATA/msg$mail--no-inbody-headers"
38 then
39 check_mailinfo "$mail" --no-inbody-headers
40 fi &&
41 if test -f "$DATA/msg$mail--message-id"
42 then
43 check_mailinfo "$mail" --message-id
46 done
49 test_expect_success 'split box with rfc2047 samples' \
50 'mkdir rfc2047 &&
51 git mailsplit -orfc2047 "$DATA/rfc2047-samples.mbox" \
52 >rfc2047/last &&
53 last=$(cat rfc2047/last) &&
54 echo total is $last &&
55 test $(cat rfc2047/last) = 11'
57 for mail in rfc2047/00*
59 test_expect_success "mailinfo $mail" '
60 git mailinfo -u "$mail-msg" "$mail-patch" <"$mail" >"$mail-info" &&
61 echo msg &&
62 test_cmp "$DATA/empty" "$mail-msg" &&
63 echo patch &&
64 test_cmp "$DATA/empty" "$mail-patch" &&
65 echo info &&
66 test_cmp "$DATA/rfc2047-info-$(basename $mail)" "$mail-info"
68 done
70 test_expect_success 'respect NULs' '
72 git mailsplit -d3 -o. "$DATA/nul-plain" &&
73 test_cmp "$DATA/nul-plain" 001 &&
74 git mailinfo msg patch <001 &&
75 test_line_count = 4 patch
79 test_expect_success 'Preserve NULs out of MIME encoded message' '
81 git mailsplit -d5 -o. "$DATA/nul-b64.in" &&
82 test_cmp "$DATA/nul-b64.in" 00001 &&
83 git mailinfo msg patch <00001 &&
84 test_cmp "$DATA/nul-b64.expect" patch
88 test_expect_success 'mailinfo on from header without name works' '
90 mkdir info-from &&
91 git mailsplit -oinfo-from "$DATA/info-from.in" &&
92 test_cmp "$DATA/info-from.in" info-from/0001 &&
93 git mailinfo info-from/msg info-from/patch \
94 <info-from/0001 >info-from/out &&
95 test_cmp "$DATA/info-from.expect" info-from/out
99 test_expect_success 'mailinfo finds headers after embedded From line' '
100 mkdir embed-from &&
101 git mailsplit -oembed-from "$DATA/embed-from.in" &&
102 test_cmp "$DATA/embed-from.in" embed-from/0001 &&
103 git mailinfo embed-from/msg embed-from/patch \
104 <embed-from/0001 >embed-from/out &&
105 test_cmp "$DATA/embed-from.expect" embed-from/out
108 test_expect_success 'mailinfo on message with quoted >From' '
109 mkdir quoted-from &&
110 git mailsplit -oquoted-from "$DATA/quoted-from.in" &&
111 test_cmp "$DATA/quoted-from.in" quoted-from/0001 &&
112 git mailinfo quoted-from/msg quoted-from/patch \
113 <quoted-from/0001 >quoted-from/out &&
114 test_cmp "$DATA/quoted-from.expect" quoted-from/msg
117 test_expect_success 'mailinfo unescapes with --mboxrd' '
118 mkdir mboxrd &&
119 git mailsplit -omboxrd --mboxrd \
120 "$DATA/sample.mboxrd" >last &&
121 test x"$(cat last)" = x2 &&
122 for i in 0001 0002
124 git mailinfo mboxrd/msg mboxrd/patch \
125 <mboxrd/$i >mboxrd/out &&
126 test_cmp "$DATA/${i}mboxrd" mboxrd/msg || return 1
127 done &&
128 sp=" " &&
129 echo "From " >expect &&
130 echo "From " >>expect &&
131 echo >> expect &&
132 cat >sp <<-INPUT_END &&
133 From mboxrd Mon Sep 17 00:00:00 2001
134 From: trailing spacer <sp@example.com>
135 Subject: [PATCH] a commit with trailing space
137 From$sp
138 >From$sp
140 INPUT_END
142 git mailsplit -f2 -omboxrd --mboxrd <sp >last &&
143 test x"$(cat last)" = x1 &&
144 git mailinfo mboxrd/msg mboxrd/patch <mboxrd/0003 &&
145 test_cmp expect mboxrd/msg
148 test_expect_success 'mailinfo handles rfc2822 quoted-string' '
149 mkdir quoted-string &&
150 git mailinfo /dev/null /dev/null <"$DATA/quoted-string.in" \
151 >quoted-string/info &&
152 test_cmp "$DATA/quoted-string.expect" quoted-string/info
155 test_expect_success 'mailinfo handles rfc2822 comment' '
156 mkdir comment &&
157 git mailinfo /dev/null /dev/null <"$DATA/comment.in" \
158 >comment/info &&
159 test_cmp "$DATA/comment.expect" comment/info
162 test_expect_success 'mailinfo with mailinfo.scissors config' '
163 test_config mailinfo.scissors true &&
165 mkdir sub &&
166 cd sub &&
167 git mailinfo ../msg0014.sc ../patch0014.sc <../0014 >../info0014.sc
168 ) &&
169 test_cmp "$DATA/msg0014--scissors" msg0014.sc &&
170 test_cmp "$DATA/patch0014--scissors" patch0014.sc &&
171 test_cmp "$DATA/info0014--scissors" info0014.sc
175 test_expect_success 'mailinfo no options' '
176 subj="$(echo "Subject: [PATCH] [other] [PATCH] message" |
177 git mailinfo /dev/null /dev/null)" &&
178 test z"$subj" = z"Subject: message"
181 test_expect_success 'mailinfo -k' '
182 subj="$(echo "Subject: [PATCH] [other] [PATCH] message" |
183 git mailinfo -k /dev/null /dev/null)" &&
184 test z"$subj" = z"Subject: [PATCH] [other] [PATCH] message"
187 test_expect_success 'mailinfo -b no [PATCH]' '
188 subj="$(echo "Subject: [other] message" |
189 git mailinfo -b /dev/null /dev/null)" &&
190 test z"$subj" = z"Subject: [other] message"
193 test_expect_success 'mailinfo -b leading [PATCH]' '
194 subj="$(echo "Subject: [PATCH] [other] message" |
195 git mailinfo -b /dev/null /dev/null)" &&
196 test z"$subj" = z"Subject: [other] message"
199 test_expect_success 'mailinfo -b double [PATCH]' '
200 subj="$(echo "Subject: [PATCH] [PATCH] message" |
201 git mailinfo -b /dev/null /dev/null)" &&
202 test z"$subj" = z"Subject: message"
205 test_expect_success 'mailinfo -b trailing [PATCH]' '
206 subj="$(echo "Subject: [other] [PATCH] message" |
207 git mailinfo -b /dev/null /dev/null)" &&
208 test z"$subj" = z"Subject: [other] message"
211 test_expect_success 'mailinfo -b separated double [PATCH]' '
212 subj="$(echo "Subject: [PATCH] [other] [PATCH] message" |
213 git mailinfo -b /dev/null /dev/null)" &&
214 test z"$subj" = z"Subject: [other] message"
217 test_expect_success 'mailinfo handles unusual header whitespace' '
218 git mailinfo /dev/null /dev/null >actual <<-\EOF &&
219 From:Real Name <user@example.com>
220 Subject: extra spaces
223 cat >expect <<-\EOF &&
224 Author: Real Name
225 Email: user@example.com
226 Subject: extra spaces
229 test_cmp expect actual
232 check_quoted_cr_mail () {
233 mail="$1" && shift &&
234 git mailinfo -u "$@" "$mail.msg" "$mail.patch" \
235 <"$mail" >"$mail.info" 2>"$mail.err" &&
236 test_cmp "$mail-expected.msg" "$mail.msg" &&
237 test_cmp "$mail-expected.patch" "$mail.patch" &&
238 test_cmp "$DATA/quoted-cr-info" "$mail.info"
241 test_expect_success 'split base64 email with quoted-cr' '
242 mkdir quoted-cr &&
243 git mailsplit -oquoted-cr "$DATA/quoted-cr.mbox" >quoted-cr/last &&
244 test $(cat quoted-cr/last) = 2
247 test_expect_success 'mailinfo warn CR in base64 encoded email' '
248 sed -e "s/%%$//" -e "s/%%/$(printf \\015)/g" "$DATA/quoted-cr-msg" \
249 >quoted-cr/0001-expected.msg &&
250 sed "s/%%/$(printf \\015)/g" "$DATA/quoted-cr-msg" \
251 >quoted-cr/0002-expected.msg &&
252 sed -e "s/%%$//" -e "s/%%/$(printf \\015)/g" "$DATA/quoted-cr-patch" \
253 >quoted-cr/0001-expected.patch &&
254 sed "s/%%/$(printf \\015)/g" "$DATA/quoted-cr-patch" \
255 >quoted-cr/0002-expected.patch &&
256 check_quoted_cr_mail quoted-cr/0001 &&
257 test_must_be_empty quoted-cr/0001.err &&
258 check_quoted_cr_mail quoted-cr/0002 &&
259 grep "quoted CRLF detected" quoted-cr/0002.err &&
260 check_quoted_cr_mail quoted-cr/0001 --quoted-cr=nowarn &&
261 test_must_be_empty quoted-cr/0001.err &&
262 check_quoted_cr_mail quoted-cr/0002 --quoted-cr=nowarn &&
263 test_must_be_empty quoted-cr/0002.err &&
264 cp quoted-cr/0001-expected.msg quoted-cr/0002-expected.msg &&
265 cp quoted-cr/0001-expected.patch quoted-cr/0002-expected.patch &&
266 check_quoted_cr_mail quoted-cr/0001 --quoted-cr=strip &&
267 test_must_be_empty quoted-cr/0001.err &&
268 check_quoted_cr_mail quoted-cr/0002 --quoted-cr=strip &&
269 test_must_be_empty quoted-cr/0002.err
272 test_expect_success 'from line with unterminated quoted string' '
273 echo "From: bob \"unterminated string smith <bob@example.com>" >in &&
274 git mailinfo /dev/null /dev/null <in >actual &&
275 cat >expect <<-\EOF &&
276 Author: bob unterminated string smith
277 Email: bob@example.com
280 test_cmp expect actual
283 test_expect_success 'from line with unterminated comment' '
284 echo "From: bob (unterminated comment smith <bob@example.com>" >in &&
285 git mailinfo /dev/null /dev/null <in >actual &&
286 cat >expect <<-\EOF &&
287 Author: bob (unterminated comment smith
288 Email: bob@example.com
291 test_cmp expect actual
294 test_done