Sambar Server Documentation
|
Mail Routing Rules
Pro Server Only |
Overview The WebMail interface provides a mechanism that allows users to automatically route mail messages to folders or CGI scripts as well as forward and delete mail messages. Routing rules allow wild-card pattern matching based on Subject, To, From, Cc mail headers. The CGI script execution follows the same mechanism as POST scripts executed from an HTTP server. The CONTENT_LENGTH environment variable is set indicating the mail message content length. In addition, there are several other environment variables set that correspond with the mail message: MBOX, TO, FROM, CC, MIME, REPLYTO, SUBJECT and SPOOLNAME. The following perl script demonstrates how to process a mail message. Note: The original mail file found in mail/mbox/spool is passed to the the CGI script in the SPOOLNAME environment variable.
|
A default bin/mailcgi.pl Router CGI Script is included which utilizes SpamAssasin to analyze mail messages and route them accordingly.
The following example illustrates a simple Router CGI Script that logs the spool file to a temporary file and then deletes the spool file. Important! This will result in no mail being delivered to either internal or external users (due to the unlink() call).
#
# Perl-based Mailbox Router CGI
#
# Copyright 2002 Tod Sambar
# All rights reserved.
#
# MAIL SPOOLNAME
my $spoolname = $ENV{'SPOOLNAME'};
#
# Log the spool file name
#
$filename = "router.tmp";
open(FILE, ">>$filename") || exit(1);
binmode FILE;
print FILE "SPOOLNAME ".$spoolname."\n";
close FILE;
#
# DELETE the mail message (no delivery to any user)
#
unlink($spoolname);
# DONE
exit(0);