line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: TheSchwartz.pm 3 2007-05-04 01:54:52Z btrott $ |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Email::Send::TheSchwartz; |
4
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
53
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
1308
|
use Email::Address; |
|
1
|
|
|
|
|
80232
|
|
|
1
|
|
|
|
|
105
|
|
7
|
1
|
|
|
1
|
|
10013
|
use Return::Value; |
|
1
|
|
|
|
|
2203
|
|
|
1
|
|
|
|
|
755
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $SCHWARTZ; |
10
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub is_available { |
13
|
0
|
|
|
0
|
0
|
|
return eval { require TheSchwartz }; |
|
0
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub send { |
17
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
18
|
0
|
|
|
|
|
|
my($msg, %args) = @_; |
19
|
|
|
|
|
|
|
|
20
|
0
|
|
|
|
|
|
require TheSchwartz; |
21
|
0
|
0
|
|
|
|
|
if (keys %args) { |
22
|
0
|
0
|
|
|
|
|
$SCHWARTZ = eval { $args{_client} || TheSchwartz->new(%args) }; |
|
0
|
|
|
|
|
|
|
23
|
0
|
0
|
|
|
|
|
return failure "$@" if $@; |
24
|
|
|
|
|
|
|
} |
25
|
0
|
0
|
|
|
|
|
return failure "Can't send to TheSchwartz unless client is initialized" |
26
|
|
|
|
|
|
|
unless $SCHWARTZ; |
27
|
|
|
|
|
|
|
|
28
|
0
|
|
|
|
|
|
my $env_sender = (Email::Address->parse($msg->header('From')))[0]->address; |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
my %to = map { $_->address => 1 } |
|
0
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
map { Email::Address->parse($msg->header($_)) } |
32
|
|
|
|
|
|
|
qw(To Cc Bcc); |
33
|
0
|
|
|
|
|
|
my @rcpts = keys %to; |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
my $host; |
36
|
0
|
0
|
|
|
|
|
if (@rcpts == 1) { |
37
|
0
|
|
|
|
|
|
$rcpts[0] =~ /(.+)@(.+)$/; |
38
|
0
|
|
|
|
|
|
$host = lc($2) . '@' . lc($1); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
my $handle; |
42
|
0
|
|
|
|
|
|
eval { |
43
|
0
|
|
|
|
|
|
my $job = TheSchwartz::Job->new( |
44
|
|
|
|
|
|
|
funcname => 'TheSchwartz::Worker::SendEmail', |
45
|
|
|
|
|
|
|
arg => { |
46
|
|
|
|
|
|
|
env_from => $env_sender, |
47
|
|
|
|
|
|
|
rcpts => \@rcpts, |
48
|
|
|
|
|
|
|
data => $msg->as_string, |
49
|
|
|
|
|
|
|
}, |
50
|
|
|
|
|
|
|
coalesce => $host, |
51
|
|
|
|
|
|
|
); |
52
|
0
|
|
|
|
|
|
$handle = $SCHWARTZ->insert($job); |
53
|
|
|
|
|
|
|
}; |
54
|
|
|
|
|
|
|
|
55
|
0
|
0
|
0
|
|
|
|
return failure "Can't create job: $@" unless !$@ && $handle; |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
return success "Message sent", prop => { handle => $handle }; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
1; |
61
|
|
|
|
|
|
|
__END__ |