-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
For HTML messages, add HTML tags to all URIs in message footer/header text #1916
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,6 +63,8 @@ | |
use Sympa::Tools::SMIME; | ||
use Sympa::Tools::Text; | ||
use Sympa::User; | ||
use CGI; | ||
use URI::Find::Schemeless; | ||
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.36 on ubuntu-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.36 on ubuntu-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.36 on ubuntu-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.36 on ubuntu-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.38 on ubuntu-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.38 on ubuntu-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.38 on ubuntu-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.38 on ubuntu-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.26 on ubuntu-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.26 on ubuntu-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.26 on ubuntu-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.26 on ubuntu-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5 on ubuntu-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5 on ubuntu-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5 on ubuntu-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5 on ubuntu-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.24 on ubuntu-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.24 on ubuntu-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.24 on ubuntu-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.24 on ubuntu-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.30 on ubuntu-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.30 on ubuntu-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.30 on ubuntu-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.30 on ubuntu-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.32 on ubuntu-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.32 on ubuntu-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.32 on ubuntu-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.32 on ubuntu-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.20 on ubuntu-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.20 on ubuntu-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.20 on ubuntu-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.20 on ubuntu-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.16 on ubuntu-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.16 on ubuntu-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.16 on ubuntu-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.16 on ubuntu-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.20 on macos-13
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.20 on macos-13
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.20 on macos-13
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.20 on macos-13
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.30 on macos-13
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.30 on macos-13
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.30 on macos-13
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.30 on macos-13
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5 on macos-13
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5 on macos-13
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5 on macos-13
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5 on macos-13
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.24 on macos-13
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.24 on macos-13
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.24 on macos-13
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.24 on macos-13
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.16 on macos-13
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.16 on macos-13
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.16 on macos-13
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.16 on macos-13
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5 on macos-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5 on macos-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5 on macos-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5 on macos-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.26 on macos-13
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.26 on macos-13
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.26 on macos-13
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.26 on macos-13
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.36 on macos-13
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.36 on macos-13
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.36 on macos-13
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.36 on macos-13
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.32 on macos-13
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.32 on macos-13
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.32 on macos-13
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.32 on macos-13
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.20 on macos-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.20 on macos-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.20 on macos-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.20 on macos-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.16 on macos-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.16 on macos-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.16 on macos-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.16 on macos-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.24 on macos-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.24 on macos-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.24 on macos-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.24 on macos-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.26 on macos-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.26 on macos-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.26 on macos-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.26 on macos-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.38 on macos-13
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.38 on macos-13
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.38 on macos-13
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.38 on macos-13
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.30 on macos-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.30 on macos-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.30 on macos-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.30 on macos-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.36 on macos-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.36 on macos-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.36 on macos-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.36 on macos-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.32 on macos-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.32 on macos-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.32 on macos-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.32 on macos-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.38 on macos-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.38 on macos-latest
Check failure on line 67 in src/lib/Sympa/Message.pm GitHub Actions / Perl 5.38 on macos-latest
|
||
|
||
my $language = Sympa::Language->instance; | ||
my $log = Sympa::Log->instance; | ||
|
@@ -2167,16 +2169,22 @@ | |
$log->syslog('debug3', "Treating text/html part"); | ||
|
||
# Escape special characters. | ||
#---acb: and for all three header/footer parts, wrap all URIs | ||
# in HTML tags, and keep newlines for readability and for | ||
# outlook.com parsing: | ||
$header_msg = Sympa::Tools::Text::encode_html($header_msg); | ||
$header_msg = uri_finder($header_msg); | ||
$header_msg =~ s/(\r\n|\r|\n)$//; # strip the last newline. | ||
$header_msg =~ s,(\r\n|\r|\n),<br/>,g; | ||
$header_msg =~ s,(\r\n|\r|\n),<br/>$1,g; # keep newlines | ||
$footer_msg = Sympa::Tools::Text::encode_html($footer_msg); | ||
$footer_msg = uri_finder($footer_msg); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. HTML encoding (escaping) should be done only in The same is true for |
||
$footer_msg =~ s/(\r\n|\r|\n)$//; # strip the last newline. | ||
$footer_msg =~ s,(\r\n|\r|\n),<br/>,g; | ||
$footer_msg =~ s,(\r\n|\r|\n),<br/>$1,g; # keep newlines | ||
$global_footer_msg = | ||
Sympa::Tools::Text::encode_html($global_footer_msg); | ||
$global_footer_msg = uri_finder($global_footer_msg); | ||
$global_footer_msg =~ s/(\r\n|\r|\n)$//; # strip the last newline. | ||
$global_footer_msg =~ s,(\r\n|\r|\n),<br/>,g; | ||
$global_footer_msg =~ s,(\r\n|\r|\n),<br/>$1,g; # keep newlines | ||
|
||
$new_body = $body; | ||
if (length $header_msg) { | ||
|
@@ -3700,6 +3708,26 @@ | |
return join '/', grep {$_} ($id, $shelved); | ||
} | ||
|
||
# autodetect all URIs in block of text and wrap them in HTML tags | ||
sub uri_finder { | ||
my $text = shift; | ||
|
||
# insert "mailto:" on all email addresses, so URI::Find will find them: | ||
$text =~ s,(^|\s)(\S+)@(\S+)($|\s),$1mailto:$2\@$3$4,g; | ||
|
||
# wrap all URIs in HTML tags | ||
my $finder = URI::Find::Schemeless->new(sub { | ||
my($uri, $orig_uri) = @_; | ||
return qq|<a href="$uri">$orig_uri</a>|; | ||
}); | ||
$finder->find(\$text, \&CGI::escapeHTML); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use |
||
|
||
# and finally clean up the displayed link text on mailto links: | ||
$text =~ s/>mailto:/>/g; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I personally think that this “ |
||
|
||
return $text; | ||
} | ||
|
||
1; | ||
__END__ | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
URI::Find::Schemeless should also be added to the
cpanfile
file on the top of source tree as arequires
section.