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
=`run_prog mhstore -file - < $MH_TEST_DIR/Mail/inbox/5 2>&1 | \
51 check
$expected $stored_contents 'keep first'
54 run_prog 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 run_prog 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 VGhpcyBpcyB0aGUgZm91cnRoIHRleHQvcGxhaW4gcGFydC4NClRoaXMgdGVzdCBoYXMgbXVsdGlw
122 ------- =_aaaaaaaaaa0--
126 cat > $expected <<EOF
127 This is the third text/plain part.
129 run_test
'mhstore last -part 3' 'storing message 11 part 3 as file 11.3.txt'
130 check
$expected 11.3.txt
132 # check -part of a subpart
133 cat > $expected <<EOF
134 This is the first text/plain part, in a subpart.
136 run_test
'mhstore last -part 1.1' \
137 'storing message 11 part 1.1 as file 11.1.1.txt'
138 check
$expected 11.1.1.txt
'keep first'
141 run_test
'mhstore last -type text/plain' \
142 'storing message 11 part 1.1 as file 11.1.1.txt
143 storing message 11 part 2 as file 11.2.txt
144 storing message 11 part 3 as file 11.3.txt
145 storing message 11 part 4 as file 11.4.txt'
146 check
$expected 11.1.1.txt
147 cat > $expected <<EOF
148 This is the second text/plain part.
150 check
$expected 11.2.txt
151 cat > $expected <<EOF
152 This is the third text/plain part.
154 check
$expected 11.3.txt
155 cat > $expected <<EOF
156 This is the fourth text/plain part.
157 This test has multiple lines.
159 check
$expected 11.4.txt
162 cat > $expected <<EOF
163 This is the fourth text/plain part.
164 This test has multiple lines.
166 run_test
'mhstore last -part 4 -auto' \
167 'storing message 11 part 4 as file test4.txt'
168 check
$expected test4.txt
'keep first'
170 # check -noauto, the default
171 run_test
'mhstore last -part 4 -auto -noauto' \
172 'storing message 11 part 4 as file 11.4.txt'
173 check
$expected 11.4.txt
'keep first'
175 # check -verbose, which doesn't do anything
176 run_test
'mhstore last -part 4 -verbose' \
177 'storing message 11 part 4 as file 11.4.txt'
178 check
$expected 11.4.txt
'keep first'
180 # check -noverbose, the default
181 run_test
'mhstore last -part 4 -verbose -noverbose' \
182 'storing message 11 part 4 as file 11.4.txt'
183 check
$expected 11.4.txt
185 # check that -auto obeys Content-Disposition header
186 cat > $expected <<EOF
187 This is the first text/plain part, in a subpart.
189 run_test
'mhstore last -part 1.1 -auto' \
190 'storing message 11 part 1.1 as file test1.txt'
191 check
$expected test1.txt
194 cat > $expected <<EOF
195 This is the second text/plain part.
197 run_test
'mhstore last -part 2 -check' \
198 'storing message 11 part 2 as file 11.2.txt'
199 check
$expected 11.2.txt
'keep first'
201 # check -check with bad MD5 checksum
202 sed 's/\(Content-MD5: \)kq+Hnc/\1BADBAD/' $msgfile > $MH_TEST_DIR/$$.tmp
203 mv -f $MH_TEST_DIR/$$.tmp
$msgfile
204 run_test
'mhstore last -part 2 -check' \
205 'storing message 11 part 2 as file 11.2.txt
206 mhstore: content integrity suspect (digest mismatch) -- continuing
207 (content text/plain in message 11, part 2)'
208 check
$expected 11.2.txt
'keep first'
210 # check -nocheck, the default
211 run_test
'mhstore last -part 2 -check -nocheck' \
212 'storing message 11 part 2 as file 11.2.txt'
213 check
$expected 11.2.txt
215 # check reassembly of message/partial messages (RFC 1521, 7.3.2)
218 To: recipient@example.com
219 From: sender@example.com
222 Content-Type: message/partial; id="test-mhstore message/partial test"; number=1
224 Content-Type: text/plain; charset="iso-8859-1"
226 This is part one of three.
231 To: recipient@example.com
232 From: sender@example.com
235 Content-Type: message/partial; id="test-mhstore message/partial test"; number=2
237 This is part two of three.
242 To: recipient@example.com
243 From: sender@example.com
246 Content-Type: message/partial; id="test-mhstore message/partial test"; number=3;
249 This is part three of three.
252 run_test
'mhstore last:3' \
253 'reassembling partials 12,13,14 to folder inbox as message 15'
255 cat > $expected <<EOF
256 This is part one of three.
257 This is part two of three.
258 This is part three of three.
260 run_test
'mhstore last' 'storing message 15 as file 15.txt'
261 check
$expected 15.txt
263 # cd into Mail directory because it gets cleaned up by the exit trap.
266 # check -clobber always
267 folder
+inbox
7 > /dev
/null
269 cat > $expected <<EOF
270 This is message number 7
272 run_test
'mhstore' 'storing message 7 as file 7.txt'
273 check
$expected 7.txt
'keep first'
274 run_test
'mhstore -clobber ask -clobber always' \
275 'storing message 7 as file 7.txt'
276 check
$expected 7.txt
'keep first'
278 # check -clobber auto
280 run_test
'mhstore -clobber auto' 'storing message 7 as file 7-1.txt'
281 check
$expected 7-1.txt
'keep first'
283 run_test
'mhstore -clobber auto' 'storing message 7 as file 7-2.txt'
284 check
$expected 7-2.txt
'keep first'
286 # check -clobber suffix
287 run_test
'mhstore -clobber suffix' 'storing message 7 as file 7.txt.1'
288 check
$expected 7.txt
.1 'keep first'
290 run_test
'mhstore -clobber suffix' 'storing message 7 as file 7.txt.2'
291 check
$expected 7.txt
.2 'keep first'
293 # Don't check -clobber ask because it requires connection to a
294 # terminal, and this test won't always be run with one.
296 # check -clobber never. Its exit status is the number of files not overwritten.
297 run_test
'mhstore -clobber never' \
298 "mhstore: will not overwrite `pwd`/7.txt with -clobber never"
300 mhstore
-clobber never
>/dev
/null
2>&1
306 # check with relative nmh-storage profile component
307 storagedir
=storagedir
308 dir
="$MH_TEST_DIR/Mail/inbox/$storagedir"
310 echo "nmh-storage: $storagedir" >> $MH
311 cat > $expected <<EOF
312 This is the fourth text/plain part.
313 This test has multiple lines.
315 run_test
'mhstore 11 -part 4' \
316 "storing message 11 part 4 as file $storagedir/11.4.txt"
317 check
$expected "$dir/11.4.txt" 'keep first'
319 # check with relative nmh-storage profile component and -auto
320 run_test
'mhstore 11 -part 4 -auto' \
321 "storing message 11 part 4 as file $storagedir/test4.txt"
322 check
$expected "$dir/test4.txt" 'keep first'
324 # check with absolute nmh-storage profile component
325 absstoragedir
="$MH_TEST_DIR/$storagedir"
326 mkdir "$absstoragedir"
327 sed "s%\(nmh-storage: \)storagedir%\1$absstoragedir%" $MH > $MH.new
329 run_test
'mhstore 11 -part 4' \
330 "storing message 11 part 4 as file $storagedir/11.4.txt"
331 check
$expected "$absstoragedir/11.4.txt" 'keep first'
333 # check with absolute nmh-storage profile component and -auto
334 run_test
'mhstore 11 -part 4 -auto' \
335 "storing message 11 part 4 as file $storagedir/test4.txt"
336 check
$expected "$absstoragedir/test4.txt"
337 rmdir "$absstoragedir"