blib/lib/Email/Reply.pm

filter: Statementstmt 100% 95 / 95 Branchbran 78.9% 30 / 38 Conditioncond 51.5% 17 / 33 MC/DCmcdc 22.2% 4 / 18 Subroutinesub 100% 16 / 16 Podpod 100% 1 / 1 totaltotal 81.0% 163 / 201 CC 32 SCAR 19.2
CC
32
Cov
86%
_make_headers
10.1
_quote_body
9.8
_new
8.9
CRAP 6.8
↑ Summary
1 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 package Email::Reply;
4 {
5 2 $Email::Reply::VERSION = '1.203';
6 }
7 # ABSTRACT: reply to an email message
8  
9 2 ▶use Email::Abstract 2.01;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Email::Address 1.80;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Email::MIME 1.82;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use Exporter 5.57 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 my $CLASS = __PACKAGE__;
15 2 our @EXPORT = qw[reply];
16 2 my $CRLF = "\x0d\x0a";
17  
18 # Want to subclass and still use the functional interface?
19 # That's cool, just add these lines to your package:
20 # use base qw[Exporter];
21 # use vars qw[@EXPORT $CLASS];
22 # @EXPORT = qw[reply];
23 # $CLASS = __PACKAGE__;
24 # *reply = \&Email::Reply::reply;
25  
26 sub reply {
27 3 ▶ my $reply = $CLASS->_new(@_);
Subroutine reply: called CC=6 SCAR=18.7
Pod documented
28 3 $reply->_make_headers;
29 3 ▶ $reply->_encapsulate_message if $reply->{attach};
Branch: 1 branch
BranchTrueFalseTotal
if $reply->{"attach"} 1 2 3
30 $reply->_quote_body($reply->{original})
31 3 ▶ if $reply->{quote} || $reply->{top_post};
Branch: 1 branch
BranchTrueFalseTotal
if $reply->{"quote"} or $reply->{"top_post"} 3 0 3
Condition33%1/3
$reply->{"quote"} or $reply->{"top_post"}
l!l&&r!l&&!r
300
MC/DC0%0/2
$reply->{"quote"} or $reply->{"top_post"}
$reply->{"quote"} $reply->{"top_post"}
Truth table33%1/3
A or B
A= $reply->{"quote"}B= $reply->{"top_post"}
ABresult
1X1
011
000
32 3 ▶ $reply->_post_reply if $reply->{body};
Branch: 1 branch
BranchTrueFalseTotal
if $reply->{"body"} 3 0 3
33 3 ▶ return $reply->{message} ? $reply->_mime : $reply->_simple;
Branch: 1 branch
BranchTrueFalseTotal
$reply->{'message'} ? : 1 2 3
34 }
35  
36 sub _new {
37 3 ▶ my ($class, %args) = @_;
Subroutine _new: called CC=8 SCAR=21.9
38 3 my $self = {};
39 3 $self->{original} = Email::MIME->new(Email::Abstract->as_string($args{to}));
40  
41 ($self->{from}) =
42 3 ▶ Email::Address->parse($args{from} || $self->{original}->header('To'));
Condition66%2/3
$args{'from'} || $self->{'original'}->header('To')
l!l&&r!l&&!r
120
MC/DC0%0/2
$args{'from'} || $self->{'original'}->header('To')
$args{'from'} $self->{'original'}->header('To')
Truth table66%2/3
A || B
A= $args{'from'}B= $self->{'original'}->header('To')
ABresult
1X1
011
000
43  
44 ($self->{to}) = Email::Address->parse(
45 $self->{original}->header('Reply-To')
46 || $self->{original}->header('From')
47 3 ▶ || $self->{original}->header('Return-Path')
Condition33%2/6
$self->{'original'}->header('Reply-To') || $self->{'original'}->header('From') || $self->{'original'}->header('Return-Path')
l!l&&r!l&&!r
300
$self->{"original"}->header("Reply-To") or $self->{"original"}->header("From")
l!l&&r!l&&!r
030
MC/DC0%0/3
$self->{'original'}->header('Reply-To') || $self->{'original'}->header('From') || $self->{'original'}->header('Return-Path')
$self->{"original"}->header("Reply-To") $self->{"original"}->header("From") $self->{'original'}->header('Return-Path')
Truth table25%1/4
A or B || C
A= $self->{"original"}->header("Reply-To")B= $self->{"original"}->header("From")C= $self->{'original'}->header('Return-Path')
ABCresult
1XX1
01X1
0011
0000
48 );
49  
50 $self->{attrib} = $args{attrib}
51 3 ▶ || (($self->{to}->name || join($self->{to}->address, '<', '>')) . ' wrote:');
Condition60%3/5
$args{'attrib'} || ($self->{'to'}->name || join($self->{'to'}->address, '<', '>')) . ' wrote:'
l!l
12
$self->{'to'}->name || join($self->{'to'}->address, '<', '>')
l!l&&r!l&&!r
200
MC/DC100%1/1
$args{'attrib'} || ($self->{'to'}->name || join($self->{'to'}->address, '<', '>')) . ' wrote:'
$args{'attrib'}
Truth table100%2/2
A
A= $args{'attrib'}
Aresult
11
00
52  
53 3 ▶ $self->{prefix} = $args{prefix} || '> ';
Condition100%2/2
$args{'prefix'} || '> '
l!l
12
MC/DC100%1/1
$args{'prefix'} || '> '
$args{'prefix'}
Truth table100%2/2
A
A= $args{'prefix'}
Aresult
11
00
54 3 $self->{top_post} = $args{top_post};
55 3 ▶ $self->{quote} = exists $args{quote} ? $args{quote} : 1;
Branch: 1 branch
BranchTrueFalseTotal
exists $args{'quote'} ? : 0 3 3
56 3 $self->{all} = $args{all};
57 3 $self->{quoted} = '';
58 3 $self->{body} = $args{body};
59 3 $self->{attach} = $args{attach};
60 3 $self->{keep_sig} = $args{keep_sig};
61  
62 3 return bless $self, $class;
63 }
64  
65 sub _make_headers {
66 3 ▶ my $self = shift;
Subroutine _make_headers: called CC=10 SCAR=23.1
67  
68 3 my @header = (From => $self->{from},);
69  
70 $self->{to}
71 ->name((Email::Address->parse($self->{original}->header('From')))[0]->name)
72 3 ▶ unless $self->{to}->name;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"to"}->name 0 3 3
73 3 push @header, To => $self->{to};
74  
75 3 ▶ my $subject = $self->{original}->header('Subject') || '';
Condition50%1/2
$self->{'original'}->header('Subject') || ''
l!l
30
MC/DC0%0/1
$self->{'original'}->header('Subject') || ''
$self->{'original'}->header('Subject')
Truth table50%1/2
A
A= $self->{'original'}->header('Subject')
Aresult
11
00
76 3 ▶ $subject = "Re: $subject" unless $subject =~ /\bRe:/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $subject =~ /\bRe:/i 2 1 3
77 3 push @header, Subject => $subject;
78  
79 3 my ($msg_id) = Email::Address->parse($self->{original}->header('Message-ID'));
80 3 push @header, 'In-Reply-To' => $msg_id;
81  
82 3 my @refs = Email::Address->parse($self->{original}->header('References'));
83 3 ▶ @refs = Email::Address->parse($self->{original}->header('In-Reply-To'))
Branch: 1 branch
BranchTrueFalseTotal
unless @refs 2 1 3
84 unless @refs;
85 3 ▶ push @refs, $msg_id if $msg_id;
Branch: 1 branch
BranchTrueFalseTotal
if $msg_id 2 1 3
86 3 ▶ push @header, References => join ' ', @refs if @refs;
Branch: 1 branch
BranchTrueFalseTotal
if @refs 2 1 3
87  
88 3 ▶ if ($self->{all}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"all"}) 1 2 3
89 my @addrs = (
90 Email::Address->parse($self->{original}->header('To')),
91 1 Email::Address->parse($self->{original}->header('Cc')),
92 );
93 1 ▶ unless ($self->{self}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"self"}) 1 0 1
94 1 @addrs = grep { $_->address ne $self->{from}->address } @addrs;
95 }
96 1 ▶ push @header, Cc => join ', ', @addrs if @addrs;
Branch: 1 branch
BranchTrueFalseTotal
if @addrs 1 0 1
97 }
98  
99 3 $self->{header} = \@header;
100 }
101  
102 sub _encapsulate_message {
103 1 ▶ my $self = shift;
Subroutine _encapsulate_message: called CC=1 SCAR=0.0
104 $self->{message} = Email::MIME->create(
105 attributes => { content_type => 'message/rfc822', },
106 body => $self->{original}->as_string,
107 1 );
108 }
109  
110 2 my $crlf = qr/\x0a\x0d|\x0d\x0a|\x0a|\x0d/;
111  
112 sub _quote_body {
113 5 ▶ my ($self, $part) = @_;
Subroutine _quote_body: called CC=9 SCAR=22.8
114 5 ▶ return if length $self->{quoted};
Branch: 1 branch
BranchTrueFalseTotal
if length $self->{"quoted"} 1 4 5
115 4 ▶ return map $self->_quote_body($_), $part->parts if $part->parts > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $part->parts > 1 1 3 4
116 3 ▶ return if $part->content_type && $part->content_type !~ m[\btext/plain\b];
Branch: 1 branch
BranchTrueFalseTotal
if $part->content_type and not $part->content_type =~ m[\btext/plain\b] 0 3 3
Condition33%1/3
$part->content_type and not $part->content_type =~ m[\btext/plain\b]
!ll&&!rl&&r
300
MC/DC0%0/2
$part->content_type and not $part->content_type =~ m[\btext/plain\b]
$part->content_type not $part->content_type =~ m[\btext/plain\b]
Truth table33%1/3
A and not(B)
A= $part->content_typeB= not $part->content_type =~ m[\btext/plain\b]
ABresult
0X0
100
111
117  
118 3 my $body = $part->body;
119  
120 $body = ($self->_strip_sig($body) || $body)
121 3 ▶ if !$self->{keep_sig} && $body =~ /$crlf--\s*$crlf/o;
Branch: 1 branch
BranchTrueFalseTotal
if not $self->{"keep_sig"} and $body =~ /$crlf--\s*$crlf/o 1 2 3
Condition66%4/6
not $self->{"keep_sig"} and $body =~ /$crlf--\s*$crlf/o
!ll&&!rl&&r
111
$self->_strip_sig($body) || $body
l!l&&r!l&&!r
100
MC/DC100%2/2
not $self->{"keep_sig"} and $body =~ /$crlf--\s*$crlf/o
not $self->{"keep_sig"} $body =~ /$crlf--\s*$crlf/o
MC/DC0%0/2
$self->_strip_sig($body) || $body
$self->_strip_sig($body) $body
Truth table100%3/3
not(A) and B
A= not $self->{"keep_sig"}B= $body =~ /$crlf--\s*$crlf/o
ABresult
0X0
100
111
Truth table33%1/3
A || B
A= $self->_strip_sig($body)B= $body
ABresult
1X1
011
000
122  
123 3 my ($end) = $body =~ /($crlf)/;
124 3 ▶ $end ||= $CRLF;
Condition33%1/3
$end ||= $CRLF
l!l&&r!l&&!r
300
MC/DC0%0/2
$end ||= $CRLF
$end $CRLF
Truth table33%1/3
A ||= B
A= $endB= $CRLF
ABresult
1X1
011
000
125 3 $body =~ s/[\r\n\s]+$//;
126 3 $body = $self->_quote_orig_body($body);
127 3 $body = "$self->{attrib}$end$body$end";
128  
129 3 $self->{crlf} = $end;
130 3 $self->{quoted} = $body;
131 }
132  
133 # Yes, you are witnessing elitism.
134 1 ▶sub _strip_sig { reverse +(split /$crlf\s*--$crlf/o, reverse(pop), 2)[1] }
Subroutine _strip_sig: called CC=1 SCAR=0.0
135  
136 sub _quote_orig_body {
137 3 ▶ my ($self, $body) = @_;
Subroutine _quote_orig_body: called CC=1 SCAR=0.0
138 3 $body =~ s/($crlf)/$1$self->{prefix}/g;
139 3 "$self->{prefix}$body";
140 }
141  
142 sub _post_reply {
143 3 ▶ my $self = shift;
Subroutine _post_reply: called CC=3 SCAR=11.0
144 return $self->{reply_body} = $self->{body}
145 3 ▶ unless length $self->{quoted};
Branch: 1 branch
BranchTrueFalseTotal
unless length $self->{"quoted"} 0 3 3
146 3 my @parts = (@{$self}{qw[quoted body]});
147 3 ▶ @parts = reverse @parts if $self->{top_post};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"top_post"} 1 2 3
148 3 $self->{reply_body} = join $self->{crlf}, @parts;
149 }
150  
151 sub _mime {
152 1 ▶ my $self = shift;
Subroutine _mime: called CC=1 SCAR=0.0
153 Email::MIME->create(
154 header => $self->{header},
155 parts =>
156 1 [ Email::MIME->create(body => $self->{reply_body}), $self->{message}, ],
157 );
158 }
159  
160 sub _simple {
161 2 ▶ my $self = shift;
Subroutine _simple: called CC=1 SCAR=0.0
162 Email::Simple->create(
163 header => $self->{header},
164 body => $self->{reply_body},
165 2 );
166 }
167  
168 2 1;
169  
170 __END__
↑ Summary