]>
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 expected_err
="$MH_TEST_DIR/test-mhmail$$.expected_err"
21 actual
="$MH_TEST_DIR/test-mhstore$$.actual"
22 actual_err
="$MH_TEST_DIR/test-mhmail$$.actual_err"
26 # check with no options and no current message
27 run_test
'mhstore' 'mhstore: no cur message'
29 # check with no options and current message
30 folder
+inbox
5 >/dev
/null
31 cat >"$expected" <<'EOF'
32 This is message number 5
34 run_test
'mhstore' 'storing message 5 as file 5.txt'
35 check
"$expected" 5.txt
'keep first'
37 # check with folder and current message
38 run_test
'mhstore +inbox' 'storing message 5 as file 5.txt'
39 check
"$expected" 5.txt
'keep first'
41 # check with specified message
42 run_test
'mhstore 5' 'storing message 5 as file 5.txt'
43 check
"$expected" 5.txt
'keep first'
46 run_test
"mhstore -file $MH_TEST_DIR/Mail/inbox/5" \
47 "storing message $MH_TEST_DIR/Mail/inbox/5 as file 5.txt"
48 check
"$expected" 5.txt
'keep first'
51 stored_contents
=`run_prog mhstore -file - < $MH_TEST_DIR/Mail/inbox/5 2>&1 | \
53 check
"$expected" "$stored_contents" 'keep first'
55 # check -outfile and -noverbose
56 run_prog mhstore
5 -noverbose -outfile "$actual" >"$actual_err" 2>&1
57 printf '' >"$expected_err"
58 check
"$expected" "$actual" 'keep first'
59 check
"$expected_err" "$actual_err"
62 printf '%s\n' 'storing message 5 to stdout' >>"$expected"
63 run_prog mhstore
5 -outfile - >"$actual" 2>&1
64 check
"$expected" "$actual"
66 # check message number greater than highest
67 run_test
'mhstore 11' "mhstore: message 11 doesn't exist"
69 # check multiple messages
70 run_test
'mhstore 4 6' 'storing message 4 as file 4.txt
71 storing message 6 as file 6.txt'
72 cat >"$expected" <<'EOF'
73 This is message number 4
75 check
"$expected" 4.txt
76 cat >"$expected" <<'EOF'
77 This is message number 6
79 check
"$expected" 6.txt
81 # Write message with a text/plain subpart.
83 cat >"$msgfile" <<'EOF'
84 To: recipient@example.com
85 From: sender@example.com
88 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
91 Content-Type: multipart/related;
92 type="multipart/alternative";
93 boundary="subpart__1.1"
96 Content-Type: text/plain; charset="iso-8859-1"
97 Content-Disposition: attachment; filename="test1.txt"
99 This is the first text/plain part, in a subpart.
103 ------- =_aaaaaaaaaa0
104 Content-Type: text/plain; charset="iso-8859-1"
105 Content-Disposition: attachment; filename="test2.txt"
106 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
107 Content-Transfer-Encoding: quoted-printable
109 This is the second text/plain part.
111 ------- =_aaaaaaaaaa0
112 Content-Type: text/plain; charset="iso-8859-1"
113 Content-Disposition: attachment; filename="test3.txt"
115 This is the third text/plain part.
117 ------- =_aaaaaaaaaa0
118 Content-Type: text/plain; charset="iso-8859-1"; name="test4.txt"
119 Content-Disposition: attachment; filename="test4.txt"
120 Content-Transfer-Encoding: base64
122 VGhpcyBpcyB0aGUgZm91cnRoIHRleHQvcGxhaW4gcGFydC4NClRoaXMgdGVzdCBoYXMgbXVsdGlw
125 ------- =_aaaaaaaaaa0--
129 cat >"$expected" <<'EOF'
130 This is the third text/plain part.
132 run_test
'mhstore last -part 3' 'storing message 11 part 3 as file 11.3.txt'
133 check
"$expected" 11.3.txt
135 # check -part of a subpart
136 cat >"$expected" <<'EOF'
137 This is the first text/plain part, in a subpart.
139 run_test
'mhstore last -part 1.1' \
140 'storing message 11 part 1.1 as file 11.1.1.txt'
141 check
"$expected" 11.1.1.txt
'keep first'
144 run_test
'mhstore last -type text/plain' \
145 'storing message 11 part 1.1 as file 11.1.1.txt
146 storing message 11 part 2 as file 11.2.txt
147 storing message 11 part 3 as file 11.3.txt
148 storing message 11 part 4 as file 11.4.txt'
149 check
"$expected" 11.1.1.txt
150 cat >"$expected" <<'EOF'
151 This is the second text/plain part.
153 check
"$expected" 11.2.txt
154 cat >"$expected" <<'EOF'
155 This is the third text/plain part.
157 check
"$expected" 11.3.txt
158 cat >"$expected" <<'EOF'
159 This is the fourth text/plain part.
160 This test has multiple lines.
162 check
"$expected" 11.4.txt
165 cat >"$expected" <<'EOF'
166 This is the fourth text/plain part.
167 This test has multiple lines.
169 run_test
'mhstore last -part 4 -auto' \
170 'storing message 11 part 4 as file test4.txt'
171 check
"$expected" test4.txt
'keep first'
173 # check -noauto, the default
174 run_test
'mhstore last -part 4 -auto -noauto' \
175 'storing message 11 part 4 as file 11.4.txt'
176 check
"$expected" 11.4.txt
'keep first'
178 # check -verbose, the default
179 run_test
'mhstore last -part 4 -noverbose -verbose' \
180 'storing message 11 part 4 as file 11.4.txt'
181 check
"$expected" 11.4.txt
'keep first'
184 run_test
'mhstore last -part 4 -noverbose' ''
185 check
"$expected" 11.4.txt
187 # check that -auto obeys Content-Disposition header
188 cat >"$expected" <<'EOF'
189 This is the first text/plain part, in a subpart.
191 run_test
'mhstore last -part 1.1 -auto' \
192 'storing message 11 part 1.1 as file test1.txt'
193 check
"$expected" test1.txt
196 cat >"$expected" <<'EOF'
197 This is the second text/plain part.
199 run_test
'mhstore last -part 2 -check' \
200 'storing message 11 part 2 as file 11.2.txt'
201 check
"$expected" 11.2.txt
'keep first'
203 # check -check with bad MD5 checksum
204 sed 's/\(Content-MD5: \)kq+Hnc/\1BADBAD/' "$msgfile" >"$MH_TEST_DIR/$$.tmp"
205 mv -f "$MH_TEST_DIR/$$.tmp" "$msgfile"
206 run_test
'mhstore last -part 2 -check' \
207 'storing message 11 part 2 as file 11.2.txt
208 mhstore: content integrity suspect (digest mismatch) -- continuing
209 (content text/plain in message 11, part 2)'
210 check
"$expected" 11.2.txt
'keep first'
212 # check -nocheck, the default
213 run_test
'mhstore last -part 2 -check -nocheck' \
214 'storing message 11 part 2 as file 11.2.txt'
215 check
"$expected" 11.2.txt
'keep first'
217 # check -outfile - with -file
218 run_prog mhstore
-noverbose -file `mhpath 11` -part 2 -outfile - >"$actual" 2>&1
219 check
"$expected" "$actual"
221 # check reassembly of message/partial messages (RFC 1521, 7.3.2)
223 cat >"$msgfile" <<'EOF'
224 To: recipient@example.com
225 From: sender@example.com
228 Content-Type: message/partial; id="test-mhstore message/partial test"; number=1
230 Content-Type: text/plain; charset="iso-8859-1"
232 This is part one of three.
236 cat >"$msgfile" <<'EOF'
237 To: recipient@example.com
238 From: sender@example.com
241 Content-Type: message/partial; id="test-mhstore message/partial test"; number=2
243 This is part two 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=3;
255 This is part three of three.
258 run_test
'mhstore last:3' \
259 'reassembling partials 12,13,14 to folder inbox as message 15'
261 cat >"$expected" <<'EOF'
262 This is part one of three.
263 This is part two of three.
264 This is part three of three.
266 run_test
'mhstore last' 'storing message 15 as file 15.txt'
267 check
"$expected" 15.txt
269 # cd into Mail directory because it gets cleaned up by the exit trap.
272 # check -clobber always
273 folder
+inbox
7 >/dev
/null
275 cat >"$expected" <<'EOF'
276 This is message number 7
278 run_test
'mhstore' 'storing message 7 as file 7.txt'
279 check
"$expected" 7.txt
'keep first'
280 run_test
'mhstore -clobber ask -clobber always' \
281 'storing message 7 as file 7.txt'
282 check
"$expected" 7.txt
'keep first'
284 # check -clobber auto
286 run_test
'mhstore -clobber auto' 'storing message 7 as file 7-1.txt'
287 check
"$expected" 7-1.txt
'keep first'
289 run_test
'mhstore -clobber auto' 'storing message 7 as file 7-2.txt'
290 check
"$expected" 7-2.txt
'keep first'
292 # check -clobber suffix
293 run_test
'mhstore -clobber suffix' 'storing message 7 as file 7.txt.1'
294 check
"$expected" 7.txt
.1 'keep first'
296 run_test
'mhstore -clobber suffix' 'storing message 7 as file 7.txt.2'
297 check
"$expected" 7.txt
.2 'keep first'
299 # Don't check -clobber ask because it requires connection to a
300 # terminal, and this test won't always be run with one.
302 # check -clobber never. Its exit status is the number of files not overwritten.
303 run_test
'mhstore -clobber never' \
304 "mhstore: will not overwrite `pwd`/7.txt with -clobber never"
306 mhstore
-clobber never
>/dev
/null
2>&1
312 # check with relative nmh-storage profile component
313 storagedir
=storagedir
314 dir
="$MH_TEST_DIR/Mail/inbox/$storagedir"
316 printf '%s\n' "nmh-storage: $storagedir" >>"$MH"
317 cat >"$expected" <<'EOF'
318 This is the fourth text/plain part.
319 This test has multiple lines.
321 run_test
'mhstore 11 -part 4' \
322 "storing message 11 part 4 as file $storagedir/11.4.txt"
323 check
"$expected" "$dir/11.4.txt" 'keep first'
325 # check with relative nmh-storage profile component and -auto
326 run_test
'mhstore 11 -part 4 -auto' \
327 "storing message 11 part 4 as file $storagedir/test4.txt"
328 check
"$expected" "$dir/test4.txt" 'keep first'
330 # check with absolute nmh-storage profile component
331 absstoragedir
="$MH_TEST_DIR/$storagedir"
332 mkdir "$absstoragedir"
333 sed "s%\(nmh-storage: \)storagedir%\1$absstoragedir%" "$MH" >"$MH.new"
334 mv -f "$MH.new" "$MH"
335 run_test
'mhstore 11 -part 4' \
336 "storing message 11 part 4 as file $storagedir/11.4.txt"
337 check
"$expected" "$absstoragedir/11.4.txt" 'keep first'
339 # check with absolute nmh-storage profile component and -auto
340 run_test
'mhstore 11 -part 4 -auto' \
341 "storing message 11 part 4 as file $storagedir/test4.txt"
342 check
"$expected" "$absstoragedir/test4.txt"
343 rmdir "$absstoragedir"