line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package XAS::Lib::Modules::Email; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.02'; |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
602
|
use Try::Tiny; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
44
|
|
6
|
1
|
|
|
1
|
|
706
|
use MIME::Lite; |
|
1
|
|
|
|
|
14725
|
|
|
1
|
|
|
|
|
28
|
|
7
|
1
|
|
|
1
|
|
6
|
use File::Basename; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
59
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use XAS::Class |
10
|
1
|
|
|
|
|
7
|
debug => 0, |
11
|
|
|
|
|
|
|
version => $VERSION, |
12
|
|
|
|
|
|
|
base => 'XAS::Singleton', |
13
|
|
|
|
|
|
|
utils => ':validation dotid compress', |
14
|
1
|
|
|
1
|
|
4
|
; |
|
1
|
|
|
|
|
1
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
#use Data::Dumper; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
19
|
|
|
|
|
|
|
# Public Methods |
20
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub send { |
23
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
24
|
0
|
|
|
|
|
|
my $p = validate_params(\@_, { |
25
|
|
|
|
|
|
|
-to => 1, |
26
|
|
|
|
|
|
|
-from => 1, |
27
|
|
|
|
|
|
|
-subject => 1, |
28
|
|
|
|
|
|
|
-message => { optional => 1, default => ' '}, |
29
|
|
|
|
|
|
|
-attachment => { optional => 1, default => undef } |
30
|
|
|
|
|
|
|
}); |
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
my $msg; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
try { |
35
|
|
|
|
|
|
|
|
36
|
0
|
0
|
|
0
|
|
|
if ($self->env->mxmailer eq 'smtp') { |
37
|
|
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
MIME::Lite->send( |
39
|
|
|
|
|
|
|
$self->env->mxmailer, |
40
|
|
|
|
|
|
|
$self->env->mxserver, |
41
|
|
|
|
|
|
|
Timeout => $self->env->mxtimeout, |
42
|
|
|
|
|
|
|
Port => $self->env->mxport, |
43
|
|
|
|
|
|
|
); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
$msg = MIME::Lite->new( |
48
|
|
|
|
|
|
|
To => $p->{'to'}, |
49
|
|
|
|
|
|
|
From => $p->{'from'}, |
50
|
0
|
|
|
|
|
|
Subject => $p->{'subject'}, |
51
|
|
|
|
|
|
|
Type => 'multipart/mixed' |
52
|
|
|
|
|
|
|
); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
$msg->attach( |
55
|
|
|
|
|
|
|
Type => 'TEXT', |
56
|
0
|
|
|
|
|
|
Data => $p->{'message'} |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
|
if (defined($p->{'attachment'})) { |
60
|
|
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
my $filename = $p->{'attachment'}; |
62
|
0
|
|
|
|
|
|
my ($name, $path, $suffix) = fileparse($filename, qr{\..*}); |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
$msg->attach( |
65
|
|
|
|
|
|
|
Type => 'AUTO', |
66
|
|
|
|
|
|
|
Path => $filename, |
67
|
|
|
|
|
|
|
Filename => $name . $suffix, |
68
|
|
|
|
|
|
|
Dispostition => 'attachment' |
69
|
|
|
|
|
|
|
); |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
$msg->send(); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
} catch { |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
0
|
|
|
my $ex = $_; |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
$self->throw_msg( |
80
|
|
|
|
|
|
|
dotid($self->class) . '.send.undeliverable', |
81
|
|
|
|
|
|
|
'enail_undeliverable', |
82
|
0
|
|
|
|
|
|
$p->{'to'}, |
83
|
|
|
|
|
|
|
compress($ex) |
84
|
|
|
|
|
|
|
); |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
}; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
91
|
|
|
|
|
|
|
# Private methods |
92
|
|
|
|
|
|
|
# ------------------------------------------------------------------------ |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
__END__ |