From bec036b7465a66ad8fea842d01ce4cd53eed146f Mon Sep 17 00:00:00 2001 From: Don Armstrong Date: Tue, 1 Oct 2013 12:14:09 -0700 Subject: [PATCH] Support blacklisting avatars --- Debbugs/Config.pm | 13 ++++++++++++- Debbugs/Libravatar.pm | 28 +++++++++++++++++++++++++--- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/Debbugs/Config.pm b/Debbugs/Config.pm index f076585..f13e3a2 100644 --- a/Debbugs/Config.pm +++ b/Debbugs/Config.pm @@ -78,7 +78,7 @@ BEGIN { ], text => [qw($gBadEmailPrefix $gHTMLTail $gHTMLExpireNote), ], - cgi => [qw($gLibravatarUri $gLibravatarUriOptions)], + cgi => [qw($gLibravatarUri $gLibravatarUriOptions @gLibravatarBlacklist)], config => [qw(%config)], ); @EXPORT_OK = (); @@ -1017,6 +1017,17 @@ Default: $config{web_dir}/libravatar/ set_default(\%config,'libravatar_cache_dir',$config{web_dir}.'/libravatar/'); +=item libravatar_blacklist + +Array of regular expressions to match against emails, domains, or +images to only show the default image + +Default: empty array + +=cut + +set_default(\%config,'libravatar_blacklist',[]); + =back =head2 Text Fields diff --git a/Debbugs/Libravatar.pm b/Debbugs/Libravatar.pm index 08915fd..283db41 100644 --- a/Debbugs/Libravatar.pm +++ b/Debbugs/Libravatar.pm @@ -66,9 +66,11 @@ sub cache_valid{ return 0; } -=item retreive_libravatar +=over - $cache_location = retreive_libravatar(location => $cache_location, +=item retrieve_libravatar + + $cache_location = retrieve_libravatar(location => $cache_location, email => lc($param{email}), ); @@ -78,7 +80,7 @@ there isn't a matching avatar, or there is an error, returns undef. =cut -sub retreive_libravatar{ +sub retrieve_libravatar{ my %type_mapping = (jpeg => 'jpg', png => 'png', @@ -173,6 +175,22 @@ sub retreive_libravatar{ return $cache_location.'.'.$dest_type; } +sub blocked_libravatar { + my ($email,$md5sum) = @_; + my $blocked = 0; + for my $blocker (@{$config{libravatar_blacklist}||[]}) { + for my $element ($email,$md5sum) { + next unless defined $element; + eval { + if ($element =~ /$blocker/) { + $blocked=1; + } + }; + } + } + return $blocked; +} + sub cache_location { my %param = @_; my $md5sum; @@ -183,6 +201,7 @@ sub cache_location { } else { croak("cache_location must be called with one of md5sum or email"); } + return undef if blocked_libravatar($param{email},$md5sum); for my $ext (qw(.png .jpg)) { if (-e $config{libravatar_cache_dir}.'/'.$md5sum.$ext) { return $config{libravatar_cache_dir}.'/'.$md5sum.$ext; @@ -269,6 +288,9 @@ sub serve_cache_mod_perl { $r->finfo(APR::Finfo::stat($cache_location, APR::Const::FINFO_NORM, $r->pool)); } +=back + +=cut 1; -- 2.39.2