line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyrights 2001-2022 by [Mark Overmeer ]. |
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
|
|
|
1
|
|
752
|
use vars '$VERSION'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
59
|
|
11
|
|
|
|
|
|
|
$VERSION = '3.012'; |
12
|
|
|
|
|
|
|
|
13
|
1
|
|
|
1
|
|
6
|
use base 'Mail::Message::Convert'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
398
|
|
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
15
|
|
16
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
20
|
|
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
323
|
|
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub init($) |
22
|
2
|
|
|
2
|
0
|
6
|
{ my ($self, $args) = @_; |
23
|
|
|
|
|
|
|
|
24
|
2
|
|
|
|
|
10
|
$self->SUPER::init($args); |
25
|
|
|
|
|
|
|
|
26
|
2
|
|
100
|
|
|
8
|
my $produce = $args->{produce} || 'HTML'; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
$self->{MMCH_tail} |
29
|
2
|
50
|
|
|
|
9
|
= $produce eq 'HTML' ? '>' |
|
|
100
|
|
|
|
|
|
30
|
|
|
|
|
|
|
: $produce eq 'XHTML' ? ' />' |
31
|
|
|
|
|
|
|
: carp "Produce XHTML or HTML, not $produce."; |
32
|
|
|
|
|
|
|
|
33
|
2
|
|
|
|
|
5
|
$self; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
#------------------------------------------ |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub textToHtml(@) |
40
|
52
|
|
|
52
|
1
|
73
|
{ my $self = shift; |
41
|
|
|
|
|
|
|
|
42
|
52
|
|
|
|
|
79
|
my @lines = @_; # copy is required |
43
|
52
|
|
|
|
|
73
|
foreach (@lines) |
44
|
52
|
|
|
|
|
78
|
{ s/\&/&/gs; s/\</gs; |
|
52
|
|
|
|
|
60
|
|
45
|
52
|
|
|
|
|
62
|
s/\>/>/gs; s/\"/"/gs; |
|
52
|
|
|
|
|
77
|
|
46
|
|
|
|
|
|
|
} |
47
|
52
|
100
|
|
|
|
204
|
wantarray ? @lines : join('', @lines); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
#------------------------------------------ |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub fieldToHtml($;$) |
54
|
2
|
|
|
2
|
1
|
12
|
{ my ($self, $field, $subject) = @_; |
55
|
2
|
|
|
|
|
8
|
''. $self->textToHtml($field->wellformedName) |
56
|
|
|
|
|
|
|
.': ' . $self->fieldContentsToHtml($field,$subject); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
#------------------------------------------ |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub headToHtmlTable($;$) |
63
|
2
|
|
|
2
|
1
|
589
|
{ my ($self, $head) = (shift, shift); |
64
|
2
|
50
|
|
|
|
8
|
my $tp = @_ ? ' '.shift : ''; |
65
|
|
|
|
|
|
|
|
66
|
2
|
|
|
|
|
2
|
my $subject; |
67
|
2
|
50
|
|
|
|
6
|
if($self->{MMHC_mailto_subject}) |
68
|
0
|
|
|
|
|
0
|
{ my $s = $head->get('subject'); |
69
|
|
|
|
|
|
|
|
70
|
1
|
|
|
1
|
|
7
|
use Mail::Message::Construct; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
705
|
|
71
|
0
|
0
|
|
|
|
0
|
$subject = Mail::Message::Construct->replySubject($s) |
72
|
|
|
|
|
|
|
if defined $subject; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
2
|
|
|
|
|
6
|
my @lines = "\n";
76
|
2
|
|
|
|
|
9
|
foreach my $f ($self->selectedFields($head)) |
77
|
6
|
|
|
|
|
14
|
{ my $name_html = $self->textToHtml($f->wellformedName); |
78
|
6
|
|
|
|
|
13
|
my $cont_html = $self->fieldContentsToHtml($f, $subject); |
79
|
6
|
|
|
|
|
24
|
push @lines, qq( | $name_html: | \n)
80
|
|
|
|
|
|
|
, qq( | $cont_html | \n);
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
2
|
|
|
|
|
4
|
push @lines, " | \n"; |
84
|
2
|
50
|
|
|
|
11
|
wantarray ? @lines : join('',@lines); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
#------------------------------------------ |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub headToHtmlHead($@) |
91
|
4
|
|
|
4
|
1
|
2266
|
{ my ($self, $head) = (shift,shift); |
92
|
4
|
|
|
|
|
8
|
my %meta; |
93
|
4
|
|
|
|
|
11
|
while(@_) {my $k = shift; $meta{lc $k} = shift } |
|
7
|
|
|
|
|
11
|
|
|
7
|
|
|
|
|
16
|
|
94
|
|
|
|
|
|
|
|
95
|
4
|
|
50
|
|
|
19
|
my $title = delete $meta{title} || $head->get('subject') || ''; |
96
|
|
|
|
|
|
|
|
97
|
4
|
|
|
|
|
10
|
my @lines = |
98
|
|
|
|
|
|
|
( "\n" |
99
|
|
|
|
|
|
|
, "".$self->textToHtml($title) . "\n" |
100
|
|
|
|
|
|
|
); |
101
|
|
|
|
|
|
|
|
102
|
4
|
|
|
|
|
8
|
my $author = delete $meta{author}; |
103
|
4
|
50
|
|
|
|
9
|
unless(defined $author) |
104
|
4
|
|
|
|
|
12
|
{ my $from = $head->get('from'); |
105
|
4
|
50
|
|
|
|
16
|
my @addr = defined $from ? $from->addresses : (); |
106
|
4
|
50
|
|
|
|
1394
|
$author = @addr ? $addr[0]->format : undef; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
4
|
50
|
|
|
|
87
|
push @lines, '
110
|
|
|
|
|
|
|
. $self->textToHtml($author) . "\"$self->{MMCH_tail}\n" |
111
|
|
|
|
|
|
|
if defined $author; |
112
|
|
|
|
|
|
|
|
113
|
4
|
|
|
|
|
11
|
foreach my $f (map {lc} keys %meta) |
|
5
|
|
|
|
|
11
|
|
114
|
5
|
100
|
|
|
|
12
|
{ next if $meta{$f} eq ''; # empty is skipped. |
115
|
|
|
|
|
|
|
push @lines, '
116
|
4
|
|
|
|
|
7
|
. '" content="'. $self->textToHtml($meta{$f}) |
117
|
|
|
|
|
|
|
."\"$self->{MMCH_tail}\n"; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
4
|
|
|
|
|
13
|
foreach my $f ($self->selectedFields($head)) |
121
|
12
|
100
|
|
|
|
23
|
{ next if exists $meta{$f->name}; |
122
|
10
|
|
|
|
|
24
|
push @lines, '
123
|
|
|
|
|
|
|
. '" content="' . $self->textToHtml($f->content) |
124
|
|
|
|
|
|
|
. "\"$self->{MMCH_tail}\n"; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
4
|
|
|
|
|
8
|
push @lines, "\n"; |
128
|
4
|
50
|
|
|
|
23
|
wantarray ? @lines : join('',@lines); |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
#------------------------------------------ |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
my $atom = qr/[^()<>@,;:\\".\[\]\s[:cntrl:]]+/; |
135
|
|
|
|
|
|
|
my $email_address = qr/(($atom(?:\.$atom)*)\@($atom(?:\.$atom)+))/o; |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
sub fieldContentsToHtml($;$) |
138
|
8
|
|
|
8
|
1
|
14
|
{ my ($self, $field) = (shift,shift); |
139
|
8
|
50
|
|
|
|
13
|
my $subject = defined $_[0] ? '?subject='.$self->textToHtml(shift) : ''; |
140
|
|
|
|
|
|
|
|
141
|
8
|
|
|
|
|
21
|
my ($body, $comment) = ($self->textToHtml($field->body), $field->comment); |
142
|
|
|
|
|
|
|
|
143
|
8
|
100
|
|
|
|
20
|
$body =~ s#$email_address#$1#gx |
144
|
|
|
|
|
|
|
if $field->name =~ m/^(resent-)?(to|from|cc|bcc|reply\-to)$/; |
145
|
|
|
|
|
|
|
|
146
|
8
|
50
|
|
|
|
36
|
$body . ($comment ? '; '.$self->textToHtml($comment) : ''); |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
#------------------------------------------ |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
1; |