e49b390268d672ec2502e22178b7831ce8a9b34d
[mmh] / 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_LIB_DIR}/rcvdist"
21
22 expected=$MH_TEST_DIR/$$.expected
23 actual=$MH_TEST_DIR/$$.actual
24
25
26 # check -help
27 cat >$expected <<EOF
28 Usage: rcvdist [switches] [switches for postproc] address ...
29   switches are:
30   -(form) formfile
31   -version
32   -help
33 EOF
34
35 $rcvdist -help >"$actual" 2>&1
36 check "$expected" "$actual"
37
38 # check -version
39 case `$rcvdist -v` in
40   rcvdist\ --*) ;;
41   *           ) printf "$0: rcvdist -v generated unexpected output\n" >&2
42                 failed=`expr ${failed:-0} + 1`;;
43 esac
44
45 # check unknown switch
46 run_test "$rcvdist -nonexistent" \
47   'rcvdist: usage: rcvdist [switches] [switches for postproc] address ...'
48
49 # check with no switches
50 run_test "$rcvdist" \
51   'rcvdist: usage: rcvdist [switches] [switches for postproc] address ...'
52
53 #### Use sendmail/pipe below to override default mts.
54 mts_fakesendmail="${MHMTSCONF}-fakesendmail"
55 sed -e 's/^mts:.*/mts: sendmail\/pipe/' "${MHMTSCONF}" > "$mts_fakesendmail"
56 printf "sendmail: ${srcdir}/test/fakesendmail\n" >>"$mts_fakesendmail"
57 MHMTSCONF="$mts_fakesendmail"
58
59 # arguments: rcvdist switches
60 test_rcvdist ()
61 {
62   $rcvdist "$@"
63
64   # fakesendmail drops the message and any cc's into this mbox.
65   mbox="${MH_TEST_DIR}"/Mail/fakesendmail.mbox
66   inc -silent -file "$mbox"
67   rm -f "$mbox" "$mbox.map"
68
69   # It's hard to calculate the exact Date: header post is going to
70   # use, so we'll just use sed to remove the actual date so we can
71   # easily compare it against our "correct" output.
72   sed -e 's/^Resent-Date:.*/Resent-Date:/' `mhpath last` > "$actual"
73
74   check "$expected" "$actual"
75 }
76
77 # check with address
78
79 cat > "$expected" <<EOF
80 From: Test1 <test1@example.com>
81 To: Some User <user@example.com>
82 Date: Fri, 29 Sep 2006 00:00:00
83 Subject: Testing message 1
84 Resent-From: `${MH_LIB_DIR}/ap -format '%(localmbox)' 0`
85 Resent-To: recipient@example.com
86 Resent-Date:
87
88 This is message number 1
89 EOF
90
91 test_rcvdist recipient@example.com < "$MH_TEST_DIR/Mail/inbox/1"
92
93 # check -form
94 cat > "$expected" <<EOF
95 From: Test2 <test2@example.com>
96 To: Some User <user@example.com>
97 Date: Fri, 29 Sep 2006 00:00:00
98 Subject: Testing message 2
99 Resent-To: recipient@example.com
100 Resent-From: Some User <user@example.com>
101 Resent-Date:
102
103 This is message number 2
104 EOF
105
106 cat > "$MH_TEST_DIR/Mail/rcvdistcomps" <<'EOF'
107 %(lit)%(formataddr{addresses})\
108 %<(nonnull)%(void(width))%(putaddr Resent-To:)%>
109 %(lit)%(formataddr{to})\
110 %<(nonnull)%(void(width))%(putaddr Resent-From:)\n%>
111 EOF
112
113 test_rcvdist -form "$MH_TEST_DIR/Mail/rcvdistcomps" recipient@example.com \
114   < "$MH_TEST_DIR/Mail/inbox/2"
115
116
117 exit ${failed:-0}