develooper Front page | perl.qpsmtpd | Postings from December 2015

helo plugin fails to match badhelo

Thread Next
From:
Chris Dallimore
Date:
December 17, 2015 17:17
Subject:
helo plugin fails to match badhelo
Message ID:
5672EE13.8020700@pigstrough.co.uk
The helo plugin fails to match any entries in badhelo, as the 
is_regex_match sub returns after the first (usually unsuccessful) test.

This works for me:

--- a/plugins/helo
+++ b/plugins/helo
@@ -301,40 +301,27 @@

  sub is_in_badhelo {
      my ($self, $host) = @_;
-
-    my $error = "I do not believe you are $host.";
+    my $error = "Your HELO hostname is not allowed";

      $host = lc $host;
      foreach my $bad ($self->qp->config('badhelo')) {
          if ($bad =~ /[\{\}\[\]\(\)\^\$\|\*\+\?\\\!]/) {    # it's a regexp
-            return $self->is_regex_match($host, $bad);
+            #$self->log( LOGDEBUG, "is regex ($bad)");
+            if (substr($bad, 0, 1) eq '!') {
+                $bad = substr $bad, 1;
+                if ($host !~ /$bad/) {
+                    #$self->log( LOGDEBUG, "matched negative pattern 
(\!$bad)");
+                    return $error, "badhelo negative pattern match 
(\!$bad)";
          }
-        if ($host eq lc $bad) {
-            return $error, "in badhelo";
          }
+            elsif ($host =~ /$bad/) {
+                #$self->log( LOGDEBUG, "matched ($bad)");
+                return $error, "badhelo pattern match ($bad)";
      }
-    return;
  }
-
-sub is_regex_match {
-    my ($self, $host, $pattern) = @_;
-
-    my $error = "Your HELO hostname is not allowed";
-
-    #$self->log( LOGDEBUG, "is regex ($pattern)");
-    if (substr($pattern, 0, 1) eq '!') {
-        $pattern = substr $pattern, 1;
-        if ($host !~ /$pattern/) {
-
-            #$self->log( LOGDEBUG, "matched ($pattern)");
-            return $error, "badhelo pattern match ($pattern)";
+        elsif ($host eq lc $bad) {
+            return $error, "($bad) in badhelo";
          }
-        return;
-    }
-    if ($host =~ /$pattern/) {
-
-        #$self->log( LOGDEBUG, "matched ($pattern)");
-        return $error, "badhelo pattern match ($pattern)";
      }
      return;
  }

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About