line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Net::SMTP::OneLiner; |
3
|
|
|
|
|
|
|
|
4
|
2
|
|
|
2
|
|
7980
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
86
|
|
5
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
160
|
|
6
|
|
|
|
|
|
|
|
7
|
2
|
|
|
2
|
|
24
|
use Carp; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
154
|
|
8
|
2
|
|
|
2
|
|
2850
|
use Net::SMTP; |
|
2
|
|
|
|
|
106842
|
|
|
2
|
|
|
|
|
1412
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
require Exporter; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our @EXPORT = qw( send_mail ); ## no critic |
15
|
|
|
|
|
|
|
our $VERSION = "2.0005"; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $HOSTNAME = "localhost"; |
18
|
|
|
|
|
|
|
our $PORT = 25; |
19
|
|
|
|
|
|
|
our $ELHO = "localhost"; |
20
|
|
|
|
|
|
|
our $DEBUG = 0; |
21
|
|
|
|
|
|
|
our $TIMEO = 20; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our $CONTENT_TYPE = "text/plain; charset=UTF-8"; |
24
|
|
|
|
|
|
|
our $TRANSFER_ENCODING = "quoted-printable"; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub send_mail { |
27
|
0
|
|
|
0
|
0
|
|
my ($from, $to, $subj, $msg, $cc, $bcc, $labl) = @_; |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
|
my $to_hit = $HOSTNAME; |
30
|
0
|
0
|
|
|
|
|
$to_hit .= ":$PORT" if $PORT ne "25"; |
31
|
|
|
|
|
|
|
|
32
|
0
|
0
|
|
|
|
|
my $smtp = Net::SMTP->new($to_hit, Hello=>$ELHO, Timeout=>$TIMEO, Debug=>$DEBUG) or croak $!; |
33
|
|
|
|
|
|
|
|
34
|
0
|
0
|
|
|
|
|
$to = [ $to ] unless ref $to; |
35
|
0
|
0
|
|
|
|
|
$cc = [ $cc ] unless ref $cc; |
36
|
0
|
0
|
|
|
|
|
$bcc = [ $bcc ] unless ref $bcc; |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
@$to = grep {defined $_} @$to; |
|
0
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
@$cc = grep {defined $_} @$cc; |
|
0
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
@$bcc = grep {defined $_} @$bcc; |
|
0
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
|
42
|
0
|
0
|
|
|
|
|
croak "You need to specifie at least one recipient" unless (@$to + @$cc + @$bcc) > 0; |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
|
$smtp->mail($from); |
45
|
0
|
|
|
|
|
|
$smtp->to(@$to, @$cc, @$bcc); |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
$smtp->data; |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
for ($from, @$to, @$cc) { |
50
|
0
|
0
|
|
|
|
|
$_ = "$labl->{$_} <$_>" if defined $labl->{$_}; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
$to = join(", ", @$to); |
54
|
0
|
|
|
|
|
|
$cc = join(", ", @$cc); |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
$smtp->datasend("From: $from\n"); |
57
|
0
|
0
|
|
|
|
|
$smtp->datasend("To: $to\n") if $to; |
58
|
0
|
0
|
|
|
|
|
$smtp->datasend("CC: $cc\n") if $cc; |
59
|
0
|
0
|
|
|
|
|
$smtp->datasend("Subject: $subj\n") if $subj; |
60
|
0
|
|
|
|
|
|
$smtp->datasend("Content-Type: $CONTENT_TYPE\n"); |
61
|
0
|
|
|
|
|
|
$smtp->datasend("Content-Transfer-Encoding: $TRANSFER_ENCODING\n"); |
62
|
0
|
|
|
|
|
|
$smtp->datasend("\n"); |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
$smtp->datasend($msg); |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
$smtp->dataend; |
67
|
0
|
|
|
|
|
|
$smtp->quit; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
return; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1; |