diff --git a/mailboxes/boxes-lib.pl b/mailboxes/boxes-lib.pl index b40c6c74c..9e58d2213 100755 --- a/mailboxes/boxes-lib.pl +++ b/mailboxes/boxes-lib.pl @@ -1444,19 +1444,28 @@ else { } } -# simplify_subject(subject) -# Simplifies and truncates a subject for display in the mail list -sub simplify_subject +# convert_header_for_display(string, [max-non-html-length]) +# Given a string from an email header, perform all mime-decoding, charset +# changes and HTML escaping needed to render it in a browser +sub convert_header_for_display { -local ($mw, $cs) = &decode_mimewords($_[0]); -if (&get_charset() eq 'UTF-8' && $cs && &can_convert_to_utf8($mw, $cs)) { +local ($str, $max) = @_; +local ($mw, $cs) = &decode_mimewords($str); +if (&get_charset() eq 'UTF-8' && &can_convert_to_utf8($mw, $cs)) { $mw = &convert_to_utf8($mw, $cs); } local $rv = &eucconv($mw); -$rv = substr($rv, 0, 80)." .." if (length($rv) > 80); +$rv = substr($rv, 0, $max)." .." if ($max && length($rv) > $max); return &html_escape($rv); } +# simplify_subject(subject) +# Simplifies and truncates a subject header for display in the mail list +sub simplify_subject +{ +return &convert_header_for_display($_[0], 80); +} + # quoted_decode(text) # Converts quoted-printable format to the original sub quoted_decode @@ -1595,6 +1604,7 @@ sub can_convert_to_utf8 { my ($str, $cs) = @_; return 0 if ($cs eq "UTF-8"); +return 0 if (!$cs); eval "use Encode"; return 0 if ($@); eval "use utf8"; @@ -1831,6 +1841,7 @@ sub j2e { } # eucconv_and_escape(string) +# Convert a string for display sub eucconv_and_escape { return &html_escape(&eucconv($_[0])); } diff --git a/mailboxes/view_mail.cgi b/mailboxes/view_mail.cgi index bd0efa6bd..c1f965711 100755 --- a/mailboxes/view_mail.cgi +++ b/mailboxes/view_mail.cgi @@ -61,8 +61,15 @@ if ($body && $body eq $htmlbody) { $headstuff = &head_html($body->{'data'}); } -# Set the character set for the page to match email -$main::force_charset = &get_mail_charset($mail, $body); +$mail_charset = &get_mail_charset($mail, $body); +if (&get_charset() eq 'UTF-8' && &can_convert_to_utf8(undef, $mail_charset)) { + # Convert to UTF-8 + $body->{'data'} = &convert_to_utf8($body->{'data'}, $mail_charset); + } +else { + # Set the character set for the page to match email + $main::force_charset = &get_mail_charset($mail, $body); + } &mail_page_header($text{'view_title'}, $headstuff, undef, &folder_link($in{'user'}, $folder)); @@ -93,13 +100,13 @@ if ($config{'top_buttons'} == 2 && &editable_mail($mail)) { } # Start of headers section -$hbase = "view_mail.cgi?idx=$in{'idx'}&body=$in{'body'}&". +$hbase = "view_mail.cgi?idx=$in{'idx'}&". "folder=$in{'folder'}&dom=$in{'dom'}&user=$uuser$subs"; if ($in{'headers'}) { - push(@hmode, "$text{'view_noheaders'}"); + push(@hmode, "$text{'view_noheaders'}"); } else { - push(@hmode, "$text{'view_allheaders'}"); + push(@hmode, "$text{'view_allheaders'}"); } push(@hmode, "$text{'view_raw'}"); print &ui_table_start($text{'view_headers'}, @@ -131,8 +138,7 @@ else { &eucconv_and_escape( &simplify_date($mail->{'header'}->{'date'}))); print &ui_table_row($text{'mail_subject'}, - &eucconv_and_escape(&decode_mimewords( - $mail->{'header'}->{'subject'}))); + &convert_header_for_display($mail->{'header'}->{'subject'})); } print &ui_table_end(); @@ -325,7 +331,11 @@ print "
\n"; # address_link(address) sub address_link { -local @addrs = &split_addresses(&decode_mimewords($_[0])); +local ($mw, $cs) = &decode_mimewords($_[0]); +if (&get_charset() eq 'UTF-8' && &can_convert_to_utf8($mw, $cs)) { + $mw = &convert_to_utf8($mw, $cs); + } +local @addrs = &split_addresses($mw); local @rv; foreach $a (@addrs) { push(@rv, &eucconv_and_escape($a->[2]));