| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# |
|
2
|
|
|
|
|
|
|
# Mail/Salsa/Sendmail.pm |
|
3
|
|
|
|
|
|
|
# Last Modification: Wed Jun 23 17:11:01 WEST 2004 |
|
4
|
|
|
|
|
|
|
# |
|
5
|
|
|
|
|
|
|
# Copyright (c) 2004 Henrique Dias . All rights reserved. |
|
6
|
|
|
|
|
|
|
# This module is free software; you can redistribute it and/or modify |
|
7
|
|
|
|
|
|
|
# it under the same terms as Perl itself. |
|
8
|
|
|
|
|
|
|
# |
|
9
|
|
|
|
|
|
|
package Mail::Salsa::Sendmail; |
|
10
|
|
|
|
|
|
|
|
|
11
|
11
|
|
|
11
|
|
26933
|
use 5.008000; |
|
|
11
|
|
|
|
|
37
|
|
|
|
11
|
|
|
|
|
427
|
|
|
12
|
11
|
|
|
11
|
|
60
|
use strict; |
|
|
11
|
|
|
|
|
24
|
|
|
|
11
|
|
|
|
|
324
|
|
|
13
|
11
|
|
|
11
|
|
54
|
use warnings; |
|
|
11
|
|
|
|
|
21
|
|
|
|
11
|
|
|
|
|
318
|
|
|
14
|
11
|
|
|
11
|
|
11031
|
use IO::Socket; |
|
|
11
|
|
|
|
|
402367
|
|
|
|
11
|
|
|
|
|
61
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
require Exporter; |
|
17
|
11
|
|
|
11
|
|
10134
|
use AutoLoader qw(AUTOLOAD); |
|
|
11
|
|
|
|
|
1795
|
|
|
|
11
|
|
|
|
|
97
|
|
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
|
22
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
|
23
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# This allows declaration use Mail::Salsa::Sendmail ':all'; |
|
26
|
|
|
|
|
|
|
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK |
|
27
|
|
|
|
|
|
|
# will save memory. |
|
28
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw() ] ); |
|
29
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
|
30
|
|
|
|
|
|
|
our @EXPORT = qw(); |
|
31
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub new { |
|
34
|
0
|
|
|
0
|
0
|
|
my $proto = shift; |
|
35
|
0
|
|
0
|
|
|
|
my $class = ref($proto) || $proto; |
|
36
|
0
|
|
|
|
|
|
my $self = { |
|
37
|
|
|
|
|
|
|
'smtp_server' => ["localhost"], |
|
38
|
|
|
|
|
|
|
'smtp_port' => 25, |
|
39
|
|
|
|
|
|
|
'timeout' => 120, |
|
40
|
|
|
|
|
|
|
'mail_from' => "", |
|
41
|
|
|
|
|
|
|
'rcpt_to' => [], |
|
42
|
|
|
|
|
|
|
'list_file' => "", |
|
43
|
|
|
|
|
|
|
'data' => undef, |
|
44
|
|
|
|
|
|
|
'filehandle' => undef, |
|
45
|
|
|
|
|
|
|
@_ |
|
46
|
|
|
|
|
|
|
}; |
|
47
|
0
|
|
|
|
|
|
bless ($self, $class); |
|
48
|
0
|
0
|
|
|
|
|
return($self->init() ? $self : undef); |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub send_data { |
|
52
|
0
|
|
|
0
|
0
|
|
my $handle = shift; |
|
53
|
0
|
|
|
|
|
|
my $data = shift; |
|
54
|
|
|
|
|
|
|
|
|
55
|
0
|
0
|
|
|
|
|
unless($data =~ /\n+$/) { $data = join("", $data, "\n"); } |
|
|
0
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
print $handle "$data"; |
|
57
|
0
|
|
|
|
|
|
return(&get_answer($handle)); |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub helo { |
|
61
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
62
|
|
|
|
|
|
|
|
|
63
|
0
|
0
|
|
|
|
|
defined($self->{'filehandle'}) or return("Error"); |
|
64
|
0
|
|
|
|
|
|
my $hostname = $self->{'smtp_server'}->[0]; |
|
65
|
0
|
|
|
|
|
|
return(&send_data($self->{'filehandle'}, "HELO $hostname\n")); |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub mail_from { |
|
69
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
70
|
0
|
|
0
|
|
|
|
my $mailfrom = shift || return("Error"); |
|
71
|
|
|
|
|
|
|
|
|
72
|
0
|
0
|
|
|
|
|
defined($self->{'filehandle'}) or return("Error"); |
|
73
|
0
|
|
|
|
|
|
return(&send_data($self->{'filehandle'}, "MAIL FROM: $mailfrom\n")); |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub rcpt_to { |
|
77
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
78
|
0
|
|
|
|
|
|
my $param = { |
|
79
|
|
|
|
|
|
|
list_file => "", |
|
80
|
|
|
|
|
|
|
addresses => [], |
|
81
|
|
|
|
|
|
|
@_, |
|
82
|
|
|
|
|
|
|
}; |
|
83
|
0
|
0
|
|
|
|
|
defined($self->{'filehandle'}) or return("Error"); |
|
84
|
0
|
0
|
0
|
|
|
|
if($param->{'list_file'} && -e $param->{'list_file'} && -s $param->{'list_file'}) { |
|
|
|
|
0
|
|
|
|
|
|
85
|
0
|
0
|
|
|
|
|
open(LIST, "<", $param->{'list_file'}) or die("$!"); |
|
86
|
0
|
|
|
|
|
|
while() { |
|
87
|
0
|
0
|
|
|
|
|
next if(/^\#/); |
|
88
|
0
|
|
|
|
|
|
chomp; |
|
89
|
0
|
|
|
|
|
|
my ($email) = (/\([^\@\<\>]+\@[^\@\<\>]+)\>?/); |
|
90
|
0
|
|
|
|
|
|
&send_data($self->{'filehandle'}, "RCPT TO: $email\n"); |
|
91
|
|
|
|
|
|
|
} |
|
92
|
0
|
|
|
|
|
|
close(LIST); |
|
93
|
|
|
|
|
|
|
} |
|
94
|
0
|
0
|
|
|
|
|
if(scalar(@{$param->{'addresses'}})) { |
|
|
0
|
|
|
|
|
|
|
|
95
|
0
|
|
|
|
|
|
for my $email (@{$param->{'addresses'}}) { |
|
|
0
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
&send_data($self->{'filehandle'}, "RCPT TO: $email\n"); |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
} |
|
99
|
0
|
|
|
|
|
|
return(); |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub data { |
|
103
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
104
|
0
|
|
0
|
|
|
|
my $code = shift || return("Error"); |
|
105
|
|
|
|
|
|
|
|
|
106
|
0
|
0
|
|
|
|
|
defined($self->{'filehandle'}) or return("Error"); |
|
107
|
0
|
|
|
|
|
|
&send_data($self->{'filehandle'}, "DATA\n"); |
|
108
|
0
|
0
|
|
|
|
|
(ref($code) eq "CODE") or return("Error"); |
|
109
|
0
|
|
|
|
|
|
$code->($self->{'filehandle'}); |
|
110
|
0
|
|
|
|
|
|
return(&send_data($self->{'filehandle'}, ".\n")); |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub quit { |
|
114
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
115
|
|
|
|
|
|
|
|
|
116
|
0
|
0
|
|
|
|
|
defined($self->{'filehandle'}) or return("Error"); |
|
117
|
0
|
|
|
|
|
|
&send_data($self->{'filehandle'}, "QUIT\n"); |
|
118
|
0
|
|
|
|
|
|
$self->{'filehandle'}->close(); |
|
119
|
0
|
|
|
|
|
|
return(); |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
sub everything { |
|
123
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
124
|
0
|
|
|
|
|
|
my $param = { |
|
125
|
|
|
|
|
|
|
'mail_from' => $self->{'mail_from'}, |
|
126
|
|
|
|
|
|
|
'rcpt_to' => $self->{'rcpt_to'}, |
|
127
|
|
|
|
|
|
|
'list_file' => $self->{'list_file'}, |
|
128
|
|
|
|
|
|
|
'data' => $self->{'data'}, |
|
129
|
|
|
|
|
|
|
@_ |
|
130
|
|
|
|
|
|
|
}; |
|
131
|
0
|
|
|
|
|
|
$self->helo(); |
|
132
|
0
|
|
|
|
|
|
$self->mail_from($param->{'mail_from'}); |
|
133
|
0
|
|
|
|
|
|
$self->rcpt_to( |
|
134
|
|
|
|
|
|
|
list_file => $param->{'list_file'}, |
|
135
|
|
|
|
|
|
|
addresses => $param->{'rcpt_to'} |
|
136
|
|
|
|
|
|
|
); |
|
137
|
0
|
|
|
|
|
|
$self->data($param->{'data'}); |
|
138
|
0
|
|
|
|
|
|
$self->quit(); |
|
139
|
0
|
|
|
|
|
|
return(); |
|
140
|
|
|
|
|
|
|
} |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub init { |
|
143
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
144
|
|
|
|
|
|
|
|
|
145
|
0
|
|
|
|
|
|
my $handle; |
|
146
|
0
|
|
|
|
|
|
for my $host (@{$self->{'smtp_server'}}) { |
|
|
0
|
|
|
|
|
|
|
|
147
|
0
|
|
|
|
|
|
$handle = IO::Socket::INET->new( |
|
148
|
|
|
|
|
|
|
Timeout => $self->{'timeout'}, |
|
149
|
|
|
|
|
|
|
Proto => "tcp", |
|
150
|
|
|
|
|
|
|
PeerAddr => $host, |
|
151
|
|
|
|
|
|
|
PeerPort => $self->{'smtp_port'} |
|
152
|
|
|
|
|
|
|
); |
|
153
|
0
|
|
|
|
|
|
$self->{'smtp_server'}->[0] = $host; |
|
154
|
0
|
0
|
|
|
|
|
last if(defined($handle)); |
|
155
|
|
|
|
|
|
|
} |
|
156
|
|
|
|
|
|
|
|
|
157
|
0
|
0
|
|
|
|
|
defined($handle) or return(); |
|
158
|
0
|
|
|
|
|
|
$handle->autoflush(1); |
|
159
|
0
|
|
|
|
|
|
&get_answer($handle); |
|
160
|
|
|
|
|
|
|
|
|
161
|
0
|
|
|
|
|
|
$self->{'filehandle'} = $handle; |
|
162
|
0
|
|
|
|
|
|
return(1); |
|
163
|
|
|
|
|
|
|
} |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
sub get_answer { |
|
166
|
0
|
|
|
0
|
0
|
|
my $handle = shift; |
|
167
|
0
|
|
|
|
|
|
my $answer = <$handle>; |
|
168
|
0
|
|
|
|
|
|
my ($code) = ($answer =~ /^(\d\d\d) /); |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
## &logs("SMTP ANSWER: $answer"); |
|
171
|
0
|
0
|
|
|
|
|
($code < 500) or return($answer); |
|
172
|
|
|
|
|
|
|
## print "SMTP ANSWER: $answer\n"; |
|
173
|
0
|
|
|
|
|
|
return(); |
|
174
|
|
|
|
|
|
|
} |
|
175
|
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
sub logs { |
|
177
|
0
|
|
|
0
|
0
|
|
my $string = shift; |
|
178
|
0
|
0
|
|
|
|
|
open(LOGS, ">>", "/tmp/____logs.log") or die("$!"); |
|
179
|
0
|
|
|
|
|
|
print LOGS "$string\n"; |
|
180
|
0
|
|
|
|
|
|
close(LOGS); |
|
181
|
0
|
|
|
|
|
|
return(); |
|
182
|
|
|
|
|
|
|
} |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
# Preloaded methods go here. |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
# Autoload methods go after =cut, and are processed by the autosplit program. |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
1; |
|
189
|
|
|
|
|
|
|
__END__ |