]>
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 actual
="$MH_TEST_DIR/test-mhstore$$.actual"
24 # check with no options and no current message
25 run_test
'mhstore' 'mhstore: no cur message'
27 # check with no options and current message
28 folder
+inbox
5 > /dev
/null
30 This is message number 5
32 run_test
'mhstore' 'storing message 5 as file 5.txt'
33 check
$expected 5.txt
'keep first'
35 # check with folder and current message
36 run_test
'mhstore +inbox' 'storing message 5 as file 5.txt'
37 check
$expected 5.txt
'keep first'
39 # check with specified message
40 run_test
'mhstore 5' 'storing message 5 as file 5.txt'
41 check
$expected 5.txt
'keep first'
44 run_test
"mhstore -file $MH_TEST_DIR/Mail/inbox/5" \
45 "storing message $MH_TEST_DIR/Mail/inbox/5 as file 5.txt"
46 check
$expected 5.txt
'keep first'
49 stored_contents
=`mhstore -file - < $MH_TEST_DIR/Mail/inbox/5 2>&1 | \
51 check
$expected $stored_contents 'keep first'
54 mhstore
5 -outfile "$actual" 2>&1 | grep -v '^storing' && \
55 echo unexpected output from
test-mhstore check
-outfile >&2
56 check
$expected "$actual" 'keep first'
59 echo 'storing message 5 to stdout' >>"$expected"
60 mhstore
5 -outfile - >"$actual" 2>&1
61 check
$expected "$actual"
63 # check message number greater than highest
64 run_test
'mhstore 11' "mhstore: message 11 doesn't exist"
66 # check multiple messages
67 run_test
'mhstore 4 6' 'storing message 4 as file 4.txt
68 storing message 6 as file 6.txt'
70 This is message number 4
74 This is message number 6
78 # Write message with a text/plain subpart.
81 To: recipient@example.com
82 From: sender@example.com
85 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0"
88 Content-Type: multipart/related;
89 type="multipart/alternative";
90 boundary="subpart__1.1"
93 Content-Type: text/plain; charset="iso-8859-1"
94 Content-Disposition: attachment; filename="test1.txt"
96 This is the first text/plain part, in a subpart.
100 ------- =_aaaaaaaaaa0
101 Content-Type: text/plain; charset="iso-8859-1"
102 Content-Disposition: attachment; filename="test2.txt"
103 Content-MD5: kq+Hnc2SD/eKwAnkFBDuEA==
104 Content-Transfer-Encoding: quoted-printable
106 This is the second text/plain part.
108 ------- =_aaaaaaaaaa0
109 Content-Type: text/plain; charset="iso-8859-1"
110 Content-Disposition: attachment; filename="test3.txt"
112 This is the third text/plain part.
114 ------- =_aaaaaaaaaa0
115 Content-Type: text/plain; charset="iso-8859-1"; name="test4.txt"
116 Content-Disposition: attachment; filename="test4.txt"
117 Content-Transfer-Encoding: base64
119 VGhpcyBpcyB0aGUgZm91cnRoIHRleHQvcGxhaW4gcGFydC4K
121 ------- =_aaaaaaaaaa0--
125 cat > $expected <<EOF
126 This is the third text/plain part.
128 run_test
'mhstore last -part 3' 'storing message 11 part 3 as file 11.3.txt'
129 check
$expected 11.3.txt
131 # check -part of a subpart
132 cat > $expected <<EOF
133 This is the first text/plain part, in a subpart.
135 run_test
'mhstore last -part 1.1' \
136 'storing message 11 part 1.1 as file 11.1.1.txt'
137 check
$expected 11.1.1.txt
'keep first'
140 run_test
'mhstore last -type text/plain' \
141 'storing message 11 part 1.1 as file 11.1.1.txt
142 storing message 11 part 2 as file 11.2.txt
143 storing message 11 part 3 as file 11.3.txt
144 storing message 11 part 4 as file 11.4.txt'
145 check
$expected 11.1.1.txt
146 cat > $expected <<EOF
147 This is the second text/plain part.
149 check
$expected 11.2.txt
150 cat > $expected <<EOF
151 This is the third text/plain part.
153 check
$expected 11.3.txt
154 cat > $expected <<EOF
155 This is the fourth text/plain part.
157 check
$expected 11.4.txt
160 cat > $expected <<EOF
161 This is the fourth text/plain part.
163 run_test
'mhstore last -part 4 -auto' \
164 'storing message 11 part 4 as file test4.txt'
165 check
$expected test4.txt
'keep first'
167 # check -noauto, the default
168 run_test
'mhstore last -part 4 -auto -noauto' \
169 'storing message 11 part 4 as file 11.4.txt'
170 check
$expected 11.4.txt
'keep first'
172 # check -verbose, which doesn't do anything
173 run_test
'mhstore last -part 4 -verbose' \
174 'storing message 11 part 4 as file 11.4.txt'
175 check
$expected 11.4.txt
'keep first'
177 # check -noverbose, the default
178 run_test
'mhstore last -part 4 -verbose -noverbose' \
179 'storing message 11 part 4 as file 11.4.txt'
180 check
$expected 11.4.txt
182 # check that -auto obeys Content-Disposition header
183 cat > $expected <<EOF
184 This is the first text/plain part, in a subpart.
186 run_test
'mhstore last -part 1.1 -auto' \
187 'storing message 11 part 1.1 as file test1.txt'
188 check
$expected test1.txt
191 cat > $expected <<EOF
192 This is the second text/plain part.
194 run_test
'mhstore last -part 2 -check' \
195 'storing message 11 part 2 as file 11.2.txt'
196 check
$expected 11.2.txt
'keep first'
198 # check -check with bad MD5 checksum
199 sed 's/\(Content-MD5: \)kq+Hnc/\1BADBAD/' $msgfile > $MH_TEST_DIR/$$.tmp
200 mv -f $MH_TEST_DIR/$$.tmp
$msgfile
201 run_test
'mhstore last -part 2 -check' \
202 'storing message 11 part 2 as file 11.2.txt
203 mhstore: content integrity suspect (digest mismatch) -- continuing
204 (content text/plain in message 11, part 2)'
205 check
$expected 11.2.txt
'keep first'
207 # check -nocheck, the default
208 run_test
'mhstore last -part 2 -check -nocheck' \
209 'storing message 11 part 2 as file 11.2.txt'
210 check
$expected 11.2.txt
212 # check reassembly of message/partial messages (RFC 1521, 7.3.2)
215 To: recipient@example.com
216 From: sender@example.com
219 Content-Type: message/partial; id="test-mhstore message/partial test"; number=1
221 Content-Type: text/plain; charset="iso-8859-1"
223 This is part one of three.
228 To: recipient@example.com
229 From: sender@example.com
232 Content-Type: message/partial; id="test-mhstore message/partial test"; number=2
234 This is part two of three.
239 To: recipient@example.com
240 From: sender@example.com
243 Content-Type: message/partial; id="test-mhstore message/partial test"; number=3;
246 This is part three of three.
249 run_test
'mhstore last:3' \
250 'reassembling partials 12,13,14 to folder inbox as message 15'
252 cat > $expected <<EOF
253 This is part one of three.
254 This is part two of three.
255 This is part three of three.
257 run_test
'mhstore last' 'storing message 15 as file 15.txt'
258 check
$expected 15.txt
260 # cd into Mail directory because it gets cleaned up by the exit trap.
263 # check -clobber always
264 folder
+inbox
7 > /dev
/null
266 cat > $expected <<EOF
267 This is message number 7
269 run_test
'mhstore' 'storing message 7 as file 7.txt'
270 check
$expected 7.txt
'keep first'
271 run_test
'mhstore -clobber ask -clobber always' \
272 'storing message 7 as file 7.txt'
273 check
$expected 7.txt
'keep first'
275 # check -clobber auto
277 run_test
'mhstore -clobber auto' 'storing message 7 as file 7-1.txt'
278 check
$expected 7-1.txt
'keep first'
280 run_test
'mhstore -clobber auto' 'storing message 7 as file 7-2.txt'
281 check
$expected 7-2.txt
'keep first'
283 # check -clobber suffix
284 run_test
'mhstore -clobber suffix' 'storing message 7 as file 7.txt.1'
285 check
$expected 7.txt
.1 'keep first'
287 run_test
'mhstore -clobber suffix' 'storing message 7 as file 7.txt.2'
288 check
$expected 7.txt
.2 'keep first'
290 # Don't check -clobber ask because it requires connection to a
291 # terminal, and this test won't always be run with one.
293 # check -clobber never. Its exit status is the number of files not overwritten.
294 run_test
'mhstore -clobber never' \
295 "mhstore: will not overwrite `pwd`/7.txt with -clobber never"
297 mhstore
-clobber never
>/dev
/null
2>&1
303 # check with relative nmh-storage profile component
304 storagedir
=storagedir
305 dir
="$MH_TEST_DIR/Mail/inbox/$storagedir"
307 echo "nmh-storage: $storagedir" >> $MH
308 cat > $expected <<EOF
309 This is the fourth text/plain part.
311 run_test
'mhstore 11 -part 4' \
312 "storing message 11 part 4 as file $storagedir/11.4.txt"
313 check
$expected "$dir/11.4.txt" 'keep first'
315 # check with relative nmh-storage profile component and -auto
316 run_test
'mhstore 11 -part 4 -auto' \
317 "storing message 11 part 4 as file $storagedir/test4.txt"
318 check
$expected "$dir/test4.txt" 'keep first'
320 # check with absolute nmh-storage profile component
321 absstoragedir
="$MH_TEST_DIR/$storagedir"
322 mkdir "$absstoragedir"
323 sed "s%\(nmh-storage: \)storagedir%\1$absstoragedir%" $MH > $MH.new
325 run_test
'mhstore 11 -part 4' \
326 "storing message 11 part 4 as file $storagedir/11.4.txt"
327 check
$expected "$absstoragedir/11.4.txt" 'keep first'
329 # check with absolute nmh-storage profile component and -auto
330 run_test
'mhstore 11 -part 4 -auto' \
331 "storing message 11 part 4 as file $storagedir/test4.txt"
332 check
$expected "$absstoragedir/test4.txt"
333 rmdir "$absstoragedir"