Skip to content

Commit

Permalink
Add Mailchimp support
Browse files Browse the repository at this point in the history
  • Loading branch information
bigio committed Nov 7, 2020
1 parent 4cb596d commit a64ab45
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 3 deletions.
5 changes: 5 additions & 0 deletions Esp.cf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ mailup_feed /etc/mail/spamassassin/mailup_id.txt

maildome_feed /etc/mail/spamassassin/maildome_id.txt

mailchimp_feed /etc/mail/spamassassin/mailchimp_id.txt

# header SPBL_SENDGRID_ID eval:esp_sendgrid_check_id()
# describe SPBL_SENDGRID_ID Message from Sendgrid abused account

Expand All @@ -27,6 +29,9 @@ describe MAILUP Message from Mailup abused account
header MAILDOME eval:esp_maildome_check()
describe MAILDOME Message from Maildome abused account

header MAILCHIMP eval:esp_mailchimp_check()
describe MAILCHIMP Message from Mailchimp abused account

ifplugin Mail::SpamAssassin::Plugin::AskDNS
askdns RBL_SENDGRID_ID _SENDGRIDID_.rblid.domain.tld A 127.0.0.2
describe RBL_SENDGRID_ID Invaluement Sendgrid Id blacklist
Expand Down
50 changes: 48 additions & 2 deletions Esp.pm
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ sub new {
$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);
# XXX Deprecated subs
$self->register_eval_rule('sendgrid_check_domain', $Mail::SpamAssassin::Conf::TYPE_HEAD_EVALS);
$self->register_eval_rule('sendgrid_check_id', $Mail::SpamAssassin::Conf::TYPE_HEAD_EVALS);
Expand All @@ -88,6 +89,9 @@ endif
Usage:
esp_mailchimp_check()
Checks for Mailchimp abused accounts
esp_maildome_check()
Checks for Maildome abused accounts
Expand Down Expand Up @@ -134,6 +138,10 @@ A file with abused Mailup accounts.
A file with abused Maildome accounts.
=item mailchimp_feed [...]
A file with abused Mailchimp accounts.
=back
=head1 TEMPLATE TAGS
Expand Down Expand Up @@ -171,6 +179,9 @@ MAILUPID
=item *
MAILDOMEID
=item *
MAILCHIMPID
=back
=cut
Expand Down Expand Up @@ -209,6 +220,12 @@ sub set_config {
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);
}

Expand All @@ -219,6 +236,7 @@ sub finish_parsing_end {
$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 {
Expand Down Expand Up @@ -413,9 +431,8 @@ sub esp_maildome_check {
if((not defined $xmailer) or ($xmailer !~ /MaildomeMTA/)) {
return;
}
# All Mailup emails have the X-Abuse header that must match
$maildome_id = $pms->get("List-Unsubscribe", undef);

$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;
Expand All @@ -433,5 +450,34 @@ sub esp_maildome_check {
}
}

}

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;
}
}

}
1;
10 changes: 9 additions & 1 deletion man/man3p/Mail::SpamAssassin::Plugin::Esp.3p
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@
.\" ========================================================================
.\"
.IX Title "Esp 3"
.TH Esp 3 "2020-11-06" "perl v5.32.0" "User Contributed Perl Documentation"
.TH Esp 3 "2020-11-07" "perl v5.32.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 @@ -167,6 +167,9 @@ endif
Usage:
.PP
.Vb 2
\& esp_mailchimp_check()
\& Checks for Mailchimp abused accounts
\&
\& esp_maildome_check()
\& Checks for Maildome abused accounts
\&
Expand Down Expand Up @@ -206,6 +209,9 @@ A file with abused Mailup accounts.
.IP "maildome_feed [...]" 4
.IX Item "maildome_feed [...]"
A file with abused Maildome accounts.
.IP "mailchimp_feed [...]" 4
.IX Item "mailchimp_feed [...]"
A file with abused Mailchimp accounts.
.SH "TEMPLATE TAGS"
.IX Header "TEMPLATE TAGS"
.RS 4
Expand Down Expand Up @@ -233,3 +239,5 @@ Tags that the plugin could set are:
\&\s-1MAILUPID\s0
.IP "\(bu" 4
\&\s-1MAILDOMEID\s0
.IP "\(bu" 4
\&\s-1MAILCHIMPID\s0

0 comments on commit a64ab45

Please sign in to comment.