On Sun, 10 May 2009 17:33:28 -0400
"Chris Lewis" <cle...@nortel.com> wrote:
> This might be a good opportunity to introduce standardization into 
> pattern matching plugins with common config file parser.  I can offer up 
> my set, but once you see one, you don't need the rest.  I use this 
> mechanism for _all_ pattern matching (mailfrom, from, rcptto, To, rdns, 
> body strings etc).  They'll need a little tweaking because my plugins 
> themselves _never_ DENY, they use subsequent plugins to decide what 
> action to take (the notes() stuff).
> 
> Here's my helo plugin - note the NTMqplib::configpattern call, and the 
>     if ( $host =~ /$self->{f_badhelo}/o ) { line.
Hmm, this wouldn't easily allow adding exceptions if a match was found
Yes, you can always tweak the regexp, but without //x in a config file
it will be unreadable / unmaintainable. 

What about something like the attached? The main logic is the same as
in the rcpt_regexp plugin, see the docs there until there's
documentation for this module. Additional: '%s' in the comment field
will be replaced by the argument given to check(). Checks (i.e. new
sample config) for check_spamhelo can be (REs taken from
http://www.nntp.perl.org/group/perl.qpsmtpd/2004/07/msg1674.html):

# these domains never uses their domain when greeting us, so reject
# transactions, both get the default arguments of
# "DENY", "Sorry, I don't believe that you are %s."
aol.com
yahoo.com
# new (additional):
/^\[[a-z\d\-]*[a-z\d]:([^\\\[\]]|\\.)+\]$/i DECLINED IPv6 literal
/^\[(((?(?<!\[)\.)(25[0-5]|2[0-4]\d|[01]?\d?\d)){4})\]$/ DECLINED IPv4
literal
/^((?!-)[a-z\d\-]+(?<!-)\.)+[a-z]{2,}$/ DECLINED looks like valid
domain name
/^.*$/ DENY HELO %s is not a valid FQDN or a valid address literal: see
RFC821/1123/2821.
## use another plugin to check the forward <-> reverse mapping of 
## the HELO host

The "check_spamhelo" can be rewritten like below without any troubles
for upgrading users. 

use Qpsmtpd::ConfigRE;

sub register {
    my ($self, $qp, @args) = @_;
    $self->configure("badhelo",
                # defaults for "old" check_spamhelo:
                "DENY", # string, not the constant!
                q{Sorry, I don't believe that you are %s.} 
                # '%s' will be replaced by the arg given to ->check()
            );
}

sub hook_helo {
    my ($self, $transaction, $host) = @_;
    ($host = lc $host) or return DECLINED;
    return $self->check($host);
}

# also support EHLO
*hook_ehlo = \&hook_helo;

        Hanno

Attachment: ConfigRE.pm
Description: Perl program

Reply via email to