Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to call custom filter script?

142 views
Skip to first unread message

Carsten Wolters

unread,
Jul 22, 2004, 8:12:48 AM7/22/04
to
Hi all!

I just got postfix + amavisd-new running. Now I want to call a script
for custom content filtering an each email processed by amavisd.

How can I do this? Where can I hook the script into the amavids
process?

Thank you
Carsten

patrice...@gmail.com

unread,
Jan 10, 2018, 2:34:51 AM1/10/18
to
Hello,

I wonder if there's an answer to this question.
I recently started using Amavisd-new and looking for creating custom hook.

If anyone could help me getting started with custom hook, I would be very grateful.

Thank you,
Sam

patrice...@gmail.com

unread,
Jan 11, 2018, 3:57:05 AM1/11/18
to
Hi,

I found the way, thanks to the documentation and trial and error method.

1) Created a file /etc/amavis/conf.d/my-custom-hook.conf:
===========================================================
package Amavis::Custom;
use strict;
use warnings;
no warnings qw(uninitialized redefine);
use DBI qw(:sql_types);
use DBD::mysql;
BEGIN {
import Amavis::Conf qw(:platform :confvars c cr ca $myhostname);
import Amavis::Util qw(do_log untaint safe_encode safe_decode);
import Amavis::rfc2821_2822_Tools;
import Amavis::Notify qw(build_mime_entity);
}

sub new {
my($class,$conn,$msginfo) = @_;
my($self) = bless {}, $class;
my($conn_h) = Amavis::Out::SQL::Connection->new(
['DBI:mysql:database=mydb;host=127.0.0.1', 'user', 'password'] );
$self->{'conn_h'} = $conn_h;
$self; # returning an object activates further callbacks,
# returning undef disables them
}

sub before_send {
my($self,$conn,$msginfo) = @_;
# $self ... whatever was returned by new()
# $conn ... object with information about a SMTP connection
# $msginfo ... object with info. about a mail message being processed

my($ll) = 2; # log level (0 is the most important level, 1, 2,... 5 less so)
do_log($ll,"CUSTOM: new message");

my($sender) = $msginfo->sender; # envelope sender address, e.g. 'u...@e.com'
do_log($ll,"CUSTOM: Envelope sender: <%s>", $sender);
}

1;
===========================================================

2) Added the following in the /etc/amavis/conf.d/50-user :

include_config_files('/etc/amavis/conf.d/my-custom-hook.conf');

3) Ensured log level set to 2 (according to the code above) in the /etc/amavis/conf.d/50-user :

$log_level = 2;

4) Restarted Amavis:

sudo /etc/init.d/amavis restart

I verified it by sending mail to the MTA (Postfix) and checking the entry in /var/log/mail.log

Hope it helps!

Regards,
Sam
0 new messages