]>
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 # check with no options and no current message
28 run_test
'mhstore' 'mhstore: no cur message'
30 # check with no options and current message
31 folder
+inbox
5 >/dev
/null
32 cat >"$expected" <<'EOF'
33 This is message number 5
35 run_test
'mhstore' 'storing message 5 as file 5.txt'
36 check
"$expected" 5.txt
'keep first'
38 # check with folder and current message
39 run_test
'mhstore +inbox' 'storing message 5 as file 5.txt'
40 check
"$expected" 5.txt
'keep first'
42 # check with specified message
43 run_test
'mhstore 5' 'storing message 5 as file 5.txt'
44 check
"$expected" 5.txt
'keep first'
47 run_test
"mhstore -file $MH_TEST_DIR/Mail/inbox/5" \
48 "storing message $MH_TEST_DIR/Mail/inbox/5 as file 5.txt"
49 check
"$expected" 5.txt
'keep first'
52 stored_contents
=`run_prog mhstore -file - < $MH_TEST_DIR/Mail/inbox/5 2>&1 | \
54 check
"$expected" "$stored_contents" 'keep first'
56 # check -outfile and -noverbose
57 run_prog mhstore
5 -noverbose -outfile "$actual" >"$actual_err" 2>&1
58 printf '' >"$expected_err"
59 check
"$expected" "$actual" 'keep first'
60 check
"$expected_err" "$actual_err"
63 printf '%s\n' 'storing message 5 to stdout' >>"$expected"
64 run_prog mhstore
5 -outfile - >"$actual" 2>&1
65 check
"$expected" "$actual"
67 # check message number greater than highest
68 run_test
'mhstore 11' "mhstore: message 11 doesn't exist"
70 # check multiple messages
71 run_test
'mhstore 4 6' 'storing message 4 as file 4.txt
72 storing message 6 as file 6.txt'
73 cat >"$expected" <<'EOF'
74 This is message number 4
76 check
"$expected" 4.txt
77 cat >"$expected" <<'EOF'
78 This is message number 6
80 check
"$expected" 6.txt
82 # Write message with a text/plain subpart.
84 cat >"$msgfile" <<'EOF'
85 To: recipient@example.com
86 From: sender@example.com
89 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
92 Content-Type: multipart/related;
93 type="multipart/alternative";
94 boundary="subpart__1.1"
97 Content-Type: text/plain; charset="iso-8859-1"
98 Content-Disposition: attachment; filename="test1.txt"
100 This is the first text/plain part, in a subpart.
104 ------- =_aaaaaaaaaa0
105 Content-Type: text/plain; charset="iso-8859-1"
106 Content-Disposition: attachment; filename="test2.txt"
107 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
108 Content-Transfer-Encoding: quoted-printable
110 This is the second text/plain part.
112 ------- =_aaaaaaaaaa0
113 Content-Type: text/plain; charset="iso-8859-1"
114 Content-Disposition: attachment; filename="test3.txt"
116 This is the third text/plain part.
118 ------- =_aaaaaaaaaa0
119 Content-Type: text/plain; charset="iso-8859-1"; name="test4.txt"
120 Content-Disposition: attachment; filename="test4.txt"
121 Content-MD5: cMI1lB/LZ4jgVl3EbhdyWA==
122 Content-Transfer-Encoding: base64
124 VGhpcyBpcyB0aGUgZm91cnRoIHRleHQvcGxhaW4gcGFydC4NClRoaXMgdGVzdCBoYXMgbXVsdGlw
127 ------- =_aaaaaaaaaa0--
131 cat >"$expected" <<'EOF'
132 This is the third text/plain part.
134 run_test
'mhstore last -part 3' 'storing message 11 part 3 as file 11.3.txt'
135 check
"$expected" 11.3.txt
137 # check -part of a subpart
138 cat >"$expected" <<'EOF'
139 This is the first text/plain part, in a subpart.
141 run_test
'mhstore last -part 1.1' \
142 'storing message 11 part 1.1 as file 11.1.1.txt'
143 check
"$expected" 11.1.1.txt
'keep first'
146 run_test
'mhstore last -type text/plain' \
147 'storing message 11 part 1.1 as file 11.1.1.txt
148 storing message 11 part 2 as file 11.2.txt
149 storing message 11 part 3 as file 11.3.txt
150 storing message 11 part 4 as file 11.4.txt'
151 check
"$expected" 11.1.1.txt
152 cat >"$expected" <<'EOF'
153 This is the second text/plain part.
155 check
"$expected" 11.2.txt
156 cat >"$expected" <<'EOF'
157 This is the third text/plain part.
159 check
"$expected" 11.3.txt
160 cat >"$expected" <<'EOF'
161 This is the fourth text/plain part.
162 This test has multiple lines.
164 check
"$expected" 11.4.txt
167 cat >"$expected" <<'EOF'
168 This is the fourth text/plain part.
169 This test has multiple lines.
171 run_test
'mhstore last -part 4 -auto' \
172 'storing message 11 part 4 as file test4.txt'
173 check
"$expected" test4.txt
'keep first'
175 # check -noauto, the default
176 run_test
'mhstore last -part 4 -auto -noauto' \
177 'storing message 11 part 4 as file 11.4.txt'
178 check
"$expected" 11.4.txt
'keep first'
180 # check -verbose, the default
181 run_test
'mhstore last -part 4 -noverbose -verbose' \
182 'storing message 11 part 4 as file 11.4.txt'
183 check
"$expected" 11.4.txt
'keep first'
186 run_test
'mhstore last -part 4 -noverbose' ''
187 check
"$expected" 11.4.txt
189 # check that -auto obeys Content-Disposition header
190 cat >"$expected" <<'EOF'
191 This is the first text/plain part, in a subpart.
193 run_test
'mhstore last -part 1.1 -auto' \
194 'storing message 11 part 1.1 as file test1.txt'
195 check
"$expected" test1.txt
198 cat >"$expected" <<'EOF'
199 This is the second text/plain part.
201 run_test
'mhstore last -part 2 -check' \
202 'storing message 11 part 2 as file 11.2.txt'
203 check
"$expected" 11.2.txt
'keep first'
205 # check with -check on base64 encoded part
206 cat >"$expected2" <<'EOF'
207 This is the fourth text/plain part.
208 This test has multiple lines.
210 run_test
'mhstore last -part 4 -check' \
211 'storing message 11 part 4 as file 11.4.txt'
212 check
"$expected2" 11.4.txt
214 # check -check with bad MD5 checksum
215 sed 's/\(Content-MD5: \)kq+Hnc/\1BADBAD/' "$msgfile" >"$MH_TEST_DIR/$$.tmp"
216 mv -f "$MH_TEST_DIR/$$.tmp" "$msgfile"
217 run_test
'mhstore last -part 2 -check' \
218 'storing message 11 part 2 as file 11.2.txt
219 mhstore: content integrity suspect (digest mismatch) -- continuing
220 (content text/plain in message 11, part 2)'
221 check
"$expected" 11.2.txt
'keep first'
223 # check -nocheck, the default
224 run_test
'mhstore last -part 2 -check -nocheck' \
225 'storing message 11 part 2 as file 11.2.txt'
226 check
"$expected" 11.2.txt
'keep first'
228 # check -outfile - with -file
229 run_prog mhstore
-noverbose -file `mhpath 11` -part 2 -outfile - >"$actual" 2>&1
230 check
"$expected" "$actual"
232 # check reassembly of message/partial messages (RFC 1521, 7.3.2)
234 cat >"$msgfile" <<'EOF'
235 To: recipient@example.com
236 From: sender@example.com
239 Content-Type: message/partial; id="test-mhstore message/partial test"; number=1
241 Content-Type: text/plain; charset="iso-8859-1"
243 This is part one of three.
247 cat >"$msgfile" <<'EOF'
248 To: recipient@example.com
249 From: sender@example.com
252 Content-Type: message/partial; id="test-mhstore message/partial test"; number=2
254 This is part two of three.
258 cat >"$msgfile" <<'EOF'
259 To: recipient@example.com
260 From: sender@example.com
263 Content-Type: message/partial; id="test-mhstore message/partial test"; number=3;
266 This is part three of three.
269 run_test
'mhstore last:3' \
270 'reassembling partials 12,13,14 to folder inbox as message 15'
272 cat >"$expected" <<'EOF'
273 This is part one of three.
274 This is part two of three.
275 This is part three of three.
277 run_test
'mhstore last' 'storing message 15 as file 15.txt'
278 check
"$expected" 15.txt
280 # cd into Mail directory because it gets cleaned up by the exit trap.
283 # check -clobber always
284 folder
+inbox
7 >/dev
/null
286 cat >"$expected" <<'EOF'
287 This is message number 7
289 run_test
'mhstore' 'storing message 7 as file 7.txt'
290 check
"$expected" 7.txt
'keep first'
291 run_test
'mhstore -clobber ask -clobber always' \
292 'storing message 7 as file 7.txt'
293 check
"$expected" 7.txt
'keep first'
295 # check -clobber auto
297 run_test
'mhstore -clobber auto' 'storing message 7 as file 7-1.txt'
298 check
"$expected" 7-1.txt
'keep first'
300 run_test
'mhstore -clobber auto' 'storing message 7 as file 7-2.txt'
301 check
"$expected" 7-2.txt
'keep first'
303 # check -clobber suffix
304 run_test
'mhstore -clobber suffix' 'storing message 7 as file 7.txt.1'
305 check
"$expected" 7.txt
.1 'keep first'
307 run_test
'mhstore -clobber suffix' 'storing message 7 as file 7.txt.2'
308 check
"$expected" 7.txt
.2 'keep first'
310 # Don't check -clobber ask because it requires connection to a
311 # terminal, and this test won't always be run with one.
313 # check -clobber never. Its exit status is the number of files not overwritten.
314 run_test
'mhstore -clobber never' \
315 "mhstore: will not overwrite $MH_TEST_DIR/Mail/7.txt with -clobber never"
317 mhstore
-clobber never
>/dev
/null
2>&1
323 # check with relative nmh-storage profile component
324 storagedir
=storagedir
325 dir
="$MH_TEST_DIR/Mail/inbox/$storagedir"
327 printf '%s\n' "nmh-storage: $storagedir" >>"$MH"
328 cat >"$expected" <<'EOF'
329 This is the fourth text/plain part.
330 This test has multiple lines.
332 run_test
'mhstore 11 -part 4' \
333 "storing message 11 part 4 as file $storagedir/11.4.txt"
334 check
"$expected" "$dir/11.4.txt" 'keep first'
336 # check with relative nmh-storage profile component and -auto
337 run_test
'mhstore 11 -part 4 -auto' \
338 "storing message 11 part 4 as file $storagedir/test4.txt"
339 check
"$expected" "$dir/test4.txt" 'keep first'
341 # check with absolute nmh-storage profile component
342 absstoragedir
="$MH_TEST_DIR/$storagedir"
343 mkdir "$absstoragedir"
344 sed "s%\(nmh-storage: \)storagedir%\1$absstoragedir%" "$MH" >"$MH.new"
345 mv -f "$MH.new" "$MH"
346 run_test
'mhstore 11 -part 4' \
347 "storing message 11 part 4 as file $storagedir/11.4.txt"
348 check
"$expected" "$absstoragedir/11.4.txt" 'keep first'
350 # check with absolute nmh-storage profile component and -auto
351 run_test
'mhstore 11 -part 4 -auto' \
352 "storing message 11 part 4 as file $storagedir/test4.txt"
353 check
"$expected" "$absstoragedir/test4.txt"
354 rmdir "$absstoragedir"