<?xml version="1.0" encoding="windows-1252"?>
<node id="731028" title="Re^3: Simple (but robust) email server (receiver)" created="2008-12-17 14:23:32" updated="2008-12-17 14:23:32">
<type id="11">
note</type>
<author id="194370">
skx</author>
<data>
<field name="doctext">
&lt;p&gt;I don't maintain a database handle throughout the transaction - instead I use the connection object to make notes as the SMTP transaction is completed.&lt;/p&gt;
&lt;p&gt;e.g.&lt;/p&gt;
&lt;code&gt;
sub hook_helo
{
    my ( $self, $transaction, $host ) = @_;

    #
    #  Make sure helo includes a domain
    #
    if ( $host !~ /\./ )
    {
        $self-&gt;log( LOGWARN, "HELO $host doesn't contain a period." );
        $transaction-&gt;notes( "reject", 1 );
        $transaction-&gt;notes( "reason", "invalid helo" );
    }

    return DECLINED;
}
&lt;/code&gt;
&lt;p&gt;Then I have a series of plugins which do different things at the last step, either forward the message or reject it, but archive a searchable copy for the recipients benefit.  Here's a simplified version of the reject + archive plugin:&lt;/p&gt;
&lt;code&gt;
sub hook_queue
{
    my ( $self, $transaction ) = @_;

    #
    # We only log mails which have been rejected.
    #
    if ( 0 == ( $transaction-&gt;notes("reject") || 0 ) )
    {
        return DECLINED;
    }

    # connect to DB
    # archive message  
    # disconnect

    return ( DECLINED, "Rejected this is spam: "  . $transaction-Notes("reason" ) );
}
&lt;/code&gt;
&lt;p&gt;(Actually this is a polite fiction.  I actually archive messages to local disk, if they were to be rejected, then later rsync them to a central location - and import them to MySQL there.&lt;/p&gt;
&lt;!-- Node text goes above. Div tags should contain sig only --&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-194370"&gt;
&lt;a href="http://www.steve.org.uk/"&gt;Steve&lt;/a&gt;&lt;br/&gt;
-- &lt;br/&gt;

&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
730642</field>
<field name="parent_node">
730920</field>
</data>
</node>
