| 1 | package NG::EMail; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use base 'NG::Object'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use NG::Hashtable; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use NG::Array; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use NG::HTTP::DOM; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Net::SMTP; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Net::POP3; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Email::MIME; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Encode; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | =head2 send | ||||||||||||||||||||||||||||
| 14 | send 'smtp.host.com', \%headers, $body; | ||||||||||||||||||||||||||||
| 15 | =cut | ||||||||||||||||||||||||||||
| 16 | 0 | ▶ | sub send { | ||||||||||||||||||||||||||
|
Subroutine
send: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 17 | 0 | my ( $host, $headers, $body ) = @_; | |||||||||||||||||||||||||||
| 18 | 0 | my $smtp = Net::SMTP->new($host); | |||||||||||||||||||||||||||
| 19 | 0 | ▶ | if ( $headers->{username} and $headers->{password} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$headers->{"username"} and $headers->{"password"}
MC/DC0%0/2
$headers->{"username"} and $headers->{"password"}
$headers->{"username"}
$headers->{"password"}
Truth table0%0/3
A and B
A= $headers->{"username"}B= $headers->{"password"}
| |||||||||||||||||||||||||||||
| 20 | 0 | $smtp->auth( $headers->{username}, $headers->{password} ); | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | 0 | my $dataheader; | |||||||||||||||||||||||||||
| 23 | 0 | for my $i (qw/to cc bcc/) { | |||||||||||||||||||||||||||
| 24 | 0 | ▶ | next unless $headers->{$i}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | 0 | eval $smtp->$i( $headers->{bcc} ); | |||||||||||||||||||||||||||
| 26 | 0 | $dataheader .= uc($i) . ': ' . $headers->{$i} . "\n"; | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 0 | $smtp->data(); | |||||||||||||||||||||||||||
| 30 | 0 | $smtp->datasend($dataheader); | |||||||||||||||||||||||||||
| 31 | 0 | $smtp->datasend("$body\n"); | |||||||||||||||||||||||||||
| 32 | 0 | $smtp->dataend(); | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | $smtp->quit; | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | =head2 get | ||||||||||||||||||||||||||||
| 38 | get 'pop3.host.com', $user, $password, sub { | ||||||||||||||||||||||||||||
| 39 | my ( $headers, $body, $num, $pop ) = @_; | ||||||||||||||||||||||||||||
| 40 | say $headers->get('Subject'); | ||||||||||||||||||||||||||||
| 41 | say $body->get(0)->text; | ||||||||||||||||||||||||||||
| 42 | $pop->delete($num); | ||||||||||||||||||||||||||||
| 43 | }; | ||||||||||||||||||||||||||||
| 44 | =cut | ||||||||||||||||||||||||||||
| 45 | 0 | ▶ | sub get { | ||||||||||||||||||||||||||
|
Subroutine
get: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 46 | 0 | my $cb = pop; | |||||||||||||||||||||||||||
| 47 | 0 | my ( $host, $user, $pass ) = @_; | |||||||||||||||||||||||||||
| 48 | 0 | my $pop = Net::POP3->new($host); | |||||||||||||||||||||||||||
| 49 | 0 | ▶ | return unless $pop->login( $user, $pass ) > 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 0 | my $msgnums = $pop->list; | |||||||||||||||||||||||||||
| 52 | 0 | for my $msgnum ( sort { $b <=> $a } keys %$msgnums ) { | |||||||||||||||||||||||||||
| 53 | 0 | my $parsed = Email::MIME->new( join( '', @{ $pop->get($msgnum) } ) ); | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 0 | my $headers = NG::Hashtable->new( @{ $parsed->{header}->{headers} } ); | |||||||||||||||||||||||||||
| 56 | $headers->each( | ||||||||||||||||||||||||||||
| 57 | 0 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 58 | 0 | $headers->put( $_[0], Encode::decode( 'MIME-Header', $_[1] ) ); | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | 0 | ); | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | my $body = new NG::Array; | |||||||||||||||||||||||||||
| 63 | 0 | my @parts = $parsed->parts; | |||||||||||||||||||||||||||
| 64 | 0 | my $html = +( shift @parts )->body_str; | |||||||||||||||||||||||||||
| 65 | 0 | ▶ | $html = '<html><head></head><body><div>' . $html . '</div></body></html>' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | if $html !~ /^\s*\<htm/; | ||||||||||||||||||||||||||||
| 67 | 0 | $body->push( NG::HTTP::DOM->new($html) ); | |||||||||||||||||||||||||||
| 68 | 0 | $body->push( $_->body_raw ) for @parts; | |||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 0 | $cb->( $headers, $body, $msgnum, $pop ); | |||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | $pop->quit; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 1 | 1; | |||||||||||||||||||||||||||