line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mail::Sender::Easy; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
21371
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
4
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
24
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
133
|
|
7
|
1
|
|
|
1
|
|
1265
|
use Mail::Sender; |
|
1
|
|
|
|
|
136603
|
|
|
1
|
|
|
|
|
63
|
|
8
|
1
|
|
|
1
|
|
13
|
use File::Spec; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
147
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
my $hostname_code = sub { |
11
|
|
|
|
|
|
|
require POSIX; |
12
|
|
|
|
|
|
|
return (POSIX::uname())[1]; |
13
|
|
|
|
|
|
|
}; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
if(!eval { |
16
|
|
|
|
|
|
|
require Sys::Hostname::FQDN; |
17
|
|
|
|
|
|
|
$hostname_code = \&Sys::Hostname::FQDN::fqdn; |
18
|
|
|
|
|
|
|
return 1; |
19
|
|
|
|
|
|
|
}){ |
20
|
|
|
|
|
|
|
eval { |
21
|
|
|
|
|
|
|
require Net::Domain; |
22
|
|
|
|
|
|
|
$hostname_code = \&Net::Domain::hostfqdn; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
require Exporter; |
27
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
28
|
|
|
|
|
|
|
our @EXPORT_OK = qw(email); |
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
1
|
|
915
|
use version;our $VERSION = qv('0.0.5'); |
|
1
|
|
|
|
|
1903
|
|
|
1
|
|
|
|
|
6
|
|
31
|
|
|
|
|
|
|
|
32
|
0
|
|
|
0
|
1
|
|
sub email { Mail::Sender->new()->easy(shift()); } |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub Mail::Sender::easy { |
35
|
0
|
|
|
0
|
0
|
|
my($sndr, $mail_ref) = @_; |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
my $text = delete $mail_ref->{'_text'}; |
38
|
0
|
|
|
|
|
|
my $html = delete $mail_ref->{'_html'}; |
39
|
0
|
|
|
|
|
|
my $attachments = delete $mail_ref->{'_attachments'}; |
40
|
|
|
|
|
|
|
|
41
|
0
|
0
|
|
|
|
|
my $text_info = ref $mail_ref->{'_text_info'} eq 'HASH' |
42
|
|
|
|
|
|
|
? delete $mail_ref->{'_text_info'} : {}; |
43
|
0
|
0
|
|
|
|
|
delete $mail_ref->{'_text_info'} if exists $mail_ref->{'_text_info'}; |
44
|
0
|
|
|
|
|
|
delete $text_info->{$_} for qw(ctype disposition msg); |
45
|
|
|
|
|
|
|
|
46
|
0
|
0
|
|
|
|
|
my $html_info = ref $mail_ref->{'_html_info'} eq 'HASH' |
47
|
|
|
|
|
|
|
? delete $mail_ref->{'_html_info'} : {}; |
48
|
0
|
0
|
|
|
|
|
delete $mail_ref->{'_html_info'} if exists $mail_ref->{'_html_info'}; |
49
|
0
|
|
|
|
|
|
delete $html_info->{$_} for qw(ctype disposition msg); |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
my $time = time; |
52
|
0
|
0
|
|
|
|
|
my $user = $^O eq 'MSWin32' ? "(Windows: $<)" : getpwuid($<); |
53
|
0
|
0
|
|
|
|
|
my $eusr = $^O eq 'MSWin32' ? "(Windows: $>)" : getpwuid($>); |
54
|
0
|
|
|
|
|
|
my $file = File::Spec->rel2abs($0); |
55
|
0
|
|
|
|
|
|
my $host = $hostname_code->(); |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
my @siteheaders = ( |
58
|
|
|
|
|
|
|
qq{X-Mailer: use SimpleMood; - Sent via the email() function or easy() method of Mail/Sender/Easy.pm and/or SimpleMood.pm both by Daniel Muey.}, |
59
|
|
|
|
|
|
|
qq{X-Mailer: Sent via $file ($0) on $host by uid $< ($user) / euid $> ($eusr) at $time (unix epoch)}, |
60
|
|
|
|
|
|
|
); |
61
|
0
|
0
|
|
|
|
|
push @siteheaders, qq(X-Mailer: SMTP Auth provided by (object data) $sndr->{'authid'}) if $sndr->{'authid'}; |
62
|
0
|
0
|
|
|
|
|
push @siteheaders, qq(X-Mailer: SMTP Auth provided by (hashref arg) $mail_ref->{'authid'}) if $mail_ref->{'authid'}; |
63
|
|
|
|
|
|
|
|
64
|
0
|
0
|
|
|
|
|
croak q{You must specify the "_text" key.} if !defined $text; |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
eval { |
67
|
0
|
|
0
|
|
|
|
local $Mail::Sender::SITE_HEADERS = join("\015\012", @siteheaders) || ''; |
68
|
|
|
|
|
|
|
|
69
|
0
|
0
|
0
|
|
|
|
if($html) { |
|
|
0
|
|
|
|
|
|
70
|
0
|
|
|
|
|
|
$mail_ref->{'multipart'} = 'mixed'; |
71
|
0
|
|
|
|
|
|
$sndr->OpenMultipart($mail_ref); |
72
|
0
|
|
|
|
|
|
$sndr->Part({ |
73
|
|
|
|
|
|
|
'ctype' => 'multipart/alternative' |
74
|
|
|
|
|
|
|
}); |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
$sndr->Part({ |
77
|
0
|
|
|
|
|
|
%{ $text_info }, |
78
|
|
|
|
|
|
|
'ctype' => 'text/plain', |
79
|
|
|
|
|
|
|
'disposition' => 'NONE', |
80
|
|
|
|
|
|
|
# 'msg' => "$text$CRLF" |
81
|
|
|
|
|
|
|
}); |
82
|
0
|
|
|
|
|
|
$sndr->SendLineEnc($text); |
83
|
|
|
|
|
|
|
|
84
|
0
|
|
|
|
|
|
$sndr->Part({ |
85
|
0
|
|
|
|
|
|
%{ $html_info }, |
86
|
|
|
|
|
|
|
'ctype' => 'text/html', |
87
|
|
|
|
|
|
|
'disposition' => 'NONE', |
88
|
|
|
|
|
|
|
# 'msg' => "$html$CRLF" |
89
|
|
|
|
|
|
|
}); |
90
|
0
|
|
|
|
|
|
$sndr->SendLineEnc($html); |
91
|
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
$sndr->EndPart('multipart/alternative'); |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
elsif(!$html && $attachments) { |
95
|
0
|
|
|
|
|
|
$sndr->OpenMultipart($mail_ref); |
96
|
0
|
|
|
|
|
|
$sndr->Body({ |
97
|
0
|
|
|
|
|
|
%{ $text_info }, |
98
|
|
|
|
|
|
|
'ctype' => 'text/plain', |
99
|
|
|
|
|
|
|
'disposition' => 'NONE', |
100
|
|
|
|
|
|
|
# 'msg' => $text, |
101
|
|
|
|
|
|
|
}); |
102
|
0
|
|
|
|
|
|
$sndr->SendLineEnc($text); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
else { |
105
|
0
|
|
|
|
|
|
$sndr->Open({ |
106
|
0
|
|
|
|
|
|
%{ $text_info }, |
107
|
0
|
|
|
|
|
|
%{ $mail_ref }, |
108
|
|
|
|
|
|
|
}); |
109
|
0
|
|
|
|
|
|
$sndr->SendLineEnc($text); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
0
|
0
|
0
|
|
|
|
if(defined $attachments && ref $attachments eq 'HASH') { |
113
|
0
|
|
|
|
|
|
for my $attach (keys %{ $attachments }) { |
|
0
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
|
115
|
0
|
0
|
|
|
|
|
$attachments->{ $attach }{'description'} = $attach |
116
|
|
|
|
|
|
|
if !defined $attachments->{ $attach }{'description'}; |
117
|
0
|
0
|
|
|
|
|
$attachments->{ $attach }{'ctype'} = 'text/plain' |
118
|
|
|
|
|
|
|
if !defined $attachments->{ $attach }{'ctype'}; |
119
|
0
|
0
|
|
|
|
|
$attachments->{ $attach }{'_disptype'} = $attach |
120
|
|
|
|
|
|
|
if !defined $attachments->{ $attach }{'_disptype'}; |
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
my $disp = qq(attachment; filename="$attach"; ) |
123
|
|
|
|
|
|
|
. qq(type=$attachments->{ $attach }{'_disptype'}); |
124
|
0
|
0
|
0
|
|
|
|
if(defined $attachments->{ $attach }{'_inline'} && $html) { |
125
|
0
|
|
|
|
|
|
$disp = qq(inline; filename="$attach";\r\nContent-ID: ) |
126
|
|
|
|
|
|
|
. qq(<$attachments->{ $attach }{'_inline'}>); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
0
|
0
|
|
|
|
|
if($attachments->{ $attach }{'msg'}) { |
|
|
0
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
$sndr->Part({ |
131
|
|
|
|
|
|
|
'description' => |
132
|
|
|
|
|
|
|
$attachments->{ $attach }{'description'}, |
133
|
|
|
|
|
|
|
'ctype' => $attachments->{ $attach }{'ctype'}, |
134
|
|
|
|
|
|
|
'encoding' => 'Base64', |
135
|
|
|
|
|
|
|
'disposition' => $disp, |
136
|
|
|
|
|
|
|
'msg' => $attachments->{ $attach }{'msg'}, |
137
|
|
|
|
|
|
|
}); |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
elsif($attachments->{ $attach }{'file'}) { |
140
|
0
|
|
|
|
|
|
$sndr->Attach({ |
141
|
|
|
|
|
|
|
'description' => |
142
|
|
|
|
|
|
|
$attachments->{ $attach }{'description'}, |
143
|
|
|
|
|
|
|
'ctype' => $attachments->{ $attach }{'ctype'}, |
144
|
|
|
|
|
|
|
'encoding' => 'Base64', |
145
|
|
|
|
|
|
|
'disposition' => $disp, |
146
|
|
|
|
|
|
|
'file' => $attachments->{ $attach }{'file'}, |
147
|
|
|
|
|
|
|
}); |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
else { |
150
|
0
|
|
|
|
|
|
Carp::carp q(Attachment data needs either 'msg' or ) |
151
|
|
|
|
|
|
|
. qq('file' specified in $attach - Message ) |
152
|
|
|
|
|
|
|
. q(still sent *pending other errors* but ) |
153
|
|
|
|
|
|
|
. qq(attachment not created.\n); |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
} |
157
|
0
|
|
|
|
|
|
$sndr->Close(); |
158
|
|
|
|
|
|
|
}; |
159
|
|
|
|
|
|
|
|
160
|
0
|
0
|
0
|
|
|
|
if($@ || $Mail::Sender::Error) { |
161
|
0
|
0
|
|
|
|
|
if($Mail::Sender::Error) { |
162
|
0
|
0
|
|
|
|
|
$@ .= $@ ? qq(\nMail::Sender::Error: $Mail::Sender::Error) |
163
|
|
|
|
|
|
|
: qq(Mail::Sender::Error: $Mail::Sender::Error); |
164
|
|
|
|
|
|
|
} |
165
|
0
|
|
|
|
|
|
return; |
166
|
|
|
|
|
|
|
} |
167
|
0
|
|
|
|
|
|
return 1; |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
1; |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
__END__ |