]> diplodocus.org Git - nmh/blob - test/post/test-post-aliases
Moved "mhparam iconv" description to mhparam(1) man page and put
[nmh] / test / post / test-post-aliases
1 #!/bin/sh
2 ######################################################
3 #
4 # Test aliases all the way through post
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 . "${srcdir}/test/post/test-post-common.sh"
16
17 # Note that the last address in the blind list does not end with a
18 # semicolon.
19 cat >"${MH_TEST_DIR}/Mail/aliases" <<EOF
20 blind_list: Blind List: one, two, three
21 named.list; one@example.com, two@example.com
22 one: one@example.com
23 two: two@example.com
24 three: three@example.com
25 EOF
26
27 #### Rely on sendmail/smtp or sendmail/pipe below to override default mts.
28 mts_fakesendmail="${MHMTSCONF}-fakesendmail"
29 cp "${MHMTSCONF}" "$mts_fakesendmail"
30 printf 'sendmail: %s/test/fakesendmail\n' "$srcdir" >>"$mts_fakesendmail"
31 MHMTSCONF="$mts_fakesendmail"
32
33 # $1: -mts switch selection
34 # $2: expected output
35 test_alias ()
36 {
37 if [ "$1" = 'sendmail/smtp' ]; then
38 run_prog send -draft -alias "${MH_TEST_DIR}/Mail/aliases" -mts sendmail/smtp
39
40 # fakesendmail drops the message and any cc's into this mbox.
41 mbox="${MH_TEST_DIR}"/Mail/fakesendmail.mbox
42 inc -silent -file "$mbox"
43 rm -f "$mbox" "$mbox.map"
44
45 # It's hard to calculate the exact Date: header post is going to
46 # use, so we'll just use sed to remove the actual date so we can easily
47 # compare it against our "correct" output.
48 sed -e 's/^Date:.*/Date:/' "`mhpath cur`" >"${testname}.actual"
49
50 check "${testname}.actual" "$2"
51
52 if [ "`mhpath cur`" != "`mhpath last`" ]; then
53 folder next >/dev/null
54 arith_eval $n + 1; n=$arith_val
55 fi
56
57 elif [ "$1" = 'sendmail/pipe' ]; then
58 set +e
59 run_prog send -draft -alias "${MH_TEST_DIR}/Mail/aliases" \
60 -mts sendmail/pipe >"${testname}.actual" 2>&1
61 if [ $? -eq 0 ]; then
62 printf '%s: sendmail/pipe should have failed but didn'"'"'t\n' "$0"
63 else
64 set -e
65 check "${testname}.actual" "$2"
66 fi
67
68 else
69 printf '%s: invalid -mts switch selection\n' "$0"
70 exit 1
71 fi
72 }
73
74
75 # check blind list
76 cat >"${MH_TEST_DIR}/Mail/draft" <<EOF
77 From: Mr Nobody <nobody@example.com>
78 To: blind_list
79 Subject: blind list test
80
81 This is test of a blind list.
82 EOF
83 cp -p "${MH_TEST_DIR}/Mail/draft" "${MH_TEST_DIR}/Mail/draft2"
84
85 cat >"${testname}.expected" <<EOF
86 From: Mr Nobody <nobody@example.com>
87 To: Blind List: ;
88 Subject: blind list test
89 MIME-Version: 1.0
90 Content-Type: text/plain; charset="us-ascii"
91 Date:
92
93 This is test of a blind list.
94 EOF
95
96 test_alias sendmail/smtp "${testname}.expected"
97
98 # Make sure the addresses were expanded correctly.
99 mv "${MH_TEST_DIR}/Mail/draft2" "${MH_TEST_DIR}/Mail/draft"
100
101 cat > "${testname}.expected" <<EOF
102 EHLO nosuchhost.example.com
103 MAIL FROM:<nobody@example.com>
104 RCPT TO:<one@example.com>
105 RCPT TO:<two@example.com>
106 RCPT TO:<three@example.com>
107 DATA
108 From: Mr Nobody <nobody@example.com>
109 To: Blind List: ;
110 Subject: blind list test
111 MIME-Version: 1.0
112 Content-Type: text/plain; charset="us-ascii"
113 Date:
114
115 This is test of a blind list.
116 .
117 QUIT
118 EOF
119
120 test_post "${testname}.actual" "${testname}.expected" \
121 "-alias ${MH_TEST_DIR}/Mail/aliases"
122
123 # check named list (alias followed by ;)
124 cat >"${MH_TEST_DIR}/Mail/draft" <<EOF
125 From: Mr Nobody <nobody@example.com>
126 To: named.list
127 Subject: named list test
128
129 This is test of a named list.
130 EOF
131
132 cat >"${testname}.expected" <<EOF
133 From: Mr Nobody <nobody@example.com>
134 To: "named.list" <one@example.com>, "named.list" <two@example.com>
135 Subject: named list test
136 MIME-Version: 1.0
137 Content-Type: text/plain; charset="us-ascii"
138 Date:
139
140 This is test of a named list.
141 EOF
142
143 test_alias sendmail/smtp "${testname}.expected"
144
145 # check blind list with -mts sendmail/pipe, which should fail
146 cat >"${MH_TEST_DIR}/Mail/draft" <<EOF
147 From: Mr Nobody <nobody@example.com>
148 To: blind_list
149 Subject: blind list test
150
151 This is test of a blind list.
152 EOF
153
154 cat >"${testname}.expected" <<EOF
155 post: blind lists not compatible with sendmail/pipe
156 send: message not delivered to anyone
157 EOF
158
159 test_alias sendmail/pipe "${testname}.expected"
160
161
162 exit ${failed:-0}