On Aug 20, 2019 4:29 AM, Gilles Chehade <gil...@poolp.org> wrote:
>
> On Mon, Aug 19, 2019 at 01:48:05PM -0500, Edgar Pettijohn wrote:
> > Nothing urgent here. Probably can wait for filter documentation. However, 
> > I've been
> > playing with filters off and on with limited success. It seems like 
> > data-line will 
> > be the most useful to filter on so thats been my focus lately. I have the 
> > following
> > script:
> > 
> > #!/usr/bin/perl
> > 
> > use strict;
> > use warnings;
> > use diagnostics;
> > 
> > open(my $fh, '>', '/tmp/log.txt') or die $!;
> > 
> > # remove line buffering
> > select(STDOUT);
> > $|++;
> > select($fh);
> > $|++;
> > 
> > print STDOUT "register|filter|smtp-in|data-line\n";
> > print STDOUT "register|ready\n";
> > 
> > while ( <> ) {
> >         chomp; # get rid of newline
> > 
> >         my @report = split /\|/;
> > 
> >         next if $report[0] eq 'config';
> > 
> >         foreach (@report) {
> >                 print $fh "$_\|"; # just to see whats there
> >         }
> >  print $fh "\n";
> > 
> >         my $inbody = 0;
> >         my ($sid, $token, $line);
> >         $sid = $report[5];
> >         $token = $report[6];
> >         $line = $report[$#report];
> >         if ($report[0] eq 'filter' and $report[3] eq 'smtp-in' and 
> >$report[4] eq 'data-line') {
> >                 die "invalid filter command" if (scalar @report < 7);
> >                 if ($line eq '') { print $fh "end of headers\n"; $inbody++; 
> >}
> >                 if ($line eq '.') { print $fh "end of message\n"; 
> >$inbody--; }
> >                 print $fh "filter-dataline|$token|$sid|$line\n";
> >                 print STDOUT "filter-dataline|$token|$sid|$line\n";
> >         }
> > }
> > 
> > close $fh;
> > 
> > 0;
> > 
> > It prints the following in /tmp/log.txt after a 
> > $ echo "HI" | mail edgar
> > 
> > filter|0|1566239933.835511|smtp-in|data-line|c0002b41f6bd164d|ef8747a12860387a|Received:
> >  from localhost (deathstar.my.domain [local])|
> > filter-dataline|ef8747a12860387a|c0002b41f6bd164d|Received: from localhost 
> > (deathstar.my.domain [local])
> > filter|0|1566239933.835523|smtp-in|data-line|c0002b41f6bd164d|ef8747a12860387a|
> >  by deathstar.my.domain (OpenSMTPD) with ESMTPA id 7052ea5a|
> > filter-dataline|ef8747a12860387a|c0002b41f6bd164d|      by 
> > deathstar.my.domain (OpenSMTPD) with ESMTPA id 7052ea5a
> > filter|0|1566239933.835529|smtp-in|data-line|c0002b41f6bd164d|ef8747a12860387a|
> >  for <ed...@deathstar.my.domain>;|
> > filter-dataline|ef8747a12860387a|c0002b41f6bd164d|      for 
> > <ed...@deathstar.my.domain>;
> > filter|0|1566239933.835533|smtp-in|data-line|c0002b41f6bd164d|ef8747a12860387a|
> >  Mon, 19 Aug 2019 13:38:53 -0500 (CDT)|
> > filter-dataline|ef8747a12860387a|c0002b41f6bd164d|      Mon, 19 Aug 2019 
> > 13:38:53 -0500 (CDT)
> > filter|0|1566239933.836673|smtp-in|data-line|c0002b41f6bd164d|ef8747a12860387a|From:
> >  Edgar Pettijohn <ed...@deathstar.my.domain>|
> > filter-dataline|ef8747a12860387a|c0002b41f6bd164d|From: Edgar Pettijohn 
> > <ed...@deathstar.my.domain>
> > filter|0|1566239933.836681|smtp-in|data-line|c0002b41f6bd164d|ef8747a12860387a|Date:
> >  Mon, 19 Aug 2019 13:38:53 -0500 (CDT)|
> > filter-dataline|ef8747a12860387a|c0002b41f6bd164d|Date: Mon, 19 Aug 2019 
> > 13:38:53 -0500 (CDT)
> > filter|0|1566239933.836685|smtp-in|data-line|c0002b41f6bd164d|ef8747a12860387a|To:
> >  edgar|
> > filter-dataline|ef8747a12860387a|c0002b41f6bd164d|To: edgar
> > filter|0|1566239933.836688|smtp-in|data-line|c0002b41f6bd164d|ef8747a12860387a|
> > filter-dataline|ef8747a12860387a|c0002b41f6bd164d|ef8747a12860387a
> > filter|0|1566239933.836692|smtp-in|data-line|c0002b41f6bd164d|ef8747a12860387a|HI|
> > filter-dataline|ef8747a12860387a|c0002b41f6bd164d|HI
> > filter|0|1566239933.836695|smtp-in|data-line|c0002b41f6bd164d|ef8747a12860387a|.|
> > end of message
> > filter-dataline|ef8747a12860387a|c0002b41f6bd164d|.
> > 
> > I get the following response:
> > deathstar$ sendmail: command failed: 550 5.7.1 Delivery not authorized, 
> > message refused: Message is not RFC 2822 compliant
> > 
> > I see the same from a telnet session as well.
> > 
> > So there are 2 problems. First my script doesn't appear to acurately 
> > determine that the headers are finished. Second mail
> > doesn't go through. Any suggestions are appreciated.
> > 
>
> This error occurs when you don't have at least an empty line to separate
> headers from the body.

That's what I thought so not sure why the mail command would mess it up.

>
> Based on your output, it seems that you are generating a bad line:
>
> > filter|0|1566239933.836688|smtp-in|data-line|c0002b41f6bd164d|ef8747a12860387a|
> > filter-dataline|ef8747a12860387a|c0002b41f6bd164d|ef8747a12860387a
>
> There should be a | at the end of your filter-dataline because it is not
> valid as is, I'll check why smtpd did not hit a fatal.
>

I originally used spaces as the delimiter and it errors out with misbehaving 
filter. Then i realized it probably wanted the same input as it gives. Just 
didn't notice the trailing pipe.

Thanks,

Edgar
>
> -- 
> Gilles Chehade        @poolpOrg
>
> https://www.poolp.org            patreon: https://www.patreon.com/gilles

Reply via email to