| 1 | # This code is part of Perl distribution Mail-Message version 4.05. | ||||||||||||||||||||||||
| 2 | # The POD got stripped from this file by OODoc version 3.06. | ||||||||||||||||||||||||
| 3 | # For contributors see file ChangeLog. | ||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||
| 5 | # This software is copyright (c) 2001-2026 by Mark Overmeer. | ||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||
| 7 | # This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||
| 8 | # the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||
| 9 | # SPDX-License-Identifier: Artistic-1.0-Perl OR GPL-1.0-or-later | ||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||
| 12 | package Mail::Message::Convert::Html;{ | ||||||||||||||||||||||||
| 13 | 1 | our $VERSION = '4.05'; | |||||||||||||||||||||||
| 14 | } | ||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||
| 16 | 1 | ▶ | use parent 'Mail::Message::Convert'; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||
| 18 | 1 | ▶ | use strict; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 19 | 1 | ▶ | use warnings; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||
| 21 | 1 | ▶ | use Log::Report 'mail-message', import => [ qw/__x error/ ]; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||
| 23 | #-------------------- | ||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||
| 25 | sub init($) | ||||||||||||||||||||||||
| 26 | 2 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||||||||
|
Subroutine
init: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||
| 28 | 2 | $self->SUPER::init($args); | |||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||
| 30 | 2 | ▶ | my $produce = $args->{produce} || 'HTML'; | ||||||||||||||||||||||
|
Condition100%2/2
$args->{'produce'} || 'HTML'
MC/DC100%1/1
$args->{'produce'} || 'HTML'
$args->{'produce'}
Truth table100%2/2
A
A= $args->{'produce'}
| |||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||
| 32 | $self->{MMCH_tail} | ||||||||||||||||||||||||
| 33 | 2 | ▶ | = $produce eq 'HTML' ? '>' | ||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||
| 34 | : $produce eq 'XHTML' ? ' />' | ||||||||||||||||||||||||
| 35 | : error __x"produce XHTML or HTML, not {what UNKNOWN}.", what => $produce; | ||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||
| 37 | 2 | $self; | |||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||
| 40 | #-------------------- | ||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||
| 42 | sub textToHtml(@) | ||||||||||||||||||||||||
| 43 | 52 | ▶ | { my $self = shift; | ||||||||||||||||||||||
|
Subroutine
textToHtml: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||
| 45 | 52 | my @lines = @_; # copy is required | |||||||||||||||||||||||
| 46 | 52 | foreach (@lines) | |||||||||||||||||||||||
| 47 | 52 | { s/\&/&/gs; s/\</</gs; | |||||||||||||||||||||||
| 48 | 52 | s/\>/>/gs; s/\"/"/gs; | |||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||
| 50 | 52 | ▶ | wantarray ? @lines : join('', @lines); | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||
| 54 | sub fieldToHtml($;$) | ||||||||||||||||||||||||
| 55 | 2 | ▶ | { my ($self, $field, $subject) = @_; | ||||||||||||||||||||||
|
Subroutine
fieldToHtml: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||
| 56 | 2 | '<strong>'. $self->textToHtml($field->wellformedName) . ': </strong>' . $self->fieldContentsToHtml($field, $subject); | |||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||
| 60 | sub headToHtmlTable($;$) | ||||||||||||||||||||||||
| 61 | 2 | ▶ | { my ($self, $head) = (shift, shift); | ||||||||||||||||||||||
|
Subroutine
headToHtmlTable: called CC=6 SCAR=19.3
Pod
documented
| |||||||||||||||||||||||||
| 62 | 2 | ▶ | my $tp = @_ ? ' '.shift : ''; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||
| 64 | 2 | my $subject; | |||||||||||||||||||||||
| 65 | 2 | ▶ | if($self->{MMHC_mailto_subject}) | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 66 | 0 | { my $s = $head->get('subject'); | |||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||
| 68 | 1 | ▶ | use Mail::Message::Construct; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 69 | 0 | ▶ | $subject = Mail::Message::Construct->replySubject($s) if defined $s; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||
| 72 | 2 | my @lines = "<table $tp>\n"; | |||||||||||||||||||||||
| 73 | 2 | foreach my $f ($self->selectedFields($head)) | |||||||||||||||||||||||
| 74 | 6 | { my $name_html = $self->textToHtml($f->wellformedName); | |||||||||||||||||||||||
| 75 | 6 | my $cont_html = $self->fieldContentsToHtml($f, $subject); | |||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||
| 77 | 6 | push @lines, | |||||||||||||||||||||||
| 78 | qq(<tr><th valign="top" align="left">$name_html:</th>\n), | ||||||||||||||||||||||||
| 79 | qq( <td valign="top">$cont_html</td></tr>\n); | ||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||
| 82 | 2 | push @lines, "</table>\n"; | |||||||||||||||||||||||
| 83 | 2 | ▶ | wantarray ? @lines : join('',@lines); | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||
| 87 | sub headToHtmlHead($@) | ||||||||||||||||||||||||
| 88 | 4 | ▶ | { my ($self, $head) = (shift,shift); | ||||||||||||||||||||||
|
Subroutine
headToHtmlHead: called CC=13 SCAR=26.2
Pod
documented
| |||||||||||||||||||||||||
| 89 | 4 | my %meta; | |||||||||||||||||||||||
| 90 | 4 | ▶ | while(@_) { my $k = shift; $meta{lc $k} = shift } | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||
| 92 | 4 | ▶ | my $title = delete $meta{title} || $head->get('subject') || '<no subject>'; | ||||||||||||||||||||||
|
Condition60%3/5
delete $meta{'title'} || $head->get('subject') || '<no subject>'
delete $meta{"title"} or $head->get("subject")
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")
| |||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||
| 94 | 4 | my @lines = ( | |||||||||||||||||||||||
| 95 | "<head>\n", | ||||||||||||||||||||||||
| 96 | "<title>".$self->textToHtml($title) . "</title>\n", | ||||||||||||||||||||||||
| 97 | ); | ||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||
| 99 | 4 | my $author = delete $meta{author}; | |||||||||||||||||||||||
| 100 | 4 | ▶ | unless(defined $author) | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 101 | 4 | { my $from = $head->get('from'); | |||||||||||||||||||||||
| 102 | 4 | ▶ | my @addr = defined $from ? $from->addresses : (); | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 103 | 4 | ▶ | $author = @addr ? $addr[0]->format : undef; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||
| 106 | 4 | ▶ | push @lines, '<meta name="Author" content="' . $self->textToHtml($author) . "\"$self->{MMCH_tail}\n" | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 107 | if defined $author; | ||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||
| 109 | 4 | foreach my $f (map {lc} keys %meta) | |||||||||||||||||||||||
| 110 | 5 | ▶ | { next if $meta{$f} eq ''; # empty is skipped. | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 111 | push @lines, | ||||||||||||||||||||||||
| 112 | '<meta name="'. ucfirst lc $self->textToHtml($f) | ||||||||||||||||||||||||
| 113 | 4 | . '" content="'. $self->textToHtml($meta{$f}) | |||||||||||||||||||||||
| 114 | ."\"$self->{MMCH_tail}\n"; | ||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||
| 117 | 4 | foreach my $f ($self->selectedFields($head)) | |||||||||||||||||||||||
| 118 | 12 | ▶ | { next if exists $meta{$f->name}; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 119 | 10 | push @lines, | |||||||||||||||||||||||
| 120 | '<meta name="' . $self->textToHtml($f->wellformedName) | ||||||||||||||||||||||||
| 121 | . '" content="' . $self->textToHtml($f->content) | ||||||||||||||||||||||||
| 122 | . "\"$self->{MMCH_tail}\n"; | ||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||
| 125 | 4 | push @lines, "</head>\n"; | |||||||||||||||||||||||
| 126 | 4 | ▶ | wantarray ? @lines : join('',@lines); | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||
| 130 | 1 | my $atom = qr/[^()<>@,;:\\".\[\]\s[:cntrl:]]+/; | |||||||||||||||||||||||
| 131 | 1 | my $email_address = qr/(($atom(?:\.$atom)*)\@($atom(?:\.$atom)+))/o; | |||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||
| 133 | sub fieldContentsToHtml($;$) | ||||||||||||||||||||||||
| 134 | 8 | ▶ | { my ($self, $field, $subj) = @_; | ||||||||||||||||||||||
|
Subroutine
fieldContentsToHtml: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||
| 136 | 8 | ▶ | my $subject = defined $subj ? '?subject='.$self->textToHtml($subj) : ''; | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 137 | 8 | my $body = $self->textToHtml($field->body); | |||||||||||||||||||||||
| 138 | 8 | my $comment = $field->comment; | |||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||
| 140 | 8 | ▶ | $body =~ s#$email_address#<a href="mailto:$1$subject">$1</a>#gx | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 141 | if $field->name =~ m/^(resent-)?(to|from|cc|bcc|reply\-to)$/; | ||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||
| 143 | 8 | ▶ | $body . ($comment ? '; '.$self->textToHtml($comment) : ''); | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||
| 146 | 1 | 1; | |||||||||||||||||||||||