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