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/$$.expected
20 expected_err=$MH_TEST_DIR/$$.expected_err
21 actual=$MH_TEST_DIR/$$.actual
22 actual_err=$MH_TEST_DIR/$$.actual_err
23 localmbox=`$MH_LIB_DIR/ap -format "%(localmbox)" 0`
24 #### Use this script itself for the test file.
25 testfiledir="$srcdir/test/post"
26 testfile=`basename $0`
30 cat >"$expected_err" <<EOF
34 #### Copy fakesendmail and the testfile because we cd to the
35 #### test directory, because tar doesn't like absolute paths.
36 cp "$srcdir/test/fakesendmail" "$testfiledir/$testfile" "$MH_TEST_DIR"
38 #### Use sendmail/pipe below to override default mts.
39 mts_fakesendmail="$MHMTSCONF-fakesendmail"
40 sed -e 's/^mts:.*/mts: sendmail\/pipe/' "$MHMTSCONF" > "$mts_fakesendmail"
41 printf 'sendmail: %s/fakesendmail\n' "$MH_TEST_DIR" >>"$mts_fakesendmail"
42 MHMTSCONF="$mts_fakesendmail"
44 # $1: uncompress command
46 # new: -to recipient -subject subject
47 # old: recipient subject
48 # remaining arguments: sendfiles switches
51 uncompress="$1"; shift
54 if [ "$argstyle" = 'new' ]; then
56 sendfiles "$@" -to recipient@example.com -subject "sendfiles test" \
57 "$testfile" >/dev/null 2>"$actual_err")
58 elif [ "$argstyle" = 'old' ]; then
60 sendfiles "$@" recipient@example.com "sendfiles test" \
61 "$testfile" >/dev/null 2>"$actual_err")
64 check "$expected_err" "$actual_err" 'keep first'
66 # fakesendmail drops the message and any cc's into this mbox.
67 mbox="$MH_TEST_DIR"/Mail/fakesendmail.mbox
68 inc -silent -file "$mbox"
69 rm -f "$mbox" "$mbox.map"
71 mhlist -verbose last | sed -e 's/ *$//' >"$actual"
72 (cd $MH_TEST_DIR/tmp &&
73 contents=`mhstore -noauto last 2>&1 | \
74 sed -e 's/storing message.*as file //'` &&
75 $uncompress "$contents" | tar xpf - && rm -f "$contents")
78 check "$testfiledir/$testfile" "$MH_TEST_DIR/tmp/$testfile" \
81 [ -f "$expected" ] && check "$expected" "$actual" || rm -f "$actual"
86 cat >"$expected" <<EOF
87 Usage: sendfiles [switches] -to recipient -subject subject file1 [file2 ...]
89 sendfiles [switches] recipient subject file1 [file2 ...]
91 -compress [bzip2 | compress | gzip | lzma | none | zip]
93 -[delay] <delay> (expressed in seconds)
96 Can use PERSON environment variable instead of -from switch.
99 sendfiles -help >"$actual" 2>&1
100 check "$expected" "$actual"
103 case `sendfiles -v` in
105 * ) printf '%s: sendfiles -v generated unexpected output\n' "$0" >&2
106 failed=`expr ${failed:-0} + 1`;;
109 # check unknown switch
110 run_test 'sendfiles -nonexistent' "Usage: sendfiles [switches] -to recipient \
111 -subject subject file1 [file2 ...]
113 sendfiles [switches] recipient subject file1 [file2 ...]
115 -compress [bzip2 | compress | gzip | lzma | none | zip]
117 -[delay] <delay> (expressed in seconds)
120 Can use PERSON environment variable instead of -from switch."
122 # check unknown compression method
123 run_test 'sendfiles -compress unknown to subject file' \
124 'sendfiles: unknown compression method "unknown"'"
125 Usage: sendfiles [switches] -to recipient \
126 -subject subject file1 [file2 ...]
128 sendfiles [switches] recipient subject file1 [file2 ...]
130 -compress [bzip2 | compress | gzip | lzma | none | zip]
132 -[delay] <delay> (expressed in seconds)
135 Can use PERSON environment variable instead of -from switch."
137 # Check basic operation, using specified compression method.
138 # Don't check the mhlist output, by not creating an $expected file,
139 # because it will vary with compression method and compressed file
141 [ "`findprog bzip2`" ] && test_sendfiles 'bzip2 -cd' new -compress bzip2
142 [ "`findprog compress`" ] && test_sendfiles uncompress new -compress compress
143 [ "`findprog gzip`" ] && test_sendfiles 'gzip -cd' new -compress gzip
144 [ "`findprog gzip`" ] && test_sendfiles 'gzip -cd' new -gzip
145 [ "`findprog lzma`" ] && test_sendfiles 'lzma -cd' new -compress lzma
146 [ "`findprog zip`" ] && test_sendfiles 'unzip -p' new -compress zip
148 # check with no compression
149 cat >"$expected" <<EOF
150 msg part type/subtype size description
151 11 application/octet-stream 10K
153 (extract with cat | tar xvpf -)
156 test_sendfiles cat new -compress none
158 # check with no compression, -none
159 cat >"$expected" <<EOF
160 msg part type/subtype size description
161 11 application/octet-stream 10K
163 (extract with cat | tar xvpf -)
166 test_sendfiles cat new -none
168 # check old argument style (without -to and -subject)
169 cat >"$expected" <<EOF
170 msg part type/subtype size description
171 11 application/octet-stream 10K
173 (extract with cat | tar xvpf -)
176 test_sendfiles cat old -compress none
179 cat >"$expected" <<EOF
180 msg part type/subtype size description
181 11 application/octet-stream 10K
183 (extract with cat | tar xvpf -)
186 test_sendfiles cat new -compress none -from 'Sender <sender@example.com>'
188 # check PERSON environment variable
189 cat >"$expected" <<EOF
190 msg part type/subtype size description
191 11 application/octet-stream 10K
193 (extract with cat | tar xvpf -)
196 PERSON='Sender <sender@example.com>' test_sendfiles cat new -compress none
198 # check -delay, though for a small file it doesn't do anything
199 cat >"$expected" <<EOF
200 msg part type/subtype size description
201 11 application/octet-stream 10K
203 (extract with cat | tar xvpf -)
206 test_sendfiles cat new -compress none -delay 5
208 # check old style -delay, though for a small file it doesn't do anything
209 cat >"$expected" <<EOF
210 msg part type/subtype size description
211 11 application/octet-stream 10K
213 (extract with cat | tar xvpf -)
216 test_sendfiles cat new -compress none -5
218 rm -fr "$MH_TEST_DIR/fakesendmail" "$MH_TEST_DIR/$testfile" \
219 "$expected_err" "$MH_TEST_DIR/tmp"