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 that is passed to the script via stdin. In addition, there are several other environment variables set that correspond with the mail message: MBOX, TO, FROM, CC, MIME, REPLYTO, SUBJECT. The following perl script demonstrates how to process a mail message.

#
# Perl-based Mail CGI Script
#
# Copyright 2001 Tod Sambar
# All rights reserved.
#


#
# PARSE THE CGI FORM
#
	$content_len = $ENV{'CONTENT_LENGTH'};
	$mbox = $ENV{'MBOX'};
	$to = $ENV{'TO'};
	$from = $ENV{'FROM'};
	$cc = $ENV{'CC'};
	$mime = $ENV{'MIME'};
	$replyto = $ENV{'REPLYTO'};
	$subject = $ENV{'SUBJECT'};

	# Buffer the MAIL content
	binmode STDIN;
	read(STDIN, $buffer, $content_len);

#
# Write out the mail file
#
	$filename = "mail.tmp";
	open(FILE, ">$filename") || exit(1);
	binmode FILE;

	print FILE "CONTENT_LENGTH ".$content_len."\n";
	print FILE "MBOX ".$mbox."\n";
	print FILE "TO ".$to."\n";
	print FILE "FROM ".$from."\n";
	print FILE "CC ".$cc."\n";
	print FILE "MIME ".$mime."\n";
	print FILE "REPLYTO ".$replyto."\n";
	print FILE "SUBJECT ".$subject."\n";
	print FILE "\n";

	print FILE $buffer;
	close FILE;

#
# DONE
#
exit(0);


© 2001 Sambar Technologies. All rights reserved. Terms of Use.