Amavis Postfix and Altermime
From Wickle Wiki
This is a document about installing a mail server who checks for virus, spam and it insert a disclaimer on every outgoing message. Simple , isn't ??
Resume
First of all we must have a working copy of postfix. thats simnple because postfix is installed from apt-get or rpm easily. To doing that you must MODIFY amavisd-new DAEMON
After that , install amavisd-new (i installed it easily from apt-get)
Them configure postfix to use it : Relevant parts of main.cf:
content_filter = smtp-amavis:[127.0.0.1]:10024
Relevant parts of master.cf :
smtp inet n - - - - smtpd
smtp-amavis unix - - n - 2 smtp
-o smtp_data_done_timeout=1200
-o smtp_send_xforward_command=yes
-o disable_dns_lookups=yes
127.0.0.1:10025 inet n - n - - smtpd
-o content_filter=
-o smtp_send_xforward_command=yes
-o local_recipient_maps=
-o relay_recipient_maps=
-o smtpd_restriction_classes=
-o smtpd_client_restrictions=
-o smtpd_helo_restrictions=
-o smtpd_sender_restrictions=
-o smtpd_recipient_restrictions=permit_mynetworks,reject
-o mynetworks=127.0.0.0/8
-o strict_rfc821_envelopes=yes
-o smtpd_error_sleep_time=0
-o smtpd_soft_error_limit=1001
-o smtpd_hard_error_limit=1000
Now , restart amavis, restart postfix and try it logs are on /var/log/amavis.log
Installing altermime
You can install altermime from apt, or downloading it from http://www.pldaniels.com/altermime/
you must configure and make it, them install (i have it under /usr/local/bin) them we will modify amavisd-new daemon to insert a disclaimer on every outgoing mail.
This is the code, insert it on the line 5740, just before :
# THIRD: now that we know what to do with it, do it!
if ($forward_method ne '') { # message must be delivered explicitly
Code:
my $sender = $msginfo->sender;
my $is_outgoing = lookup($sender, \@local_domains_acl);
# $is_outgoing=1;
do_log(1,"dominio: @local_domains_acl");
do_log(1,"is_outgoing ? sender: $sender, result: $is_outgoing");
# Add disclaimer
if ($is_outgoing) {
my $disc_bypass = 0;
my $res = 0;
my($hdr_edits) = $msginfo->header_edits;
$hdr_edits = Amavis::Out::EditHeader->new() if ! $hdr_edits;
do_log(1,"ok, not yet in message, add disclaimer to message");
$hdr_edits->append_header('X-Disclaimer-NNA','Disclaimer added elprogreso.com');
# add Disclaimer to message
$fh->close() or die "Can't close file to run altermime: $!";
my $cmd = "/usr/local/bin/altermime --input=$tempdir/email.txt --disclaimer=/etc/postfix/disclaimer.txt";
$cmd .= " --disclaimer-html=/etc/postfix/disclaimer.txt";
#Actually run the command
system($cmd);
$fh = IO::File->new("$tempdir/email.txt") or die "Can't reopen altermimed file: $!";
$fh->seek(0,0) or die "Can't rewind mail file (9): $!";
binmode($fh,":bytes") or die "Can't cancel :utf8 mode: $!" if $unicode_aware;
$msginfo->mail_text($fh);
# save headers
$msginfo->header_edits($hdr_edits);
do_log(1,"-------- DISCLAIMER ANADIDO");
} else {
do_log(5,"NO Disclaimer - From:<$sender> isn't local");
}
and after :
$which_section = "forwarding";
ensure_mime_entity($msginfo,$fh,$tempdir,\@virusname); #need header
To make this work well, the variable local_domains_acl on main.cf must be defined and pointing to all local domains.
Alert the sender on remitent vacation
This is the script i use to alert a mail sender that the remitent is not on the office (on holidays for example) You need activate procmail, for example with this on main.cf:
mailbox_command = procmail -a "$EXTENSION"
and you need to put the file .procmailrc on the vacation home user:
PMDIR=$HOME
:0 Whc: vacation.lock
# The three (ANDed) conditions address the following:
# Reply if mail is addressed to me.
# Don't reply to daemons or mailing lists (! = not).
# Avoid mail loops (don't reply to mail I might send myself).
* $^To:.*\<$\LOGNAME\>
* !^FROM_DAEMON
* !^X-Loop: mymail@mydomain.com
# Store sender's address in vacation.cache if not there already.
| formail -rD 8192 vacation.cache
# If sender's address not in cache (e=previous recipe failed), send
# mail containing vacation message. Note: Trailing backslashes (\)
# required to denote continuation of single action line.
:0 ehc
| (formail -rA"Precedence: junk" \
-A"X-Loop: mymail@mydomain.com ; \
cat $PMDIR/vacation.msg \
) | $SENDMAIL -oi -t
The file ~HOME/vacation.msg must exist and contains the message:
I am at holidays trip. sorry cya

