@@ -26,10 +26,32 @@ local function smtp_h(s)
26
26
s :write (' 250 HELP\r\n ' )
27
27
elseif l :find (' MAIL FROM:' ) then
28
28
mail .from = l :sub (11 ):sub (1 , - 3 )
29
- s :write (' 250 OK\r\n ' )
29
+ if l :find (' 3xx' ) then
30
+ s :write (' 354 Start mail input\r\n ' )
31
+ elseif l :find (' 4xx' ) then
32
+ s :write (' 451 Requested action aborted: local error in processing\r\n ' )
33
+ elseif l :find (' 5xx' ) then
34
+ s :write (' 510 Bad email address\r\n ' )
35
+ elseif l :find (' 10xx' ) then
36
+ s :write (' 1000 UNKNOWN ERROR\r\n ' )
37
+ return
38
+ else
39
+ s :write (' 250 OK\r\n ' )
40
+ end
30
41
elseif l :find (' RCPT TO:' ) then
31
42
mail .rcpt [# mail .rcpt + 1 ] = l :sub (9 ):sub (1 , - 3 )
32
- s :write (' 250 OK\r\n ' )
43
+ if l :find (' 3xx' ) then
44
+ s :write (' 354 Start mail input\r\n ' )
45
+ elseif l :find (' 4xx' ) then
46
+ s :write (' 421 Service not available, closing transmission channel\r\n ' )
47
+ elseif l :find (' 5xx' ) then
48
+ s :write (' 510 Bad email address\r\n ' )
49
+ elseif l :find (' 10xx' ) then
50
+ s :write (' 1000 UNKNOWN ERROR\r\n ' )
51
+ return
52
+ else
53
+ s :write (' 250 OK\r\n ' )
54
+ end
33
55
elseif l == ' DATA\r\n ' then
34
56
s :write (' 354 Enter message, ending with "." on a line by itself\r\n ' )
35
57
while true do
@@ -56,7 +78,7 @@ local server = socket.tcp_server('127.0.0.1', 0, smtp_h)
56
78
local addr = ' smtp://127.0.0.1:' .. server :name ().port
57
79
58
80
test :test (" smtp.client" , function (test )
59
- test :plan (10 )
81
+ test :plan (18 )
60
82
local r
61
83
local m
62
84
@@ -143,9 +165,50 @@ test:test("smtp.client", function(test)
143
165
144
166
m = mails :get ()
145
167
subj = select (2 , string.gsub (
146
- m .text ,
147
- " Subject: =%?utf%-8%?b%?YWJjZGVmZ2hpamvRj2xtbm9wcXJzdHV2d3h5eg==%?=" , " " ))
168
+ m .text ,
169
+ " Subject: =%?utf%-8%?b%?YWJjZGVmZ2hpamvRj2xtbm9wcXJzdHV2d3h5eg==%?=" , " " ))
148
170
test :is (subj , 1 , ' subject codes >127' )
171
+
172
+ r = client :
request (
addr ,
' [email protected] ' ,
173
+
174
+ ' mail.body' )
175
+ test :is (r .reason , ' MAIL failed: 354 (SMTP error)' , ' Errors 3xx' )
176
+
177
+ r = client :
request (
addr ,
' [email protected] ' ,
178
+
179
+ ' mail.body' )
180
+ test :is (r .reason , ' MAIL failed: 451 (SMTP error)' , ' service unavailable' )
181
+
182
+ r = client :
request (
addr ,
' [email protected] ' ,
183
+
184
+ ' mail.body' )
185
+ test :is (r .reason , ' MAIL failed: 510 (SMTP error)' , ' unexisting recipient' )
186
+
187
+ r = client :
request (
addr ,
' [email protected] ' ,
188
+
189
+ ' mail.body' )
190
+ test :is (r .reason , ' response reading failed (SMTP error)' , ' unexisting recipient' )
191
+
192
+ r = client :
request (
addr ,
' [email protected] ' ,
193
+
194
+ ' mail.body' )
195
+ test :is (r .reason , ' RCPT failed: 354 (SMTP error)' , ' Errors 3xx' )
196
+
197
+ r = client :
request (
addr ,
' [email protected] ' ,
198
+
199
+ ' mail.body' )
200
+ test :is (r .reason , ' RCPT failed: 421 (SMTP error)' , ' service unavailable' )
201
+
202
+ r = client :
request (
addr ,
' [email protected] ' ,
203
+
204
+ ' mail.body' )
205
+ test :is (r .reason , ' RCPT failed: 510 (SMTP error)' , ' unexisting recipient' )
206
+
207
+ r = client :
request (
addr ,
' [email protected] ' ,
208
+
209
+ ' mail.body' )
210
+ test :is (r .reason , ' response reading failed (SMTP error)' , ' unexisting recipient' )
211
+
149
212
end )
150
213
151
214
os.exit (test :check () == true and 0 or - 1 )
0 commit comments