]>
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
217 # check reassembly of message/partial messages (RFC 1521, 7.3.2)
219 cat >"$msgfile" <<'EOF'
220 To: recipient@example.com
221 From: sender@example.com
224 Content-Type: message/partial; id="test-mhstore message/partial test"; number=1
226 Content-Type: text/plain; charset="iso-8859-1"
228 This is part one of three.
232 cat >"$msgfile" <<'EOF'
233 To: recipient@example.com
234 From: sender@example.com
237 Content-Type: message/partial; id="test-mhstore message/partial test"; number=2
239 This is part two of three.
243 cat >"$msgfile" <<'EOF'
244 To: recipient@example.com
245 From: sender@example.com
248 Content-Type: message/partial; id="test-mhstore message/partial test"; number=3;
251 This is part three of three.
254 run_test
'mhstore last:3' \
255 'reassembling partials 12,13,14 to folder inbox as message 15'
257 cat >"$expected" <<'EOF'
258 This is part one of three.
259 This is part two of three.
260 This is part three of three.
262 run_test
'mhstore last' 'storing message 15 as file 15.txt'
263 check
"$expected" 15.txt
265 # cd into Mail directory because it gets cleaned up by the exit trap.
268 # check -clobber always
269 folder
+inbox
7 >/dev
/null
271 cat >"$expected" <<'EOF'
272 This is message number 7
274 run_test
'mhstore' 'storing message 7 as file 7.txt'
275 check
"$expected" 7.txt
'keep first'
276 run_test
'mhstore -clobber ask -clobber always' \
277 'storing message 7 as file 7.txt'
278 check
"$expected" 7.txt
'keep first'
280 # check -clobber auto
282 run_test
'mhstore -clobber auto' 'storing message 7 as file 7-1.txt'
283 check
"$expected" 7-1.txt
'keep first'
285 run_test
'mhstore -clobber auto' 'storing message 7 as file 7-2.txt'
286 check
"$expected" 7-2.txt
'keep first'
288 # check -clobber suffix
289 run_test
'mhstore -clobber suffix' 'storing message 7 as file 7.txt.1'
290 check
"$expected" 7.txt
.1 'keep first'
292 run_test
'mhstore -clobber suffix' 'storing message 7 as file 7.txt.2'
293 check
"$expected" 7.txt
.2 'keep first'
295 # Don't check -clobber ask because it requires connection to a
296 # terminal, and this test won't always be run with one.
298 # check -clobber never. Its exit status is the number of files not overwritten.
299 run_test
'mhstore -clobber never' \
300 "mhstore: will not overwrite `pwd`/7.txt with -clobber never"
302 mhstore
-clobber never
>/dev
/null
2>&1
308 # check with relative nmh-storage profile component
309 storagedir
=storagedir
310 dir
="$MH_TEST_DIR/Mail/inbox/$storagedir"
312 printf '%s\n' "nmh-storage: $storagedir" >>"$MH"
313 cat >"$expected" <<'EOF'
314 This is the fourth text/plain part.
315 This test has multiple lines.
317 run_test
'mhstore 11 -part 4' \
318 "storing message 11 part 4 as file $storagedir/11.4.txt"
319 check
"$expected" "$dir/11.4.txt" 'keep first'
321 # check with relative nmh-storage profile component and -auto
322 run_test
'mhstore 11 -part 4 -auto' \
323 "storing message 11 part 4 as file $storagedir/test4.txt"
324 check
"$expected" "$dir/test4.txt" 'keep first'
326 # check with absolute nmh-storage profile component
327 absstoragedir
="$MH_TEST_DIR/$storagedir"
328 mkdir "$absstoragedir"
329 sed "s%\(nmh-storage: \)storagedir%\1$absstoragedir%" "$MH" >"$MH.new"
330 mv -f "$MH.new" "$MH"
331 run_test
'mhstore 11 -part 4' \
332 "storing message 11 part 4 as file $storagedir/11.4.txt"
333 check
"$expected" "$absstoragedir/11.4.txt" 'keep first'
335 # check with absolute nmh-storage profile component and -auto
336 run_test
'mhstore 11 -part 4 -auto' \
337 "storing message 11 part 4 as file $storagedir/test4.txt"
338 check
"$expected" "$absstoragedir/test4.txt"
339 rmdir "$absstoragedir"