Updates to test/common.sh.in:
[mmh] / test / post / test-post-envelope
1 #!/bin/sh
2 #
3 # Test the setting of the envelope-from address for SMTP
4 #
5 # Note here we use multiple From: addresses for some tests so we pick up
6 # some cases skipped in other tests.
7 #
8
9 set -e
10
11 if test -z "${MH_OBJ_DIR}"; then
12     srcdir=`dirname "$0"`/../..
13     MH_OBJ_DIR=`cd "$srcdir" && pwd`; export MH_OBJ_DIR
14 fi
15
16 . "${srcdir}/test/post/test-post-common.sh"
17
18 #
19 # Sender
20 #
21
22 cat > "${MH_TEST_DIR}/Mail/draft" <<EOF
23 From: Mr Nobody One <nobody1@example.com>,
24       Mr Nobody Two <nobody2@example.com>
25 Sender: Mr Nobody Three <nobody3@example.com>
26 To: Somebody Else <somebody@example.com>
27 Subject: Sender test
28
29 This is a test of the Sender header.
30 EOF
31
32 cat > "${testname}.0.expected" <<EOF
33 EHLO nosuchhost.example.com
34 MAIL FROM:<nobody3@example.com>
35 RCPT TO:<somebody@example.com>
36 DATA
37 From: Mr Nobody One <nobody1@example.com>,
38       Mr Nobody Two <nobody2@example.com>
39 Sender: Mr Nobody Three <nobody3@example.com>
40 To: Somebody Else <somebody@example.com>
41 Subject: Sender test
42 Date:
43
44 This is a test of the Sender header.
45 .
46 QUIT
47 EOF
48
49 test_post "${testname}.0.actual" "${testname}.0.expected"
50
51 #
52 # Check to see if Envelope-From overrides Sender
53 #
54
55 cat > "${MH_TEST_DIR}/Mail/draft" <<EOF
56 From: Mr Nobody One <nobody1@example.com>,
57       Mr Nobody Two <nobody2@example.com>
58 Sender: Mr Nobody Three <nobody3@example.com>
59 Envelope-From: Mr Nobody Four <nobody4@example.com>
60 To: Somebody Else <somebody@example.com>
61 Subject: Envelope-From test
62
63 This is a test of the Envelope-From header.
64 EOF
65
66 cat > "${testname}.1.expected" <<EOF
67 EHLO nosuchhost.example.com
68 MAIL FROM:<nobody4@example.com>
69 RCPT TO:<somebody@example.com>
70 DATA
71 From: Mr Nobody One <nobody1@example.com>,
72       Mr Nobody Two <nobody2@example.com>
73 Sender: Mr Nobody Three <nobody3@example.com>
74 To: Somebody Else <somebody@example.com>
75 Subject: Envelope-From test
76 Date:
77
78 This is a test of the Envelope-From header.
79 .
80 QUIT
81 EOF
82
83 test_post "${testname}.1.actual" "${testname}.1.expected"
84
85 #
86 # See if Envelope-From will generate a Sender: header with multiple From:
87 # addresses
88 #
89
90 cat > "${MH_TEST_DIR}/Mail/draft" <<EOF
91 From: Mr Nobody One <nobody1@example.com>,
92       Mr Nobody Two <nobody2@example.com>
93 Envelope-From: Mr Nobody Four <nobody4@example.com>
94 To: Somebody Else <somebody@example.com>
95 Subject: Envelope-From and Sender test
96
97 This is a test of the Envelope-From and Sender headers.
98 EOF
99
100 cat > "${testname}.2.expected" <<EOF
101 EHLO nosuchhost.example.com
102 MAIL FROM:<nobody4@example.com>
103 RCPT TO:<somebody@example.com>
104 DATA
105 From: Mr Nobody One <nobody1@example.com>,
106       Mr Nobody Two <nobody2@example.com>
107 To: Somebody Else <somebody@example.com>
108 Subject: Envelope-From and Sender test
109 Date:
110 Sender: nobody4@example.com
111
112 This is a test of the Envelope-From and Sender headers.
113 .
114 QUIT
115 EOF
116
117 test_post "${testname}.2.actual" "${testname}.2.expected"
118
119 #
120 # And make sure we do NOT get a Sender with only one From:
121 #
122
123 cat > "${MH_TEST_DIR}/Mail/draft" <<EOF
124 From: Mr Nobody One <nobody1@example.com>
125 Envelope-From: Mr Nobody Five <nobody5@example.com>
126 To: Somebody Else <somebody@example.com>
127 Subject: Solo Envelope-From test
128
129 This is a solo test of the Envelope-From header.
130 EOF
131
132 cat > "${testname}.3.expected" <<EOF
133 EHLO nosuchhost.example.com
134 MAIL FROM:<nobody5@example.com>
135 RCPT TO:<somebody@example.com>
136 DATA
137 From: Mr Nobody One <nobody1@example.com>
138 To: Somebody Else <somebody@example.com>
139 Subject: Solo Envelope-From test
140 Date:
141
142 This is a solo test of the Envelope-From header.
143 .
144 QUIT
145 EOF
146
147 test_post "${testname}.3.actual" "${testname}.3.expected"
148
149 #
150 # Make sure blank Envelope-From does what we expect it to
151 #
152
153 cat > "${MH_TEST_DIR}/Mail/draft" <<EOF
154 From: Mr Nobody One <nobody1@example.com>
155 Envelope-From:
156 To: Somebody Else <somebody@example.com>
157 Subject: Blank Envelope-From test
158
159 This is a blank test of the Envelope-From header.
160 EOF
161
162 cat > "${testname}.4.expected" <<EOF
163 EHLO nosuchhost.example.com
164 MAIL FROM:<>
165 RCPT TO:<somebody@example.com>
166 DATA
167 From: Mr Nobody One <nobody1@example.com>
168 To: Somebody Else <somebody@example.com>
169 Subject: Blank Envelope-From test
170 Date:
171
172 This is a blank test of the Envelope-From header.
173 .
174 QUIT
175 EOF
176
177 test_post "${testname}.4.actual" "${testname}.4.expected"
178
179 exit ${failed:-0}