Here's a better test of Resent-From: in test-rcvdist: use the user's
[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 # check with address
54 # Replace post:
55 cat >"$MH_TEST_DIR/Mail/notpost" <<EOF
56 if grep '^Resent-From: ' "\$2" >/dev/null; then
57   cp "\$2" "$actual"
58 else
59   printf 'post: message has no Resent-From: header\n'
60   printf 'post: See default components files for examples\n'
61   printf 'post: re-format message and try again\n'
62   exit 1
63 fi
64 EOF
65 chmod u+x "$MH_TEST_DIR/Mail/notpost"
66 sed 's/postproc:.*/#:/' "$MH" > "${MH}-new"
67 printf "postproc: $MH_TEST_DIR/Mail/notpost\n" >>"${MH}-new"
68 mv -f "${MH}-new" "$MH"
69
70 #### An extra space gets inserted between each header field name
71 #### and body.  That probably should be fixed.
72 cat > "$expected" <<EOF
73 From:  Test1 <test1@example.com>
74 To:  Some User <user@example.com>
75 Date:  Fri, 29 Sep 2006 00:00:00
76 Subject:  Testing message 1
77 Resent-From:  `${MH_LIB_DIR}/ap -format '%(localmbox)' 0`
78 Resent-To:  recipient@example.com
79
80 This is message number 1
81 EOF
82
83 $rcvdist recipient@example.com < "$MH_TEST_DIR/Mail/inbox/1"
84 check "$expected" "$actual"
85
86 # check -form
87 cat > "$expected" <<EOF
88 From:  Test1 <test1@example.com>
89 To:  Some User <user@example.com>
90 Date:  Fri, 29 Sep 2006 00:00:00
91 Subject:  Testing message 1
92 Resent-To: recipient@example.com
93 Resent-From: Some User <user@example.com>
94
95 This is message number 1
96 EOF
97
98 cat > "$MH_TEST_DIR/Mail/rcvdistcomps" <<'EOF'
99 %(lit)%(formataddr{addresses})\
100 %<(nonnull)%(void(width))%(putaddr Resent-To:)%>
101 %(lit)%(formataddr{to})\
102 %<(nonnull)%(void(width))%(putaddr Resent-From:)\n%>
103 EOF
104
105 $rcvdist -form "$MH_TEST_DIR/Mail/rcvdistcomps" recipient@example.com < \
106   "$MH_TEST_DIR/Mail/inbox/1"
107 check "$expected" "$actual"
108
109 exit ${failed:-0}