[Pymilter] Unknown command and further processing

Larry G. Wapnitsky LWapnitsky at ph.wrtdesign.com
Wed May 23 15:12:24 EDT 2012


OK, so here's the issue.

 

My original milter would "crap out" when an unknown command was sent to
Postfix.  That milter is designed to remove attachments from a message,
save them and replace them with a single HTML file pointing to where the
attachments have been saved.  I was never able to diagnose why until I
saw the postfix logs having Unknown commands at the exact same time as
the message was received.  I started logging these and, lo and behold,
coincidence.  

 

Now, I have a milter that comes before my original that just passes on
e-mail with unknown commands, but logs when they occur, to whom they
were sent, etc.  

 

I've just written yet another milter (evolved from the original) that I
want to call when the unknown commands are hit.  This one would log the
headers, et. al. to a database, with the attachments as blobs.

 

My concern is that this one will fail as well.  How do I tell my milter
to only to the DB stuff if the unknown command is received?  Should that
be  a true/false value as the trigger when unknown is hit?

 

Let me know if you'd like to see the code to my milters for
clarification.

 

 

Regards,

 

Larry G. Wapnitsky MBA, MCSE, MCP+I
IT SUPPORT & ADMINISTRATION COORDINATOR
WRT <http://www.wrtdesign.com/>   |  Wallace Roberts & Todd, LLC
<http://www.wrtdesign.com/> 
1700 Market Street, 28th Fl
Philadelphia, PA 19103
T  215.430.5068
C  215.713.8635
E  lwapnitsky at WRTdesign.com <mailto:lwapnitsky at WRTdesign.com> 

 

From: Larry G. Wapnitsky 
Sent: Wednesday, May 23, 2012 12:01 PM
To: 'Stuart D Gathman'; pymilter at bmsi.com
Subject: RE: [Pymilter] Unknown command and further processing

 

No problem yet.  I'm modifying two bits of existing code write now and
wanted to make sure I could do what I needed to before continuing on.
I'll keep you  posted on progress.

 

Larry G. Wapnitsky MBA, MCSE, MCP+I
IT SUPPORT & ADMINISTRATION COORDINATOR
WRT <http://www.wrtdesign.com/>   |  Wallace Roberts & Todd, LLC
<http://www.wrtdesign.com/> 
1700 Market Street, 28th Fl
Philadelphia, PA 19103
T  215.430.5068
C  215.713.8635
E  lwapnitsky at WRTdesign.com <mailto:lwapnitsky at WRTdesign.com> 

 

From: Stuart D Gathman [mailto:stuart at bmsi.com] 
Sent: Tuesday, May 22, 2012 2:59 PM
To: pymilter at bmsi.com
Subject: Re: [Pymilter] Unknown command and further processing

 

Long ago, Nostradamus foresaw that on 05/22/2012 11:54 AM, Larry G.
Wapnitsky would write: 

I have the following code in a milter that determines when Postfix has
received an unknown command:

 

@Milter.noreply

    def unknown(self, cmd):

        self.unkMilterlog.warning('Invalid command sent: %s' % cmd)

        try:

            self.unkMilterlog.warning('From: %s' % self.canon_from)

        except:

            self.unkMilterlog.warning('unable to determine Sender')

        try:

            for R in self.R:

                for recipient in R:

                    if not len(recipient) < 1: self.log('To %s' %
recipient)

        except:

            self.unkMilterlog.warning('unable to determine
Recipient(s)')

        return Milter.CONTINUE

 

Is it possible to do further processing on a message when "unknown" has
been called?  Part of the reason this was initially created (for logging
purposes) was that another milter was not being hit when an unknown
command was being interpreted.  What I'd like to do is take the full
message and put it into a MySQL blob for further analysis.

 

Nothing about milter prevents further processing.   I tested with
sendmail, results below.  What problem are you having, exactly?

Milter code:

  @Milter.noreply
  def unknown(self, cmd):
    self.log('Invalid command sent: %s' % cmd)
    return Milter.CONTINUE

Client side:

220 mail.bmsi.com ESMTP Sendmail 8.14.3/8.14.3; Tue, 22 May 2012
14:50:40 -0400
HELO hulk
250 mail.bmsi.com Hello hulk [192.168.0.102], pleased to meet you
HELP
214-2.0.0 This is sendmail version 8.14.3
214-2.0.0 Topics:
214-2.0.0     HELO    EHLO    MAIL    RCPT    DATA
214-2.0.0     RSET    NOOP    QUIT    HELP    VRFY
214-2.0.0     EXPN    VERB    ETRN    DSN    AUTH
214-2.0.0     STARTTLS
214-2.0.0 For more info use "HELP <topic>".
214-2.0.0 To report bugs in the implementation see
214-2.0.0     http://www.sendmail.org/email-addresses.html
214-2.0.0 For local information send email to Postmaster at your site.
214 2.0.0 End of HELP info
PING super
500 5.5.1 Command unrecognized: "PING super"
MAIL FROM: <stuart at hulk.bmsi.com> <mailto:stuart at hulk.bmsi.com> 
250 2.1.0 <stuart at hulk.bmsi.com> <mailto:stuart at hulk.bmsi.com> ...
Sender ok
RCPT TO: <stuart at bmsi.com> <mailto:stuart at bmsi.com> 
250 2.1.5 <stuart at bmsi.com> <mailto:stuart at bmsi.com> ... Recipient ok
SCRIBBLE: foo
500 5.5.1 Command unrecognized: "SCRIBBLE: foo"
DATA
354 Enter mail, end with "." on a line by itself
Testing
.
250 2.0.0 q4MIoefa002370 Message accepted for delivery
quit
221 2.0.0 mail.bmsi.com closing connection
Connection closed by foreign host.

Milter log:

2012May22 14:50:40 [1] connect from hulk at ('192.168.0.102', 34367)
INTERNAL
2012May22 14:50:54 [1] hello from hulk
2012May22 14:51:14 [1] Invalid command sent: PING super
2012May22 14:51:49 [1] mail from <stuart at hulk.bmsi.com>
<mailto:stuart at hulk.bmsi.com>  ()
2012May22 14:51:58 [1] rcpt to <stuart at bmsi.com>
<mailto:stuart at bmsi.com>  ()
2012May22 14:52:06 [1] Invalid command sent: SCRIBBLE: foo
2012May22 14:52:17 [1] Authentication-Results: mail.bmsi.com; iprev=pass
policy.iprev=192.168.0.102 (hulk)
2012May22 14:52:17 [1] X-DSpam-Score: 0.152536
2012May22 14:52:17 [1] eom






----wrtmail--%3423wrt%----
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://gathman.org/pipermail/pymilter/attachments/20120523/e9d9087b/attachment.html>


More information about the Pymilter mailing list