Unverified Commit 77ef6bcf authored by IKEDA Soji's avatar IKEDA Soji Committed by GitHub
Browse files

Merge pull request #627 from ldidry/fix-621 by ldidry

Fix #621 — Add a 'gecos' option to web_archive_spam_protection
parents ac6a7b97 416800be
......@@ -1829,7 +1829,7 @@ our @params = (
{ 'name' => 'web_archive_spam_protection',
'gettext_id' => 'Protect web archive against spam harvesters',
'gettext_comment' =>
"The same as \"spam_protection\", but restricted to the web archive.\nIn addition to it:\ncookie: users must submit a small form in order to receive a cookie before browsing the web archive.",
"The same as \"spam_protection\", but restricted to the web archive.\nIn addition to it:\ncookie: users must submit a small form in order to receive a cookie before browsing the web archive.\ngecos: \nonly gecos is displayed.",
'default' => 'cookie',
'vhost' => '1',
},
......
......@@ -27,6 +27,7 @@ package Sympa::HTMLDecorator;
use strict;
use warnings;
use Sympa::Language;
use Sympa::Regexps;
use Sympa::Tools::Text;
......@@ -184,6 +185,7 @@ sub decorate {
if ($options{email}) {
$self->{_shdEmailFunc} =
$options{email} eq 'at' ? \&decorate_email_at
: $options{email} eq 'gecos' ? \&decorate_email_gecos
: $options{email} eq 'javascript' ? \&decorate_email_js
: undef;
}
......@@ -230,6 +232,31 @@ sub decorate_email_at {
return $decorated;
}
sub decorate_email_gecos {
my $self = shift;
my $decorated = '';
my $email_re = Sympa::Regexps::addrspec();
my $language = Sympa::Language->instance;
while (my $item = $self->_queue_shift) {
if ($item->{event} eq 'text') {
my $dtext = Sympa::Tools::Text::decode_html($item->{text});
my $replacement = $language->gettext('address@concealed');
if ($dtext =~ s{\b($email_re)\b}{$replacement}g) {
$decorated .= Sympa::Tools::Text::encode_html($dtext);
} else {
$decorated .= $item->{text};
}
} else {
$decorated .= $item->{text};
}
}
$decorated .= $language->gettext('No gecos') if ($decorated eq ': ');
return $decorated;
}
sub decorate_email_js {
my $self = shift;
......
......@@ -878,7 +878,7 @@ our %pinfo = (
'gettext_id' => "email address protection method",
'gettext_comment' =>
'Idem spam_protection is provided but it can be used only for web archives. Access requires a cookie, and users must submit a small form in order to receive a cookie before browsing the archives. This blocks all robot, even google and co.',
'format' => ['cookie', 'javascript', 'at', 'none'],
'format' => ['cookie', 'javascript', 'at', 'gecos', 'none'],
'occurrence' => '1',
'default' => {'conf' => 'web_archive_spam_protection'}
},
......
......@@ -197,6 +197,7 @@ our %list_option = (
# web_archive_spam_protection
'cookie' => {'gettext_id' => 'use HTTP cookie'},
'gecos' => {'gettext_id' => 'only show gecos'},
# verp_rate
'100%' => {'gettext_id' => '100% - always'},
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment