line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# $Id$ |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# email::send Brik |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
package Metabrik::Email::Send; |
7
|
1
|
|
|
1
|
|
624
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
28
|
|
8
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
6
|
use base qw(Metabrik::Network::Smtp); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
433
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub brik_properties { |
13
|
|
|
|
|
|
|
return { |
14
|
0
|
|
|
0
|
1
|
|
revision => '$Revision$', |
15
|
|
|
|
|
|
|
tags => [ qw(unstable smtp) ], |
16
|
|
|
|
|
|
|
author => 'GomoR ', |
17
|
|
|
|
|
|
|
license => 'http://opensource.org/licenses/BSD-3-Clause', |
18
|
|
|
|
|
|
|
attributes => { |
19
|
|
|
|
|
|
|
from => [ qw(from) ], |
20
|
|
|
|
|
|
|
to => [ qw(to) ], |
21
|
|
|
|
|
|
|
cc => [ qw(cc) ], |
22
|
|
|
|
|
|
|
bcc => [ qw(bcc) ], |
23
|
|
|
|
|
|
|
subject => [ qw(subject) ], |
24
|
|
|
|
|
|
|
server => [ qw(server) ], |
25
|
|
|
|
|
|
|
port => [ qw(port) ], |
26
|
|
|
|
|
|
|
hello => [ qw(hello) ], |
27
|
|
|
|
|
|
|
auth_mechanism => [ qw(none|GSSAPI) ], |
28
|
|
|
|
|
|
|
use_starttls => [ qw(0|1) ], |
29
|
|
|
|
|
|
|
username => [ qw(username) ], |
30
|
|
|
|
|
|
|
password => [ qw(password) ], |
31
|
|
|
|
|
|
|
}, |
32
|
|
|
|
|
|
|
attributes_default => { |
33
|
|
|
|
|
|
|
from => 'from@example.com', |
34
|
|
|
|
|
|
|
to => 'to@example.com', |
35
|
|
|
|
|
|
|
subject => 'My subject', |
36
|
|
|
|
|
|
|
server => 'localhost', |
37
|
|
|
|
|
|
|
port => 25, |
38
|
|
|
|
|
|
|
use_starttls => 0, |
39
|
|
|
|
|
|
|
}, |
40
|
|
|
|
|
|
|
commands => { |
41
|
|
|
|
|
|
|
send => [ qw(email from|OPTIONAL to|OPTIONAL subject|OPTIONAL) ], |
42
|
|
|
|
|
|
|
}, |
43
|
|
|
|
|
|
|
require_modules => { |
44
|
|
|
|
|
|
|
'DateTime' => [ ], |
45
|
|
|
|
|
|
|
'DateTime::Format::Mail' => [ ], |
46
|
|
|
|
|
|
|
}, |
47
|
|
|
|
|
|
|
}; |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub send { |
51
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
52
|
0
|
|
|
|
|
|
my ($email, $from, $to, $subject) = @_; |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
0
|
|
|
|
$from ||= $self->from; |
55
|
0
|
|
0
|
|
|
|
$to ||= $self->to; |
56
|
0
|
|
0
|
|
|
|
$subject ||= $self->subject; |
57
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('send', $email) or return; |
58
|
0
|
0
|
|
|
|
|
$self->brik_help_run_invalid_arg('send', $email, 'Email::Simple') or return; |
59
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('send', $from) or return; |
60
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('send', $to) or return; |
61
|
0
|
0
|
|
|
|
|
$self->brik_help_run_undef_arg('send', $subject) or return; |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
my $cc = $self->cc; |
64
|
0
|
|
|
|
|
|
my $bcc = $self->bcc; |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
my $ct = $email->header('Content-Type'); |
67
|
0
|
|
|
|
|
|
my $cl = $email->header('Content-Length'); |
68
|
0
|
|
|
|
|
|
my $ce = $email->header('Content-Transfer-Encoding'); |
69
|
0
|
|
|
|
|
|
my $lc = $email->header('Lines'); |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my $dt = DateTime->now; |
72
|
0
|
|
|
|
|
|
my $date = DateTime::Format::Mail->format_datetime($dt); |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
$self->log->verbose("send: From [$from]"); |
75
|
0
|
|
|
|
|
|
$self->log->verbose("send: To [$to]"); |
76
|
0
|
|
|
|
|
|
$self->log->verbose("send: Date [$date]"); |
77
|
0
|
|
|
|
|
|
$self->log->verbose("send: Subject [$subject]"); |
78
|
|
|
|
|
|
|
#print "Content-Type [$ct]\n\n"; |
79
|
|
|
|
|
|
|
#print $email->body,"\n"; |
80
|
|
|
|
|
|
|
|
81
|
0
|
0
|
|
|
|
|
my $smtp = $self->open or return; |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
$smtp->mail($from); |
84
|
0
|
|
|
|
|
|
$smtp->to($to); |
85
|
|
|
|
|
|
|
|
86
|
0
|
0
|
|
|
|
|
if (defined($cc)) { |
87
|
0
|
|
|
|
|
|
$smtp->cc($cc); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
0
|
0
|
|
|
|
|
if (defined($bcc)) { |
91
|
0
|
|
|
|
|
|
$smtp->bcc($bcc); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
$smtp->data; |
95
|
0
|
0
|
|
|
|
|
$smtp->datasend("Content-Type: $ct\r\n") if defined($ct); |
96
|
0
|
0
|
|
|
|
|
$smtp->datasend("Content-Length: $cl\r\n") if defined($cl); |
97
|
0
|
0
|
|
|
|
|
$smtp->datasend("Content-Transfer-Encoding: $ce\r\n") if defined($ce); |
98
|
0
|
0
|
|
|
|
|
$smtp->datasend("Lines: $lc\r\n") if defined($lc); |
99
|
0
|
|
|
|
|
|
$smtp->datasend("Date: $date\r\n"); |
100
|
0
|
|
|
|
|
|
$smtp->datasend("From: $from\r\n"); |
101
|
0
|
|
|
|
|
|
$smtp->datasend("To: $to\r\n"); |
102
|
0
|
0
|
|
|
|
|
if (defined($cc)) { |
103
|
0
|
|
|
|
|
|
$smtp->datasend("Cc: $cc\r\n"); |
104
|
|
|
|
|
|
|
} |
105
|
0
|
|
|
|
|
|
$smtp->datasend("Subject: $subject\r\n\r\n"); |
106
|
0
|
|
|
|
|
|
$smtp->datasend($email->body); |
107
|
0
|
|
|
|
|
|
$smtp->dataend; |
108
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
$self->log->verbose("send: message sent"); |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
|
$self->close; |
112
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
return 1; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
1; |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
__END__ |