git-p4: fix typos
[git/gitster.git] / t / t5100-mailinfo.sh
blobc8d06554541cb5d7c575b69c83bd7d3828d49924
1 #!/bin/sh
3 # Copyright (c) 2005 Junio C Hamano
6 test_description='git mailinfo and git mailsplit test'
8 . ./test-lib.sh
10 DATA="$TEST_DIRECTORY/t5100"
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'
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"
28 for mail in 00*
30 test_expect_success "mailinfo $mail" '
31 check_mailinfo "$mail" "" &&
32 if test -f "$DATA/msg$mail--scissors"
33 then
34 check_mailinfo "$mail" --scissors
35 fi &&
36 if test -f "$DATA/msg$mail--no-inbody-headers"
37 then
38 check_mailinfo "$mail" --no-inbody-headers
39 fi &&
40 if test -f "$DATA/msg$mail--message-id"
41 then
42 check_mailinfo "$mail" --message-id
45 done
48 test_expect_success 'split box with rfc2047 samples' \
49 'mkdir rfc2047 &&
50 git mailsplit -orfc2047 "$DATA/rfc2047-samples.mbox" \
51 >rfc2047/last &&
52 last=$(cat rfc2047/last) &&
53 echo total is $last &&
54 test $(cat rfc2047/last) = 11'
56 for mail in rfc2047/00*
58 test_expect_success "mailinfo $mail" '
59 git mailinfo -u "$mail-msg" "$mail-patch" <"$mail" >"$mail-info" &&
60 echo msg &&
61 test_cmp "$DATA/empty" "$mail-msg" &&
62 echo patch &&
63 test_cmp "$DATA/empty" "$mail-patch" &&
64 echo info &&
65 test_cmp "$DATA/rfc2047-info-$(basename $mail)" "$mail-info"
67 done
69 test_expect_success 'respect NULs' '
71 git mailsplit -d3 -o. "$DATA/nul-plain" &&
72 test_cmp "$DATA/nul-plain" 001 &&
73 git mailinfo msg patch <001 &&
74 test_line_count = 4 patch
78 test_expect_success 'Preserve NULs out of MIME encoded message' '
80 git mailsplit -d5 -o. "$DATA/nul-b64.in" &&
81 test_cmp "$DATA/nul-b64.in" 00001 &&
82 git mailinfo msg patch <00001 &&
83 test_cmp "$DATA/nul-b64.expect" patch
87 test_expect_success 'mailinfo on from header without name works' '
89 mkdir info-from &&
90 git mailsplit -oinfo-from "$DATA/info-from.in" &&
91 test_cmp "$DATA/info-from.in" info-from/0001 &&
92 git mailinfo info-from/msg info-from/patch \
93 <info-from/0001 >info-from/out &&
94 test_cmp "$DATA/info-from.expect" info-from/out
98 test_expect_success 'mailinfo finds headers after embedded From line' '
99 mkdir embed-from &&
100 git mailsplit -oembed-from "$DATA/embed-from.in" &&
101 test_cmp "$DATA/embed-from.in" embed-from/0001 &&
102 git mailinfo embed-from/msg embed-from/patch \
103 <embed-from/0001 >embed-from/out &&
104 test_cmp "$DATA/embed-from.expect" embed-from/out
107 test_expect_success 'mailinfo on message with quoted >From' '
108 mkdir quoted-from &&
109 git mailsplit -oquoted-from "$DATA/quoted-from.in" &&
110 test_cmp "$DATA/quoted-from.in" quoted-from/0001 &&
111 git mailinfo quoted-from/msg quoted-from/patch \
112 <quoted-from/0001 >quoted-from/out &&
113 test_cmp "$DATA/quoted-from.expect" quoted-from/msg
116 test_expect_success 'mailinfo unescapes with --mboxrd' '
117 mkdir mboxrd &&
118 git mailsplit -omboxrd --mboxrd \
119 "$DATA/sample.mboxrd" >last &&
120 test x"$(cat last)" = x2 &&
121 for i in 0001 0002
123 git mailinfo mboxrd/msg mboxrd/patch \
124 <mboxrd/$i >mboxrd/out &&
125 test_cmp "$DATA/${i}mboxrd" mboxrd/msg || return 1
126 done &&
127 sp=" " &&
128 echo "From " >expect &&
129 echo "From " >>expect &&
130 echo >> expect &&
131 cat >sp <<-INPUT_END &&
132 From mboxrd Mon Sep 17 00:00:00 2001
133 From: trailing spacer <sp@example.com>
134 Subject: [PATCH] a commit with trailing space
136 From$sp
137 >From$sp
139 INPUT_END
141 git mailsplit -f2 -omboxrd --mboxrd <sp >last &&
142 test x"$(cat last)" = x1 &&
143 git mailinfo mboxrd/msg mboxrd/patch <mboxrd/0003 &&
144 test_cmp expect mboxrd/msg
147 test_expect_success 'mailinfo handles rfc2822 quoted-string' '
148 mkdir quoted-string &&
149 git mailinfo /dev/null /dev/null <"$DATA/quoted-string.in" \
150 >quoted-string/info &&
151 test_cmp "$DATA/quoted-string.expect" quoted-string/info
154 test_expect_success 'mailinfo handles rfc2822 comment' '
155 mkdir comment &&
156 git mailinfo /dev/null /dev/null <"$DATA/comment.in" \
157 >comment/info &&
158 test_cmp "$DATA/comment.expect" comment/info
161 test_expect_success 'mailinfo with mailinfo.scissors config' '
162 test_config mailinfo.scissors true &&
164 mkdir sub &&
165 cd sub &&
166 git mailinfo ../msg0014.sc ../patch0014.sc <../0014 >../info0014.sc
167 ) &&
168 test_cmp "$DATA/msg0014--scissors" msg0014.sc &&
169 test_cmp "$DATA/patch0014--scissors" patch0014.sc &&
170 test_cmp "$DATA/info0014--scissors" info0014.sc
174 test_expect_success 'mailinfo no options' '
175 subj="$(echo "Subject: [PATCH] [other] [PATCH] message" |
176 git mailinfo /dev/null /dev/null)" &&
177 test z"$subj" = z"Subject: message"
180 test_expect_success 'mailinfo -k' '
181 subj="$(echo "Subject: [PATCH] [other] [PATCH] message" |
182 git mailinfo -k /dev/null /dev/null)" &&
183 test z"$subj" = z"Subject: [PATCH] [other] [PATCH] message"
186 test_expect_success 'mailinfo -b no [PATCH]' '
187 subj="$(echo "Subject: [other] message" |
188 git mailinfo -b /dev/null /dev/null)" &&
189 test z"$subj" = z"Subject: [other] message"
192 test_expect_success 'mailinfo -b leading [PATCH]' '
193 subj="$(echo "Subject: [PATCH] [other] message" |
194 git mailinfo -b /dev/null /dev/null)" &&
195 test z"$subj" = z"Subject: [other] message"
198 test_expect_success 'mailinfo -b double [PATCH]' '
199 subj="$(echo "Subject: [PATCH] [PATCH] message" |
200 git mailinfo -b /dev/null /dev/null)" &&
201 test z"$subj" = z"Subject: message"
204 test_expect_success 'mailinfo -b trailing [PATCH]' '
205 subj="$(echo "Subject: [other] [PATCH] message" |
206 git mailinfo -b /dev/null /dev/null)" &&
207 test z"$subj" = z"Subject: [other] message"
210 test_expect_success 'mailinfo -b separated double [PATCH]' '
211 subj="$(echo "Subject: [PATCH] [other] [PATCH] message" |
212 git mailinfo -b /dev/null /dev/null)" &&
213 test z"$subj" = z"Subject: [other] message"
216 test_expect_success 'mailinfo handles unusual header whitespace' '
217 git mailinfo /dev/null /dev/null >actual <<-\EOF &&
218 From:Real Name <user@example.com>
219 Subject: extra spaces
222 cat >expect <<-\EOF &&
223 Author: Real Name
224 Email: user@example.com
225 Subject: extra spaces
228 test_cmp expect actual
231 check_quoted_cr_mail () {
232 mail="$1" && shift &&
233 git mailinfo -u "$@" "$mail.msg" "$mail.patch" \
234 <"$mail" >"$mail.info" 2>"$mail.err" &&
235 test_cmp "$mail-expected.msg" "$mail.msg" &&
236 test_cmp "$mail-expected.patch" "$mail.patch" &&
237 test_cmp "$DATA/quoted-cr-info" "$mail.info"
240 test_expect_success 'split base64 email with quoted-cr' '
241 mkdir quoted-cr &&
242 git mailsplit -oquoted-cr "$DATA/quoted-cr.mbox" >quoted-cr/last &&
243 test $(cat quoted-cr/last) = 2
246 test_expect_success 'mailinfo warn CR in base64 encoded email' '
247 sed -e "s/%%$//" -e "s/%%/$(printf \\015)/g" "$DATA/quoted-cr-msg" \
248 >quoted-cr/0001-expected.msg &&
249 sed "s/%%/$(printf \\015)/g" "$DATA/quoted-cr-msg" \
250 >quoted-cr/0002-expected.msg &&
251 sed -e "s/%%$//" -e "s/%%/$(printf \\015)/g" "$DATA/quoted-cr-patch" \
252 >quoted-cr/0001-expected.patch &&
253 sed "s/%%/$(printf \\015)/g" "$DATA/quoted-cr-patch" \
254 >quoted-cr/0002-expected.patch &&
255 check_quoted_cr_mail quoted-cr/0001 &&
256 test_must_be_empty quoted-cr/0001.err &&
257 check_quoted_cr_mail quoted-cr/0002 &&
258 grep "quoted CRLF detected" quoted-cr/0002.err &&
259 check_quoted_cr_mail quoted-cr/0001 --quoted-cr=nowarn &&
260 test_must_be_empty quoted-cr/0001.err &&
261 check_quoted_cr_mail quoted-cr/0002 --quoted-cr=nowarn &&
262 test_must_be_empty quoted-cr/0002.err &&
263 cp quoted-cr/0001-expected.msg quoted-cr/0002-expected.msg &&
264 cp quoted-cr/0001-expected.patch quoted-cr/0002-expected.patch &&
265 check_quoted_cr_mail quoted-cr/0001 --quoted-cr=strip &&
266 test_must_be_empty quoted-cr/0001.err &&
267 check_quoted_cr_mail quoted-cr/0002 --quoted-cr=strip &&
268 test_must_be_empty quoted-cr/0002.err
271 test_expect_success 'from line with unterminated quoted string' '
272 echo "From: bob \"unterminated string smith <bob@example.com>" >in &&
273 git mailinfo /dev/null /dev/null <in >actual &&
274 cat >expect <<-\EOF &&
275 Author: bob unterminated string smith
276 Email: bob@example.com
279 test_cmp expect actual
282 test_expect_success 'from line with unterminated comment' '
283 echo "From: bob (unterminated comment smith <bob@example.com>" >in &&
284 git mailinfo /dev/null /dev/null <in >actual &&
285 cat >expect <<-\EOF &&
286 Author: bob (unterminated comment smith
287 Email: bob@example.com
290 test_cmp expect actual
293 test_done