]> diplodocus.org Git - nmh/blob - test/post/test-sendfiles
Add support for a -nosasl switch.
[nmh] / test / post / test-sendfiles
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_LIB_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 sendfiles "$@" -to recipient@example.com -subject "sendfiles test" \
51 "$testfile" >/dev/null 2>&1)
52 elif [ "$argstyle" = 'old' ]; then
53 (cd "$MH_TEST_DIR" &&
54 sendfiles "$@" recipient@example.com "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" "$mbox.map"
62
63 mhlist -verbose last | sed -e 's/ *$//' >"$actual"
64 (cd $MH_TEST_DIR/tmp &&
65 contents=`mhstore -noauto last 2>&1 | \
66 sed -e 's/storing message.*as file //'` &&
67 $uncompress "$contents" | tar xpf - && rm -f "$contents")
68
69 rmm last
70 check "$testfiledir/$testfile" "$MH_TEST_DIR/tmp/$testfile" \
71 'keep first'
72
73 [ -f "$expected" ] && check "$expected" "$actual" || rm -f "$actual"
74 }
75
76
77 # check -help
78 cat >"$expected" <<EOF
79 Usage: sendfiles [switches] -to recipient -subject subject file1 [file2 ...]
80 or
81 sendfiles [switches] recipient subject file1 [file2 ...]
82 switches are:
83 -compress [bzip2 | compress | gzip | lzma | none]
84 -from <sender>
85 -[delay] <delay> (expressed in seconds)
86 -version
87 -help
88 Can use PERSON environment variable instead of -from switch.
89 EOF
90
91 sendfiles -help >"$actual" 2>&1
92 check "$expected" "$actual"
93
94 # check -version
95 case `sendfiles -v` in
96 sendfiles\ --*) ;;
97 * ) printf '%s: sendfiles -v generated unexpected output\n' "$0" >&2
98 failed=`expr ${failed:-0} + 1`;;
99 esac
100
101 # check unknown switch
102 run_test 'sendfiles -nonexistent' "Usage: sendfiles [switches] -to recipient \
103 -subject subject file1 [file2 ...]
104 or
105 sendfiles [switches] recipient subject file1 [file2 ...]
106 switches are:
107 -compress [bzip2 | compress | gzip | lzma | none]
108 -from <sender>
109 -[delay] <delay> (expressed in seconds)
110 -version
111 -help
112 Can use PERSON environment variable instead of -from switch."
113
114 # check unknown compression method
115 run_test 'sendfiles -compress unknown to subject file' \
116 'sendfiles: unknown compression method "unknown"'"
117 Usage: sendfiles [switches] -to recipient \
118 -subject subject file1 [file2 ...]
119 or
120 sendfiles [switches] recipient subject file1 [file2 ...]
121 switches are:
122 -compress [bzip2 | compress | gzip | lzma | none]
123 -from <sender>
124 -[delay] <delay> (expressed in seconds)
125 -version
126 -help
127 Can use PERSON environment variable instead of -from switch."
128
129 # Check basic operation, using specified compression method.
130 # Don't check the mhlist output, by not creating an $expected file,
131 # because it will vary with compression method and compressed file
132 # size.
133 [ "`findprog bzip2`" ] && test_sendfiles 'bzip2 -cd' new -compress bzip2
134 [ "`findprog compress`" ] && test_sendfiles 'uncompress -c' new \
135 -compress compress
136 [ "`findprog gzip`" ] && test_sendfiles 'gzip -cd' new -compress gzip
137 [ "`findprog gzip`" ] && test_sendfiles 'gzip -cd' new -gzip
138 [ "`findprog lzma`" ] && test_sendfiles 'lzma -cd' new -compress lzma
139
140 # check with no compression
141 cat >"$expected" <<EOF
142 msg part type/subtype size description
143 11 application/octet-stream 10K
144 type="tar"
145 (extract with cat | tar xvpf -)
146 EOF
147
148 test_sendfiles cat new -compress none
149
150 # check with no compression, -none
151 cat >"$expected" <<EOF
152 msg part type/subtype size description
153 11 application/octet-stream 10K
154 type="tar"
155 (extract with cat | tar xvpf -)
156 EOF
157
158 test_sendfiles cat new -none
159
160 # check old argument style (without -to and -subject)
161 cat >"$expected" <<EOF
162 msg part type/subtype size description
163 11 application/octet-stream 10K
164 type="tar"
165 (extract with cat | tar xvpf -)
166 EOF
167
168 test_sendfiles cat old -compress none
169
170 # check -from
171 cat >"$expected" <<EOF
172 msg part type/subtype size description
173 11 application/octet-stream 10K
174 type="tar"
175 (extract with cat | tar xvpf -)
176 EOF
177
178 test_sendfiles cat new -compress none -from 'Sender <sender@example.com>'
179
180 # check PERSON environment variable
181 cat >"$expected" <<EOF
182 msg part type/subtype size description
183 11 application/octet-stream 10K
184 type="tar"
185 (extract with cat | tar xvpf -)
186 EOF
187
188 PERSON='Sender <sender@example.com>' test_sendfiles cat new -compress none
189
190 # check -delay, though for a small file it doesn't do anything
191 cat >"$expected" <<EOF
192 msg part type/subtype size description
193 11 application/octet-stream 10K
194 type="tar"
195 (extract with cat | tar xvpf -)
196 EOF
197
198 test_sendfiles cat new -compress none -delay 5
199
200 # check old style -delay, though for a small file it doesn't do anything
201 cat >"$expected" <<EOF
202 msg part type/subtype size description
203 11 application/octet-stream 10K
204 type="tar"
205 (extract with cat | tar xvpf -)
206 EOF
207
208 test_sendfiles cat new -compress none -5
209
210 rm -fr "$MH_TEST_DIR/fakesendmail" "$MH_TEST_DIR/$testfile" "$MH_TEST_DIR/tmp"
211
212
213 exit ${failed:-0}