3 # This is a SpamAssassin module that kills mail from newly-born domains.
4 # Copyright (c) 2022-2023 by Art Cancro
5 # Use, duplication, or disclosure are subject to the terms of the GNU General Public License v3.
9 use Mail::SpamAssassin::Plugin;
11 use Sys::Syslog qw(:standard :macros);
16 our @ISA = qw(Mail::SpamAssassin::Plugin);
19 my ($class, $mailsa) = @_;
21 # the usual perlobj boilerplate to create a subclass object
22 $class = ref($class) || $class;
23 my $self = $class->SUPER::new($mailsa);
24 bless ($self, $class);
27 syslog('info', 'Initializing INFANTICIDE for SpamAssassin (c) 2022-2023 by Art Cancro');
29 # Register evaluation rules
30 $self->register_eval_rule ("check_for_disposable_domain");
32 # and return the new plugin object
38 my $s = shift; $s =~ s/^\s+|\s+$//g; return $s
42 sub infanticide_get_creation_date {
43 my $domain_to_test = $_[0];
46 open my $fh, "-|", "whois", $domain_to_test or return("");
47 my @lines = <$fh> or return("");
48 close $fh or return("");
50 if (index($_, "Creation Date:") != -1) {
51 my @arr = split("Creation Date:", $_);
52 $cDate = trim($arr[1]);
53 # 2017-06-02T13:15:42Z
60 sub check_for_disposable_domain() {
61 $counter = $counter + 1;
63 my ($self, $pms) = @_;
64 my $fromaddr = $pms->get("From:addr", undef);
65 my @fromarr = split('@', $fromaddr);
66 my $domain = $fromarr[1];
67 my $creationDate = infanticide_get_creation_date($domain);
68 if ($creationDate eq "") {
69 syslog('debug', "infanticide: no creation date for " . $domain);
72 my $dt = str2time($creationDate);
73 my $daysAgo = ceil((time() - $dt) / 86400);
74 syslog("debug", "infanticide: " . $domain . " was created " . $daysAgo . " days ago");