setup_test
-expected=$MH_TEST_DIR/$$.expected
-actual=$MH_TEST_DIR/$$.actual
+expected="$MH_TEST_DIR/test-mhstore$$.expected"
+actual="$MH_TEST_DIR/test-mhstore$$.actual"
cd $MH_TEST_DIR
# check -file -
stored_contents=`mhstore -file - < $MH_TEST_DIR/Mail/inbox/5 2>&1 | \
sed 's/.*as file //'`
-check $expected $stored_contents
+check $expected $stored_contents 'keep first'
+
+# check -outfile
+mhstore 5 -outfile "$actual" 2>&1 | grep -v '^storing' && \
+ echo unexpected output from test-mhstore check -outfile >&2
+check $expected "$actual" 'keep first'
+
+# check -outfile -
+echo 'storing message 5 to stdout' >>"$expected"
+mhstore 5 -outfile - >"$actual" 2>&1
+check $expected "$actual"
# check message number greater than highest
run_test 'mhstore 11' "mhstore: message 11 doesn't exist"
'storing message 11 part 4 as file 11.4.txt'
check $expected 11.4.txt
+# check that -auto obeys Content-Disposition header
+cat > $expected <<EOF
+This is the first text/plain part, in a subpart.
+EOF
+run_test 'mhstore last -part 1.1 -auto' \
+ 'storing message 11 part 1.1 as file test1.txt'
+check $expected test1.txt
+
# check -check
cat > $expected <<EOF
This is the second text/plain part.
run_test 'mhstore last' 'storing message 15 as file 15.txt'
check $expected 15.txt
+# cd into Mail directory because it gets cleaned up by the exit trap.
+cd Mail
+
+# check -clobber always
+folder +inbox 7 > /dev/null
+touch 7.txt
+cat > $expected <<EOF
+This is message number 7
+EOF
+run_test 'mhstore' 'storing message 7 as file 7.txt'
+check $expected 7.txt 'keep first'
+run_test 'mhstore -clobber ask -clobber always' \
+ 'storing message 7 as file 7.txt'
+check $expected 7.txt 'keep first'
+
+# check -clobber auto
+touch 7.txt
+run_test 'mhstore -clobber auto' 'storing message 7 as file 7-1.txt'
+check $expected 7-1.txt 'keep first'
+touch 7-1.txt
+run_test 'mhstore -clobber auto' 'storing message 7 as file 7-2.txt'
+check $expected 7-2.txt 'keep first'
+
+# check -clobber suffix
+run_test 'mhstore -clobber suffix' 'storing message 7 as file 7.txt.1'
+check $expected 7.txt.1 'keep first'
+touch 7.txt.1
+run_test 'mhstore -clobber suffix' 'storing message 7 as file 7.txt.2'
+check $expected 7.txt.2 'keep first'
+
+# Don't check -clobber ask because it requires connection to a
+# terminal, and this test won't always be run with one.
+
+# check -clobber never. Its exit status is the number of files not overwritten.
+run_test 'mhstore -clobber never' \
+ "mhstore: will not overwrite `pwd`/7.txt with -clobber never"
+set +e
+mhstore -clobber never >/dev/null 2>&1
+run_test "echo $?" 1
+set -e
+
+cd ..
+
# check with relative nmh-storage profile component
storagedir=storagedir
dir="$MH_TEST_DIR/Mail/inbox/$storagedir"