]> git.donarmstrong.com Git - debbugs.git/commitdiff
Support blacklisting avatars
authorDon Armstrong <don@donarmstrong.com>
Tue, 1 Oct 2013 19:14:09 +0000 (12:14 -0700)
committerDon Armstrong <don@donarmstrong.com>
Tue, 1 Oct 2013 19:14:09 +0000 (12:14 -0700)
Debbugs/Config.pm
Debbugs/Libravatar.pm

index f076585a21dd80d1c205deb83561025279264367..f13e3a2bdcf58e6bf5d966affe806b855af7c314 100644 (file)
@@ -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
index 08915fd4f1dab8612f41fae02c738bbb5afeeb18..283db41af2e1b6bf794d067fd36eb126a8713dce 100644 (file)
@@ -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;