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