]> diplodocus.org Git - nmh/blob - test/slocal/test-slocal
Removed obsolete spec for default password with -sasl for POP.
[nmh] / test / slocal / test-slocal
1 #!/bin/sh
2 ######################################################
3 #
4 # Test slocal
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 # Use proper program, maybe not the first one on PATH.
20 slocal="$MH_LIBEXEC_DIR"/slocal
21
22 check_exit '-eq 1' $slocal -
23
24 expected="$MH_TEST_DIR"/$$.expected
25 actual="$MH_TEST_DIR"/$$.actual
26 actual2="$MH_TEST_DIR"/$$.actual2
27 md="$MH_TEST_DIR"/Mail/maildelivery
28
29 # check -help
30 cat >"$expected" <<EOF
31 Usage: slocal [switches]
32 switches are:
33 -addr address
34 -user name
35 -file file
36 -sender address
37 -mailbox file
38 -info data
39 -maildelivery file
40 -[no]verbose
41 -[no]suppressdup
42 -debug
43 -version
44 -help
45 EOF
46
47 #### Skip nmh intro text.
48 run_prog $slocal -help 2>&1 | sed '/^$/,$d' >"$actual"
49 check "$expected" "$actual"
50
51 # check -version
52 case `$slocal -vers` in
53 slocal\ --*) ;;
54 * ) printf '%s: slocal -vers generated unexpected output\n' "$0" >&2
55 failed=`expr ${failed:-0} + 1`;;
56 esac
57
58 # check unknown switch
59 run_test "$slocal -nonexistent" 'slocal: -nonexistent unknown'
60
61 # check non-switch argument
62 run_test "$slocal nonexistent" 'slocal: only switch arguments are supported'
63
64 # If no mail spool, explicitly specify the mailbox.
65 if grep 'mmdfldir:.*/dev/null' ${MHMTSCONF}.old >/dev/null; then
66 mbox="-mailbox ${MH_TEST_DIR}/Mail/mbox"
67 else
68 mbox=
69 fi
70
71 #### Need to specify full path to tee on Cygwin.
72 [ -x /usr/bin/tee ] && tee=/usr/bin/tee || tee=tee
73
74 # check basic operation
75 # Can't use rcvstore because slocal wipes out the environment.
76 # So, it would put the message in the user's inbox, not the
77 # test inbox. slocal also freopens stdout and stderr to
78 # /dev/null, so we can't view them to verify simulated delivery.
79 cat >"$md" <<EOF
80 * - qpipe A "$tee $actual"
81 EOF
82 chmod go-w "$md"
83
84 run_prog $slocal -maildelivery "$md" $mbox <"$MH_TEST_DIR"/Mail/inbox/1
85 check "$MH_TEST_DIR/Mail/inbox/1" "$actual" 'keep first'
86
87 if [ ${failed:-0} -eq 1 ]; then
88 printf "\nRerunning failed basic slocal command with -verbose -debug to help
89 diagnose test failure . . .\n\n"
90 run_prog $slocal -verbose -debug -maildelivery "$md" $mbox \
91 <"$MH_TEST_DIR"/Mail/inbox/1
92 exit 1
93 fi
94
95 # check -debug
96 run_prog $slocal -debug -maildelivery "$md" $mbox <"$MH_TEST_DIR"/Mail/inbox/1 \
97 >"$actual2" 2>&1
98 run_test "grep ^retrieving $actual2" 'retrieving message from stdin'
99
100 # check -verbose
101 run_prog $slocal -verbose -maildelivery "$md" $mbox \
102 <"$MH_TEST_DIR"/Mail/inbox/1 >"$actual2" 2>&1
103 run_test "grep ^delivering $actual2" "delivering to pipe \"$tee\", success."
104
105 # check -noverbose
106 run_prog $slocal -verbose -noverbose -maildelivery "$md" $mbox \
107 <"$MH_TEST_DIR"/Mail/inbox/1 >"$actual2" 2>&1
108 run_test "grep ^delivering $actual2" ''
109 rm -f "$actual2"
110
111 # check match of From
112 cat >"$md" <<EOF
113 From test2@example.com qpipe A "$tee $actual"
114 EOF
115
116 run_prog $slocal -maildelivery "$md" $mbox <"$MH_TEST_DIR"/Mail/inbox/2
117 check "$MH_TEST_DIR/Mail/inbox/2" "$actual" 'keep first'
118
119 # check R and ?
120 cat >"$md" <<EOF
121 From test3@example.com qpipe R "$tee $actual"
122 From test3@example.com qpipe ? "$tee $actual2"
123 EOF
124
125 run_prog $slocal -maildelivery "$md" $mbox <"$MH_TEST_DIR"/Mail/inbox/3
126 check "$MH_TEST_DIR/Mail/inbox/3" "$actual" 'keep first'
127 check "$MH_TEST_DIR/Mail/inbox/3" "$actual2" 'keep first'
128
129 # check R and N
130 cat >"$md" <<EOF
131 From test4@example.com qpipe R "$tee $actual"
132 From test4@example.com qpipe N "$tee $actual2"
133 EOF
134
135 run_prog $slocal -maildelivery "$md" $mbox <"$MH_TEST_DIR"/Mail/inbox/4
136 check "$MH_TEST_DIR/Mail/inbox/4" "$actual" 'keep first'
137 check "$MH_TEST_DIR/Mail/inbox/4" "$actual2" 'keep first'
138
139 # check default
140 cat >"$md" <<EOF
141 From test5@example.com qpipe R "$tee $actual"
142 default 1 qpipe A "$tee $actual2"
143 EOF
144
145 run_prog $slocal -maildelivery "$md" $mbox <"$MH_TEST_DIR"/Mail/inbox/5
146 check "$MH_TEST_DIR/Mail/inbox/5" "$actual" 'keep first'
147 check "$MH_TEST_DIR/Mail/inbox/5" "$actual2" 'keep first'
148
149 # check -addr
150 cat >"$md" <<EOF
151 addr someaddress qpipe A "$tee $actual"
152 EOF
153
154 run_prog $slocal -addr someaddress -maildelivery "$md" $mbox \
155 <"$MH_TEST_DIR"/Mail/inbox/6
156 check "$MH_TEST_DIR/Mail/inbox/6" "$actual" 'keep first'
157
158 # check -addr with . in address
159 cat >"$md" <<EOF
160 addr "first.last" qpipe A "$tee $actual"
161 EOF
162 run_prog $slocal -addr 'first.last' \
163 -maildelivery "$md" $mbox <"$MH_TEST_DIR"/Mail/inbox/6
164 check "$MH_TEST_DIR/Mail/inbox/6" "$actual" 'keep first'
165
166 # check -info
167 cat >"$md" <<EOF
168 * - qpipe A "\$(info) $actual"
169 EOF
170
171 run_prog $slocal -info $tee -maildelivery "$md" $mbox \
172 <"$MH_TEST_DIR"/Mail/inbox/7
173 check "$MH_TEST_DIR/Mail/inbox/7" "$actual" 'keep first'
174
175 # check -sender, which is compared with "source"
176 cat >"$md" <<EOF
177 source somesender qpipe A "$tee $actual"
178 EOF
179
180 run_prog $slocal -sender somesender -maildelivery "$md" $mbox \
181 <"$MH_TEST_DIR"/Mail/inbox/8
182 check "$MH_TEST_DIR/Mail/inbox/8" "$actual" 'keep first'
183
184 # check -user
185 cat >"$md" <<EOF
186 * - qpipe A "$tee $actual"
187 EOF
188
189 # Use current login for user because it must be an existing user on the host.
190 me=`"$MH_LIBEXEC_DIR"/ap -format '%(me)' 0`
191 run_prog $slocal -user "$me" -maildelivery "$md" $mbox \
192 <"$MH_TEST_DIR"/Mail/inbox/9
193 check "$MH_TEST_DIR/Mail/inbox/9" "$actual" 'keep first'
194
195 # Can't check -user with . in address because the user must
196 # have an account on the local system, and we can't guarantee
197 # that there is one.
198
199 # check -mailbox
200 cat >"$md" <<EOF
201 EOF
202
203 run_prog $slocal -mailbox "$actual" -maildelivery "$md" \
204 <"$MH_TEST_DIR"/Mail/inbox/10
205 inc -file "$actual" -silent -truncate
206 rm -f "$actual"
207 check "$MH_TEST_DIR/Mail/inbox/10" "$MH_TEST_DIR/Mail/inbox/11" 'keep first'
208
209 # check -file
210 run_prog $slocal -mailbox "$actual" -maildelivery "$md" \
211 -file "$MH_TEST_DIR"/Mail/inbox/1
212 inc -file "$actual" -silent -truncate
213 rm -f "$actual"
214 check "$MH_TEST_DIR/Mail/inbox/1" "$MH_TEST_DIR/Mail/inbox/11" 'keep first'
215
216 # check -suppressdup
217 cat >"$md" <<EOF
218 * - qpipe A "$tee $actual"
219 EOF
220
221 run_prog $slocal -suppressdup -maildelivery "$md" $mbox \
222 <"$MH_TEST_DIR"/Mail/inbox/2
223 check "$MH_TEST_DIR/Mail/inbox/2" "$actual" 'keep first'
224
225 run_prog $slocal -suppressdup -maildelivery "$md" $mbox \
226 <"$MH_TEST_DIR"/Mail/inbox/2
227 if [ -f "$actual" ]; then
228 echo $0: check -suppressdup failed
229 failed=`expr ${failed:-0} + 1`
230 fi
231
232 # check -nosuppressdup
233 run_prog $slocal -suppress -nosuppressdup -maildelivery "$md" $mbox \
234 <"$MH_TEST_DIR"/Mail/inbox/2
235 check "$MH_TEST_DIR/Mail/inbox/2" "$actual" 'keep first'
236
237 exit ${failed:-0}