More Hacking amavisd $msginfo
Alex
mysqlstudent at gmail.com
Sun May 1 22:35:49 CEST 2022
Hi,
I'm trying to find or develop a way to quarantine mail from specific
senders for specific domains. Is there a well-defined way to do this?
It appears the amavisd.conf doesn't provide the ability to specify
different policies based on domains.
So eleven years ago(!!!) I posted this somewhat related question:
https://lists.amavis.org/pipermail/amavis-users/2011-June/000503.html
Is it possible to use the $msginfo structure to inspect the different
headers and somehow make a policy decision on whether to quarantine an
email there? In other words, if I built a custom hook using the
$msginfo structure, and found one of the senders I wished to block,
based on the recipient domain, could I quarantine it from there?
I don't have an answer for what to do if a sender is on the blocklist
for one domain and not on another. I hoped it could be decided in a
per-recipient basis.
Here's (most) of the contents of my custom.conf.
package Amavis::Custom;
use strict;
use warnings;
#use diagnostics;
no warnings qw(uninitialized redefine);
# needed for write_to_db()
use DB_File;
use IO::File;
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($mail_size) = $msginfo->msg_size; # mail size in bytes
my($mail_size_mb) = $mail_size/(1024*1024);
my($hdr_edits) = $msginfo->header_edits;
$hdr_edits->add_header('X-ActualMessageSizeBytes', $mail_size);
$hdr_edits->add_header('X-ActualMessageSize',
'*' x ($mail_size_mb > 50 ? 50 : $mail_size_mb));
$self; # returning an object activates further callbacks,
# returning undef disables them
}
sub before_send {
my($self,$conn,$msginfo) = @_;
my($loc_subj) = $msginfo->get_header_field_body('subject');
my($loc_from) = $msginfo->get_header_field_body('from'); #
raw full field
my($loc_recip) = $msginfo->get_header_field_body('recip_addr_smtp');
my($loc_recip_final) = $msginfo->get_header_field_body('rfc2822_sender');
my($loc_to) = $msginfo->get_header_field_body('to'); #
raw full field
my($loc_sender) = $msginfo->sender; # envelope sender
address, e.g. 'usr at e.com'
...
}
More information about the amavis-users
mailing list