Skip to content

Instantly share code, notes, and snippets.

@gslin
Last active October 23, 2023 08:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gslin/a260b284f18c70c013ef412105049ac3 to your computer and use it in GitHub Desktop.
Save gslin/a260b284f18c70c013ef412105049ac3 to your computer and use it in GitHub Desktop.
Cleanfeed + SpamAssassin
# vim: set syntax=perl
use Mail::SpamAssassin;
my $sa_agent = Mail::SpamAssassin->new();
sub local_filter_last {
return unless $hdr{Path} =~ /google-groups\.googlegroups\.com/;
my %myhdr = %hdr;
delete $myhdr{__BODY__};
delete $myhdr{__LINES__};
my $header_str = join "\n", map { "$_: $hdr{$_}" } keys %myhdr;
my $article_str = "$header_str\n\n$hdr{__BODY__}";
my $mail = $sa_agent->parse($article_str);
my $status = $sa_agent->check($mail);
my $spamness = $status->is_spam();
# GC first, to prevent from leaking.
$status->finish();
$mail->finish();
if ($spamness) {
my $reason = sprintf 'Reject Google Groups posting to %s by SpamAssassin', $hdr{Newsgroups};
return reject($reason);
}
return;
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment