Milter to accept/reject connecting hosts matching regex(es)
use Mail::Milter::Module::ConnectMatchesHostname;
my $milter = new Mail::Milter::Module::ConnectMatchesHostname;
my $milter2 = &ConnectMatchesHostname; # convenience
$milter2->set_message('Connecting hostname %H looks like a dynamic address');
This milter module rejects any connecting host whose hostname contains one of a group of built-in patterns that match the \s-1IP\s0 address of the connecting host. This is normally used to detect dynamic pool addresses.
Currently the following patterns embedded in the hostname are considered matching, where 10.11.12.13 is the IPv4 address of the connecting host. In the following cases, the string must be preceded by a non-digit character or otherwise must be at the start of the hostname.
010.011.012.013. (optionally without internal dots, or with - in place of .) 013.012.011.010. (optionally with - in place of .) 10.11.12.13. (optionally without internal dots, or with - in place of .) 13.12.11.10. (optionally with - in place of .) 0A0B0C0D (hexadecimal, ignoring case)
More specific patterns are anticipated to be added in the future. Because of this, if you use ConnectMatchesHostname, pay attention to this perldoc manual page when updating to a newer version of Mail::Milter.
One final note. ISPs can and do use \*(L"dynamic-looking\*(R" reverse \s-1DNS\s0 entries for what they consider to be legitimate server addresses. This is not ideal, and may require embedding this module in a Chain set to \*(L"accept_break\*(R" with regular expressions; for example:
my $milter = new Mail::Milter::Chain( &ConnectRegex( '\.fooisp\.com$', )->accept_match(1); &ConnectMatchesHostname, )->accept_break(1);
Creates a ConnectMatchesHostname object.
Sets the message used when rejecting connections. This string may contain the substring %H, which will be replaced by the matching hostname, and/or the substring %A, which will be replaced by the matching \s-1IP\s0 address. This method returns a reference to the object itself, allowing this method call to be chained.
In Sendmail 8.11 and 8.12, a milter rejection at \*(L"connect\*(R" stage does not allow the reply message to be set \*(-- it simply becomes \*(L"not accepting messages\*(R". However, this module still attempts to set the reply code and message in the hope that this will be fixed.
The implementation of this module could be much more efficient.
Todd Vierling, <[email protected]> <[email protected]>
Mail::Milter::Object