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 # Use proper program, likely not the first one on PATH.
20 rcvdist
="${MH_LIBEXEC_DIR}/rcvdist"
22 arith_eval
64000 + $$
% 1000
24 testname
="${MH_TEST_DIR}/$$"
26 check_exit
'-eq 1' $rcvdist -
28 expected
=$MH_TEST_DIR/$$.expected
29 actual
=$MH_TEST_DIR/$$.actual
35 Usage: rcvdist [switches] [switches for postproc] address ...
42 #### Skip nmh intro text.
43 run_prog
"$rcvdist" -help 2>&1 | sed '/^$/,$d' >"$actual"
44 check
"$expected" "$actual"
50 * ) printf '%s: rcvdist -v generated unexpected output\n' "$0" >&2
51 failed
=`expr ${failed:-0} + 1`;;
54 # check unknown switch
55 start_test
'unknown switch'
56 run_test
"$rcvdist -nonexistent" \
57 'rcvdist: usage: rcvdist [switches] [switches for postproc] address ...'
59 # check with no switches
60 start_test
'no switches'
62 'rcvdist: usage: rcvdist [switches] [switches for postproc] address ...'
64 #### Use fakesmtp for this first test.
65 # check post switch with argument
66 start_test
'post switch with argument'
68 cat > "${MH_TEST_DIR}/Mail/draft" <<EOF
69 From: Mr Nobody <nobody@example.com>
70 To: Somebody Else <somebody@example.com>
73 Content-Type: text/plain; charset="us-ascii"
74 Date: Sun, 14 Jan 2018 12:00:00 -0500
79 cat > "${testname}.expected" <<EOF
80 EHLO nosuchhost.example.com
81 MAIL FROM:<somebody@example.com>
82 RCPT TO:<somebody@example.com>
84 From: Mr Nobody <nobody@example.com>
85 To: Somebody Else <somebody@example.com>
88 Content-Type: text/plain; charset="us-ascii"
90 Resent-To: somebody@example.com
91 Resent-From: Somebody Else <somebody@example.com>
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%>
106 # Set this for the EHLO command
107 echo "clientname: nosuchhost.example.com" >> ${MHMTSCONF}
109 # $1: message draft file
110 # $2: output filename for fakesmtp, i.e., the sent message
113 pid
=`"${MH_OBJ_DIR}/test/fakesmtp" "$2" $localport`
115 run_prog
$rcvdist -form "$MH_TEST_DIR/Mail/rcvdistcomps" -server 127.0.0.1 -port $localport somebody@example.com
<$1
117 sed -e 's/^Date:.*/Date:/' -e 's/^Resent-Date:.*/Resent-Date:/' "$2" > "$2".nodate
120 check
"$2".nodate
"$3"
123 test_post
"${MH_TEST_DIR}/Mail/draft" "${testname}.fakesmtp" "${testname}.expected"
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"
131 # arguments: rcvdist switches
134 run_prog
$rcvdist "$@"
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"
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"
146 check
"$expected" "$actual"
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>
161 This is message number 1
164 test_rcvdist recipient@example.com
< "$MH_TEST_DIR/Mail/inbox/1"
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>
178 This is message number 2
181 test_rcvdist
-form "$MH_TEST_DIR/Mail/rcvdistcomps" recipient@example.com \
182 < "$MH_TEST_DIR/Mail/inbox/2"