[Bps-public-commit] cpan2rt branch master updated. 0503b91d9cf3227474004a86a712a7850d9e0f89

BPS Git Server git at git.bestpractical.com
Wed Dec 22 20:57:22 UTC 2021


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "cpan2rt".

The branch, master has been updated
       via  0503b91d9cf3227474004a86a712a7850d9e0f89 (commit)
      from  2d940a92ca598c45f81ba8ce4fecb6bb2f9e4491 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 0503b91d9cf3227474004a86a712a7850d9e0f89
Author: Brian Conry <bconry at bestpractical.com>
Date:   Wed Dec 22 14:52:28 2021 -0600

    Unset email addresses known to bounce
    
    Bounces from cpan RT affect our mail reputation for all customers.
    
    Read email address from 'bounce_list' and prevent them from being set on
    users, unsetting them if they are already present.

diff --git a/lib/CPAN2RT.pm b/lib/CPAN2RT.pm
index bd0cb55..8c93ab5 100644
--- a/lib/CPAN2RT.pm
+++ b/lib/CPAN2RT.pm
@@ -24,6 +24,7 @@ use Email::Address;
 use List::Compare;
 use CPAN::DistnameInfo;
 use List::MoreUtils qw(uniq);
+use File::Copy;
 
 our $DEBUG = 0;
 sub debug(&);
@@ -273,11 +274,30 @@ sub for_all_distributions {
 sub sync_authors {
     my $self = shift;
     my $force = shift;
-    if ( !$force && !$self->is_new_file( '00whois.xml' ) ) {
+    if ( !$force && !$self->is_new_file( '00whois.xml' ) && !$self->is_new_file( 'bounce_list' ) ) {
         debug { "Skip syncing, file's not changed\n" };
         return (1);
     }
 
+    my $bouncefile_path = $self->file_path( 'bounce_list' );
+
+    # is_new_file compares the mtimes of $file and $file.old
+    # the other files have their .old created by backup_file, but
+    # we can't use $self->backup_file here because it moves the current
+    # file, expecting that we'll fetch a new copy from somewhere,
+    # and we don't have new copy to fetch.
+    copy( $bouncefile_path, $bouncefile_path . '.old' );
+
+    # one email per line
+    my $bounce_map = $self->{bounce_map} = {};
+
+    open my $fh, "<:utf8", $bouncefile_path or die "Couldn't open '$bouncefile_path': $!";
+
+    while( my $email = <$fh> ) {
+        chomp $email;
+        $bounce_map->{ $email } = 1;
+    }
+
     my ($i, @errors) = (0);
     my $authors = $self->authors;
     while ( my ($cpanid, $meta) = each %$authors ) {
@@ -782,6 +802,8 @@ sub load_or_create_user {
     my $self = shift;
     my ($cpanid, $realname, $email) = @_;
 
+    my $bounce_map = $self->{bounce_map};
+
     my $bycpanid = RT::User->new($RT::SystemUser);
     $bycpanid->LoadByCol( Name => $cpanid );
 
@@ -798,10 +820,19 @@ sub load_or_create_user {
         # XXX: as we have no way to detect email changes on PAUSE
         # then we set email to the public version from PAUSE only when
         # user in RT has no email. The same applies to name.
-        $bycpanid->SetEmailAddress( $email )
-            unless $bycpanid->EmailAddress;
+
+        # don't use email addresses known to bounce, unsetting them on users if they are already set
+        if( exists $bounce_map->{ $email } ) {
+            $byemail->SetEmailAddress( '' ) if $byemail->id;
+        }
+        else {
+            $bycpanid->SetEmailAddress( $email )
+                unless $bycpanid->EmailAddress;
+        }
+
         $bycpanid->SetRealName( $realname )
             unless $bycpanid->RealName;
+
         return $bycpanid;
     }
     elsif ( $bycpanid->id && $byemail->id ) {

-----------------------------------------------------------------------

Summary of changes:
 lib/CPAN2RT.pm | 37 ++++++++++++++++++++++++++++++++++---
 1 file changed, 34 insertions(+), 3 deletions(-)


hooks/post-receive
-- 
cpan2rt


More information about the Bps-public-commit mailing list