2012-04-29 10:35:59 +02:00
|
|
|
#!perl -w
|
2012-04-08 02:11:16 +02:00
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
|
|
|
parse_addr_withhelo
|
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
|
|
|
|
|
|
|
strict RFC 821 forbids parameters after the
|
|
|
|
|
|
|
|
MAIL FROM:<user@example.net>
|
|
|
|
and
|
|
|
|
RCPT TO:<someone@example.com>
|
|
|
|
|
|
|
|
load this plugin to enforce, else the default EHLO parsing with
|
|
|
|
parameters is done.
|
|
|
|
|
|
|
|
=cut
|
2006-04-07 20:58:02 +02:00
|
|
|
|
2012-06-23 06:47:46 +02:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
use Qpsmtpd::Constants;
|
|
|
|
|
2006-04-07 20:58:02 +02:00
|
|
|
sub hook_mail_parse {
|
|
|
|
my $self = shift;
|
2014-09-18 03:28:51 +02:00
|
|
|
return OK, \&_parse if $self->qp->connection->hello eq 'helo';
|
|
|
|
return DECLINED;
|
2006-04-07 20:58:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub hook_rcpt_parse {
|
|
|
|
my $self = shift;
|
2014-09-18 03:28:51 +02:00
|
|
|
return OK, \&_parse if $self->qp->connection->hello eq 'helo';
|
|
|
|
return DECLINED;
|
2006-04-07 20:58:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
sub _parse {
|
2013-04-21 06:50:39 +02:00
|
|
|
my ($self, $cmd, $line) = @_;
|
2006-04-07 20:58:02 +02:00
|
|
|
$self->log(LOGDEBUG, "_parse() cmd=[$cmd], line=[$line]");
|
|
|
|
if ($cmd eq 'mail') {
|
2014-09-18 03:28:51 +02:00
|
|
|
return DENY, "Syntax error in command" if $line !~ s/^from:\s*//i;
|
2006-04-07 20:58:02 +02:00
|
|
|
}
|
2013-04-21 06:50:39 +02:00
|
|
|
else { # cmd eq 'rcpt'
|
2014-09-18 03:28:51 +02:00
|
|
|
return DENY, "Syntax error in command" if $line !~ s/^to:\s*//i;
|
2006-04-07 20:58:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($line =~ s/^(<.*>)\s*//) {
|
|
|
|
my $addr = $1;
|
2014-09-18 03:28:51 +02:00
|
|
|
return DENY, "No parameters allowed in " . uc($cmd)
|
|
|
|
if $line =~ /^\S/;
|
|
|
|
return OK, $addr, ();
|
2006-04-07 20:58:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
## now, no <> are given
|
|
|
|
$line =~ s/\s*$//;
|
|
|
|
if ($line =~ /\@/) {
|
2014-09-18 03:28:51 +02:00
|
|
|
return DENY, "No parameters allowed in " . uc($cmd)
|
|
|
|
if $line =~ /\@\S+\s+\S/;
|
|
|
|
return OK, $line, ();
|
2006-04-07 20:58:02 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($cmd eq "mail") {
|
2014-09-18 03:28:51 +02:00
|
|
|
return OK, "<>" if !$line; # 'MAIL FROM:' -> 'MAIL FROM:<>'
|
|
|
|
return DENY, "Could not parse your MAIL FROM command";
|
2006-04-07 20:58:02 +02:00
|
|
|
}
|
|
|
|
else {
|
2014-09-18 03:28:51 +02:00
|
|
|
return DENY, "Could not parse your RCPT TO command"
|
|
|
|
if $line !~ /^(postmaster|abuse)$/i;
|
2006-04-07 20:58:02 +02:00
|
|
|
}
|
|
|
|
}
|