line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::SMTP; |
2
|
|
|
|
|
|
|
|
3
|
9
|
|
|
9
|
|
364228
|
use strict; |
|
9
|
|
|
|
|
18
|
|
|
9
|
|
|
|
|
308
|
|
4
|
9
|
|
|
9
|
|
50
|
use warnings; |
|
9
|
|
|
|
|
17
|
|
|
9
|
|
|
|
|
371
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
BEGIN { |
7
|
9
|
|
|
9
|
|
49
|
use Exporter (); |
|
9
|
|
|
|
|
19
|
|
|
9
|
|
|
|
|
142
|
|
8
|
9
|
|
|
9
|
|
76
|
use Carp; |
|
9
|
|
|
|
|
15
|
|
|
9
|
|
|
|
|
717
|
|
9
|
9
|
|
|
9
|
|
9523
|
use Net::SMTP_auth; |
|
9
|
|
|
|
|
476114
|
|
|
9
|
|
|
|
|
529
|
|
10
|
9
|
|
|
9
|
|
6854
|
use Test::Builder::Module; |
|
9
|
|
|
|
|
124240
|
|
|
9
|
|
|
|
|
81
|
|
11
|
|
|
|
|
|
|
|
12
|
9
|
|
|
9
|
|
343
|
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); |
|
9
|
|
|
|
|
21
|
|
|
9
|
|
|
|
|
1044
|
|
13
|
9
|
|
|
9
|
|
25
|
$VERSION = '0.04'; |
14
|
9
|
|
|
|
|
367
|
@ISA = qw(Net::SMTP_auth Test::Builder::Module); |
15
|
|
|
|
|
|
|
#Give a hoot don't pollute, do not export more than needed by default |
16
|
9
|
|
|
|
|
22
|
@EXPORT = qw(); |
17
|
9
|
|
|
|
|
24
|
@EXPORT_OK = qw(plan); |
18
|
9
|
|
|
|
|
39693
|
%EXPORT_TAGS = (); |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 NAME |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
Test::SMTP - Module for writing SMTP Server tests |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head1 SYNOPSIS |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
use Test::SMTP; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
plan tests => 10; |
30
|
|
|
|
|
|
|
# Constructors |
31
|
|
|
|
|
|
|
my $client1 = Test::SMTP->connect_ok('connect to mailhost', |
32
|
|
|
|
|
|
|
Host => '127.0.0.1', AutoHello => 1); |
33
|
|
|
|
|
|
|
$client1->mail_from_ok('test@example.com', 'Accept an example mail from'); |
34
|
|
|
|
|
|
|
$client1->rcpt_to_ko('test2@example.com', 'Reject an example domain in rcpt to'); |
35
|
|
|
|
|
|
|
$client1->quit_ok('Quit OK'); |
36
|
|
|
|
|
|
|
my $client2 = Test::SMTP->connect_ok('connect to mailhost', |
37
|
|
|
|
|
|
|
Host => '127.0.0.1', AutoHello => 1); |
38
|
|
|
|
|
|
|
... |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=head1 DESCRIPTION |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
This module is designed for easily building tests for SMTP servers. |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Test::SMTP is a subclass of Net::SMTP_auth, that is a subclass of Net::SMTP, |
47
|
|
|
|
|
|
|
that in turn is a subclass of Net::Cmd and IO::Socket::INET. Don't be too confident |
48
|
|
|
|
|
|
|
of it beeing a Net::SMTP_auth subclass for too much time, though (v 0.03 changed from |
49
|
|
|
|
|
|
|
Net::SMTP to Net::SMTP_auth so you can control authentication tests better). Compatibility |
50
|
|
|
|
|
|
|
will always try to be kept so you can still call the subclass methods. |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head1 PLAN |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=over 4 |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=item plan |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Plan tests a la Test::More. Exported on demand (not necessary to export if you are already using a test module that exports I). |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
use Test::SMTP qw(plan); |
61
|
|
|
|
|
|
|
plan tests => 5; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=cut |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub plan { |
66
|
1
|
|
|
1
|
1
|
44
|
my $tb = __PACKAGE__->builder; |
67
|
1
|
|
|
|
|
28
|
$tb->plan(@_); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=back |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 CONSTRUCTOR |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=over 4 |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=item connect_ok($name, Host => $host, AutoHello => 1, [ Timeout => 1 ]) |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
Passes if the client connects to the SMTP Server. Everything after I is passed to the Net::SMTP_auth I method. returns a Test::SMTP object. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Net::SMTP_auth parameters of interest: |
81
|
|
|
|
|
|
|
Port => $port (connect to non-standard SMTP port) |
82
|
|
|
|
|
|
|
Hello => 'my (he|eh)lo' hello to send to the server |
83
|
|
|
|
|
|
|
Debug => 1 Outputs via STDERR the conversation with the server |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
You have to pass AutoHello => 1, this will enable auto EHLO/HELO negotiation. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=cut |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub connect_ok { |
90
|
6
|
|
|
6
|
1
|
2014938
|
my ($class, $name, %params) = @_; |
91
|
|
|
|
|
|
|
|
92
|
6
|
100
|
100
|
|
|
223
|
if ((not defined($params{'AutoHello'})) or ($params{'AutoHello'} != 1)){ |
93
|
2
|
|
|
|
|
36
|
croak "Can only handle AutoHello for now..."; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
4
|
|
|
|
|
313
|
my $smtp = Net::SMTP_auth->new(%params); |
97
|
|
|
|
|
|
|
|
98
|
4
|
|
|
|
|
155919
|
my $tb = __PACKAGE__->builder(); |
99
|
4
|
|
|
|
|
151
|
$tb->ok(defined $smtp, $name); |
100
|
|
|
|
|
|
|
|
101
|
4
|
100
|
|
|
|
4638
|
if (not defined($smtp)){ |
102
|
1
|
|
|
|
|
7
|
return undef; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
3
|
|
|
|
|
23
|
bless $smtp, $class; |
106
|
3
|
|
|
|
|
25
|
return $smtp; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=item connect_ko($name, Host => $host, [ Timeout => 1 ]) |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Passes test if the client does not connect to the SMTP Server. Everything after I is passed to the Net::SMTP_auth I method. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=cut |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub connect_ko { |
116
|
3
|
|
|
3
|
1
|
1142
|
my ($class, $name, @params) = @_; |
117
|
|
|
|
|
|
|
|
118
|
3
|
|
|
|
|
45
|
my $smtp = Net::SMTP_auth->new(@params); |
119
|
3
|
|
|
|
|
46278
|
my $tb = __PACKAGE__->builder(); |
120
|
|
|
|
|
|
|
|
121
|
3
|
|
|
|
|
64
|
$tb->ok(not(defined $smtp), $name); |
122
|
|
|
|
|
|
|
|
123
|
3
|
100
|
|
|
|
1701
|
if (not defined $smtp){ |
124
|
2
|
|
|
|
|
128
|
return undef; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
1
|
|
|
|
|
3
|
bless $smtp, $class; |
128
|
1
|
|
|
|
|
6
|
return $smtp; |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=back |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head1 TEST METHODS |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=over 4 |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=cut |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=item code_is ($expected, $name) |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Passes if the last SMTP code returned by the server was I. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=cut |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub code_is { |
146
|
6
|
|
|
6
|
1
|
2076
|
my ($self, $expected, $name) = @_; |
147
|
6
|
|
|
|
|
22
|
my $tb = __PACKAGE__->builder(); |
148
|
|
|
|
|
|
|
|
149
|
6
|
|
|
|
|
70
|
$tb->cmp_ok($self->code(), '==', $expected, $name); |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=item code_isnt ($expected, $name) |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
Passes if the last SMTP code returned by the server was'nt I. |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=cut |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub code_isnt { |
159
|
6
|
|
|
6
|
1
|
8801
|
my ($self, $expected, $name) = @_; |
160
|
6
|
|
|
|
|
26
|
my $tb = __PACKAGE__->builder(); |
161
|
|
|
|
|
|
|
|
162
|
6
|
|
|
|
|
57
|
$tb->cmp_ok($self->code(), '!=', $expected, $name); |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=item code_is_success($name) |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
Passes if the last SMTP code returned by the server indicates success. |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=cut |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
sub code_is_success { |
172
|
4
|
|
|
4
|
1
|
877
|
my ($self, $name) = @_; |
173
|
4
|
|
|
|
|
15
|
my $tb = __PACKAGE__->builder(); |
174
|
|
|
|
|
|
|
|
175
|
4
|
50
|
|
|
|
49
|
if (_is_between($self->code(), 200, 399)){ |
176
|
0
|
|
|
|
|
0
|
$tb->ok(1, $name); |
177
|
|
|
|
|
|
|
} else { |
178
|
4
|
|
|
|
|
15
|
$tb->ok(0, $name); |
179
|
4
|
|
|
|
|
2656
|
$self->_smtp_diag; |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=item code_isnt_success($name) |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
Passes if the last SMTP code returned by the server doesn't indicate success. |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=cut |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
sub code_isnt_success { |
190
|
5
|
|
|
5
|
1
|
1971
|
my ($self, $name) = @_; |
191
|
5
|
|
|
|
|
20
|
my $tb = __PACKAGE__->builder(); |
192
|
|
|
|
|
|
|
|
193
|
5
|
50
|
|
|
|
45
|
if (_is_between($self->code(), 200, 399)){ |
194
|
0
|
|
|
|
|
0
|
$tb->ok(0, $name); |
195
|
0
|
|
|
|
|
0
|
$self->_smtp_diag; |
196
|
|
|
|
|
|
|
} else { |
197
|
5
|
|
|
|
|
17
|
$tb->ok(1, $name); |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=item code_is_failure($name) |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
Passes if the last SMTP code returned by the server indicates failure (either |
204
|
|
|
|
|
|
|
temporary or permanent). |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=cut |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
sub code_is_failure { |
209
|
5
|
|
|
5
|
1
|
1410
|
my ($self, $name) = @_; |
210
|
5
|
|
|
|
|
20
|
my $tb = __PACKAGE__->builder(); |
211
|
|
|
|
|
|
|
|
212
|
5
|
50
|
|
|
|
45
|
if (not _is_between($self->code(), 200, 399)){ |
213
|
5
|
|
|
|
|
18
|
$tb->ok(1, $name); |
214
|
|
|
|
|
|
|
} else { |
215
|
0
|
|
|
|
|
0
|
$tb->ok(0, $name); |
216
|
0
|
|
|
|
|
0
|
$self->_smtp_diag; |
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
=item code_isnt_failure($name) |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
Passes if the last SMTP code returned by the server doesn't indicate failure (either |
223
|
|
|
|
|
|
|
temporary or permanent). |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
=cut |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
sub code_isnt_failure { |
228
|
4
|
|
|
4
|
1
|
2087
|
my ($self, $name) = @_; |
229
|
4
|
|
|
|
|
15
|
my $tb = __PACKAGE__->builder(); |
230
|
|
|
|
|
|
|
|
231
|
4
|
50
|
|
|
|
35
|
if (not _is_between($self->code(), 200, 399)){ |
232
|
4
|
|
|
|
|
14
|
$tb->ok(0, $name); |
233
|
4
|
|
|
|
|
8837
|
$self->_smtp_diag; |
234
|
|
|
|
|
|
|
} else { |
235
|
0
|
|
|
|
|
0
|
$tb->ok(1, $name); |
236
|
|
|
|
|
|
|
} |
237
|
|
|
|
|
|
|
} |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
=item code_is_temporary($name) |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
Passes if the last SMTP code returned by the server indicates temporary failure |
242
|
|
|
|
|
|
|
|
243
|
|
|
|
|
|
|
=cut |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
sub code_is_temporary { |
246
|
4
|
|
|
4
|
1
|
1553
|
my ($self, $name) = @_; |
247
|
4
|
|
|
|
|
15
|
my $tb = __PACKAGE__->builder(); |
248
|
|
|
|
|
|
|
|
249
|
4
|
50
|
|
|
|
38
|
if (_is_between($self->code(), 400, 499)){ |
250
|
0
|
|
|
|
|
0
|
$tb->ok(1, $name); |
251
|
|
|
|
|
|
|
} else { |
252
|
4
|
|
|
|
|
14
|
$tb->ok(0, $name); |
253
|
4
|
|
|
|
|
2768
|
$self->_smtp_diag; |
254
|
|
|
|
|
|
|
} |
255
|
|
|
|
|
|
|
} |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
=item code_isnt_temporary($name) |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
Passes if the last SMTP code returned by the server doesn't indicate temporary failure |
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
=cut |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
sub code_isnt_temporary { |
264
|
5
|
|
|
5
|
1
|
2700
|
my ($self, $name) = @_; |
265
|
5
|
|
|
|
|
20
|
my $tb = __PACKAGE__->builder(); |
266
|
|
|
|
|
|
|
|
267
|
5
|
50
|
|
|
|
195
|
if (_is_between($self->code(), 400, 499)){ |
268
|
0
|
|
|
|
|
0
|
$tb->ok(0, $name); |
269
|
0
|
|
|
|
|
0
|
$self->_smtp_diag; |
270
|
|
|
|
|
|
|
} else { |
271
|
5
|
|
|
|
|
20
|
$tb->ok(1, $name); |
272
|
|
|
|
|
|
|
} |
273
|
|
|
|
|
|
|
} |
274
|
|
|
|
|
|
|
|
275
|
|
|
|
|
|
|
=item code_is_permanent($name) |
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
Passes if the last SMTP code returned by the server indicates permanent failure |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
=cut |
280
|
|
|
|
|
|
|
|
281
|
|
|
|
|
|
|
sub code_is_permanent { |
282
|
4
|
|
|
4
|
1
|
1707
|
my ($self, $name) = @_; |
283
|
4
|
|
|
|
|
22
|
my $tb = __PACKAGE__->builder(); |
284
|
|
|
|
|
|
|
|
285
|
4
|
50
|
|
|
|
44
|
if (_is_between($self->code(), 500, 599)){ |
286
|
4
|
|
|
|
|
17
|
$tb->ok(1, $name); |
287
|
|
|
|
|
|
|
} else { |
288
|
0
|
|
|
|
|
0
|
$tb->ok(0, $name); |
289
|
0
|
|
|
|
|
0
|
$self->_smtp_diag; |
290
|
|
|
|
|
|
|
} |
291
|
|
|
|
|
|
|
} |
292
|
|
|
|
|
|
|
|
293
|
|
|
|
|
|
|
=item code_isnt_permanent($name) |
294
|
|
|
|
|
|
|
|
295
|
|
|
|
|
|
|
Passes if the last SMTP code returned by the server doesn't indicate permanent failure |
296
|
|
|
|
|
|
|
|
297
|
|
|
|
|
|
|
=cut |
298
|
|
|
|
|
|
|
|
299
|
|
|
|
|
|
|
sub code_isnt_permanent { |
300
|
5
|
|
|
5
|
1
|
1550
|
my ($self, $name) = @_; |
301
|
5
|
|
|
|
|
19
|
my $tb = __PACKAGE__->builder(); |
302
|
|
|
|
|
|
|
|
303
|
5
|
50
|
|
|
|
50
|
if (_is_between($self->code(), 500, 599)){ |
304
|
5
|
|
|
|
|
18
|
$tb->ok(0, $name); |
305
|
5
|
|
|
|
|
3954
|
$self->_smtp_diag; |
306
|
|
|
|
|
|
|
} else { |
307
|
0
|
|
|
|
|
0
|
$tb->ok(1, $name); |
308
|
|
|
|
|
|
|
} |
309
|
|
|
|
|
|
|
} |
310
|
|
|
|
|
|
|
|
311
|
|
|
|
|
|
|
=item message_like(qr/REGEX/, $name) |
312
|
|
|
|
|
|
|
|
313
|
|
|
|
|
|
|
Passes if the last SMTP message returned by the server matches the regex. |
314
|
|
|
|
|
|
|
|
315
|
|
|
|
|
|
|
=cut |
316
|
|
|
|
|
|
|
|
317
|
|
|
|
|
|
|
sub message_like { |
318
|
6
|
|
|
6
|
1
|
3517
|
my ($self, $expected, $name) = @_; |
319
|
6
|
|
|
|
|
24
|
my $tb = __PACKAGE__->builder(); |
320
|
|
|
|
|
|
|
|
321
|
6
|
|
|
|
|
61
|
my $message = $self->message(); |
322
|
6
|
|
|
|
|
70
|
$tb->like($message, $expected, $name); |
323
|
|
|
|
|
|
|
} |
324
|
|
|
|
|
|
|
|
325
|
|
|
|
|
|
|
=item message_unlike(qr/REGEX/, $name) |
326
|
|
|
|
|
|
|
|
327
|
|
|
|
|
|
|
Passes if the last SMTP message returned by the server does'nt match the regex. |
328
|
|
|
|
|
|
|
|
329
|
|
|
|
|
|
|
=cut |
330
|
|
|
|
|
|
|
|
331
|
|
|
|
|
|
|
sub message_unlike { |
332
|
6
|
|
|
6
|
1
|
7941
|
my ($self, $expected, $name) = @_; |
333
|
6
|
|
|
|
|
23
|
my $tb = __PACKAGE__->builder(); |
334
|
|
|
|
|
|
|
|
335
|
6
|
|
|
|
|
58
|
my $message = $self->message(); |
336
|
6
|
|
|
|
|
73
|
$tb->unlike($message, $expected, $name); |
337
|
|
|
|
|
|
|
} |
338
|
|
|
|
|
|
|
|
339
|
|
|
|
|
|
|
=item auth_ok($method, $user, $password, $name) |
340
|
|
|
|
|
|
|
|
341
|
|
|
|
|
|
|
Passes if I<$user> with I<$password> with SASL method I<$method> |
342
|
|
|
|
|
|
|
is AUTHorized on the server. |
343
|
|
|
|
|
|
|
|
344
|
|
|
|
|
|
|
=cut |
345
|
|
|
|
|
|
|
|
346
|
|
|
|
|
|
|
sub auth_ok { |
347
|
0
|
|
|
0
|
1
|
0
|
my ($self, $method, $user, $password, $name) = @_; |
348
|
0
|
|
|
|
|
0
|
my $tb = __PACKAGE__->builder(); |
349
|
|
|
|
|
|
|
|
350
|
0
|
|
|
|
|
0
|
my $result = $self->auth($method, $user, $password); |
351
|
0
|
0
|
|
|
|
0
|
if ($result){ |
352
|
0
|
|
|
|
|
0
|
$tb->ok(1, $name); |
353
|
|
|
|
|
|
|
} else { |
354
|
0
|
|
|
|
|
0
|
$tb->ok(0, $name); |
355
|
0
|
|
|
|
|
0
|
$self->_smtp_diag; |
356
|
|
|
|
|
|
|
} |
357
|
|
|
|
|
|
|
} |
358
|
|
|
|
|
|
|
|
359
|
|
|
|
|
|
|
=item auth_ko($method, $user, $password, $name) |
360
|
|
|
|
|
|
|
|
361
|
|
|
|
|
|
|
Passes if I<$user> with I<$password> with SASL method I<$method> |
362
|
|
|
|
|
|
|
is not AUTHorized on the server. |
363
|
|
|
|
|
|
|
|
364
|
|
|
|
|
|
|
=cut |
365
|
|
|
|
|
|
|
|
366
|
|
|
|
|
|
|
sub auth_ko { |
367
|
0
|
|
|
0
|
1
|
0
|
my ($self, $method, $user, $password, $name) = @_; |
368
|
0
|
|
|
|
|
0
|
my $tb = __PACKAGE__->builder(); |
369
|
|
|
|
|
|
|
|
370
|
0
|
|
|
|
|
0
|
my $result = $self->auth($method, $user, $password); |
371
|
0
|
0
|
|
|
|
0
|
if ($result){ |
372
|
0
|
|
|
|
|
0
|
$tb->ok(0, $name); |
373
|
0
|
|
|
|
|
0
|
$self->_smtp_diag; |
374
|
|
|
|
|
|
|
} else { |
375
|
0
|
|
|
|
|
0
|
$tb->ok(1, $name); |
376
|
|
|
|
|
|
|
} |
377
|
|
|
|
|
|
|
} |
378
|
|
|
|
|
|
|
|
379
|
|
|
|
|
|
|
=item starttls_ok($name) |
380
|
|
|
|
|
|
|
|
381
|
|
|
|
|
|
|
Start TLS conversation with the server. Pass if server said that it's OK to start TLS and the SSL negotiation went OK. |
382
|
|
|
|
|
|
|
|
383
|
|
|
|
|
|
|
=cut |
384
|
|
|
|
|
|
|
|
385
|
|
|
|
|
|
|
sub starttls_ok { |
386
|
0
|
|
|
0
|
1
|
0
|
my ($self, $name) = @_; |
387
|
0
|
|
|
|
|
0
|
my $tb = __PACKAGE__->builder(); |
388
|
|
|
|
|
|
|
|
389
|
0
|
0
|
|
|
|
0
|
if (not ($self->command('STARTTLS')->response() == Net::Cmd::CMD_OK)){ |
390
|
0
|
|
|
|
|
0
|
$tb->ok(0, $name); |
391
|
0
|
|
|
|
|
0
|
$self->_smtp_diag; |
392
|
0
|
|
|
|
|
0
|
return; |
393
|
|
|
|
|
|
|
} |
394
|
0
|
0
|
|
|
|
0
|
if (not $self->_convert_to_ssl()){ |
395
|
0
|
|
|
|
|
0
|
$tb->ok(0, $name); |
396
|
0
|
|
|
|
|
0
|
$tb->diag('SSL: ' . IO::Socket::SSL::errstr()); |
397
|
0
|
|
|
|
|
0
|
return; |
398
|
|
|
|
|
|
|
} |
399
|
|
|
|
|
|
|
|
400
|
0
|
|
|
|
|
0
|
$tb->ok(1, $name); |
401
|
|
|
|
|
|
|
} |
402
|
|
|
|
|
|
|
|
403
|
|
|
|
|
|
|
=item starttls_ko($name) |
404
|
|
|
|
|
|
|
|
405
|
|
|
|
|
|
|
Start TLS conversation with the server. Pass if server said that it's not OK to start TLS or if the SSL negotiation failed. |
406
|
|
|
|
|
|
|
|
407
|
|
|
|
|
|
|
=cut |
408
|
|
|
|
|
|
|
|
409
|
|
|
|
|
|
|
sub starttls_ko { |
410
|
0
|
|
|
0
|
1
|
0
|
my ($self, $name) = @_; |
411
|
0
|
|
|
|
|
0
|
my $tb = __PACKAGE__->builder(); |
412
|
|
|
|
|
|
|
|
413
|
0
|
0
|
|
|
|
0
|
if (not ($self->command('STARTTLS')->response() == Net::Cmd::CMD_OK)){ |
414
|
0
|
|
|
|
|
0
|
$tb->ok(1, $name); |
415
|
0
|
|
|
|
|
0
|
return; |
416
|
|
|
|
|
|
|
} |
417
|
0
|
0
|
|
|
|
0
|
if (not $self->_convert_to_ssl()){ |
418
|
0
|
|
|
|
|
0
|
$tb->ok(1, $name); |
419
|
0
|
|
|
|
|
0
|
return; |
420
|
|
|
|
|
|
|
} |
421
|
|
|
|
|
|
|
|
422
|
0
|
|
|
|
|
0
|
$tb->ok(0, $name); |
423
|
0
|
|
|
|
|
0
|
$self->_smtp_diag; |
424
|
0
|
|
|
|
|
0
|
$tb->diag('And SSL negotiation went OK'); |
425
|
|
|
|
|
|
|
} |
426
|
|
|
|
|
|
|
|
427
|
|
|
|
|
|
|
sub _convert_to_ssl { |
428
|
0
|
|
|
0
|
|
0
|
my ($self) = @_; |
429
|
0
|
0
|
|
|
|
0
|
require IO::Socket::SSL or die "starttls requires IO::Socket::SSL"; |
430
|
|
|
|
|
|
|
# the socket is stored in ${*self}{'_ssl_sock'}. |
431
|
|
|
|
|
|
|
# If not, when starttls sub ends *$self is not tied to the SSL |
432
|
|
|
|
|
|
|
# socket anymore, instead, it's tied to the old socket. |
433
|
0
|
0
|
|
|
|
0
|
my $ssl_sock = IO::Socket::SSL->new_from_fd($self->fileno) |
434
|
|
|
|
|
|
|
or return 0; |
435
|
0
|
|
|
|
|
0
|
${*self}{'_ssl_sock'} = $ssl_sock; |
|
0
|
|
|
|
|
0
|
|
436
|
0
|
|
|
|
|
0
|
*$self = *$ssl_sock; |
437
|
|
|
|
|
|
|
} |
438
|
|
|
|
|
|
|
|
439
|
|
|
|
|
|
|
=item hello_ok($hello, $name) |
440
|
|
|
|
|
|
|
|
441
|
|
|
|
|
|
|
Do EHLO/HELO negotiation. Useful only after starttls_ok/ko |
442
|
|
|
|
|
|
|
|
443
|
|
|
|
|
|
|
=cut |
444
|
|
|
|
|
|
|
|
445
|
|
|
|
|
|
|
sub hello_ok { |
446
|
0
|
|
|
0
|
1
|
0
|
my ($self, $hello, $name) = @_; |
447
|
0
|
|
|
|
|
0
|
my $tb = __PACKAGE__->builder(); |
448
|
|
|
|
|
|
|
|
449
|
0
|
0
|
|
|
|
0
|
if ($self->hello($hello)){ |
450
|
0
|
|
|
|
|
0
|
$tb->ok(1, $name); |
451
|
|
|
|
|
|
|
} else { |
452
|
0
|
|
|
|
|
0
|
$tb->ok(0, $name); |
453
|
0
|
|
|
|
|
0
|
$self->_smtp_diag; |
454
|
|
|
|
|
|
|
} |
455
|
|
|
|
|
|
|
} |
456
|
|
|
|
|
|
|
|
457
|
|
|
|
|
|
|
=item hello_ko($hello, $name) |
458
|
|
|
|
|
|
|
|
459
|
|
|
|
|
|
|
Do EHLO/HELO negotiation. Useful only after starttls_ok/ko |
460
|
|
|
|
|
|
|
|
461
|
|
|
|
|
|
|
=cut |
462
|
|
|
|
|
|
|
|
463
|
|
|
|
|
|
|
sub hello_ko { |
464
|
0
|
|
|
0
|
1
|
0
|
my ($self, $hello, $name) = @_; |
465
|
0
|
|
|
|
|
0
|
my $tb = __PACKAGE__->builder(); |
466
|
|
|
|
|
|
|
|
467
|
0
|
0
|
|
|
|
0
|
if ($self->hello($hello)){ |
468
|
0
|
|
|
|
|
0
|
$tb->ok(0, $name); |
469
|
0
|
|
|
|
|
0
|
$self->_smtp_diag; |
470
|
|
|
|
|
|
|
} else { |
471
|
0
|
|
|
|
|
0
|
$tb->ok(1, $name); |
472
|
|
|
|
|
|
|
} |
473
|
|
|
|
|
|
|
} |
474
|
|
|
|
|
|
|
|
475
|
|
|
|
|
|
|
|
476
|
|
|
|
|
|
|
=item rset_ok($name) |
477
|
|
|
|
|
|
|
|
478
|
|
|
|
|
|
|
Send a RSET command to the server. Pass if command was successful |
479
|
|
|
|
|
|
|
|
480
|
|
|
|
|
|
|
=cut |
481
|
|
|
|
|
|
|
|
482
|
|
|
|
|
|
|
sub rset_ok { |
483
|
4
|
|
|
4
|
1
|
2299
|
my ($self, $name) = @_; |
484
|
4
|
|
|
|
|
18
|
my $tb = __PACKAGE__->builder(); |
485
|
|
|
|
|
|
|
|
486
|
4
|
100
|
|
|
|
56
|
if ($self->reset){ |
487
|
1
|
|
|
|
|
350
|
$tb->ok(1, $name); |
488
|
|
|
|
|
|
|
} else { |
489
|
3
|
|
|
|
|
1905
|
$tb->ok(0, $name); |
490
|
3
|
|
|
|
|
3574
|
$self->_smtp_diag; |
491
|
|
|
|
|
|
|
} |
492
|
|
|
|
|
|
|
} |
493
|
|
|
|
|
|
|
|
494
|
|
|
|
|
|
|
=item rset_ko($name) |
495
|
|
|
|
|
|
|
|
496
|
|
|
|
|
|
|
Send an RSET to the server. Pass if command was not successful |
497
|
|
|
|
|
|
|
|
498
|
|
|
|
|
|
|
=cut |
499
|
|
|
|
|
|
|
|
500
|
|
|
|
|
|
|
sub rset_ko { |
501
|
3
|
|
|
3
|
1
|
1910
|
my ($self, $name) = @_; |
502
|
3
|
|
|
|
|
12
|
my $tb = __PACKAGE__->builder(); |
503
|
|
|
|
|
|
|
|
504
|
3
|
50
|
|
|
|
45
|
if ($self->reset){ |
505
|
0
|
|
|
|
|
0
|
$tb->ok(0, $name); |
506
|
0
|
|
|
|
|
0
|
$self->_smtp_diag; |
507
|
|
|
|
|
|
|
} else { |
508
|
3
|
|
|
|
|
1128
|
$tb->ok(1, $name); |
509
|
|
|
|
|
|
|
} |
510
|
|
|
|
|
|
|
} |
511
|
|
|
|
|
|
|
|
512
|
|
|
|
|
|
|
=item supports_ok($capa, $name) |
513
|
|
|
|
|
|
|
|
514
|
|
|
|
|
|
|
Passes test if server said it supported I capability on ESMTP EHLO |
515
|
|
|
|
|
|
|
|
516
|
|
|
|
|
|
|
=cut |
517
|
|
|
|
|
|
|
|
518
|
|
|
|
|
|
|
sub supports_ok { |
519
|
3
|
|
|
3
|
1
|
1242
|
my ($self, $capa, $name) = @_; |
520
|
3
|
|
|
|
|
18
|
my $tb = __PACKAGE__->builder(); |
521
|
|
|
|
|
|
|
|
522
|
3
|
100
|
|
|
|
69
|
if (defined $self->supports($capa)){ |
523
|
2
|
|
|
|
|
31
|
$tb->ok(1, $name); |
524
|
|
|
|
|
|
|
} else { |
525
|
1
|
|
|
|
|
28
|
$tb->ok(0, $name); |
526
|
|
|
|
|
|
|
} |
527
|
|
|
|
|
|
|
} |
528
|
|
|
|
|
|
|
|
529
|
|
|
|
|
|
|
=item supports_ko($capa, $name) |
530
|
|
|
|
|
|
|
|
531
|
|
|
|
|
|
|
Passes test if server didn't say it supported I capability on ESMTP EHLO |
532
|
|
|
|
|
|
|
|
533
|
|
|
|
|
|
|
=cut |
534
|
|
|
|
|
|
|
|
535
|
|
|
|
|
|
|
sub supports_ko { |
536
|
3
|
|
|
3
|
1
|
2173
|
my ($self, $capa, $name) = @_; |
537
|
3
|
|
|
|
|
16
|
my $tb = __PACKAGE__->builder(); |
538
|
|
|
|
|
|
|
|
539
|
3
|
100
|
|
|
|
65
|
if (defined $self->supports($capa)){ |
540
|
2
|
|
|
|
|
55
|
$tb->ok(0, $name); |
541
|
2
|
|
|
|
|
1506
|
$tb->diag("Server supports the feature $capa with " . $self->supports($capa)); |
542
|
|
|
|
|
|
|
} else { |
543
|
1
|
|
|
|
|
15
|
$tb->ok(1, $name); |
544
|
|
|
|
|
|
|
} |
545
|
|
|
|
|
|
|
} |
546
|
|
|
|
|
|
|
|
547
|
|
|
|
|
|
|
=item supports_cmp_ok($capability, $operator, $expected, $name) |
548
|
|
|
|
|
|
|
|
549
|
|
|
|
|
|
|
Compares server I capability extra information with I against I. |
550
|
|
|
|
|
|
|
|
551
|
|
|
|
|
|
|
=cut |
552
|
|
|
|
|
|
|
|
553
|
|
|
|
|
|
|
sub supports_cmp_ok { |
554
|
2
|
|
|
2
|
1
|
1348
|
my ($self, $capa, $operator, $expected, $name) = @_; |
555
|
2
|
|
|
|
|
11
|
my $tb = __PACKAGE__->builder(); |
556
|
|
|
|
|
|
|
|
557
|
2
|
|
|
|
|
25
|
my $val = $self->supports($capa); |
558
|
2
|
|
|
|
|
32
|
$tb->cmp_ok($val, $operator, $expected, $name); |
559
|
|
|
|
|
|
|
} |
560
|
|
|
|
|
|
|
|
561
|
|
|
|
|
|
|
=item supports_like($capability, qr/REGEX/, $name) |
562
|
|
|
|
|
|
|
|
563
|
|
|
|
|
|
|
Passes if server I capability extra information matches against I. |
564
|
|
|
|
|
|
|
|
565
|
|
|
|
|
|
|
=cut |
566
|
|
|
|
|
|
|
|
567
|
|
|
|
|
|
|
sub supports_like { |
568
|
1
|
|
|
1
|
1
|
420
|
my ($self, $capa, $expected, $name) = @_; |
569
|
1
|
|
|
|
|
5
|
my $tb = __PACKAGE__->builder(); |
570
|
|
|
|
|
|
|
|
571
|
1
|
|
|
|
|
10
|
my $val = $self->supports($capa); |
572
|
1
|
|
|
|
|
63
|
$tb->like($val, $expected, $name); |
573
|
|
|
|
|
|
|
} |
574
|
|
|
|
|
|
|
|
575
|
|
|
|
|
|
|
=item supports_unlike($capability, qr/REGEX/, $name) |
576
|
|
|
|
|
|
|
|
577
|
|
|
|
|
|
|
Passes if server I capability extra information doesn't match against I. |
578
|
|
|
|
|
|
|
|
579
|
|
|
|
|
|
|
=cut |
580
|
|
|
|
|
|
|
|
581
|
|
|
|
|
|
|
sub supports_unlike { |
582
|
1
|
|
|
1
|
1
|
596
|
my ($self, $capa, $expected, $name) = @_; |
583
|
1
|
|
|
|
|
6
|
my $tb = __PACKAGE__->builder(); |
584
|
|
|
|
|
|
|
|
585
|
1
|
|
|
|
|
11
|
my $val = $self->supports($capa); |
586
|
1
|
|
|
|
|
15
|
$tb->unlike($val, $expected, $name); |
587
|
|
|
|
|
|
|
} |
588
|
|
|
|
|
|
|
|
589
|
|
|
|
|
|
|
=item banner_like(qr/REGEX/, $name) |
590
|
|
|
|
|
|
|
|
591
|
|
|
|
|
|
|
Passes if server banner matches against I. |
592
|
|
|
|
|
|
|
|
593
|
|
|
|
|
|
|
=cut |
594
|
|
|
|
|
|
|
|
595
|
|
|
|
|
|
|
sub banner_like { |
596
|
1
|
|
|
1
|
1
|
66
|
my ($self, $qr, $name) = @_; |
597
|
1
|
|
|
|
|
12
|
my $tb = __PACKAGE__->builder(); |
598
|
|
|
|
|
|
|
|
599
|
1
|
|
|
|
|
44
|
$tb->like($self->banner(), $qr, $name); |
600
|
|
|
|
|
|
|
} |
601
|
|
|
|
|
|
|
|
602
|
|
|
|
|
|
|
=item banner_unlike(qr/REGEX/, $name) |
603
|
|
|
|
|
|
|
|
604
|
|
|
|
|
|
|
Passes if server banner doesn't match against I. |
605
|
|
|
|
|
|
|
|
606
|
|
|
|
|
|
|
=cut |
607
|
|
|
|
|
|
|
|
608
|
|
|
|
|
|
|
sub banner_unlike { |
609
|
1
|
|
|
1
|
1
|
733
|
my ($self, $qr, $name) = @_; |
610
|
1
|
|
|
|
|
4
|
my $tb = __PACKAGE__->builder(); |
611
|
|
|
|
|
|
|
|
612
|
1
|
|
|
|
|
19
|
$tb->unlike($self->banner(), $qr, $name); |
613
|
|
|
|
|
|
|
} |
614
|
|
|
|
|
|
|
|
615
|
|
|
|
|
|
|
=item domain_like(qr/REGEX/, $name) |
616
|
|
|
|
|
|
|
|
617
|
|
|
|
|
|
|
Passes if server's announced domain matches against I. |
618
|
|
|
|
|
|
|
|
619
|
|
|
|
|
|
|
=cut |
620
|
|
|
|
|
|
|
|
621
|
|
|
|
|
|
|
sub domain_like { |
622
|
1
|
|
|
1
|
1
|
649
|
my ($self, $qr, $name) = @_; |
623
|
1
|
|
|
|
|
5
|
my $tb = __PACKAGE__->builder(); |
624
|
|
|
|
|
|
|
|
625
|
1
|
|
|
|
|
19
|
$tb->like($self->domain(), $qr, $name); |
626
|
|
|
|
|
|
|
} |
627
|
|
|
|
|
|
|
|
628
|
|
|
|
|
|
|
=item domain_unlike(qr/REGEX/, $name) |
629
|
|
|
|
|
|
|
|
630
|
|
|
|
|
|
|
Passes if server's announced domain doesn't match against I. |
631
|
|
|
|
|
|
|
|
632
|
|
|
|
|
|
|
=cut |
633
|
|
|
|
|
|
|
|
634
|
|
|
|
|
|
|
sub domain_unlike { |
635
|
1
|
|
|
1
|
1
|
852
|
my ($self, $qr, $name) = @_; |
636
|
1
|
|
|
|
|
12
|
my $tb = __PACKAGE__->builder(); |
637
|
|
|
|
|
|
|
|
638
|
1
|
|
|
|
|
12
|
$tb->unlike($self->domain(), $qr, $name); |
639
|
|
|
|
|
|
|
} |
640
|
|
|
|
|
|
|
|
641
|
|
|
|
|
|
|
=item mail_from_ok($from, $name) |
642
|
|
|
|
|
|
|
|
643
|
|
|
|
|
|
|
Sends a MAIL FROM: I to the server. Passes if the command succeeds |
644
|
|
|
|
|
|
|
|
645
|
|
|
|
|
|
|
=cut |
646
|
|
|
|
|
|
|
|
647
|
|
|
|
|
|
|
sub mail_from_ok { |
648
|
4
|
|
|
4
|
1
|
1638
|
my ($self, $from, $name) = @_; |
649
|
4
|
|
|
|
|
24
|
my $tb = __PACKAGE__->builder(); |
650
|
|
|
|
|
|
|
|
651
|
4
|
100
|
|
|
|
59
|
if ($self->mail_from($from)) { |
652
|
1
|
|
|
|
|
309
|
$tb->ok(1, $name); |
653
|
|
|
|
|
|
|
} else { |
654
|
3
|
|
|
|
|
1925
|
$tb->ok(0, $name); |
655
|
3
|
|
|
|
|
2331
|
$self->_smtp_diag; |
656
|
|
|
|
|
|
|
} |
657
|
|
|
|
|
|
|
} |
658
|
|
|
|
|
|
|
|
659
|
|
|
|
|
|
|
=item mail_from_ko($from, $name) |
660
|
|
|
|
|
|
|
|
661
|
|
|
|
|
|
|
Sends a MAIL FROM: I to the server. Passes if the command isn't successful |
662
|
|
|
|
|
|
|
|
663
|
|
|
|
|
|
|
=cut |
664
|
|
|
|
|
|
|
|
665
|
|
|
|
|
|
|
sub mail_from_ko { |
666
|
3
|
|
|
3
|
1
|
957
|
my ($self, $from, $name) = @_; |
667
|
3
|
|
|
|
|
17
|
my $tb = __PACKAGE__->builder(); |
668
|
|
|
|
|
|
|
|
669
|
3
|
50
|
|
|
|
55
|
if (not $self->mail_from($from)) { |
670
|
3
|
|
|
|
|
1675
|
$tb->ok(1, $name); |
671
|
|
|
|
|
|
|
} else { |
672
|
0
|
|
|
|
|
0
|
$tb->ok(0, $name); |
673
|
0
|
|
|
|
|
0
|
$self->_smtp_diag; |
674
|
|
|
|
|
|
|
} |
675
|
|
|
|
|
|
|
} |
676
|
|
|
|
|
|
|
|
677
|
|
|
|
|
|
|
=item rcpt_to_ok($to, $name) |
678
|
|
|
|
|
|
|
|
679
|
|
|
|
|
|
|
Sends a RCPT TO: I to the server. Passes if the command succeeds |
680
|
|
|
|
|
|
|
|
681
|
|
|
|
|
|
|
=cut |
682
|
|
|
|
|
|
|
|
683
|
|
|
|
|
|
|
sub rcpt_to_ok { |
684
|
4
|
|
|
4
|
1
|
1469
|
my ($self, $to, $name) = @_; |
685
|
4
|
|
|
|
|
84
|
my $tb = __PACKAGE__->builder(); |
686
|
|
|
|
|
|
|
|
687
|
4
|
50
|
|
|
|
57
|
if ($self->rcpt_to($to)) { |
688
|
0
|
|
|
|
|
0
|
$tb->ok(1, $name); |
689
|
|
|
|
|
|
|
} else { |
690
|
4
|
|
|
|
|
2294
|
$tb->ok(0, $name); |
691
|
4
|
|
|
|
|
2859
|
$self->_smtp_diag; |
692
|
|
|
|
|
|
|
} |
693
|
|
|
|
|
|
|
} |
694
|
|
|
|
|
|
|
|
695
|
|
|
|
|
|
|
=item rcpt_to_ko($to, $name) |
696
|
|
|
|
|
|
|
|
697
|
|
|
|
|
|
|
Sends a RCPT TO: I to the server. Passes if the command isn't successful |
698
|
|
|
|
|
|
|
|
699
|
|
|
|
|
|
|
=cut |
700
|
|
|
|
|
|
|
|
701
|
|
|
|
|
|
|
sub rcpt_to_ko { |
702
|
3
|
|
|
3
|
1
|
457
|
my ($self, $to, $name) = @_; |
703
|
3
|
|
|
|
|
12
|
my $tb = __PACKAGE__->builder(); |
704
|
|
|
|
|
|
|
|
705
|
3
|
50
|
|
|
|
28
|
if (not $self->rcpt_to($to)) { |
706
|
3
|
|
|
|
|
1402
|
$tb->ok(1, $name); |
707
|
|
|
|
|
|
|
} else { |
708
|
0
|
|
|
|
|
0
|
$tb->ok(0, $name); |
709
|
0
|
|
|
|
|
0
|
$self->_smtp_diag; |
710
|
|
|
|
|
|
|
} |
711
|
|
|
|
|
|
|
} |
712
|
|
|
|
|
|
|
|
713
|
|
|
|
|
|
|
=item data_ok($name) |
714
|
|
|
|
|
|
|
|
715
|
|
|
|
|
|
|
Sends a DATA command to the server. Passes if the command is successful. After calling this method, |
716
|
|
|
|
|
|
|
you should call datasend. |
717
|
|
|
|
|
|
|
|
718
|
|
|
|
|
|
|
=cut |
719
|
|
|
|
|
|
|
|
720
|
|
|
|
|
|
|
sub data_ok { |
721
|
3
|
|
|
3
|
1
|
623
|
my ($self, $name) = @_; |
722
|
3
|
|
|
|
|
13
|
my $tb = __PACKAGE__->builder(); |
723
|
|
|
|
|
|
|
|
724
|
3
|
50
|
|
|
|
64
|
if ($self->data == 1){ |
725
|
0
|
|
|
|
|
0
|
$tb->ok(1, $name); |
726
|
|
|
|
|
|
|
} else { |
727
|
3
|
|
|
|
|
1324
|
$tb->ok(0, $name); |
728
|
3
|
|
|
|
|
2611
|
$self->_smtp_diag; |
729
|
|
|
|
|
|
|
} |
730
|
|
|
|
|
|
|
} |
731
|
|
|
|
|
|
|
|
732
|
|
|
|
|
|
|
=item data_ko($name) |
733
|
|
|
|
|
|
|
|
734
|
|
|
|
|
|
|
Sends a DATA command to the server. Passes if the command is'nt successful |
735
|
|
|
|
|
|
|
|
736
|
|
|
|
|
|
|
=cut |
737
|
|
|
|
|
|
|
|
738
|
|
|
|
|
|
|
sub data_ko { |
739
|
2
|
|
|
2
|
1
|
435
|
my ($self, $name) = @_; |
740
|
2
|
|
|
|
|
9
|
my $tb = __PACKAGE__->builder(); |
741
|
|
|
|
|
|
|
|
742
|
2
|
50
|
|
|
|
38
|
if ($self->data != 1){ |
743
|
2
|
|
|
|
|
738
|
$tb->ok(1, $name); |
744
|
|
|
|
|
|
|
} else { |
745
|
0
|
|
|
|
|
0
|
$tb->ok(0, $name); |
746
|
0
|
|
|
|
|
0
|
$self->_smtp_diag; |
747
|
|
|
|
|
|
|
} |
748
|
|
|
|
|
|
|
} |
749
|
|
|
|
|
|
|
|
750
|
|
|
|
|
|
|
#sub datasend { |
751
|
|
|
|
|
|
|
# my ($self, $data) = @_; |
752
|
|
|
|
|
|
|
# |
753
|
|
|
|
|
|
|
# if (ref($data) eq 'ARRAY'){ |
754
|
|
|
|
|
|
|
# $self::SUPER->datasend($data); |
755
|
|
|
|
|
|
|
# } |
756
|
|
|
|
|
|
|
#} |
757
|
|
|
|
|
|
|
|
758
|
|
|
|
|
|
|
=item dataend_ok($name) |
759
|
|
|
|
|
|
|
|
760
|
|
|
|
|
|
|
Sends a . command to the server. Passes if the command is successful. |
761
|
|
|
|
|
|
|
|
762
|
|
|
|
|
|
|
=cut |
763
|
|
|
|
|
|
|
|
764
|
|
|
|
|
|
|
sub dataend_ok { |
765
|
2
|
|
|
2
|
1
|
1285
|
my ($self, $name) = @_; |
766
|
2
|
|
|
|
|
10
|
my $tb = __PACKAGE__->builder(); |
767
|
|
|
|
|
|
|
|
768
|
2
|
50
|
|
|
|
38
|
if ($self->dataend() == 1){ |
769
|
0
|
|
|
|
|
0
|
$tb->ok(1, $name); |
770
|
|
|
|
|
|
|
} else { |
771
|
2
|
|
|
|
|
655
|
$tb->ok(0, $name); |
772
|
2
|
|
|
|
|
1593
|
$self->_smtp_diag(); |
773
|
|
|
|
|
|
|
} |
774
|
|
|
|
|
|
|
} |
775
|
|
|
|
|
|
|
|
776
|
|
|
|
|
|
|
=item dataend_ko($name) |
777
|
|
|
|
|
|
|
|
778
|
|
|
|
|
|
|
Sends a . command to the server. Passes if the command is not successful. |
779
|
|
|
|
|
|
|
|
780
|
|
|
|
|
|
|
=cut |
781
|
|
|
|
|
|
|
|
782
|
|
|
|
|
|
|
sub dataend_ko { |
783
|
2
|
|
|
2
|
1
|
1452
|
my ($self, $name) = @_; |
784
|
2
|
|
|
|
|
9
|
my $tb = __PACKAGE__->builder(); |
785
|
|
|
|
|
|
|
|
786
|
2
|
50
|
|
|
|
48
|
if ($self->dataend() != 1){ |
787
|
2
|
|
|
|
|
514
|
$tb->ok(1, $name); |
788
|
|
|
|
|
|
|
} else { |
789
|
0
|
|
|
|
|
0
|
$tb->ok(0, $name); |
790
|
0
|
|
|
|
|
0
|
$self->_smtp_diag(); |
791
|
|
|
|
|
|
|
} |
792
|
|
|
|
|
|
|
} |
793
|
|
|
|
|
|
|
|
794
|
|
|
|
|
|
|
=item help_like([HELP_ON], qr/REGEX/, $name) |
795
|
|
|
|
|
|
|
|
796
|
|
|
|
|
|
|
Sends HELP I command to the server. If the returned text matches I, the test passes. To test |
797
|
|
|
|
|
|
|
plain HELP command, pass undef in HELP_ON. |
798
|
|
|
|
|
|
|
|
799
|
|
|
|
|
|
|
=cut |
800
|
|
|
|
|
|
|
|
801
|
|
|
|
|
|
|
sub help_like { |
802
|
3
|
|
|
3
|
1
|
2566
|
my ($self, $help_on, $expected, $name) = @_; |
803
|
3
|
|
|
|
|
13
|
my $tb = __PACKAGE__->builder(); |
804
|
|
|
|
|
|
|
|
805
|
3
|
|
|
|
|
48
|
$tb->like($self->help($help_on), $expected, $name); |
806
|
|
|
|
|
|
|
} |
807
|
|
|
|
|
|
|
|
808
|
|
|
|
|
|
|
=item help_unlike([HELP_ON], qr/REGEX/, $name) |
809
|
|
|
|
|
|
|
|
810
|
|
|
|
|
|
|
Sends HELP I command to the server. If the returned text doesn't match I, the test |
811
|
|
|
|
|
|
|
passes. To test plain HELP command, pass undef in HELP_ON. |
812
|
|
|
|
|
|
|
|
813
|
|
|
|
|
|
|
=cut |
814
|
|
|
|
|
|
|
|
815
|
|
|
|
|
|
|
sub help_unlike { |
816
|
2
|
|
|
2
|
1
|
3994
|
my ($self, $help_on, $expected, $name) = @_; |
817
|
2
|
|
|
|
|
9
|
my $tb = __PACKAGE__->builder(); |
818
|
|
|
|
|
|
|
|
819
|
2
|
|
|
|
|
22
|
$tb->unlike($self->help($help_on), $expected, $name); |
820
|
|
|
|
|
|
|
} |
821
|
|
|
|
|
|
|
|
822
|
|
|
|
|
|
|
=item quit_ok($name) |
823
|
|
|
|
|
|
|
|
824
|
|
|
|
|
|
|
Send a QUIT command to the server. Pass if command was successful |
825
|
|
|
|
|
|
|
|
826
|
|
|
|
|
|
|
=cut |
827
|
|
|
|
|
|
|
|
828
|
|
|
|
|
|
|
sub quit_ok { |
829
|
2
|
|
|
2
|
1
|
1734
|
my ($self, $name) = @_; |
830
|
2
|
|
|
|
|
11
|
my $tb = __PACKAGE__->builder(); |
831
|
2
|
|
|
|
|
35
|
$self->quit(); |
832
|
2
|
100
|
|
|
|
11908
|
if (_is_between($self->code(), 200, 399)){ |
833
|
1
|
|
|
|
|
14
|
$tb->ok(1, $name); |
834
|
|
|
|
|
|
|
} else { |
835
|
1
|
|
|
|
|
10
|
$tb->ok(0, $name); |
836
|
1
|
|
|
|
|
707
|
$self->_smtp_diag; |
837
|
|
|
|
|
|
|
} |
838
|
|
|
|
|
|
|
} |
839
|
|
|
|
|
|
|
|
840
|
|
|
|
|
|
|
=item quit_ko($name) |
841
|
|
|
|
|
|
|
|
842
|
|
|
|
|
|
|
Send a QUIT command to the server. Pass if command was'nt successful |
843
|
|
|
|
|
|
|
|
844
|
|
|
|
|
|
|
=cut |
845
|
|
|
|
|
|
|
|
846
|
|
|
|
|
|
|
sub quit_ko { |
847
|
2
|
|
|
2
|
1
|
1242
|
my ($self, $name) = @_; |
848
|
2
|
|
|
|
|
12
|
my $tb = __PACKAGE__->builder(); |
849
|
2
|
|
|
|
|
40
|
$self->quit(); |
850
|
2
|
100
|
|
|
|
3835
|
if (_is_between($self->code(), 200, 399)){ |
851
|
1
|
|
|
|
|
6
|
$tb->ok(0, $name); |
852
|
1
|
|
|
|
|
524
|
$self->_smtp_diag; |
853
|
|
|
|
|
|
|
} else { |
854
|
1
|
|
|
|
|
9
|
$tb->ok(1, $name); |
855
|
|
|
|
|
|
|
} |
856
|
|
|
|
|
|
|
} |
857
|
|
|
|
|
|
|
|
858
|
|
|
|
|
|
|
sub _is_between { |
859
|
40
|
|
|
40
|
|
438
|
my ($what, $start, $end) = @_; |
860
|
40
|
|
66
|
|
|
338
|
return ($what >= $start and $what <= $end); |
861
|
|
|
|
|
|
|
} |
862
|
|
|
|
|
|
|
|
863
|
|
|
|
|
|
|
sub _smtp_diag { |
864
|
34
|
|
|
34
|
|
62
|
my $self = shift; |
865
|
34
|
|
|
|
|
305
|
my $tb = __PACKAGE__->builder(); |
866
|
34
|
|
|
|
|
507
|
$tb->diag(sprintf(" Got from server %s %s\n", $self->code, $self->message)); |
867
|
|
|
|
|
|
|
} |
868
|
|
|
|
|
|
|
|
869
|
|
|
|
|
|
|
=back |
870
|
|
|
|
|
|
|
|
871
|
|
|
|
|
|
|
=head1 NON TEST METHODS |
872
|
|
|
|
|
|
|
|
873
|
|
|
|
|
|
|
=over 4 |
874
|
|
|
|
|
|
|
|
875
|
|
|
|
|
|
|
=item mail_from($from) |
876
|
|
|
|
|
|
|
|
877
|
|
|
|
|
|
|
Issues a MAIL FROM: I command to the server. |
878
|
|
|
|
|
|
|
|
879
|
|
|
|
|
|
|
=cut |
880
|
|
|
|
|
|
|
|
881
|
|
|
|
|
|
|
sub mail_from { |
882
|
8
|
|
|
8
|
1
|
1237
|
return shift->command("MAIL", "FROM:", @_)->response() == Net::Cmd::CMD_OK |
883
|
|
|
|
|
|
|
} |
884
|
|
|
|
|
|
|
|
885
|
|
|
|
|
|
|
=item rcpt_to($to) |
886
|
|
|
|
|
|
|
|
887
|
|
|
|
|
|
|
Issues a RCPT TO: I command to the server. |
888
|
|
|
|
|
|
|
|
889
|
|
|
|
|
|
|
=cut |
890
|
|
|
|
|
|
|
|
891
|
|
|
|
|
|
|
sub rcpt_to { |
892
|
8
|
|
|
8
|
1
|
492
|
return shift->command("RCPT", "TO:", @_)->response() == Net::Cmd::CMD_OK |
893
|
|
|
|
|
|
|
} |
894
|
|
|
|
|
|
|
|
895
|
|
|
|
|
|
|
=back |
896
|
|
|
|
|
|
|
|
897
|
|
|
|
|
|
|
=head1 AUTHOR |
898
|
|
|
|
|
|
|
|
899
|
|
|
|
|
|
|
Jose Luis Martinez |
900
|
|
|
|
|
|
|
CAPSiDE |
901
|
|
|
|
|
|
|
jlmartinez@capside.com |
902
|
|
|
|
|
|
|
http://www.pplusdomain.net/ |
903
|
|
|
|
|
|
|
http://www.capside.com/ |
904
|
|
|
|
|
|
|
|
905
|
|
|
|
|
|
|
=head1 COPYRIGHT |
906
|
|
|
|
|
|
|
|
907
|
|
|
|
|
|
|
This program is free software; you can redistribute |
908
|
|
|
|
|
|
|
it and/or modify it under the same terms as Perl itself. |
909
|
|
|
|
|
|
|
|
910
|
|
|
|
|
|
|
The full text of the license can be found in the |
911
|
|
|
|
|
|
|
LICENSE file included with this module. |
912
|
|
|
|
|
|
|
|
913
|
|
|
|
|
|
|
|
914
|
|
|
|
|
|
|
=cut |
915
|
|
|
|
|
|
|
|
916
|
|
|
|
|
|
|
|
917
|
|
|
|
|
|
|
1; |
918
|
|
|
|
|
|
|
|