Message/Convert/Html.pm

filter: Statementstmt 97.4% 75 / 77 Branchbran 63.8% 23 / 36 Conditioncond 71.4% 5 / 7 MC/DCmcdc 33.3% 1 / 3 Subroutinesub 100% 12 / 12 Podpod 83.3% 5 / 6 totaltotal 85.8% 121 / 141 CC 26 SCAR 19.8
CC
26
Cov
86%
headToHtmlHead
13.7
headToHtmlTable
6.9
fieldContentsToHtml
4.1
CRAP 7.3
« Message/Head/ResentGroup.pm ↑ Summary Message/Field/Structured.pm »
1 # Copyrights 2001-2022 by [Mark Overmeer <markov@cpan.org>].
2 # For other contributors see ChangeLog.
3 # See the manual pages for details on the licensing terms.
4 # Pod stripped from pm file by OODoc 2.03.
5 # This code is part of distribution Mail-Message. Meta-POD processed with
6 # OODoc into POD and HTML manual-pages. See README.md
7 # Copyright Mark Overmeer. Licensed under the same terms as Perl itself.
8  
9 package Mail::Message::Convert::Html;
10 1 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 $VERSION = '3.012';
12  
13 1 ▶use base 'Mail::Message::Convert';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20  
21 sub init($)
22 2 ▶{ my ($self, $args) = @_;
Subroutine init: called CC=4 SCAR=13.9
Pod undocumented
23  
24 2 $self->SUPER::init($args);
25  
26 2 ▶ my $produce = $args->{produce} || 'HTML';
Condition100%2/2
$args->{'produce'} || 'HTML'
l!l
11
MC/DC100%1/1
$args->{'produce'} || 'HTML'
$args->{'produce'}
Truth table100%2/2
A
A= $args->{'produce'}
Aresult
11
00
27  
28 $self->{MMCH_tail}
29 2 ▶ = $produce eq 'HTML' ? '>'
Branch: 2 branches
BranchTrueFalseTotal
$produce eq 'HTML' ? : 1 1 2
$produce eq 'XHTML' ? : 1 0 1
30 : $produce eq 'XHTML' ? ' />'
31 : carp "Produce XHTML or HTML, not $produce.";
32  
33 2 $self;
34 }
35  
36 #------------------------------------------
37  
38  
39 sub textToHtml(@)
40 52 ▶{ my $self = shift;
Subroutine textToHtml: called CC=3 SCAR=11.0
Pod documented
41  
42 52 my @lines = @_; # copy is required
43 52 foreach (@lines)
44 52 { s/\&/&amp;/gs; s/\</&lt;/gs;
45 52 s/\>/&gt;/gs; s/\"/&quot;/gs;
46 }
47 52 ▶ wantarray ? @lines : join('', @lines);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 8 44 52
48 }
49  
50 #------------------------------------------
51  
52  
53 sub fieldToHtml($;$)
54 2 ▶{ my ($self, $field, $subject) = @_;
Subroutine fieldToHtml: called CC=1 SCAR=0.0
Pod documented
55 2 '<strong>'. $self->textToHtml($field->wellformedName)
56 .': </strong>' . $self->fieldContentsToHtml($field,$subject);
57 }
58  
59 #------------------------------------------
60  
61  
62 sub headToHtmlTable($;$)
63 2 ▶{ my ($self, $head) = (shift, shift);
Subroutine headToHtmlTable: called CC=6 SCAR=19.3
Pod documented
64 2 ▶ my $tp = @_ ? ' '.shift : '';
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 2 0 2
65  
66 2 my $subject;
67 2 ▶ if($self->{MMHC_mailto_subject})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"MMHC_mailto_subject"}) 0 2 2
68 0 { my $s = $head->get('subject');
69  
70 1 ▶ use Mail::Message::Construct;
Subroutine BEGIN: called CC=1 SCAR=0.0
71 0 ▶ $subject = Mail::Message::Construct->replySubject($s)
Branch: 1 branch
BranchTrueFalseTotal
if defined $subject 0 0 0
72 if defined $subject;
73 }
74  
75 2 my @lines = "<table $tp>\n";
76 2 foreach my $f ($self->selectedFields($head))
77 6 { my $name_html = $self->textToHtml($f->wellformedName);
78 6 my $cont_html = $self->fieldContentsToHtml($f, $subject);
79 6 push @lines, qq(<tr><th valign="top" align="left">$name_html:</th>\n)
80 , qq( <td valign="top">$cont_html</td></tr>\n);
81 }
82  
83 2 push @lines, "</table>\n";
84 2 ▶ wantarray ? @lines : join('',@lines);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 2 2
85 }
86  
87 #------------------------------------------
88  
89  
90 sub headToHtmlHead($@)
91 4 ▶{ my ($self, $head) = (shift,shift);
Subroutine headToHtmlHead: called CC=13 SCAR=26.2
Pod documented
92 4 my %meta;
93 4 ▶ while(@_) {my $k = shift; $meta{lc $k} = shift }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 7 4 11
94  
95 4 ▶ my $title = delete $meta{title} || $head->get('subject') || '<no subject>';
Condition60%3/5
delete $meta{'title'} || $head->get('subject') || '<no subject>'
l!l
40
delete $meta{"title"} or $head->get("subject")
l!l&&r!l&&!r
220
MC/DC0%0/2
delete $meta{'title'} || $head->get('subject') || '<no subject>'
delete $meta{"title"} $head->get("subject")
Truth table66%2/3
A or B
A= delete $meta{"title"}B= $head->get("subject")
ABresult
1X1
011
000
96  
97 4 my @lines =
98 ( "<head>\n"
99 , "<title>".$self->textToHtml($title) . "</title>\n"
100 );
101  
102 4 my $author = delete $meta{author};
103 4 ▶ unless(defined $author)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $author) 4 0 4
104 4 { my $from = $head->get('from');
105 4 ▶ my @addr = defined $from ? $from->addresses : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $from ? : 4 0 4
106 4 ▶ $author = @addr ? $addr[0]->format : undef;
Branch: 1 branch
BranchTrueFalseTotal
@addr ? : 4 0 4
107 }
108  
109 4 ▶ push @lines, '<meta name="Author" content="'
Branch: 1 branch
BranchTrueFalseTotal
if defined $author 4 0 4
110 . $self->textToHtml($author) . "\"$self->{MMCH_tail}\n"
111 if defined $author;
112  
113 4 foreach my $f (map {lc} keys %meta)
114 5 ▶ { next if $meta{$f} eq ''; # empty is skipped.
Branch: 1 branch
BranchTrueFalseTotal
if $meta{$f} eq "" 1 4 5
115 push @lines, '<meta name="'. ucfirst lc $self->textToHtml($f)
116 4 . '" content="'. $self->textToHtml($meta{$f})
117 ."\"$self->{MMCH_tail}\n";
118 }
119  
120 4 foreach my $f ($self->selectedFields($head))
121 12 ▶ { next if exists $meta{$f->name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $meta{$f->name} 2 10 12
122 10 push @lines, '<meta name="' . $self->textToHtml($f->wellformedName)
123 . '" content="' . $self->textToHtml($f->content)
124 . "\"$self->{MMCH_tail}\n";
125 }
126  
127 4 push @lines, "</head>\n";
128 4 ▶ wantarray ? @lines : join('',@lines);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 4 4
129 }
130
131 #------------------------------------------
132  
133  
134 1 my $atom = qr/[^()<>@,;:\\".\[\]\s[:cntrl:]]+/;
135 1 my $email_address = qr/(($atom(?:\.$atom)*)\@($atom(?:\.$atom)+))/o;
136  
137 sub fieldContentsToHtml($;$)
138 8 ▶{ my ($self, $field) = (shift,shift);
Subroutine fieldContentsToHtml: called CC=4 SCAR=14.1
Pod documented
139 8 ▶ my $subject = defined $_[0] ? '?subject='.$self->textToHtml(shift) : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] ? : 0 8 8
140  
141 8 my ($body, $comment) = ($self->textToHtml($field->body), $field->comment);
142  
143 8 ▶ $body =~ s#$email_address#<a href="mailto:$1$subject">$1</a>#gx
Branch: 1 branch
BranchTrueFalseTotal
if $field->name =~ /^(resent-)?(to|from|cc|bcc|reply\-to)$/ 6 2 8
144 if $field->name =~ m/^(resent-)?(to|from|cc|bcc|reply\-to)$/;
145  
146 8 ▶ $body . ($comment ? '; '.$self->textToHtml($comment) : '');
Branch: 1 branch
BranchTrueFalseTotal
$comment ? : 0 8 8
147 }
148  
149 #------------------------------------------
150  
151 1 1;
« Message/Head/ResentGroup.pm ↑ Summary Message/Field/Structured.pm »