On 07/05/2010 23:51, mouss wrote:
Andrés Gattinoni a écrit :
On Fri, May 7, 2010 at 5:29 PM, Noel Jones<njo...@megan.vbhcs.org>  wrote:
On 5/7/2010 2:53 PM, Andrés Gattinoni wrote:
Here's an example of a shell script that receives all mail. Shouldn't be
much of a stretch to use PHP instead.
http://www.postfix.org/FILTER_README.html#simple_filter

If you still want to use amavisd-new, then use multiple postfix instances
for each filter hop.

Another alternative is to integrate your code into amavisd-new, either as a
custom hook or as a pseudo antivirus scanner.  Check the amavis-users
archives for other folks doing similar things.

Thanks for your response Noel.
I've checked out that link. The thing is that I don't actually to do
any filtering inside my script, I just need to gather some
information.

What kind of information? if it's just about envelope, then logs are
enough.

Maybe there's an easier way that I can do that without having to call
sendmail again.

[snip]


Noel Jones help you on the right way... better is to hook amavis instead adding a new command-line in php that will reduce dramatically Postfix processing.

I know is not very well documented on Amavis, but this a starting help,

you will see it easy.

Add in your amavisd.conf

include_config_files('path-to-your-perl-script.conf');




In path-to-your-perl-script.conf

package Amavis::Custom;
use strict;
#use Net::LDAP;
#use Config::IniFiles;
#use Geo::IP;
use File::Copy;
use File::stat;
use POSIX qw(ceil floor);
use Unix::Syslog qw(:macros);  # Syslog macros
use Unix::Syslog qw(:subs);    # Syslog functions

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) = @_;
  bless {}, $class;


}

sub before_send {
  my($self,$conn,$msginfo) = @_;
## do what you want before routing message to final destination.
  $self;
}

# main function that allows you to hook amavis filtering

sub checks {
   #$r->recip_addr_modified($new_addr);  # replaces delivery address!
  my($self,$conn,$msginfo) = @_;
  my($client_ip) = $msginfo->client_addr;
  my $bann_reason='';
  my $sender_domain='';
  my($log_id)=$msginfo->log_id;
  my($tempdir) = $msginfo->mail_tempdir;
  my $recipient_domain;
  my($received)=$msginfo->get_header_field_body('received');
  my($kasrate)= trim($msginfo->get_header_field_body('X-SpamTest-Rate'));
  my($mail_file_name) = $msginfo->mail_text_fn;
  my($sender_address)=$msginfo->sender;
  $message_id=Mydecode($msginfo->get_header_field_body('message-id'));
  $message_id=~ s/<//g;
  $message_id=~ s/>//g;
 #Add header token
$msginfo->header_edits->add_header('X-YOUR-scanner','0.00');


# ($country_name,$region_name,$city)=ScanGeoIP($last_recived); Example to using geoip

$sender_address=~ m/(.+?)@(.+)/;
$sender_domain=$2;

#Example log trough amavis loger
do_log(0, "%s my-plugin: client's IP [%s], last [%s] sender: <%s>, X-SpamTest-Rate: %s",$message_id,$client_ip,$last_recived,$sender_address,'');

# change the Amavis behavior using specific class Amavis::load_policy_bank('killAll');

$self;
}

1;  # insure a defined return






Reply via email to