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