NG/EMail.pm

filter: Statementstmt 46.9% 31 / 66 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 76.9% 10 / 13 Podpod 100% 2 / 2 totaltotal 45.7% 43 / 94 CC 9 SCAR 27.0
CC
9
Cov
40%
send
30.0
get
30.0
__ANON__
2.0
CRAP 14.9
« NG/Excel.pm ↑ Summary NG/Class.pm »
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
BranchTrueFalseTotal
if ($headers->{"username"} and $headers->{"password"}) 0 0 0
Condition0%0/3
$headers->{"username"} and $headers->{"password"}
!ll&&!rl&&r
000
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"}
ABresult
0X0
100
111
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
BranchTrueFalseTotal
unless $headers->{$i} 0 0 0
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
BranchTrueFalseTotal
unless $pop->login($user, $pass) > 0 0 0 0
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
BranchTrueFalseTotal
unless $html =~ /^\s*\<htm/ 0 0 0
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;
« NG/Excel.pm ↑ Summary NG/Class.pm »