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