# $DUH: helo_rawliteral,v 1.6 2002/12/16 05:14:33 tv Exp $
#
# Copyright (c) 2002 Todd Vierling <tv@pobox.com> <tv@duh.org>.
# All rights reserved.
# Please see the COPYRIGHT file, part of the PMilter distribution,
# for full copyright and license terms.

##### helo_rawliteral #####
#
# Rejects HELO commands containing an IP literal value that is
# not enclosed in [square brackets] per the RFC 2821 syntax for
# using IP literals in a HELO command (section 4.1.1.1/4.1.3).

my $errmsg = shift_errmsg(@_, 'Address literal "%1" not enclosed in [square brackets] per RFC2821, section 4.1.3');

+{
	helo => sub {
		my $ctx = shift;
		my $helo = shift;

		if ($helo =~ /^([\d\.]+|[^\[].*:.*[^\]])$/) {
			my $err = $errmsg;
			$err =~ s/%1/$helo/g; # interpolate HELO arg

			return $ctx->reject("554 HELO/EHLO command rejected: $err");
		}

		return SMFIS_ACCEPT;
	}
};
