Motivation
AntiSpamPadding is useful to stop robots spamming but Is this needed for authenticated users?
request made after consulting with Peter
Description and Documentation
AntiSpamPadding is useful to stop robots spamming but the output is not aesthetically pleasing and the emails cannot be copied/pasted. Is this needed for authenticated users? This is a request to have a configuration option to enable the padding only if the user is not authenticated.
Add a variable such as
$TWiki::cfg{AntiSpam}{EmailGuestPadding} to the LocalSite.cfg and add some code in lib/TWiki/Render.pm to check this.
Examples
Impact
Implementation
--
Contributors:
Peter Jones - 2016-11-17
Discussion
Looks good. To be specific, I think it is good to offer both options, the existing
$TWiki::cfg{AntiSpam}{EmailPadding}, and a new
$TWiki::cfg{AntiSpam}{EmailGuestPadding} option that depends on the login context of the user.
--
Peter Thoeny - 2016-11-17
Feature proposal accepted by
KampalaReleaseMeeting2016x11x17. I put Pete Jones down as committed developer, let me know if you'd like to change this.
--
Peter Thoeny - 2016-11-17
How about in
lib/TWiki/Render.pm
sub _externalLink {
my $authenticated = TWiki::Func::getContext('authenticated');
if( $url =~ /^mailto:/i ) {
if( $TWiki::cfg{AntiSpam}{EmailPadding} ){
if (($TWiki::cfg{AntiSpam}{EmailGuestPadding}) && (!$authenticated)){
$url =~ s/(\@[\w\_\-\+]+)(\.)/$1$TWiki::cfg{AntiSpam}{EmailPadding}$2/;
if ($text) {
$text =~ s/(\@[\w\_\-\+]+)(\.)/$1$TWiki::cfg{AntiSpam}{EmailPadding}$2/;
}
}
}
if( $TWiki::cfg{AntiSpam}{HideUserDetails} ) {
# Much harder obfuscation scheme. For link text we only encode '@'
# See also Item2928 and Item3430 before touching this
$url =~ s/(\W)/'&#'.ord($1).';'/ge;
if ($text) {
$text =~ s/\@/'&#'.ord('@').';'/ge;
}
}
} elsif
.
.
.
--
Peter Jones - 2016-11-21
I solved it with some modification, so that one or the other setting can be used.
Patch:
Index: TWiki.spec
===================================================================
--- TWiki.spec (revision 30274)
+++ TWiki.spec (working copy)
@@ -695,6 +695,11 @@
# rendered as fred@user.co.NOSPAM.ru
$TWiki::cfg{AntiSpam}{EmailPadding} = '';
+# **STRING 50**
+# Same as <tt>{AntiSpam}{EmailPadding}</tt>, except that the spam
+# padding is only done for non-authenticated users.
+$TWiki::cfg{AntiSpam}{EmailGuestPadding} = '';
+
# **BOOLEAN**
# Normally TWiki stores the user's sensitive information (such as their e-mail
# address) in a database out of public view. It also obfuscates e-mail
Index: TWiki/Render.pm
===================================================================
--- TWiki/Render.pm (revision 30274)
+++ TWiki/Render.pm (working copy)
@@ -1024,7 +1024,13 @@
my $opt = '';
my $icn = '';
if( $url =~ /^mailto:/i ) {
- if( $TWiki::cfg{AntiSpam}{EmailPadding} ) {
+ my $twiki = $this->{session};
+ if( $TWiki::cfg{AntiSpam}{EmailGuestPadding} && !$twiki->inContext( 'authenticated' ) ) {
+ $url =~ s/(\@[\w\_\-\+]+)(\.)/$1$TWiki::cfg{AntiSpam}{EmailGuestPadding}$2/;
+ if ($text) {
+ $text =~ s/(\@[\w\_\-\+]+)(\.)/$1$TWiki::cfg{AntiSpam}{EmailGuestPadding}$2/;
+ }
+ } elsif( $TWiki::cfg{AntiSpam}{EmailPadding} ) {
$url =~ s/(\@[\w\_\-\+]+)(\.)/$1$TWiki::cfg{AntiSpam}{EmailPadding}$2/;
if ($text) {
$text =~ s/(\@[\w\_\-\+]+)(\.)/$1$TWiki::cfg{AntiSpam}{EmailPadding}$2/;
--
Peter Thoeny - 2016-11-22
This is now
MergedToCore.
--
Peter Thoeny - 2016-11-22