3 # Copyright (c) 2005 Junio C Hamano
6 test_description
='git mailinfo and git mailsplit test'
8 TEST_PASSES_SANITIZE_LEAK
=true
11 DATA
="$TEST_DIRECTORY/t5100"
13 test_expect_success
'split sample box' \
14 'git mailsplit -o. "$DATA/sample.mbox" >last &&
16 echo total is $last &&
17 test $(cat last) = 18'
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"
36 test_expect_success
$prereq "mailinfo $mail" '
37 check_mailinfo "$mail" "" &&
38 if test -f "$DATA/msg$mail--scissors"
40 check_mailinfo "$mail" --scissors
42 if test -f "$DATA/msg$mail--no-inbody-headers"
44 check_mailinfo "$mail" --no-inbody-headers
46 if test -f "$DATA/msg$mail--message-id"
48 check_mailinfo "$mail" --message-id
54 test_expect_success
'split box with rfc2047 samples' \
56 git mailsplit -orfc2047 "$DATA/rfc2047-samples.mbox" \
58 last=$(cat rfc2047/last) &&
59 echo total is $last &&
60 test $(cat rfc2047/last) = 11'
62 for mail in rfc2047
/00*
69 test_expect_success
$prereq "mailinfo $mail" '
70 git mailinfo -u "$mail-msg" "$mail-patch" <"$mail" >"$mail-info" &&
72 test_cmp "$DATA/empty" "$mail-msg" &&
74 test_cmp "$DATA/empty" "$mail-patch" &&
76 test_cmp "$DATA/rfc2047-info-$(basename $mail)" "$mail-info"
80 test_expect_success
'respect NULs' '
82 git mailsplit -d3 -o. "$DATA/nul-plain" &&
83 test_cmp "$DATA/nul-plain" 001 &&
84 git mailinfo msg patch <001 &&
85 test_line_count = 4 patch
89 test_expect_success
'Preserve NULs out of MIME encoded message' '
91 git mailsplit -d5 -o. "$DATA/nul-b64.in" &&
92 test_cmp "$DATA/nul-b64.in" 00001 &&
93 git mailinfo msg patch <00001 &&
94 test_cmp "$DATA/nul-b64.expect" patch
98 test_expect_success
'mailinfo on from header without name works' '
101 git mailsplit -oinfo-from "$DATA/info-from.in" &&
102 test_cmp "$DATA/info-from.in" info-from/0001 &&
103 git mailinfo info-from/msg info-from/patch \
104 <info-from/0001 >info-from/out &&
105 test_cmp "$DATA/info-from.expect" info-from/out
109 test_expect_success
'mailinfo finds headers after embedded From line' '
111 git mailsplit -oembed-from "$DATA/embed-from.in" &&
112 test_cmp "$DATA/embed-from.in" embed-from/0001 &&
113 git mailinfo embed-from/msg embed-from/patch \
114 <embed-from/0001 >embed-from/out &&
115 test_cmp "$DATA/embed-from.expect" embed-from/out
118 test_expect_success
'mailinfo on message with quoted >From' '
120 git mailsplit -oquoted-from "$DATA/quoted-from.in" &&
121 test_cmp "$DATA/quoted-from.in" quoted-from/0001 &&
122 git mailinfo quoted-from/msg quoted-from/patch \
123 <quoted-from/0001 >quoted-from/out &&
124 test_cmp "$DATA/quoted-from.expect" quoted-from/msg
127 test_expect_success
'mailinfo unescapes with --mboxrd' '
129 git mailsplit -omboxrd --mboxrd \
130 "$DATA/sample.mboxrd" >last &&
131 test x"$(cat last)" = x2 &&
134 git mailinfo mboxrd/msg mboxrd/patch \
135 <mboxrd/$i >mboxrd/out &&
136 test_cmp "$DATA/${i}mboxrd" mboxrd/msg || return 1
139 echo "From " >expect &&
140 echo "From " >>expect &&
142 cat >sp <<-INPUT_END &&
143 From mboxrd Mon Sep 17 00:00:00 2001
144 From: trailing spacer <sp@example.com>
145 Subject: [PATCH] a commit with trailing space
152 git mailsplit -f2 -omboxrd --mboxrd <sp >last &&
153 test x"$(cat last)" = x1 &&
154 git mailinfo mboxrd/msg mboxrd/patch <mboxrd/0003 &&
155 test_cmp expect mboxrd/msg
158 test_expect_success
'mailinfo handles rfc2822 quoted-string' '
159 mkdir quoted-string &&
160 git mailinfo /dev/null /dev/null <"$DATA/quoted-string.in" \
161 >quoted-string/info &&
162 test_cmp "$DATA/quoted-string.expect" quoted-string/info
165 test_expect_success
'mailinfo handles rfc2822 comment' '
167 git mailinfo /dev/null /dev/null <"$DATA/comment.in" \
169 test_cmp "$DATA/comment.expect" comment/info
172 test_expect_success
'mailinfo with mailinfo.scissors config' '
173 test_config mailinfo.scissors true &&
177 git mailinfo ../msg0014.sc ../patch0014.sc <../0014 >../info0014.sc
179 test_cmp "$DATA/msg0014--scissors" msg0014.sc &&
180 test_cmp "$DATA/patch0014--scissors" patch0014.sc &&
181 test_cmp "$DATA/info0014--scissors" info0014.sc
185 test_expect_success
'mailinfo no options' '
186 subj="$(echo "Subject: [PATCH] [other] [PATCH] message" |
187 git mailinfo /dev/null /dev/null)" &&
188 test z"$subj" = z"Subject: message"
191 test_expect_success
'mailinfo -k' '
192 subj="$(echo "Subject: [PATCH] [other] [PATCH] message" |
193 git mailinfo -k /dev/null /dev/null)" &&
194 test z"$subj" = z"Subject: [PATCH] [other] [PATCH] message"
197 test_expect_success
'mailinfo -b no [PATCH]' '
198 subj="$(echo "Subject: [other] message" |
199 git mailinfo -b /dev/null /dev/null)" &&
200 test z"$subj" = z"Subject: [other] message"
203 test_expect_success
'mailinfo -b leading [PATCH]' '
204 subj="$(echo "Subject: [PATCH] [other] message" |
205 git mailinfo -b /dev/null /dev/null)" &&
206 test z"$subj" = z"Subject: [other] message"
209 test_expect_success
'mailinfo -b double [PATCH]' '
210 subj="$(echo "Subject: [PATCH] [PATCH] message" |
211 git mailinfo -b /dev/null /dev/null)" &&
212 test z"$subj" = z"Subject: message"
215 test_expect_success
'mailinfo -b trailing [PATCH]' '
216 subj="$(echo "Subject: [other] [PATCH] message" |
217 git mailinfo -b /dev/null /dev/null)" &&
218 test z"$subj" = z"Subject: [other] message"
221 test_expect_success
'mailinfo -b separated double [PATCH]' '
222 subj="$(echo "Subject: [PATCH] [other] [PATCH] message" |
223 git mailinfo -b /dev/null /dev/null)" &&
224 test z"$subj" = z"Subject: [other] message"
227 test_expect_success
'mailinfo handles unusual header whitespace' '
228 git mailinfo /dev/null /dev/null >actual <<-\EOF &&
229 From:Real Name <user@example.com>
230 Subject: extra spaces
233 cat >expect <<-\EOF &&
235 Email: user@example.com
236 Subject: extra spaces
239 test_cmp expect actual
242 check_quoted_cr_mail
() {
243 mail="$1" && shift &&
244 git mailinfo
-u "$@" "$mail.msg" "$mail.patch" \
245 <"$mail" >"$mail.info" 2>"$mail.err" &&
246 test_cmp
"$mail-expected.msg" "$mail.msg" &&
247 test_cmp
"$mail-expected.patch" "$mail.patch" &&
248 test_cmp
"$DATA/quoted-cr-info" "$mail.info"
251 test_expect_success
'split base64 email with quoted-cr' '
253 git mailsplit -oquoted-cr "$DATA/quoted-cr.mbox" >quoted-cr/last &&
254 test $(cat quoted-cr/last) = 2
257 test_expect_success
'mailinfo warn CR in base64 encoded email' '
258 sed -e "s/%%$//" -e "s/%%/$(printf \\015)/g" "$DATA/quoted-cr-msg" \
259 >quoted-cr/0001-expected.msg &&
260 sed "s/%%/$(printf \\015)/g" "$DATA/quoted-cr-msg" \
261 >quoted-cr/0002-expected.msg &&
262 sed -e "s/%%$//" -e "s/%%/$(printf \\015)/g" "$DATA/quoted-cr-patch" \
263 >quoted-cr/0001-expected.patch &&
264 sed "s/%%/$(printf \\015)/g" "$DATA/quoted-cr-patch" \
265 >quoted-cr/0002-expected.patch &&
266 check_quoted_cr_mail quoted-cr/0001 &&
267 test_must_be_empty quoted-cr/0001.err &&
268 check_quoted_cr_mail quoted-cr/0002 &&
269 grep "quoted CRLF detected" quoted-cr/0002.err &&
270 check_quoted_cr_mail quoted-cr/0001 --quoted-cr=nowarn &&
271 test_must_be_empty quoted-cr/0001.err &&
272 check_quoted_cr_mail quoted-cr/0002 --quoted-cr=nowarn &&
273 test_must_be_empty quoted-cr/0002.err &&
274 cp quoted-cr/0001-expected.msg quoted-cr/0002-expected.msg &&
275 cp quoted-cr/0001-expected.patch quoted-cr/0002-expected.patch &&
276 check_quoted_cr_mail quoted-cr/0001 --quoted-cr=strip &&
277 test_must_be_empty quoted-cr/0001.err &&
278 check_quoted_cr_mail quoted-cr/0002 --quoted-cr=strip &&
279 test_must_be_empty quoted-cr/0002.err
282 test_expect_success
'from line with unterminated quoted string' '
283 echo "From: bob \"unterminated string smith <bob@example.com>" >in &&
284 git mailinfo /dev/null /dev/null <in >actual &&
285 cat >expect <<-\EOF &&
286 Author: bob unterminated string smith
287 Email: bob@example.com
290 test_cmp expect actual
293 test_expect_success
'from line with unterminated comment' '
294 echo "From: bob (unterminated comment smith <bob@example.com>" >in &&
295 git mailinfo /dev/null /dev/null <in >actual &&
296 cat >expect <<-\EOF &&
297 Author: bob (unterminated comment smith
298 Email: bob@example.com
301 test_cmp expect actual