From cb6e110f4021afc96f308cabae7c02fa13cf682e Mon Sep 17 00:00:00 2001 From: iliajie Date: Mon, 29 May 2023 23:29:18 +0300 Subject: [PATCH 01/22] Fix not to remove images completely, as we can border them nicely --- mailboxes/folders-lib.pl | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/mailboxes/folders-lib.pl b/mailboxes/folders-lib.pl index 56ea1f4c4..f2adf2ec7 100755 --- a/mailboxes/folders-lib.pl +++ b/mailboxes/folders-lib.pl @@ -2768,10 +2768,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 +2782,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,6 +2798,25 @@ 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; } From 8319033bfa6c7767668bdbcf618592c0fdd8d65a Mon Sep 17 00:00:00 2001 From: iliajie Date: Mon, 29 May 2023 23:30:02 +0300 Subject: [PATCH 02/22] Add API to put HTML email body to `iframe` element --- mailboxes/folders-lib.pl | 51 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/mailboxes/folders-lib.pl b/mailboxes/folders-lib.pl index f2adf2ec7..4fe15c525 100755 --- a/mailboxes/folders-lib.pl +++ b/mailboxes/folders-lib.pl @@ -2820,6 +2820,57 @@ if ($masked_img) { return $newhtml; } +# iframe_body(body) +# Returns email message in an iframe HTML element +sub iframe_body +{ +my ($body) = @_; +my $iframe_styles = + ""; +my $iframe_spinner = + "
". + ""; +$iframe_styles =~ s/[\n\r\s]+/ /g; +$iframe_styles = &trim($iframe_styles); +if ($body =~ /<\/body>/) { + $body =~ s/<\/body>/$iframe_styles<\/body>/; + } + else { + $body .= $iframe_styles; + } +$body = &trim("e_escape($body, '"')); +my $iframe_body = $iframe_spinner. + ""; +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. From 76bf9ffd623fd960f380a3c06de82680dc922163 Mon Sep 17 00:00:00 2001 From: iliajie Date: Mon, 29 May 2023 23:59:05 +0300 Subject: [PATCH 03/22] Add to use a new `iframe_body` API --- mailboxes/view_mail.cgi | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mailboxes/view_mail.cgi b/mailboxes/view_mail.cgi index 0729d856d..7f782909d 100755 --- a/mailboxes/view_mail.cgi +++ b/mailboxes/view_mail.cgi @@ -161,7 +161,7 @@ if ($body && $body->{'data'} =~ /\S/) { } elsif ($body eq $htmlbody) { # Attempt to show HTML - $bodycontents = &safe_html($body->{'data'}); + $bodycontents = $body->{'data'}; $bodycontents = &fix_cids($bodycontents, \@attach, "detach.cgi?user=$uuser&idx=$in{'idx'}&folder=$in{'folder'}$subs"); if ($textbody) { @@ -169,6 +169,8 @@ if ($body && $body->{'data'} =~ /\S/) { "$text{'view_astext'}"); } } + $bodycontents = &iframe_body($bodycontents) + if ($bodycontents); } if ($bodycontents) { print &ui_table_start($text{'view_body'}, "width=100%", 1, From 93cc86315d173a59efeb1f1f2f5b23d12db321ba Mon Sep 17 00:00:00 2001 From: iliajie Date: Tue, 30 May 2023 00:36:36 +0300 Subject: [PATCH 04/22] Add better indications for hidden images --- mailboxes/folders-lib.pl | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mailboxes/folders-lib.pl b/mailboxes/folders-lib.pl index 4fe15c525..8777903ab 100755 --- a/mailboxes/folders-lib.pl +++ b/mailboxes/folders-lib.pl @@ -2803,9 +2803,12 @@ if ($masked_img) { ""; $masked_img_style =~ s/[\n\r\s]+/ /g; From 121cbc4a959e58971517dceba0382894a23c9119 Mon Sep 17 00:00:00 2001 From: iliajie Date: Tue, 30 May 2023 00:37:20 +0300 Subject: [PATCH 05/22] Add a button to display images on demand (not allow by default) --- mailboxes/view_mail.cgi | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/mailboxes/view_mail.cgi b/mailboxes/view_mail.cgi index 7f782909d..0d57c2844 100755 --- a/mailboxes/view_mail.cgi +++ b/mailboxes/view_mail.cgi @@ -162,12 +162,19 @@ if ($body && $body->{'data'} =~ /\S/) { elsif ($body eq $htmlbody) { # Attempt to show HTML $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); From 1f339f208583757c818cd09a9ee2ae78c3fd3fc7 Mon Sep 17 00:00:00 2001 From: iliajie Date: Tue, 30 May 2023 11:48:14 +0300 Subject: [PATCH 06/22] Fix to always `sandbox` email content --- mailboxes/folders-lib.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mailboxes/folders-lib.pl b/mailboxes/folders-lib.pl index 8777903ab..afc000059 100755 --- a/mailboxes/folders-lib.pl +++ b/mailboxes/folders-lib.pl @@ -2865,7 +2865,7 @@ if ($body =~ /<\/body>/) { } $body = &trim("e_escape($body, '"')); my $iframe_body = $iframe_spinner. - ""; +my $iframe_body = + $iframe_spinner." + + "; return &trim($iframe_body); } From 3f470a4bcd26bb6ee97fc9ef4b3fec373d4d2a2f Mon Sep 17 00:00:00 2001 From: iliajie Date: Tue, 30 May 2023 13:48:39 +0300 Subject: [PATCH 09/22] Fix to use more common `here-doc` to print multiline --- mailboxes/folders-lib.pl | 89 ++++++++++++++++++---------------------- 1 file changed, 41 insertions(+), 48 deletions(-) diff --git a/mailboxes/folders-lib.pl b/mailboxes/folders-lib.pl index bac06f605..85ecb97d4 100755 --- a/mailboxes/folders-lib.pl +++ b/mailboxes/folders-lib.pl @@ -2828,35 +2828,11 @@ return $newhtml; sub iframe_body { my ($body) = @_; + +# Mail iframe inner styles my $iframe_styles = - ""; -my $iframe_spinner = - "
- - "; -$iframe_styles =~ s/[\n\r\s]+/ /g; -$iframe_styles = &trim($iframe_styles); + ''; +# Add inner styles to the email body if ($body =~ /<\/body>/) { $body =~ s/<\/body>/$iframe_styles<\/body>/; } @@ -2864,26 +2840,43 @@ if ($body =~ /<\/body>/) { $body .= $iframe_styles; } $body = &trim("e_escape($body, '"')); -my $iframe_body = - $iframe_spinner." - - "; +# Email iframe stuff +my $iframe_body = < + + + +EOF return &trim($iframe_body); } From d6e21f43ce78df3f00c59fc65a0b79c53cc1b799 Mon Sep 17 00:00:00 2001 From: iliajie Date: Tue, 30 May 2023 13:52:05 +0300 Subject: [PATCH 10/22] Fix missing semicolon --- mailboxes/folders-lib.pl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mailboxes/folders-lib.pl b/mailboxes/folders-lib.pl index 85ecb97d4..c4d39e199 100755 --- a/mailboxes/folders-lib.pl +++ b/mailboxes/folders-lib.pl @@ -2841,7 +2841,7 @@ if ($body =~ /<\/body>/) { } $body = &trim("e_escape($body, '"')); # Email iframe stuff -my $iframe_body = <