You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spamassassin.apache.org by gb...@apache.org on 2023/05/04 16:16:43 UTC

svn commit: r1909609 - in /spamassassin/trunk/lib/Mail/SpamAssassin: Plugin/TxRep.pm SQLBasedAddrList.pm

Author: gbechis
Date: Thu May  4 16:16:43 2023
New Revision: 1909609

URL: http://svn.apache.org/viewvc?rev=1909609&view=rev
Log:
make "txrep_welcomelist_out" work when
"auto_welcomelist_distinguish_signed" is set
bz #7269

Modified:
    spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/TxRep.pm
    spamassassin/trunk/lib/Mail/SpamAssassin/SQLBasedAddrList.pm

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/TxRep.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/TxRep.pm?rev=1909609&r1=1909608&r2=1909609&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/TxRep.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/TxRep.pm Thu May  4 16:16:43 2023
@@ -1240,6 +1240,7 @@ sub check_senders_reputation {
 
   my $autolearn = defined $self->{autolearn};
   $self->{last_pms} = $self->{autolearn} = undef;
+  $self->{pms} = $pms;
 
   # Cases where we would not be able to use TxRep
   if(not $self->{conf}->{use_txrep}) {
@@ -1827,6 +1828,12 @@ sub pack_addr {
 
   if ( defined $origip) {$origip = $self->ip_to_awl_key($origip);}
   if (!defined $origip) {$origip = 'none';}
+  if ( $self->{conf}->{txrep_welcomelist_out} &&
+    defined $self->{pms}->{relays_internal} &&  @{$self->{pms}->{relays_internal}} &&
+    (!defined $self->{pms}->{relays_external} || !@{$self->{pms}->{relays_external}})
+    and $addr =~ /\@\w+\./) {
+      $origip = 'WELCOMELIST_OUT';
+  }
   return $addr . "|ip=" . $origip;
 }
 

Modified: spamassassin/trunk/lib/Mail/SpamAssassin/SQLBasedAddrList.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/SQLBasedAddrList.pm?rev=1909609&r1=1909608&r2=1909609&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/SQLBasedAddrList.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/SQLBasedAddrList.pm Thu May  4 16:16:43 2023
@@ -201,7 +201,38 @@ sub get_addr_entry {
 
   return $entry  unless $email ne '' && (defined $ip || defined $signedby);
 
-  my $sql = "SELECT msgcount, totscore FROM $self->{tablename} " .
+  my $sql;
+  my $sth;
+  my $rc;
+  if($self->{main}->{conf}->{txrep_welcomelist_out} and ($email =~ /\@\w+\./)) {
+    $sql = "SELECT msgcount, totscore FROM $self->{tablename} " .
+            "WHERE username = ? AND email = ? AND ip = 'WELCOMELIST_OUT'";
+    $sth = $self->{dbh}->prepare($sql);
+    unless (defined($sth)) {
+      info("auto-welcomelist: sql-based get_addr_entry %s: SQL prepare error: %s",
+         "$self->{_username}|$ip", $self->{dbh}->errstr);
+    }
+    dbg("TxRep: $sql $self->{_username} $email");
+    $rc = $sth->execute($self->{_username}, $email);
+    my $cnt = 0;
+    my $aryref;
+    # how to combine data if there are several entries (like signed by
+    # an author domain and by a remailer)?  for now just take an average
+    while ( defined($aryref = $sth->fetchrow_arrayref()) ) {
+      if (defined $entry->{msgcount} && defined $aryref->[1]) {
+        $entry->{msgcount} = $aryref->[0];
+        $entry->{totscore} = $aryref->[1];
+      }
+      $entry->{exists_p} = 1;
+      $cnt++;
+    }
+    $sth->finish();
+    return $entry if $rc;
+  }
+  undef $sth;
+  undef $rc;
+
+  $sql = "SELECT msgcount, totscore FROM $self->{tablename} " .
             "WHERE username = ? AND email = ?";
   my @args = ( $email );
   if (!$self->{_with_awl_signer}) {
@@ -221,7 +252,7 @@ sub get_addr_entry {
   }
   $sql .= " ORDER BY last_hit";
 
-  my $sth = $self->{dbh}->prepare($sql);
+  $sth = $self->{dbh}->prepare($sql);
 
   unless (defined($sth)) {
     info("auto-welcomelist: sql-based get_addr_entry %s: SQL prepare error: %s",
@@ -229,7 +260,7 @@ sub get_addr_entry {
     return $entry;
   }
 
-  my $rc = $sth->execute($self->{_username}, @args);
+  $rc = $sth->execute($self->{_username}, @args);
 
   if (!$rc) { # there was an error, but try to go on
     info("auto-welcomelist: sql-based get_addr_entry %s: SQL error: %s",
@@ -298,7 +329,7 @@ sub add_score {
 
   { my @fields = qw(username email ip msgcount totscore);
     my @signedby;
-    if ($self->{_with_awl_signer} || (defined $signedby and $signedby =~ /^spf\-/)) {
+    if ($self->{_with_awl_signer} or (defined $signedby and $signedby =~ /^spf\-/) and not ($self->{main}->{conf}->{txrep_welcomelist_out} and ($email =~ /\@\w+\./)) ) {
       push(@fields, 'signedby');
       @signedby = !defined $signedby ? () : split(' ', lc $signedby);
       @signedby = ( '' )  if !@signedby;



Re: svn commit: r1909609 - in /spamassassin/trunk/lib/Mail/SpamAssassin: Plugin/TxRep.pm SQLBasedAddrList.pm

Posted by Henrik K <he...@hege.li>.
$email =~ /\@\w+\./

Not really a great email test as it doesn't match foo-bar.com



On Thu, May 04, 2023 at 04:16:43PM -0000, gbechis@apache.org wrote:
> Author: gbechis
> Date: Thu May  4 16:16:43 2023
> New Revision: 1909609
> 
> URL: http://svn.apache.org/viewvc?rev=1909609&view=rev
> Log:
> make "txrep_welcomelist_out" work when
> "auto_welcomelist_distinguish_signed" is set
> bz #7269
> 
> Modified:
>     spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/TxRep.pm
>     spamassassin/trunk/lib/Mail/SpamAssassin/SQLBasedAddrList.pm
> 
> Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/TxRep.pm
> URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/TxRep.pm?rev=1909609&r1=1909608&r2=1909609&view=diff
> ==============================================================================
> --- spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/TxRep.pm (original)
> +++ spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/TxRep.pm Thu May  4 16:16:43 2023
> @@ -1240,6 +1240,7 @@ sub check_senders_reputation {
>  
>    my $autolearn = defined $self->{autolearn};
>    $self->{last_pms} = $self->{autolearn} = undef;
> +  $self->{pms} = $pms;
>  
>    # Cases where we would not be able to use TxRep
>    if(not $self->{conf}->{use_txrep}) {
> @@ -1827,6 +1828,12 @@ sub pack_addr {
>  
>    if ( defined $origip) {$origip = $self->ip_to_awl_key($origip);}
>    if (!defined $origip) {$origip = 'none';}
> +  if ( $self->{conf}->{txrep_welcomelist_out} &&
> +    defined $self->{pms}->{relays_internal} &&  @{$self->{pms}->{relays_internal}} &&
> +    (!defined $self->{pms}->{relays_external} || !@{$self->{pms}->{relays_external}})
> +    and $addr =~ /\@\w+\./) {
> +      $origip = 'WELCOMELIST_OUT';
> +  }
>    return $addr . "|ip=" . $origip;
>  }
>  
> 
> Modified: spamassassin/trunk/lib/Mail/SpamAssassin/SQLBasedAddrList.pm
> URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/SQLBasedAddrList.pm?rev=1909609&r1=1909608&r2=1909609&view=diff
> ==============================================================================
> --- spamassassin/trunk/lib/Mail/SpamAssassin/SQLBasedAddrList.pm (original)
> +++ spamassassin/trunk/lib/Mail/SpamAssassin/SQLBasedAddrList.pm Thu May  4 16:16:43 2023
> @@ -201,7 +201,38 @@ sub get_addr_entry {
>  
>    return $entry  unless $email ne '' && (defined $ip || defined $signedby);
>  
> -  my $sql = "SELECT msgcount, totscore FROM $self->{tablename} " .
> +  my $sql;
> +  my $sth;
> +  my $rc;
> +  if($self->{main}->{conf}->{txrep_welcomelist_out} and ($email =~ /\@\w+\./)) {
> +    $sql = "SELECT msgcount, totscore FROM $self->{tablename} " .
> +            "WHERE username = ? AND email = ? AND ip = 'WELCOMELIST_OUT'";
> +    $sth = $self->{dbh}->prepare($sql);
> +    unless (defined($sth)) {
> +      info("auto-welcomelist: sql-based get_addr_entry %s: SQL prepare error: %s",
> +         "$self->{_username}|$ip", $self->{dbh}->errstr);
> +    }
> +    dbg("TxRep: $sql $self->{_username} $email");
> +    $rc = $sth->execute($self->{_username}, $email);
> +    my $cnt = 0;
> +    my $aryref;
> +    # how to combine data if there are several entries (like signed by
> +    # an author domain and by a remailer)?  for now just take an average
> +    while ( defined($aryref = $sth->fetchrow_arrayref()) ) {
> +      if (defined $entry->{msgcount} && defined $aryref->[1]) {
> +        $entry->{msgcount} = $aryref->[0];
> +        $entry->{totscore} = $aryref->[1];
> +      }
> +      $entry->{exists_p} = 1;
> +      $cnt++;
> +    }
> +    $sth->finish();
> +    return $entry if $rc;
> +  }
> +  undef $sth;
> +  undef $rc;
> +
> +  $sql = "SELECT msgcount, totscore FROM $self->{tablename} " .
>              "WHERE username = ? AND email = ?";
>    my @args = ( $email );
>    if (!$self->{_with_awl_signer}) {
> @@ -221,7 +252,7 @@ sub get_addr_entry {
>    }
>    $sql .= " ORDER BY last_hit";
>  
> -  my $sth = $self->{dbh}->prepare($sql);
> +  $sth = $self->{dbh}->prepare($sql);
>  
>    unless (defined($sth)) {
>      info("auto-welcomelist: sql-based get_addr_entry %s: SQL prepare error: %s",
> @@ -229,7 +260,7 @@ sub get_addr_entry {
>      return $entry;
>    }
>  
> -  my $rc = $sth->execute($self->{_username}, @args);
> +  $rc = $sth->execute($self->{_username}, @args);
>  
>    if (!$rc) { # there was an error, but try to go on
>      info("auto-welcomelist: sql-based get_addr_entry %s: SQL error: %s",
> @@ -298,7 +329,7 @@ sub add_score {
>  
>    { my @fields = qw(username email ip msgcount totscore);
>      my @signedby;
> -    if ($self->{_with_awl_signer} || (defined $signedby and $signedby =~ /^spf\-/)) {
> +    if ($self->{_with_awl_signer} or (defined $signedby and $signedby =~ /^spf\-/) and not ($self->{main}->{conf}->{txrep_welcomelist_out} and ($email =~ /\@\w+\./)) ) {
>        push(@fields, 'signedby');
>        @signedby = !defined $signedby ? () : split(' ', lc $signedby);
>        @signedby = ( '' )  if !@signedby;
>