]>
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 check_exit
'-eq 1' mhstore
-
21 expected
="$MH_TEST_DIR/test-mhstore$$.expected"
22 expected2
="$MH_TEST_DIR/test-mhstore$$.expected2"
23 expected_err
="$MH_TEST_DIR/test-mhmail$$.expected_err"
24 actual
="$MH_TEST_DIR/test-mhstore$$.actual"
25 actual_err
="$MH_TEST_DIR/test-mhmail$$.actual_err"
29 # check with no options and no current message
30 start_test
'with no options and no current message'
31 run_test
'mhstore' 'mhstore: no cur message'
33 # check with no options and current message
34 start_test
'with no options and current message'
35 folder
+inbox
5 >/dev
/null
36 cat >"$expected" <<'EOF'
37 This is message number 5
39 run_test
'mhstore' 'storing message 5 as file 5.txt'
40 check
"$expected" 5.txt
'keep first'
42 # check with folder and current message
43 start_test
'with folder and current message'
44 run_test
'mhstore +inbox' 'storing message 5 as file 5.txt'
45 check
"$expected" 5.txt
'keep first'
47 # check with specified message
48 start_test
'with specified message'
49 run_test
'mhstore 5' 'storing message 5 as file 5.txt'
50 check
"$expected" 5.txt
'keep first'
54 run_test
"mhstore -file $MH_TEST_DIR/Mail/inbox/5" \
55 "storing message $MH_TEST_DIR/Mail/inbox/5 as file 5.txt"
56 check
"$expected" 5.txt
'keep first'
60 stored_contents
=`run_prog mhstore -file - < $MH_TEST_DIR/Mail/inbox/5 2>&1 | \
62 check
"$expected" "$stored_contents" 'keep first'
64 # check -outfile and -noverbose
65 start_test
'-outfile and -noverbose'
66 run_prog mhstore
5 -noverbose -outfile "$actual" >"$actual_err" 2>&1
67 printf '' >"$expected_err"
68 check
"$expected" "$actual" 'keep first'
69 check
"$expected_err" "$actual_err"
72 start_test
'-outfile -'
73 printf '%s\n' 'storing message 5 to stdout' >>"$expected"
74 run_prog mhstore
5 -outfile - >"$actual" 2>&1
75 check
"$expected" "$actual"
77 # check message number greater than highest
78 start_test
'message number greater than highest'
79 run_test
'mhstore 11' "mhstore: message 11 doesn't exist"
81 # check multiple messages
82 start_test
'multiple messages'
83 run_test
'mhstore 4 6' 'storing message 4 as file 4.txt
84 storing message 6 as file 6.txt'
85 cat >"$expected" <<'EOF'
86 This is message number 4
88 check
"$expected" 4.txt
89 cat >"$expected" <<'EOF'
90 This is message number 6
92 check
"$expected" 6.txt
94 # Write message with a text/plain subpart.
96 cat >"$msgfile" <<'EOF'
97 To: recipient@example.com
98 From: sender@example.com
101 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
103 ------- =_aaaaaaaaaa0
104 Content-Type: multipart/related;
105 type="multipart/alternative";
106 boundary="subpart__1.1"
109 Content-Type: text/plain; charset="iso-8859-1"
110 Content-Disposition: attachment; filename="test1.txt"
112 This is the first text/plain part, in a subpart.
116 ------- =_aaaaaaaaaa0
117 Content-Type: text/plain; charset="iso-8859-1"
118 Content-Disposition: attachment; filename="test2.txt"
119 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
120 Content-Transfer-Encoding: quoted-printable
122 This is the second text/plain part.
124 ------- =_aaaaaaaaaa0
125 Content-Type: text/plain; charset="iso-8859-1"
126 Content-Disposition: attachment; filename="test3.txt"
128 This is the third text/plain part.
130 ------- =_aaaaaaaaaa0
131 Content-Type: text/plain; charset="iso-8859-1"; name="test4.txt"
132 Content-Disposition: attachment; filename="test4.txt"
133 Content-MD5: cMI1lB/LZ4jgVl3EbhdyWA==
134 Content-Transfer-Encoding: base64
136 VGhpcyBpcyB0aGUgZm91cnRoIHRleHQvcGxhaW4gcGFydC4NClRoaXMgdGVzdCBoYXMgbXVsdGlw
139 ------- =_aaaaaaaaaa0--
144 cat >"$expected" <<'EOF'
145 This is the third text/plain part.
147 run_test
'mhstore last -part 3' 'storing message 11 part 3 as file 11.3.txt'
148 check
"$expected" 11.3.txt
150 # check -part of a subpart
151 start_test
'-part of a subpart'
152 cat >"$expected" <<'EOF'
153 This is the first text/plain part, in a subpart.
155 run_test
'mhstore last -part 1.1' \
156 'storing message 11 part 1.1 as file 11.1.1.txt'
157 check
"$expected" 11.1.1.txt
'keep first'
161 run_test
'mhstore last -type text/plain' \
162 'storing message 11 part 1.1 as file 11.1.1.txt
163 storing message 11 part 2 as file 11.2.txt
164 storing message 11 part 3 as file 11.3.txt
165 storing message 11 part 4 as file 11.4.txt'
166 check
"$expected" 11.1.1.txt
167 cat >"$expected" <<'EOF'
168 This is the second text/plain part.
170 check
"$expected" 11.2.txt
171 cat >"$expected" <<'EOF'
172 This is the third text/plain part.
174 check
"$expected" 11.3.txt
175 cat >"$expected" <<'EOF'
176 This is the fourth text/plain part.
177 This test has multiple lines.
179 check
"$expected" 11.4.txt
183 cat >"$expected" <<'EOF'
184 This is the fourth text/plain part.
185 This test has multiple lines.
187 run_test
'mhstore last -part 4 -auto' \
188 'storing message 11 part 4 as file test4.txt'
189 check
"$expected" test4.txt
'keep first'
191 # check -noauto, the default
192 start_test
'-noauto, the default'
193 run_test
'mhstore last -part 4 -auto -noauto' \
194 'storing message 11 part 4 as file 11.4.txt'
195 check
"$expected" 11.4.txt
'keep first'
197 # check -verbose, the default
198 start_test
'-verbose, the default'
199 run_test
'mhstore last -part 4 -noverbose -verbose' \
200 'storing message 11 part 4 as file 11.4.txt'
201 check
"$expected" 11.4.txt
'keep first'
204 start_test
'-noverbose'
205 run_test
'mhstore last -part 4 -noverbose' ''
206 check
"$expected" 11.4.txt
208 # check that -auto obeys Content-Disposition header
209 start_test
'that -auto obeys Content-Disposition header'
210 cat >"$expected" <<'EOF'
211 This is the first text/plain part, in a subpart.
213 run_test
'mhstore last -part 1.1 -auto' \
214 'storing message 11 part 1.1 as file test1.txt'
215 check
"$expected" test1.txt
219 cat >"$expected" <<'EOF'
220 This is the second text/plain part.
222 run_test
'mhstore last -part 2 -check' \
223 'storing message 11 part 2 as file 11.2.txt'
224 check
"$expected" 11.2.txt
'keep first'
226 # check with -check on base64 encoded part
227 start_test
'with -check on base64 encoded part'
228 cat >"$expected2" <<'EOF'
229 This is the fourth text/plain part.
230 This test has multiple lines.
232 run_test
'mhstore last -part 4 -check' \
233 'storing message 11 part 4 as file 11.4.txt'
234 check
"$expected2" 11.4.txt
236 # check -check with bad MD5 checksum
237 start_test
'-check with bad MD5 checksum'
238 sed 's/\(Content-MD5: \)kq+Hnc/\1BADBAD/' "$msgfile" >"$MH_TEST_DIR/$$.tmp"
239 mv -f "$MH_TEST_DIR/$$.tmp" "$msgfile"
240 run_test
'mhstore last -part 2 -check' \
241 'storing message 11 part 2 as file 11.2.txt
242 mhstore: content integrity suspect (digest mismatch) -- continuing
243 (content text/plain in message 11, part 2)'
244 check
"$expected" 11.2.txt
'keep first'
246 # check -nocheck, the default
247 start_test
'-nocheck, the default'
248 run_test
'mhstore last -part 2 -check -nocheck' \
249 'storing message 11 part 2 as file 11.2.txt'
250 check
"$expected" 11.2.txt
'keep first'
252 # check -outfile - with -file
253 start_test
'-outfile - with -file'
254 run_prog mhstore
-noverbose -file `mhpath 11` -part 2 -outfile - >"$actual" 2>&1
255 check
"$expected" "$actual"
257 # check reassembly of message/partial messages (RFC 1521, 7.3.2)
258 start_test
'reassembly of message/partial messages (RFC 1521, 7.3.2)'
260 cat >"$msgfile" <<'EOF'
261 To: recipient@example.com
262 From: sender@example.com
265 Content-Type: message/partial; id="test-mhstore message/partial test"; number=1
267 Content-Type: text/plain; charset="iso-8859-1"
269 This is part one of three.
273 cat >"$msgfile" <<'EOF'
274 To: recipient@example.com
275 From: sender@example.com
278 Content-Type: message/partial; id="test-mhstore message/partial test"; number=2
280 This is part two of three.
284 cat >"$msgfile" <<'EOF'
285 To: recipient@example.com
286 From: sender@example.com
289 Content-Type: message/partial; id="test-mhstore message/partial test"; number=3;
292 This is part three of three.
295 run_test
'mhstore last:3' \
296 'reassembling partials 12,13,14 to folder inbox as message 15'
298 cat >"$expected" <<'EOF'
299 This is part one of three.
300 This is part two of three.
301 This is part three of three.
303 run_test
'mhstore last' 'storing message 15 as file 15.txt'
304 check
"$expected" 15.txt
306 # cd into Mail directory because it gets cleaned up by the exit trap.
309 # check -clobber always
310 start_test
'-clobber always'
311 folder
+inbox
7 >/dev
/null
313 cat >"$expected" <<'EOF'
314 This is message number 7
316 run_test
'mhstore' 'storing message 7 as file 7.txt'
317 check
"$expected" 7.txt
'keep first'
318 run_test
'mhstore -clobber ask -clobber always' \
319 'storing message 7 as file 7.txt'
320 check
"$expected" 7.txt
'keep first'
322 # check -clobber auto
323 start_test
'-clobber auto'
325 run_test
'mhstore -clobber auto' 'storing message 7 as file 7-1.txt'
326 check
"$expected" 7-1.txt
'keep first'
328 run_test
'mhstore -clobber auto' 'storing message 7 as file 7-2.txt'
329 check
"$expected" 7-2.txt
'keep first'
331 # check -clobber suffix
332 start_test
'-clobber suffix'
333 run_test
'mhstore -clobber suffix' 'storing message 7 as file 7.txt.1'
334 check
"$expected" 7.txt
.1 'keep first'
336 run_test
'mhstore -clobber suffix' 'storing message 7 as file 7.txt.2'
337 check
"$expected" 7.txt
.2 'keep first'
339 # Don't check -clobber ask because it requires connection to a
340 # terminal, and this test won't always be run with one.
342 # check -clobber never. Its exit status is the number of files not overwritten.
343 start_test
'-clobber never. Its exit status is the number of files not overwritten.'
344 run_test
'mhstore -clobber never' \
345 "mhstore: will not overwrite $MH_TEST_DIR/Mail/7.txt with -clobber never"
347 mhstore
-clobber never
>/dev
/null
2>&1
353 # check with short relative nmh-storage profile component
354 start_test
'with short relative nmh-storage profile component'
356 dir
="$MH_TEST_DIR/Mail/inbox/$storagedir"
358 printf '%s\n' "nmh-storage: $storagedir" >>"$MH"
359 cat >"$expected" <<'EOF'
360 This is the fourth text/plain part.
361 This test has multiple lines.
363 run_test
'mhstore 11 -part 4' \
364 "storing message 11 part 4 as file $storagedir/11.4.txt"
365 check
"$expected" "$dir/11.4.txt" 'keep first'
367 sed '$d' "$MH" >"$MH.new"
370 # check with relative nmh-storage profile component
371 start_test
'with relative nmh-storage profile component'
372 storagedir
=storagedir
373 dir
="$MH_TEST_DIR/Mail/inbox/$storagedir"
375 printf '%s\n' "nmh-storage: $storagedir" >>"$MH"
376 run_test
'mhstore 11 -part 4' \
377 "storing message 11 part 4 as file $storagedir/11.4.txt"
378 check
"$expected" "$dir/11.4.txt" 'keep first'
380 # check with relative nmh-storage profile component and -auto
381 start_test
'with relative nmh-storage profile component and -auto'
382 run_test
'mhstore 11 -part 4 -auto' \
383 "storing message 11 part 4 as file $storagedir/test4.txt"
384 check
"$expected" "$dir/test4.txt" 'keep first'
386 # check with absolute nmh-storage profile component
387 start_test
'with absolute nmh-storage profile component'
388 absstoragedir
="$MH_TEST_DIR/$storagedir"
389 mkdir "$absstoragedir"
390 sed "s%\(nmh-storage: \)storagedir%\1$absstoragedir%" "$MH" >"$MH.new"
391 mv -f "$MH.new" "$MH"
392 run_test
'mhstore 11 -part 4' \
393 "storing message 11 part 4 as file $storagedir/11.4.txt"
394 check
"$expected" "$absstoragedir/11.4.txt" 'keep first'
396 # check with absolute nmh-storage profile component and -auto
397 start_test
'with absolute nmh-storage profile component and -auto'
398 run_test
'mhstore 11 -part 4 -auto' \
399 "storing message 11 part 4 as file $storagedir/test4.txt"
400 check
"$expected" "$absstoragedir/test4.txt"
401 rmdir "$absstoragedir"