]> diplodocus.org Git - nmh/blob - test/rcv/test-rcvdist
Tell make that uip/mhical.c depends on sbr/icalparse.h
[nmh] / test / rcv / test-rcvdist
1 #!/bin/sh
2 ######################################################
3 #
4 # Test rcvdist
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, likely not the first one on PATH.
20 rcvdist="${MH_LIBEXEC_DIR}/rcvdist"
21
22 arith_eval 64000 + $$ % 1000
23 localport=$arith_val
24 testname="${MH_TEST_DIR}/$$"
25
26 check_exit '-eq 1' $rcvdist -
27
28 expected=$MH_TEST_DIR/$$.expected
29 actual=$MH_TEST_DIR/$$.actual
30
31
32 # check -help
33 start_test -help
34 cat >$expected <<EOF
35 Usage: rcvdist [switches] [switches for postproc] address ...
36 switches are:
37 -(form) formfile
38 -version
39 -help
40 EOF
41
42 #### Skip nmh intro text.
43 run_prog "$rcvdist" -help 2>&1 | sed '/^$/,$d' >"$actual"
44 check "$expected" "$actual"
45
46 # check -version
47 start_test -version
48 case `$rcvdist -v` in
49 rcvdist\ --*) ;;
50 * ) printf '%s: rcvdist -v generated unexpected output\n' "$0" >&2
51 failed=`expr ${failed:-0} + 1`;;
52 esac
53
54 # check unknown switch
55 start_test 'unknown switch'
56 run_test "$rcvdist -nonexistent" \
57 'rcvdist: usage: rcvdist [switches] [switches for postproc] address ...'
58
59 # check with no switches
60 start_test 'no switches'
61 run_test "$rcvdist" \
62 'rcvdist: usage: rcvdist [switches] [switches for postproc] address ...'
63
64 #### Use fakesmtp for this first test.
65 # check post switch with argument
66 start_test 'post switch with argument'
67
68 cat > "${MH_TEST_DIR}/Mail/draft" <<EOF
69 From: Mr Nobody <nobody@example.com>
70 To: Somebody Else <somebody@example.com>
71 Subject: Test
72 MIME-Version: 1.0
73 Content-Type: text/plain; charset="us-ascii"
74 Date: Sun, 14 Jan 2018 12:00:00 -0500
75
76 This is a test.
77 EOF
78
79 cat > "${testname}.expected" <<EOF
80 EHLO nosuchhost.example.com
81 MAIL FROM:<somebody@example.com>
82 RCPT TO:<somebody@example.com>
83 DATA
84 From: Mr Nobody <nobody@example.com>
85 To: Somebody Else <somebody@example.com>
86 Subject: Test
87 MIME-Version: 1.0
88 Content-Type: text/plain; charset="us-ascii"
89 Date:
90 Resent-To: somebody@example.com
91 Resent-From: Somebody Else <somebody@example.com>
92 Resent-Date:
93
94 This is a test.
95 .
96 QUIT
97 EOF
98
99 cat > "$MH_TEST_DIR/Mail/rcvdistcomps" <<'EOF'
100 %(lit)%(formataddr{addresses})\
101 %<(nonnull)%(void(width))%(putaddr Resent-To:)%>
102 %(lit)%(formataddr{to})\
103 %<(nonnull)%(void(width))%(putaddr Resent-From:)\n%>
104 EOF
105
106 # Set this for the EHLO command
107 echo "clientname: nosuchhost.example.com" >> ${MHMTSCONF}
108
109 # $1: message draft file
110 # $2: output filename for fakesmtp, i.e., the sent message
111 test_post ()
112 {
113 pid=`"${MH_OBJ_DIR}/test/fakesmtp" "$2" $localport`
114
115 run_prog $rcvdist -form "$MH_TEST_DIR/Mail/rcvdistcomps" -server 127.0.0.1 -port $localport somebody@example.com <$1
116
117 sed -e 's/^Date:.*/Date:/' -e 's/^Resent-Date:.*/Resent-Date:/' "$2" > "$2".nodate
118 rm -f "$2"
119
120 check "$2".nodate "$3"
121 }
122
123 test_post "${MH_TEST_DIR}/Mail/draft" "${testname}.fakesmtp" "${testname}.expected"
124
125 #### Use sendmail/pipe below to override default mts.
126 mts_fakesendmail="${MHMTSCONF}-fakesendmail"
127 sed -e 's/^mts:.*/mts: sendmail\/pipe/' "${MHMTSCONF}" > "$mts_fakesendmail"
128 printf 'sendmail: %s/test/fakesendmail\n' "$srcdir" >>"$mts_fakesendmail"
129 MHMTSCONF="$mts_fakesendmail"
130
131 # arguments: rcvdist switches
132 test_rcvdist ()
133 {
134 run_prog $rcvdist "$@"
135
136 # fakesendmail drops the message and any cc's into this mbox.
137 mbox="${MH_TEST_DIR}"/Mail/fakesendmail.mbox
138 inc -silent -file "$mbox"
139 rm -f "$mbox"
140
141 # It's hard to calculate the exact Date: header post is going to
142 # use, so we'll just use sed to remove the actual date so we can
143 # easily compare it against our "correct" output.
144 sed -e 's/^Resent-Date:.*/Resent-Date:/' `mhpath last` > "$actual"
145
146 check "$expected" "$actual"
147 }
148
149 # check with address
150 start_test 'with address'
151 cat > "$expected" <<EOF
152 From: Test1 <test1@example.com>
153 To: Some User <user@example.com>
154 Date: Fri, 29 Sep 2006 00:00:00
155 Message-Id: 1@test.nmh
156 Subject: Testing message 1
157 Resent-To: recipient@example.com
158 Resent-From: Some User <user@example.com>
159 Resent-Date:
160
161 This is message number 1
162 EOF
163
164 test_rcvdist recipient@example.com < "$MH_TEST_DIR/Mail/inbox/1"
165
166 # check -form
167 start_test -form
168 cat > "$expected" <<EOF
169 From: Test2 <test2@example.com>
170 To: Some User <user@example.com>
171 Date: Fri, 29 Sep 2006 00:00:00
172 Message-Id: 2@test.nmh
173 Subject: Testing message 2
174 Resent-To: recipient@example.com
175 Resent-From: Some User <user@example.com>
176 Resent-Date:
177
178 This is message number 2
179 EOF
180
181 test_rcvdist -form "$MH_TEST_DIR/Mail/rcvdistcomps" recipient@example.com \
182 < "$MH_TEST_DIR/Mail/inbox/2"
183
184
185 finish_test
186 exit ${failed:-0}