Skip to content

Commit

Permalink
Fix sympa-community#621 — Add a 'gecos' option to web_archive_spam_pr…
Browse files Browse the repository at this point in the history
…otection

This allows to make web archives public without fearing to leak users
email addresses.
  • Loading branch information
ldidry committed May 24, 2019
1 parent 4be974c commit c1c7c46
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/lib/Sympa/ConfDef.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
Expand Down
34 changes: 34 additions & 0 deletions src/lib/Sympa/HTMLDecorator.pm
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ package Sympa::HTMLDecorator;
use strict;
use warnings;

use Sympa::Language;
use Sympa::Regexps;
use Sympa::Tools::Text;

Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -230,6 +232,38 @@ 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});
if ($dtext =~ s{<?\b($email_re)\b>?}{}g) {
$decorated .= Sympa::Tools::Text::encode_html($dtext);
} else {
$decorated .= $item->{text};
}
} elsif ($item->{event} eq 'start') {
my $text = $item->{text};
if ($text =~ s{\b(href=\S+)}{join '%20AT%20', split(/\@/, $1)}egi)
{
$decorated .= $text;
} 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;

Expand Down
2 changes: 1 addition & 1 deletion src/lib/Sympa/ListDef.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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'}
},
Expand Down
1 change: 1 addition & 0 deletions src/lib/Sympa/ListOpt.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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'},
Expand Down

0 comments on commit c1c7c46

Please sign in to comment.