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 2020/11/11 11:55:12 UTC
svn commit: r1883303 - in /spamassassin/trunk:
lib/Mail/SpamAssassin/Plugin/Esp.pm t/data/spam/esp/mailchimp.eml
t/data/spam/esp/mailchimp.txt t/esp.t
Author: gbechis
Date: Wed Nov 11 11:55:12 2020
New Revision: 1883303
URL: http://svn.apache.org/viewvc?rev=1883303&view=rev
Log:
Add Mailchimp and Maildome checks
refactor feed configuration parser
Added:
spamassassin/trunk/t/data/spam/esp/mailchimp.eml (with props)
spamassassin/trunk/t/data/spam/esp/mailchimp.txt
Modified:
spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Esp.pm
spamassassin/trunk/t/esp.t
Modified: spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Esp.pm
URL: http://svn.apache.org/viewvc/spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Esp.pm?rev=1883303&r1=1883302&r2=1883303&view=diff
==============================================================================
--- spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Esp.pm (original)
+++ spamassassin/trunk/lib/Mail/SpamAssassin/Plugin/Esp.pm Wed Nov 11 11:55:12 2020
@@ -61,6 +61,8 @@ sub new {
$self->register_eval_rule('esp_sendgrid_check', $Mail::SpamAssassin::Conf::TYPE_HEAD_EVALS);
$self->register_eval_rule('esp_sendinblue_check', $Mail::SpamAssassin::Conf::TYPE_HEAD_EVALS);
$self->register_eval_rule('esp_mailup_check', $Mail::SpamAssassin::Conf::TYPE_HEAD_EVALS);
+ $self->register_eval_rule('esp_maildome_check', $Mail::SpamAssassin::Conf::TYPE_HEAD_EVALS);
+ $self->register_eval_rule('esp_mailchimp_check', $Mail::SpamAssassin::Conf::TYPE_HEAD_EVALS);
return $self;
}
@@ -81,6 +83,12 @@ endif
Usage:
+ esp_mailchimp_check()
+ Checks for Mailchimp abused accounts
+
+ esp_maildome_check()
+ Checks for Maildome abused accounts
+
esp_mailup_check()
Checks for Mailup abused accounts
@@ -120,6 +128,14 @@ A file with abused Sendinblue accounts.
A file with abused Mailup accounts.
+=item maildome_feed [...]
+
+A file with abused Maildome accounts.
+
+=item mailchimp_feed [...]
+
+A file with abused Mailchimp accounts.
+
=back
=head1 TEMPLATE TAGS
@@ -154,6 +170,12 @@ SENDINBLUEID
=item *
MAILUPID
+=item *
+MAILDOMEID
+
+=item *
+MAILCHIMPID
+
=back
=cut
@@ -186,86 +208,47 @@ sub set_config {
type => $Mail::SpamAssassin::Conf::CONF_TYPE_STRING,
}
);
+ push(@cmds, {
+ setting => 'maildome_feed',
+ is_admin => 1,
+ type => $Mail::SpamAssassin::Conf::CONF_TYPE_STRING,
+ }
+ );
+ push(@cmds, {
+ setting => 'mailchimp_feed',
+ is_admin => 1,
+ type => $Mail::SpamAssassin::Conf::CONF_TYPE_STRING,
+ }
+ );
$conf->{parser}->register_commands(\@cmds);
}
sub finish_parsing_end {
my ($self, $opts) = @_;
- $self->_read_configfile($self);
+ $self->_read_configfile('sendgrid_feed', 'SENDGRID');
+ $self->_read_configfile('sendgrid_domains_feed', 'SENDGRID_DOMAINS');
+ $self->_read_configfile('sendinblue_feed', 'SENDINBLUE');
+ $self->_read_configfile('mailup_feed', 'MAILUP');
+ $self->_read_configfile('maildome_feed', 'MAILDOME');
+ $self->_read_configfile('mailchimp_feed', 'MAILCHIMP');
}
sub _read_configfile {
- my ($self) = @_;
+ my ($self, $feed, $esp) = @_;
my $conf = $self->{main}->{registryboundaries}->{conf};
- my $sendgrid_id;
- my $sendgrid_domain;
- my $sendinblue_id;
- my $mailup_id;
+ my $id;
local *F;
- if ( defined($conf->{sendgrid_feed}) && ( -f $conf->{sendgrid_feed} ) ) {
- open(F, '<', $conf->{sendgrid_feed});
- for ($!=0; <F>; $!=0) {
- chomp;
- #lines that start with pound are comments
- next if(/^\s*\#/);
- $sendgrid_id = $_;
- if ( defined $sendgrid_id ) {
- push @{$self->{ESP}->{SENDGRID}->{$sendgrid_id}}, $sendgrid_id;
- }
- }
-
- defined $_ || $!==0 or
- $!==EBADF ? dbg("ESP: error reading config file: $!")
- : die "error reading config file: $!";
- close(F) or die "error closing config file: $!";
- }
-
- if ( defined($conf->{sendgrid_domains_feed}) && ( -f $conf->{sendgrid_domains_feed} ) ) {
- open(F, '<', $conf->{sendgrid_domains_feed});
- for ($!=0; <F>; $!=0) {
- chomp;
- #lines that start with pound are comments
- next if(/^\s*\#/);
- $sendgrid_domain = $_;
- if ( defined $sendgrid_domain ) {
- push @{$self->{ESP}->{SENDGRID_DOMAIN}->{$sendgrid_domain}}, $sendgrid_domain;
- }
- }
-
- defined $_ || $!==0 or
- $!==EBADF ? dbg("ESP: error reading config file: $!")
- : die "error reading config file: $!";
- close(F) or die "error closing config file: $!";
- }
-
- if ( defined($conf->{sendinblue_feed}) && ( -f $conf->{sendinblue_feed} ) ) {
- open(F, '<', $conf->{sendinblue_feed});
- for ($!=0; <F>; $!=0) {
- chomp;
- #lines that start with pound are comments
- next if(/^\s*\#/);
- $sendinblue_id = $_;
- if ( ( defined $sendinblue_id ) and ($sendinblue_id =~ /[0-9]+/) ) {
- push @{$self->{ESP}->{SENDINBLUE}->{$sendinblue_id}}, $sendinblue_id;
- }
- }
-
- defined $_ || $!==0 or
- $!==EBADF ? dbg("ESP: error reading config file: $!")
- : die "error reading config file: $!";
- close(F) or die "error closing config file: $!";
- }
- if ( defined($conf->{mailup_feed}) && ( -f $conf->{mailup_feed} ) ) {
- open(F, '<', $conf->{mailup_feed});
+ if ( defined($conf->{$feed}) && ( -f $conf->{$feed} ) ) {
+ open(F, '<', $conf->{$feed});
for ($!=0; <F>; $!=0) {
chomp;
#lines that start with pound are comments
next if(/^\s*\#/);
- $mailup_id = $_;
- if ( defined $mailup_id ) {
- push @{$self->{ESP}->{MAILUP}->{$mailup_id}}, $mailup_id;
+ $id = $_;
+ if ( defined $id ) {
+ push @{$self->{ESP}->{$esp}->{$id}}, $id;
}
}
@@ -274,7 +257,6 @@ sub _read_configfile {
: die "error reading config file: $!";
close(F) or die "error closing config file: $!";
}
-
}
sub esp_sendgrid_check_domain {
@@ -401,6 +383,68 @@ sub esp_mailup_check {
$pms->got_hit($rulename, "", ruletype => 'eval');
return 1;
}
+ }
+
+}
+
+sub esp_maildome_check {
+ my ($self, $pms) = @_;
+ my $maildome_id;
+
+ my $rulename = $pms->get_current_eval_rule_name();
+
+ # return if X-Mailer is not what we want
+ my $xmailer = $pms->get("X-Mailer", undef);
+
+ if((not defined $xmailer) or ($xmailer !~ /MaildomeMTA/)) {
+ return;
+ }
+
+ $maildome_id = $pms->get("List-Unsubscribe", undef);
+ return if not defined $maildome_id;
+ $maildome_id =~ /subject=https:\/\/.*\/unsubscribe\/([0-9]+)\/([0-9]+)\/.*\/([0-9])\/([0-9]+)\>/;
+ $maildome_id = $2;
+
+ # if regexp doesn't match it's not Maildome
+ return if not defined $maildome_id;
+ chomp($maildome_id);
+ if(defined $maildome_id) {
+ if ( exists $self->{ESP}->{MAILDOME}->{$maildome_id} ) {
+ $pms->set_tag('MAILDOMEID', $maildome_id);
+ dbg("HIT! $maildome_id customer found in Maildome feed");
+ $pms->test_log("Maildome id: $maildome_id");
+ $pms->got_hit($rulename, "", ruletype => 'eval');
+ return 1;
+ }
+ }
+
+}
+
+sub esp_mailchimp_check {
+ my ($self, $pms) = @_;
+ my $mailchimp_id;
+
+ my $rulename = $pms->get_current_eval_rule_name();
+
+ # return if X-Mailer is not what we want
+ my $xmailer = $pms->get("X-Mailer", undef);
+
+ if((not defined $xmailer) or ($xmailer !~ /MailChimp Mailer/)) {
+ return;
+ }
+
+ $mailchimp_id = $pms->get("X-MC-User", undef);
+ return if not defined $mailchimp_id;
+
+ chomp($mailchimp_id);
+ if(defined $mailchimp_id) {
+ if ( exists $self->{ESP}->{MAILCHIMP}->{$mailchimp_id} ) {
+ $pms->set_tag('MAILCHIMPID', $mailchimp_id);
+ dbg("HIT! $mailchimp_id customer found in Mailchimp feed");
+ $pms->test_log("Mailchimp id: $mailchimp_id");
+ $pms->got_hit($rulename, "", ruletype => 'eval');
+ return 1;
+ }
}
}
Added: spamassassin/trunk/t/data/spam/esp/mailchimp.eml
URL: http://svn.apache.org/viewvc/spamassassin/trunk/t/data/spam/esp/mailchimp.eml?rev=1883303&view=auto
==============================================================================
Binary file - no diff available.
Propchange: spamassassin/trunk/t/data/spam/esp/mailchimp.eml
------------------------------------------------------------------------------
svn:mime-type = message/rfc822
Added: spamassassin/trunk/t/data/spam/esp/mailchimp.txt
URL: http://svn.apache.org/viewvc/spamassassin/trunk/t/data/spam/esp/mailchimp.txt?rev=1883303&view=auto
==============================================================================
--- spamassassin/trunk/t/data/spam/esp/mailchimp.txt (added)
+++ spamassassin/trunk/t/data/spam/esp/mailchimp.txt Wed Nov 11 11:55:12 2020
@@ -0,0 +1 @@
+1234
Modified: spamassassin/trunk/t/esp.t
URL: http://svn.apache.org/viewvc/spamassassin/trunk/t/esp.t?rev=1883303&r1=1883302&r2=1883303&view=diff
==============================================================================
--- spamassassin/trunk/t/esp.t (original)
+++ spamassassin/trunk/t/esp.t Wed Nov 11 11:55:12 2020
@@ -4,18 +4,20 @@ use lib '.'; use lib 't';
use SATest; sa_t_init("esp");
use Test::More;
-plan tests => 1;
+plan tests => 2;
tstpre ("
loadplugin Mail::SpamAssassin::Plugin::Esp
");
tstprefs("
-
sendgrid_feed data/spam/esp/sendgrid_id.txt
header SENDGRID_ID eval:esp_sendgrid_check_id()
describe SENDGRID_ID Check Sendgrid id
+mailchimp_feed data/spam/esp/mailchimp.txt
+header MAILCHIMP_ID eval:esp_mailchimp_check()
+describe MAILCHIMP_ID Check Mailchimp id
");
%patterns_sendgrid_id = (
@@ -25,3 +27,12 @@ describe SENDGRID_ID Check Sendgrid id
%patterns = %patterns_sendgrid_id;
sarun ("-L -t < data/spam/esp/sendgrid_id.eml", \&patterns_run_cb);
ok_all_patterns();
+clear_pattern_counters();
+
+%patterns_sendgrid_id = (
+ q{ MAILCHIMP_ID } => 'Mailchimp',
+ );
+
+%patterns = %patterns_sendgrid_id;
+sarun ("-L -t < data/spam/esp/mailchimp.eml", \&patterns_run_cb);
+ok_all_patterns();