diff --git a/mailboxes/config b/mailboxes/config index 3d1ea4a97..14ee28452 100644 --- a/mailboxes/config +++ b/mailboxes/config @@ -15,7 +15,7 @@ sort_mode=1 fwd_mode=0 delete_warn=y top_buttons=2 -view_html=0 +view_html=2 mail_usermin=mail sync_create=0 sync_modify=1 diff --git a/mailboxes/folders-lib.pl b/mailboxes/folders-lib.pl index 56ea1f4c4..55d4c197d 100755 --- a/mailboxes/folders-lib.pl +++ b/mailboxes/folders-lib.pl @@ -2494,14 +2494,15 @@ return $rv; # Attempts to convert some HTML to text form sub html_to_text { -local ($h2, $lynx); +my ($html) = @_; +my ($h2, $lynx); if (($h2 = &has_command("html2text")) || ($lynx = &has_command("lynx"))) { # Can use a commonly available external program local $temp = &transname().".html"; open(TEMP, ">", $temp); - print TEMP $_[0]; + print TEMP $html; close(TEMP); - open(OUT, ($lynx ? "$lynx -dump $temp" : "$h2 $temp")." 2>/dev/null |"); + open(OUT, ($lynx ? "$lynx --display_charset=utf-8 -dump $temp" : "$h2 $temp")." 2>/dev/null |"); while() { if ($lynx && $_ =~ /^\s*References\s*$/) { # Start of Lynx references output @@ -2520,13 +2521,35 @@ if (($h2 = &has_command("html2text")) || ($lynx = &has_command("lynx"))) { return $text; } else { + # Can we use Perl HTML formatter + # for the better conversion + eval "use HTML::TreeBuilder"; + if (!$@) { + eval "use HTML::FormatText"; + if (!$@) { + my $html_parser = HTML::TreeBuilder->new(); + eval "use utf8"; + utf8::decode($html) + if (!$@); + $html_parser->parse($html); + my $formatter = HTML::FormatText->new(leftmargin => 1, rightmargin => 79); + return $formatter->format($html_parser); + } + } # Do conversion manually :( - local $html = $_[0]; + $html =~ s/(<|<)(style|script).*?(>|>).*?(<|<)\/(style|script)(>|>)//gs; $html =~ s/\s+/ /g; $html =~ s/

/\n\n/gi; $html =~ s/
/\n/gi; $html =~ s/<[^>]+>//g; + my $useutf8 = 0; + eval "use utf8"; + $useutf8 = 1 if (!$@); + utf8::decode($html) + if ($useutf8); $html = &entities_to_ascii($html); + utf8::encode($html) + if ($useutf8); return $html; } } @@ -2768,10 +2791,11 @@ else { # 2=All images. Returns the URL of images found in &urls sub disable_html_images { -local ($html, $dis, $urls) = @_; -local $newhtml; +my ($html, $dis, $urls) = @_; +my $newhtml; +my $masked_img; while($html =~ /^([\000-\377]*?)(<\s*img[^>]*src=('[^']*'|"[^"]*"|\S+)[^>]*>)([\000-\377]*)/i) { - local ($before, $allimg, $img, $after) = ($1, $2, $3, $4); + my ($before, $allimg, $img, $after) = ($1, $2, $3, $4); $img =~ s/^'(.*)'$/$1/ || $img =~ s/^"(.*)"$/$1/; push(@$urls, $img) if ($urls); if ($dis == 0) { @@ -2781,7 +2805,10 @@ while($html =~ /^([\000-\377]*?)(<\s*img[^>]*src=('[^']*'|"[^"]*"|\S+)[^>]*>)([\ elsif ($dis == 1) { # Don't touch unless offsite if ($img =~ /^(http|https|ftp):/) { - $newhtml .= $before; + $masked_img++; + my $imgcont = $allimg; + $imgcont =~ s/src=/data-nosrc=/g; + $newhtml .= $before.$imgcont; } else { $newhtml .= $before.$allimg; @@ -2794,9 +2821,102 @@ while($html =~ /^([\000-\377]*?)(<\s*img[^>]*src=('[^']*'|"[^"]*"|\S+)[^>]*>)([\ $html = $after; } $newhtml .= $html; +if ($masked_img) { + my $masked_img_style = + ""; + $masked_img_style =~ s/[\n\r\s]+/ /g; + $masked_img_style = &trim($masked_img_style); + if ($newhtml =~ /<\/body>/) { + $newhtml =~ s/<\/body>/$masked_img_style<\/body>/; + } + else { + $newhtml .= $masked_img_style; + } + } return $newhtml; } +# iframe_body(body) +# Returns email message in an iframe HTML element +sub iframe_body +{ +my ($body) = @_; + +# Mail iframe inner styles +my $iframe_styles = + ''; +# Add inner styles to the email body +if ($body =~ /<\/body>/) { + $body =~ s/<\/body>/$iframe_styles<\/body>/; + } + else { + $body .= $iframe_styles; + } +$body = &trim("e_escape($body, '"')); +# Email iframe stuff +my $iframe_body = < + + + +EOF +return &trim($iframe_body); +} + # remove_body_attachments(&mail, &attach) # Returns attachments except for those that make up the message body, and those # that have sub-attachments. diff --git a/mailboxes/view_mail.cgi b/mailboxes/view_mail.cgi index 0729d856d..0d57c2844 100755 --- a/mailboxes/view_mail.cgi +++ b/mailboxes/view_mail.cgi @@ -161,14 +161,23 @@ if ($body && $body->{'data'} =~ /\S/) { } elsif ($body eq $htmlbody) { # Attempt to show HTML - $bodycontents = &safe_html($body->{'data'}); + $bodycontents = $body->{'data'}; + my @imageurls; + my $image_mode = defined($in{'images'}) ? $in{'images'} : 1; + $bodycontents = &disable_html_images($bodycontents, $image_mode, \@imageurls); $bodycontents = &fix_cids($bodycontents, \@attach, "detach.cgi?user=$uuser&idx=$in{'idx'}&folder=$in{'folder'}$subs"); if ($textbody) { push(@bodyright, "$text{'view_astext'}"); } + if (@imageurls && $image_mode) { + # Link to show images + push(@bodyright, "$text{'view_images'}"); + } } + $bodycontents = &iframe_body($bodycontents) + if ($bodycontents); } if ($bodycontents) { print &ui_table_start($text{'view_body'}, "width=100%", 1, diff --git a/makedebian.pl b/makedebian.pl index 947fd66ed..786ff6375 100755 --- a/makedebian.pl +++ b/makedebian.pl @@ -107,7 +107,7 @@ if ($product eq "webmin") { $size = int(`du -sk $tmp_dir`); @deps = ( "perl", "libnet-ssleay-perl", "openssl", "libauthen-pam-perl", "libpam-runtime", "libio-pty-perl", "unzip", "shared-mime-info", "tar", "libdigest-sha-perl", "libdigest-md5-perl" ); $deps = join(", ", @deps); -@recommends = ( "libdatetime-perl", "libdatetime-timezone-perl", "libdatetime-locale-perl", "libtime-piece-perl" ); +@recommends = ( "libdatetime-perl", "libdatetime-timezone-perl", "libdatetime-locale-perl", "libtime-piece-perl", "lynx" ); $recommends = join(", ", @recommends); open(CONTROL, ">$control_file"); print CONTROL <