| line | stmt | bran | cond | sub | pod | time | code | 
| 1 | 8 |  |  | 8 |  | 116232 | use strict; | 
|  | 8 |  |  |  |  | 32 |  | 
|  | 8 |  |  |  |  | 201 |  | 
| 2 | 8 |  |  | 8 |  | 34 | use warnings; | 
|  | 8 |  |  |  |  | 12 |  | 
|  | 8 |  |  |  |  | 272 |  | 
| 3 |  |  |  |  |  |  | package Email::Sender::Util 2.600; | 
| 4 |  |  |  |  |  |  | # ABSTRACT: random stuff that makes Email::Sender go | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 8 |  |  | 8 |  | 2033 | use Email::Address::XS; | 
|  | 8 |  |  |  |  | 14914 |  | 
|  | 8 |  |  |  |  | 309 |  | 
| 7 | 8 |  |  | 8 |  | 664 | use Email::Sender::Failure; | 
|  | 8 |  |  |  |  | 19 |  | 
|  | 8 |  |  |  |  | 209 |  | 
| 8 | 8 |  |  | 8 |  | 1104 | use Email::Sender::Failure::Permanent; | 
|  | 8 |  |  |  |  | 16 |  | 
|  | 8 |  |  |  |  | 170 |  | 
| 9 | 8 |  |  | 8 |  | 1066 | use Email::Sender::Failure::Temporary; | 
|  | 8 |  |  |  |  | 16 |  | 
|  | 8 |  |  |  |  | 198 |  | 
| 10 | 8 |  |  | 8 |  | 42 | use List::Util 1.45 (); | 
|  | 8 |  |  |  |  | 134 |  | 
|  | 8 |  |  |  |  | 170 |  | 
| 11 | 8 |  |  | 8 |  | 36 | use Module::Runtime qw(require_module); | 
|  | 8 |  |  |  |  | 14 |  | 
|  | 8 |  |  |  |  | 48 |  | 
| 12 |  |  |  |  |  |  |  | 
| 13 |  |  |  |  |  |  | # This code will be used by Email::Sender::Simple. -- rjbs, 2008-12-04 | 
| 14 |  |  |  |  |  |  | sub _recipients_from_email { | 
| 15 | 1 |  |  | 1 |  | 3 | my ($self, $email) = @_; | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | my @to = List::Util::uniq( | 
| 18 | 7 |  |  |  |  | 119 | map { $_->address } | 
| 19 | 4 |  |  |  |  | 107 | map { Email::Address::XS->parse($_) } | 
| 20 | 1 |  |  |  |  | 4 | map { $email->get_header($_) } | 
|  | 3 |  |  |  |  | 103 |  | 
| 21 |  |  |  |  |  |  | qw(to cc bcc)); | 
| 22 |  |  |  |  |  |  |  | 
| 23 | 1 |  |  |  |  | 35 | return \@to; | 
| 24 |  |  |  |  |  |  | } | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | sub _sender_from_email { | 
| 27 | 1 |  |  | 1 |  | 260 | my ($self, $email) = @_; | 
| 28 |  |  |  |  |  |  |  | 
| 29 | 1 |  |  |  |  | 39 | my ($sender) = map { $_->address } | 
| 30 | 1 |  |  |  |  | 6 | map { Email::Address::XS->parse($_) } | 
|  | 1 |  |  |  |  | 86 |  | 
| 31 |  |  |  |  |  |  | scalar $email->get_header('from'); | 
| 32 |  |  |  |  |  |  |  | 
| 33 | 1 |  |  |  |  | 71 | return $sender; | 
| 34 |  |  |  |  |  |  | } | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | # It's probably reasonable to make this code publicker at some point, but for | 
| 37 |  |  |  |  |  |  | # now I don't want to deal with making a sane set of args. -- rjbs, 2008-12-09 | 
| 38 |  |  |  |  |  |  | sub _failure { | 
| 39 | 7 |  |  | 7 |  | 7670 | my ($self, $error, $smtp, @rest) = @_; | 
| 40 |  |  |  |  |  |  |  | 
| 41 | 7 |  |  |  |  | 11 | my ($code, $message); | 
| 42 | 7 | 100 |  |  |  | 16 | if ($smtp) { | 
| 43 | 6 |  |  |  |  | 15 | $code = $smtp->code; | 
| 44 | 6 |  |  |  |  | 12 | $message = $smtp->message; | 
| 45 | 6 | 50 |  |  |  | 17 | $message = ! defined $message ? "(no SMTP error message)" | 
|  |  | 50 |  |  |  |  |  | 
| 46 |  |  |  |  |  |  | : ! length  $message ? "(empty SMTP error message)" | 
| 47 |  |  |  |  |  |  | :                       $message; | 
| 48 |  |  |  |  |  |  |  | 
| 49 | 6 | 100 | 66 |  |  | 25 | $message = defined $error && length $error | 
| 50 |  |  |  |  |  |  | ? "$error: $message" | 
| 51 |  |  |  |  |  |  | : $message; | 
| 52 |  |  |  |  |  |  | } else { | 
| 53 | 1 |  |  |  |  | 2 | $message = $error; | 
| 54 | 1 | 50 |  |  |  | 3 | $message = "(no error given)" unless defined $message; | 
| 55 | 1 | 50 |  |  |  | 4 | $message = "(empty error string)" unless length $message; | 
| 56 |  |  |  |  |  |  | } | 
| 57 |  |  |  |  |  |  |  | 
| 58 | 7 | 100 |  |  |  | 30 | my $error_class = ! $code       ? 'Email::Sender::Failure' | 
|  |  | 100 |  |  |  |  |  | 
|  |  | 100 |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | : $code =~ /^4/ ? 'Email::Sender::Failure::Temporary' | 
| 60 |  |  |  |  |  |  | : $code =~ /^5/ ? 'Email::Sender::Failure::Permanent' | 
| 61 |  |  |  |  |  |  | :                 'Email::Sender::Failure'; | 
| 62 |  |  |  |  |  |  |  | 
| 63 | 7 |  |  |  |  | 152 | $error_class->new({ | 
| 64 |  |  |  |  |  |  | message => $message, | 
| 65 |  |  |  |  |  |  | code    => $code, | 
| 66 |  |  |  |  |  |  | @rest, | 
| 67 |  |  |  |  |  |  | }); | 
| 68 |  |  |  |  |  |  | } | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  | #pod =method easy_transport | 
| 71 |  |  |  |  |  |  | #pod | 
| 72 |  |  |  |  |  |  | #pod   my $transport = Email::Sender::Util->easy_transport($class => \%arg); | 
| 73 |  |  |  |  |  |  | #pod | 
| 74 |  |  |  |  |  |  | #pod This takes the name of a transport class and a set of args to new.  It returns | 
| 75 |  |  |  |  |  |  | #pod an Email::Sender::Transport object of that class. | 
| 76 |  |  |  |  |  |  | #pod | 
| 77 |  |  |  |  |  |  | #pod C<$class> is rewritten to C unless it starts | 
| 78 |  |  |  |  |  |  | #pod with an equals sign (C<=>) or contains a colon.  The equals sign, if present, | 
| 79 |  |  |  |  |  |  | #pod will be removed. | 
| 80 |  |  |  |  |  |  | #pod | 
| 81 |  |  |  |  |  |  | #pod =cut | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  | sub _rewrite_class { | 
| 84 | 7 |  |  | 7 |  | 1626 | my $transport_class = $_[1]; | 
| 85 | 7 | 100 | 100 |  |  | 83 | if ($transport_class !~ s/^=// and $transport_class !~ m{:}) { | 
| 86 | 3 |  |  |  |  | 12 | $transport_class = "Email::Sender::Transport::$transport_class"; | 
| 87 |  |  |  |  |  |  | } | 
| 88 |  |  |  |  |  |  |  | 
| 89 | 7 |  |  |  |  | 25 | return $transport_class; | 
| 90 |  |  |  |  |  |  | } | 
| 91 |  |  |  |  |  |  |  | 
| 92 |  |  |  |  |  |  | sub easy_transport { | 
| 93 | 3 |  |  | 3 | 1 | 9 | my ($self, $transport_class, $arg) = @_; | 
| 94 |  |  |  |  |  |  |  | 
| 95 | 3 |  |  |  |  | 11 | $transport_class = $self->_rewrite_class($transport_class); | 
| 96 |  |  |  |  |  |  |  | 
| 97 | 3 |  |  |  |  | 14 | require_module($transport_class); | 
| 98 | 3 |  |  |  |  | 1970 | return $transport_class->new($arg); | 
| 99 |  |  |  |  |  |  | } | 
| 100 |  |  |  |  |  |  |  | 
| 101 |  |  |  |  |  |  | 1; | 
| 102 |  |  |  |  |  |  |  | 
| 103 |  |  |  |  |  |  | __END__ |