amavis-user June 2010 archive
Main Archive Page > Month Archives  > amavis-user archives
amavis-user: Re: [AMaViS-user] Amavis Plugin

Re: [AMaViS-user] Amavis Plugin

From: Mark Martinec <Mark.Martinec+amavis_at_nospam>
Date: Mon Jun 21 2010 - 15:48:01 GMT
To: amavis-user@lists.sourceforge.net

Jason,

> I am interested in creating a plugin that works with Amavis.
>
> The purpose of the plugin is to replace a large email attachment with a link
> to the file that was originally attached- that way the messages won't be
> bounced from larger providers who support smaller email messages (10MB).
> I realize sending such messages through email is very inefficient, but
> unfortunately many users don't understand this concept.
>
> I would like to know the injection point where I can "plug in" to Amavis?
> If possible, I would like to run my code after all the other rules have run.
>
> Any further information would be very much appreciated!

One possibility would be to hook an external program to do the transformation
on a mail file through the altermime defanging mechanism, and provide a
replacement file, which will then be adopded by amavisd and fed to a MTA.

Another possibility is using a custom hook 'before_send' and let it prepare
a modified complete message on an alternate file, open it, and let amavisd
know about the substitute, something like this (untested):

  my $old_fh = $msginfo->mail_text;
  my $old_file_name = $msginfo->mail_text_fn

  my $new_fh = IO::File->new;
  $new_fh->open($new_file_name,'<')
    or die "Can't open file $new_file_name: $!";
  binmode($new_fh,":bytes")
    or die "Can't cancel :utf8 mode: $!";

  $msginfo->mail_text($new_fh);
  $msginfo->mail_text_fn($new_file_name);

  $old_fh->close
    or die "Can't close old file: $!";
  unlink($old_file_name)
    or die "Can't delete old file $old_file_name: $!";

or alternatively, just modify the existing open temporary file
in-place, keeping its name and filehandle.

  Mark

------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the
lucky parental unit. See the prize list and enter to win:
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
AMaViS-user mailing list
AMaViS-user@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/amavis-user
 Please visit http://www.ijs.si/software/amavisd/ regularly
 For administrativa requests please send email to rainer at openantivirus dot org