Hacking amavisd $msginfo

Mark Martinec Mark.Martinec+amavis at ijs.si
Fri Jun 17 16:24:06 CEST 2011


Alex,

> I'm trying to modify amavisd-new-2.6.4 to write specific headers to
> syslog when a spam is found, and I believe utilizing the $msginfo
> header in mail_to_local_mailbox is the proper way to do this. This
> function appears to have all the information about the spam message,
> including the quarantined file's name.
> 
> I'm somewhat of a beginning perl programmer, so I'm really not sure
> how to do this. How can I access the individual elements of the
> $msginfo structure? Where are they defined?

As Sahil Tandon noted, it's probably best to start with
example code in amavisd-custom.conf. The custom hooks
are also probably a better place for your code than having
to modify the mail_to_local_mailbox().


> How can I access the individual elements of the
> $msginfo structure? Where are they defined?

See modules Amavis::In::Message and Amavis::In::Message::PerRecip.

The Amavis::In::Message carries all the methods applicable to
$msginfo.

For example:

$msginfo->sender   is a mail envelope sender address
$msginfo->msg_size  is a mail size
$msginfo->spam_level  is a spam score
$msginfo->per_recip_data  is a ref to a list of recipient objects


The Amavis::In::Message::PerRecip carries all the methods
applicable to each recipient - the list of which is in the
$msginfo->per_recip_data.

For example:

for my $r (@{$msginfo->per_recip_data}) {
  my $recipient_address = $r ->recip_addr;
  my $is_local = $r->recip_is_local;
  ... $r->recip_mbxname   # quarantine location
  ... $r->recip_smtp_response  # SMTP status
  ....
}


> I've tried variations of trying to access the hash, but I don't think
> I'm doing it properly:
>    my ($my_subject) = $msginfo->get_header_field('subject');

The get_header_field returns a triplet:
  my($f_ind, $f_name, $fld) = $msginfo->get_header_field('subject');

what you probably want is a:
  my ($my_subject) = $msginfo->get_header_field_body('subject');

> What is the proper way to access the actual list of recipients, and
> not (apparently?) a pointer to it?
> 
>   my $loc_recips = $msginfo->recips;
>   do_log(0,"loc recips: $loc_recips");

do_log(0,"loc recips: %s", join(", ",@$loc_recips))

> I realize this is probably a basic perl problem, but I hoped to learn
> more about perl and amavis, and thought this was a fun project for me.
> Ideas greatly appreciated.



  Mark


More information about the amavis-users mailing list