]>
diplodocus.org Git - nmh/blob - test/mhstore/test-mhstore
2 ######################################################
6 ######################################################
10 if test -z "${MH_OBJ_DIR}"; then
11 srcdir
=`dirname $0`/..
/..
12 MH_OBJ_DIR
=`cd $srcdir && pwd`; export MH_OBJ_DIR
15 .
"$MH_OBJ_DIR/test/common.sh"
19 expected
="$MH_TEST_DIR/test-mhstore$$.expected"
20 expected2
="$MH_TEST_DIR/test-mhstore$$.expected2"
21 expected_err
="$MH_TEST_DIR/test-mhmail$$.expected_err"
22 actual
="$MH_TEST_DIR/test-mhstore$$.actual"
23 actual_err
="$MH_TEST_DIR/test-mhmail$$.actual_err"
27 echo MH_TEST_DIR
=$MH_TEST_DIR
30 echo 'pwd -L='`pwd -L`
31 echo 'pwd -P='`pwd -P`
33 # check with no options and no current message
34 run_test
'mhstore' 'mhstore: no cur message'
36 # check with no options and current message
37 folder
+inbox
5 >/dev
/null
38 cat >"$expected" <<'EOF'
39 This is message number 5
41 run_test
'mhstore' 'storing message 5 as file 5.txt'
42 check
"$expected" 5.txt
'keep first'
44 # check with folder and current message
45 run_test
'mhstore +inbox' 'storing message 5 as file 5.txt'
46 check
"$expected" 5.txt
'keep first'
48 # check with specified message
49 run_test
'mhstore 5' 'storing message 5 as file 5.txt'
50 check
"$expected" 5.txt
'keep first'
53 run_test
"mhstore -file $MH_TEST_DIR/Mail/inbox/5" \
54 "storing message $MH_TEST_DIR/Mail/inbox/5 as file 5.txt"
55 check
"$expected" 5.txt
'keep first'
58 stored_contents
=`run_prog mhstore -file - < $MH_TEST_DIR/Mail/inbox/5 2>&1 | \
60 check
"$expected" "$stored_contents" 'keep first'
62 # check -outfile and -noverbose
63 run_prog mhstore
5 -noverbose -outfile "$actual" >"$actual_err" 2>&1
64 printf '' >"$expected_err"
65 check
"$expected" "$actual" 'keep first'
66 check
"$expected_err" "$actual_err"
69 printf '%s\n' 'storing message 5 to stdout' >>"$expected"
70 run_prog mhstore
5 -outfile - >"$actual" 2>&1
71 check
"$expected" "$actual"
73 # check message number greater than highest
74 run_test
'mhstore 11' "mhstore: message 11 doesn't exist"
76 # check multiple messages
77 run_test
'mhstore 4 6' 'storing message 4 as file 4.txt
78 storing message 6 as file 6.txt'
79 cat >"$expected" <<'EOF'
80 This is message number 4
82 check
"$expected" 4.txt
83 cat >"$expected" <<'EOF'
84 This is message number 6
86 check
"$expected" 6.txt
88 # Write message with a text/plain subpart.
90 cat >"$msgfile" <<'EOF'
91 To: recipient@example.com
92 From: sender@example.com
95 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
98 Content-Type: multipart/related;
99 type="multipart/alternative";
100 boundary="subpart__1.1"
103 Content-Type: text/plain; charset="iso-8859-1"
104 Content-Disposition: attachment; filename="test1.txt"
106 This is the first text/plain part, in a subpart.
110 ------- =_aaaaaaaaaa0
111 Content-Type: text/plain; charset="iso-8859-1"
112 Content-Disposition: attachment; filename="test2.txt"
113 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
114 Content-Transfer-Encoding: quoted-printable
116 This is the second text/plain part.
118 ------- =_aaaaaaaaaa0
119 Content-Type: text/plain; charset="iso-8859-1"
120 Content-Disposition: attachment; filename="test3.txt"
122 This is the third text/plain part.
124 ------- =_aaaaaaaaaa0
125 Content-Type: text/plain; charset="iso-8859-1"; name="test4.txt"
126 Content-Disposition: attachment; filename="test4.txt"
127 Content-MD5: cMI1lB/LZ4jgVl3EbhdyWA==
128 Content-Transfer-Encoding: base64
130 VGhpcyBpcyB0aGUgZm91cnRoIHRleHQvcGxhaW4gcGFydC4NClRoaXMgdGVzdCBoYXMgbXVsdGlw
133 ------- =_aaaaaaaaaa0--
137 cat >"$expected" <<'EOF'
138 This is the third text/plain part.
140 run_test
'mhstore last -part 3' 'storing message 11 part 3 as file 11.3.txt'
141 check
"$expected" 11.3.txt
143 # check -part of a subpart
144 cat >"$expected" <<'EOF'
145 This is the first text/plain part, in a subpart.
147 run_test
'mhstore last -part 1.1' \
148 'storing message 11 part 1.1 as file 11.1.1.txt'
149 check
"$expected" 11.1.1.txt
'keep first'
152 run_test
'mhstore last -type text/plain' \
153 'storing message 11 part 1.1 as file 11.1.1.txt
154 storing message 11 part 2 as file 11.2.txt
155 storing message 11 part 3 as file 11.3.txt
156 storing message 11 part 4 as file 11.4.txt'
157 check
"$expected" 11.1.1.txt
158 cat >"$expected" <<'EOF'
159 This is the second text/plain part.
161 check
"$expected" 11.2.txt
162 cat >"$expected" <<'EOF'
163 This is the third text/plain part.
165 check
"$expected" 11.3.txt
166 cat >"$expected" <<'EOF'
167 This is the fourth text/plain part.
168 This test has multiple lines.
170 check
"$expected" 11.4.txt
173 cat >"$expected" <<'EOF'
174 This is the fourth text/plain part.
175 This test has multiple lines.
177 run_test
'mhstore last -part 4 -auto' \
178 'storing message 11 part 4 as file test4.txt'
179 check
"$expected" test4.txt
'keep first'
181 # check -noauto, the default
182 run_test
'mhstore last -part 4 -auto -noauto' \
183 'storing message 11 part 4 as file 11.4.txt'
184 check
"$expected" 11.4.txt
'keep first'
186 # check -verbose, the default
187 run_test
'mhstore last -part 4 -noverbose -verbose' \
188 'storing message 11 part 4 as file 11.4.txt'
189 check
"$expected" 11.4.txt
'keep first'
192 run_test
'mhstore last -part 4 -noverbose' ''
193 check
"$expected" 11.4.txt
195 # check that -auto obeys Content-Disposition header
196 cat >"$expected" <<'EOF'
197 This is the first text/plain part, in a subpart.
199 run_test
'mhstore last -part 1.1 -auto' \
200 'storing message 11 part 1.1 as file test1.txt'
201 check
"$expected" test1.txt
204 cat >"$expected" <<'EOF'
205 This is the second text/plain part.
207 run_test
'mhstore last -part 2 -check' \
208 'storing message 11 part 2 as file 11.2.txt'
209 check
"$expected" 11.2.txt
'keep first'
211 # check with -check on base64 encoded part
212 cat >"$expected2" <<'EOF'
213 This is the fourth text/plain part.
214 This test has multiple lines.
216 run_test
'mhstore last -part 4 -check' \
217 'storing message 11 part 4 as file 11.4.txt'
218 check
"$expected2" 11.4.txt
220 # check -check with bad MD5 checksum
221 sed 's/\(Content-MD5: \)kq+Hnc/\1BADBAD/' "$msgfile" >"$MH_TEST_DIR/$$.tmp"
222 mv -f "$MH_TEST_DIR/$$.tmp" "$msgfile"
223 run_test
'mhstore last -part 2 -check' \
224 'storing message 11 part 2 as file 11.2.txt
225 mhstore: content integrity suspect (digest mismatch) -- continuing
226 (content text/plain in message 11, part 2)'
227 check
"$expected" 11.2.txt
'keep first'
229 # check -nocheck, the default
230 run_test
'mhstore last -part 2 -check -nocheck' \
231 'storing message 11 part 2 as file 11.2.txt'
232 check
"$expected" 11.2.txt
'keep first'
234 # check -outfile - with -file
235 run_prog mhstore
-noverbose -file `mhpath 11` -part 2 -outfile - >"$actual" 2>&1
236 check
"$expected" "$actual"
238 # check reassembly of message/partial messages (RFC 1521, 7.3.2)
240 cat >"$msgfile" <<'EOF'
241 To: recipient@example.com
242 From: sender@example.com
245 Content-Type: message/partial; id="test-mhstore message/partial test"; number=1
247 Content-Type: text/plain; charset="iso-8859-1"
249 This is part one of three.
253 cat >"$msgfile" <<'EOF'
254 To: recipient@example.com
255 From: sender@example.com
258 Content-Type: message/partial; id="test-mhstore message/partial test"; number=2
260 This is part two of three.
264 cat >"$msgfile" <<'EOF'
265 To: recipient@example.com
266 From: sender@example.com
269 Content-Type: message/partial; id="test-mhstore message/partial test"; number=3;
272 This is part three of three.
275 run_test
'mhstore last:3' \
276 'reassembling partials 12,13,14 to folder inbox as message 15'
278 cat >"$expected" <<'EOF'
279 This is part one of three.
280 This is part two of three.
281 This is part three of three.
283 run_test
'mhstore last' 'storing message 15 as file 15.txt'
284 check
"$expected" 15.txt
286 # cd into Mail directory because it gets cleaned up by the exit trap.
289 # check -clobber always
290 folder
+inbox
7 >/dev
/null
292 cat >"$expected" <<'EOF'
293 This is message number 7
295 run_test
'mhstore' 'storing message 7 as file 7.txt'
296 check
"$expected" 7.txt
'keep first'
297 run_test
'mhstore -clobber ask -clobber always' \
298 'storing message 7 as file 7.txt'
299 check
"$expected" 7.txt
'keep first'
301 # check -clobber auto
303 run_test
'mhstore -clobber auto' 'storing message 7 as file 7-1.txt'
304 check
"$expected" 7-1.txt
'keep first'
306 run_test
'mhstore -clobber auto' 'storing message 7 as file 7-2.txt'
307 check
"$expected" 7-2.txt
'keep first'
309 # check -clobber suffix
310 run_test
'mhstore -clobber suffix' 'storing message 7 as file 7.txt.1'
311 check
"$expected" 7.txt
.1 'keep first'
313 run_test
'mhstore -clobber suffix' 'storing message 7 as file 7.txt.2'
314 check
"$expected" 7.txt
.2 'keep first'
316 # Don't check -clobber ask because it requires connection to a
317 # terminal, and this test won't always be run with one.
319 # check -clobber never. Its exit status is the number of files not overwritten.
320 run_test
'mhstore -clobber never' \
321 "mhstore: will not overwrite $MH_TEST_DIR/Mail/7.txt with -clobber never"
323 mhstore
-clobber never
>/dev
/null
2>&1
329 # check with relative nmh-storage profile component
330 storagedir
=storagedir
331 dir
="$MH_TEST_DIR/Mail/inbox/$storagedir"
333 printf '%s\n' "nmh-storage: $storagedir" >>"$MH"
334 cat >"$expected" <<'EOF'
335 This is the fourth text/plain part.
336 This test has multiple lines.
338 run_test
'mhstore 11 -part 4' \
339 "storing message 11 part 4 as file $storagedir/11.4.txt"
340 check
"$expected" "$dir/11.4.txt" 'keep first'
342 # check with relative nmh-storage profile component and -auto
343 run_test
'mhstore 11 -part 4 -auto' \
344 "storing message 11 part 4 as file $storagedir/test4.txt"
345 check
"$expected" "$dir/test4.txt" 'keep first'
347 # check with absolute nmh-storage profile component
348 absstoragedir
="$MH_TEST_DIR/$storagedir"
349 mkdir "$absstoragedir"
350 sed "s%\(nmh-storage: \)storagedir%\1$absstoragedir%" "$MH" >"$MH.new"
351 mv -f "$MH.new" "$MH"
352 run_test
'mhstore 11 -part 4' \
353 "storing message 11 part 4 as file $storagedir/11.4.txt"
354 check
"$expected" "$absstoragedir/11.4.txt" 'keep first'
356 # check with absolute nmh-storage profile component and -auto
357 run_test
'mhstore 11 -part 4 -auto' \
358 "storing message 11 part 4 as file $storagedir/test4.txt"
359 check
"$expected" "$absstoragedir/test4.txt"
360 rmdir "$absstoragedir"