1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205
|
#!/bin/sh
######################################################
#
# Test sendfiles
#
######################################################
set -e
if test -z "$MH_OBJ_DIR"; then
srcdir=`dirname $0`/../..
MH_OBJ_DIR=`cd $srcdir && pwd`; export MH_OBJ_DIR
fi
. "$MH_OBJ_DIR/test/common.sh"
setup_test
expected=$MH_TEST_DIR/$$.expected
actual=$MH_TEST_DIR/$$.actual
localmbox=`$MH_LIBEXEC_DIR/ap -format "%(localmbox)" 0`
#### Use this script itself for the test file.
testfiledir="$srcdir/test/post"
testfile=`basename $0`
(cd "$MH_TEST_DIR" && mkdir -p tmp)
#### Copy fakesendmail and the testfile because we cd to the
#### test directory, because tar doesn't like absolute paths.
cp "$srcdir/test/fakesendmail" "$testfiledir/$testfile" "$MH_TEST_DIR"
#### Use sendmail/pipe below to override default mts.
mts_fakesendmail="$MHMTSCONF-fakesendmail"
sed -e 's/^mts:.*/mts: sendmail\/pipe/' "$MHMTSCONF" > "$mts_fakesendmail"
printf 'sendmail: %s/fakesendmail\n' "$MH_TEST_DIR" >>"$mts_fakesendmail"
MHMTSCONF="$mts_fakesendmail"
# $1: uncompress command
# $2: argument style:
# new: -to recipient -subject subject
# old: recipient subject
# remaining arguments: sendfiles switches
test_sendfiles ()
{
uncompress="$1"; shift
argstyle="$1"; shift
if [ "$argstyle" = 'new' ]; then
(cd "$MH_TEST_DIR" &&
run_prog sendfiles "$@" -to recipient@example.com \
-subject "sendfiles test" "$testfile" >/dev/null 2>&1)
elif [ "$argstyle" = 'old' ]; then
(cd "$MH_TEST_DIR" &&
run_prog sendfiles "$@" recipient@example.com "sendfiles test" \
"$testfile" >/dev/null 2>&1)
fi
# fakesendmail drops the message and any cc's into this mbox.
mbox="$MH_TEST_DIR"/Mail/fakesendmail.mbox
inc -silent -file "$mbox"
rm -f "$mbox"
mhlist -verbose last | sed -e 's/ *$//' -e 's/\(octet-stream\).*$/\1/' \
>"$actual"
(cd $MH_TEST_DIR/tmp &&
contents=`mhstore -noauto last 2>&1 | \
sed -e 's/storing message.*as file //'` &&
$uncompress <"$contents" | tar xpf - && rm -f "$contents")
rmm last
check "$testfiledir/$testfile" "$MH_TEST_DIR/tmp/$testfile" \
'keep first'
[ -f "$expected" ] && check "$expected" "$actual" || rm -f "$actual"
}
# check -help
start_test "-help"
cat >"$expected" <<EOF
Usage: sendfiles [switches] -to recipient -subject subject file1 [file2 ...]
or
sendfiles [switches] recipient subject file1 [file2 ...]
switches are:
-compress [bzip2 | compress | gzip | lzma | none]
-from <sender>
-version
-help
Can use PERSON environment variable instead of -from switch.
EOF
#### Skip nmh intro text.
run_prog sendfiles -help 2>&1 | sed '/^$/,$d' >"$actual"
check "$expected" "$actual"
# check -version
start_test "-version"
case `sendfiles -v` in
sendfiles\ --*) ;;
* ) printf '%s: sendfiles -v generated unexpected output\n' "$0" >&2
failed=`expr ${failed:-0} + 1`;;
esac
# check unknown switch
start_test "unknown switch"
run_test 'sendfiles -nonexistent' "Usage: sendfiles [switches] -to recipient \
-subject subject file1 [file2 ...]
or
sendfiles [switches] recipient subject file1 [file2 ...]
switches are:
-compress [bzip2 | compress | gzip | lzma | none]
-from <sender>
-version
-help
Can use PERSON environment variable instead of -from switch."
# check unknown compression method
start_test "unknown compression method"
run_test 'sendfiles -compress unknown to subject file' \
'sendfiles: unknown compression method "unknown"'"
Usage: sendfiles [switches] -to recipient \
-subject subject file1 [file2 ...]
or
sendfiles [switches] recipient subject file1 [file2 ...]
switches are:
-compress [bzip2 | compress | gzip | lzma | none]
-from <sender>
-version
-help
Can use PERSON environment variable instead of -from switch."
# Check basic operation, using specified compression method.
start_test "basic operation, using specified compression method."
# Don't check the mhlist output, by not creating an $expected file,
# because it will vary with compression method and compressed file
# size.
[ "`findprog bzip2`" ] && test_sendfiles 'bzip2 -cd' new -compress bzip2
[ "`findprog compress`" ] && test_sendfiles 'uncompress -c' new \
-compress compress
[ "`findprog gzip`" ] && test_sendfiles 'gzip -cd' new -compress gzip
[ "`findprog gzip`" ] && test_sendfiles 'gzip -cd' new -gzip
# lzma refuses to decompress file 11.tar: "unknown suffix -- unchanged"
# even with -f; -c seems to work only if input redirected
# [ "`findprog lzma`" ] && test_sendfiles 'lzma -cd' new -compress lzma
# check with no compression
start_test "with no compression"
cat >"$expected" <<EOF
msg part type/subtype size description
11 application/octet-stream
type="tar"
(extract with cat | tar xvpf -)
EOF
test_sendfiles cat new -compress none
# check with no compression, -none
start_test "with no compression, -none"
cat >"$expected" <<EOF
msg part type/subtype size description
11 application/octet-stream
type="tar"
(extract with cat | tar xvpf -)
EOF
test_sendfiles cat new -none
# check old argument style (without -to and -subject)
start_test "old argument style (without -to and -subject)"
cat >"$expected" <<EOF
msg part type/subtype size description
11 application/octet-stream
type="tar"
(extract with cat | tar xvpf -)
EOF
test_sendfiles cat old -compress none
# check -from
start_test "-from"
cat >"$expected" <<EOF
msg part type/subtype size description
11 application/octet-stream
type="tar"
(extract with cat | tar xvpf -)
EOF
test_sendfiles cat new -compress none -from 'Sender <sender@example.com>'
# check PERSON environment variable
start_test "PERSON environment variable"
cat >"$expected" <<EOF
msg part type/subtype size description
11 application/octet-stream
type="tar"
(extract with cat | tar xvpf -)
EOF
PERSON='Sender <sender@example.com>' test_sendfiles cat new -compress none
rm -fr "$MH_TEST_DIR/fakesendmail" "$MH_TEST_DIR/$testfile" "$MH_TEST_DIR/tmp"
finish_test
exit ${failed:-0}
|