Skip to content

Commit

Permalink
Add support for Mdrctr Esp
Browse files Browse the repository at this point in the history
  • Loading branch information
bigio committed Feb 3, 2022
1 parent fff63f4 commit d66d147
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 3 deletions.
7 changes: 7 additions & 0 deletions Esp.cf
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ header MAILUP eval:esp_mailup_check()
describe MAILUP Message from Mailup abused account
score MAILUP 5.0

# -------- MDRCTR --------
mdrctr_feed /etc/mail/spamassassin/mdrctr_id.txt

header MDRCTR eval:esp_mdrctr_check()
describe MDRCTR Message from Mdrctr abused account
score MDRCTR 5.0

# -------- SENDGRID - EITHER THIS --------
sendgrid_feed /etc/mail/spamassassin/sendgrid-id-dnsbl.txt
sendgrid_domains_feed /etc/mail/spamassassin/sendgrid-envelopefromdomain-dnsbl.txt
Expand Down
52 changes: 51 additions & 1 deletion Esp.pm
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use Mail::SpamAssassin::PerMsgStatus;
use vars qw(@ISA);
our @ISA = qw(Mail::SpamAssassin::Plugin);

my $VERSION = 1.4.0;
my $VERSION = 1.5.0;

sub dbg { Mail::SpamAssassin::Plugin::dbg ("Esp: @_"); }

Expand All @@ -61,6 +61,7 @@ sub new {
$self->register_eval_rule('esp_mailchimp_check', $Mail::SpamAssassin::Conf::TYPE_HEAD_EVALS);
$self->register_eval_rule('esp_mailgun_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_mdrctr_check', $Mail::SpamAssassin::Conf::TYPE_HEAD_EVALS);
$self->register_eval_rule('esp_sendgrid_check_domain', $Mail::SpamAssassin::Conf::TYPE_HEAD_EVALS);
$self->register_eval_rule('esp_sendgrid_check_id', $Mail::SpamAssassin::Conf::TYPE_HEAD_EVALS);
$self->register_eval_rule('esp_sendgrid_check', $Mail::SpamAssassin::Conf::TYPE_HEAD_EVALS);
Expand Down Expand Up @@ -100,6 +101,9 @@ Usage:
esp_mailup_check()
Checks for Mailup abused accounts
esp_mdrctr_check()
Checks for Mdrctr id abused accounts
esp_sendgrid_check()
Checks for Sendgrid abused accounts (both id and domains)
Expand Down Expand Up @@ -141,6 +145,11 @@ Files can be separated by a comma.
A list of files with abused Mailup accounts.
Files can be separated by a comma.
=item mdrctr_feed [...]
A list of files with abused Mdrctr accounts.
Files can be separated by a comma.
=item sendgrid_domains_feed [...]
A list of files with abused domains managed by Sendgrid.
Expand Down Expand Up @@ -197,6 +206,9 @@ MAILGUNID
=item *
MAILUPID
=item *
MDRCTRID
=item *
SENDGRIDDOM
Expand Down Expand Up @@ -244,6 +256,12 @@ sub set_config {
type => $Mail::SpamAssassin::Conf::CONF_TYPE_STRING,
}
);
push(@cmds, {
setting => 'mdrctr_feed',
is_admin => 1,
type => $Mail::SpamAssassin::Conf::CONF_TYPE_STRING,
}
);
push(@cmds, {
setting => 'sendgrid_domains_feed',
is_admin => 1,
Expand Down Expand Up @@ -272,6 +290,7 @@ sub finish_parsing_end {
$self->_read_configfile('maildome_feed', 'MAILDOME');
$self->_read_configfile('mailgun_feed', 'MAILGUN');
$self->_read_configfile('mailup_feed', 'MAILUP');
$self->_read_configfile('mdrctr_feed', 'MDRCTR');
$self->_read_configfile('sendgrid_domains_feed', 'SENDGRID_DOMAINS');
$self->_read_configfile('sendgrid_feed', 'SENDGRID');
$self->_read_configfile('sendinblue_feed', 'SENDINBLUE');
Expand Down Expand Up @@ -567,4 +586,35 @@ sub esp_sendinblue_check {
}
}
}

sub esp_mdrctr_check {
my ($self, $pms) = @_;
my $mdrctr_id;

# All Sendgrid emails have the X-ElasticEmail-Postback header
my $sg_eid = $pms->get("X-ElasticEmail-Postback", undef);
return if not defined $sg_eid;

my $rulename = $pms->get_current_eval_rule_name();
my $fid = $pms->get("Feedback-ID", undef);
return if not defined $fid;

my $envfrom = $pms->get("EnvelopeFrom:addr", undef);
return if ($envfrom !~ /bounces\.mdrctr\.com/);

# Find the customer id from the Return-Path
if($fid =~ /(\d+)\:(\d+)\:([a-z]+)/i) {
$mdrctr_id = $1;
if(defined $mdrctr_id) {
$pms->set_tag('MDRCTRID', $mdrctr_id);
if ( exists $self->{ESP}->{MDRCTR}->{$mdrctr_id} ) {
dbg("HIT! $mdrctr_id customer id found in Mdrctr feed");
$pms->test_log("Mdrctr id: $mdrctr_id", $rulename);
$pms->got_hit($rulename, "", ruletype => 'eval');
return 1;
}
}
}
}

1;
13 changes: 11 additions & 2 deletions man/man3p/Mail::SpamAssassin::Plugin::Esp.3p
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.42)
.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.43)
.\"
.\" Standard preamble:
.\" ========================================================================
Expand Down Expand Up @@ -133,7 +133,7 @@
.\" ========================================================================
.\"
.IX Title "Esp 3"
.TH Esp 3 "2021-05-01" "perl v5.32.1" "User Contributed Perl Documentation"
.TH Esp 3 "2022-02-03" "perl v5.34.0" "User Contributed Perl Documentation"
.\" For nroff, turn off justification. Always turn off hyphenation; it makes
.\" way too many mistakes in technical documents.
.if n .ad l
Expand Down Expand Up @@ -182,6 +182,9 @@ Usage:
\& esp_mailup_check()
\& Checks for Mailup abused accounts
\&
\& esp_mdrctr_check()
\& Checks for Mdrctr id abused accounts
\&
\& esp_sendgrid_check()
\& Checks for Sendgrid abused accounts (both id and domains)
\&
Expand Down Expand Up @@ -216,6 +219,10 @@ Files can be separated by a comma.
.IX Item "mailup_feed [...]"
A list of files with abused Mailup accounts.
Files can be separated by a comma.
.IP "mdrctr_feed [...]" 4
.IX Item "mdrctr_feed [...]"
A list of files with abused Mdrctr accounts.
Files can be separated by a comma.
.IP "sendgrid_domains_feed [...]" 4
.IX Item "sendgrid_domains_feed [...]"
A list of files with abused domains managed by Sendgrid.
Expand Down Expand Up @@ -260,6 +267,8 @@ Tags that the plugin could set are:
.IP "\(bu" 4
\&\s-1MAILUPID\s0
.IP "\(bu" 4
\&\s-1MDRCTRID\s0
.IP "\(bu" 4
\&\s-1SENDGRIDDOM\s0
.IP "\(bu" 4
\&\s-1SENDGRIDID\s0
Expand Down

0 comments on commit d66d147

Please sign in to comment.