On 2009 June 22 (Mon) 10:50:59pm PDT, Robert Spier <rsp...@pobox.com> wrote:
> 
> Thanks Tomas --
> 
> I just checked in 6345b62e82ef68e6d8b9afb011401e935f06ee0e to my tree
> which fixes this bug in a slightly different way.
> 
> -R

Cool.  I think that approach is better.

I should point out that the regular expression you used won't actually
trim trailing whitespace from the reason.  The "(.*)" part is greedy so
it'll grab all the stuff to the end of the line, including whitespace,
leaving nothing for the "\s*" that comes after it.

You'd need to make sure $reason ended with a non-whitespace character

  my ($bad, $reason) = $config =~ /^\s*(\S+)(?:\s*(.*\S)\s*)?$/;

Or make the "(.*)" part anti-greedy.

  my ($bad, $reason) = $config =~ /^\s*(\S+)(?:\s*(.*?)\s*)?$/; 

The trailing whitespace wouldn't show up in testing, though, since
$config line already had its leading and trailing whitespace trimmed
when the config file was read.

Sorry, I'm just kind of obsessive about regular expressions, and my
doctor won't prescribe anything for it.



> Tomas Lee wrote:
> > 
> > I found a minor bug in plugins/check_badmailfrom, and I didn't know
> > where to send it, so I'm posting it here.
> > 
> > When a badmailfrom issues the "RCPT TO" command, a 550 error code is
> > sent with the reason it was rejected.  The default reason is supposed
> > to be "sorry, your envelope sender is in my badmailfrom list".
> > 
> > An extension to plugins/check_badmailfrom to allows people to put in a
> > reason for specific badmailfroms to override the default reason.
> > (commit cab7466c08fec71c48cba5a77beee08ec3b190a4) You put the reason
> > on the same line as the envelope sender you wish to deny, separated by
> > whitespace.
> > 
> > The problem is that if you don't put in a reason (which is the normal
> > case), the default reason doesn't get used.  Instead it uses the
> > envelope sender as the reason.
> > 
> > That's because on line 41, where it, $reason can never be empty.  The
> > line in config/badmailfrom would have to end in whitespace, which
> > isn't normal, and whitespace is trimmed at the beginning and end of
> > the line before it got there anyway.  (It could be a false value, but
> > that would mean that "0" should be the reason, not the default.)
> > 
> > It might not be a big deal what reason you give in this case, but
> > someone cared enough about it to write code to allow per-line reasons,
> > so there must be some people out there who do care.
> > 
> > Here's the patch I used to correct this minor bug:
> > 
> > 
> > --- original/plugins/check_badmailfrom   2009-04-02 22:48:33.000000000 -0700
> > +++ revision/plugins/check_badmailfrom   2009-06-19 23:18:27.000000000 -0700
> > @@ -37,9 +37,10 @@
> >    my $from = lc($sender->user) . '@' . $host;
> > 
> >    for my $bad (@badmailfrom) {
> > -    my $reason = $bad; 
> > -    $reason =~ s/^\s*(\S+)[\t\s]+//;
> > -    $reason = "sorry, your envelope sender is in my badmailfrom list" 
> > unless $reason;
> > +    my $reason = "sorry, your envelope sender is in my badmailfrom list";
> > +    if ($bad =~ /^\s*\S+[\t\s]+(.*)/) {
> > +      $reason = $1;
> > +    }
> >      $bad =~ s/^\s*(\S+).*/$1/;
> >      next unless $bad;  
> >      $bad = lc $bad;

Reply via email to