I found the future by dredging in the past
[email protected] (Matt Simerson) Mon, 29 Apr 2013 20:23:16 -0700
| Newsgroups | perl.qpsmtpd |
|---|---|
| Message-ID | <[email protected]> |
--Apple-Mail=_BA8C7A83-AD4B-471E-B046-E6C31BBFAF95
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain;
charset=us-ascii
I found myself wanting to check for clients who are adding illegal =
whitespace after the MAIL FROM and RCPT TO commands. Before I started =
hacking, I did a quick search and found this thread:
Stricter parsing of mail from: and rcpt to:
=
http://grokbase.com/t/perl/qpsmtpd/04cmjwqh9p/stricter-parsing-of-mail-fro=
m-and-rcpt-to/oldest
The gist of the thread is that a number of people were for stricter =
parsing, a number were against, and nothing happened. A similar exchange =
was had regarding angle brackets, except that time hooks were added =
allowing plugins to rewrite the address, adding the missing angle =
brackets.
For other similar purposes, Qpsmtpd::Command was added, and the ability =
to substitute ones own parser was added, probably about the same time =
the parse_addr_withhelo plugin was added.=20
But I don't need an entirely new parser. I just want to do something =
quick and fun like:
if ( 'from: ' eq lc substr($envelope_header, 0, 6) ) {
$self->adjust_karma(-1);
};
After reading the proposed solutions, the one I adopted was storing the =
unparsed line in a connection note, making it available to plugins that =
wish to inspect and act upon it.
Matt
PS: I find it amusing that 7 or 8 years later, clients inserting that =
space have a 97+% correlation with infected PCs. Not enough to block =
based on it, but more than enough to cast suspicious glances.
--- a/lib/Qpsmtpd/SMTP.pm
+++ b/lib/Qpsmtpd/SMTP.pm
@@ -354,6 +354,7 @@ sub mail {
}
=20
$self->log(LOGDEBUG, "full from_parameter: $line");
+ $self->connection->notes('envelope_from', $line);
$self->run_hooks("mail_parse", $line);
}
=20
@@ -442,6 +443,7 @@ sub mail_respond {
=20
sub rcpt {
my ($self, $line) =3D @_;
+ $self->connection->notes('envelope_rcpt', $line);
$self->run_hooks("rcpt_parse", $line);
}
=20
--Apple-Mail=_BA8C7A83-AD4B-471E-B046-E6C31BBFAF95--