simple mail wrapper for qmail+mailman+fudforum [message #21992] |
Fri, 07 January 2005 02:56 |
mikelcu
Messages: 7 Registered: January 2005 Location: Portland, OR
Karma:
|
Junior Member |
|
|
This is a super-simple wrapper script I am using to pipe mail incoming to mailing lists to both mailman and fudforum. The benefit here is that it eliminates have to actually receive mail on any account for the forum. Mail is diverted to both mailman and fudforum when it is delivered to mailman.
Prerequisites:
Mailman up and running using qmail, using the qmail-to-mailman.py script distributed with mailman. This will NOT work using .qmail aliases. see http://list.org/mailman-install/qmail-issues.html for info on setting up mailman with qmail.
Mailman must be on the same server as FUD
The Mail::Internet perl module.
Install:
Modify .qmail-default in the Mailman home directory like this:
|preline /path/to/mailwrapper.pl
Modify mailwrapper.pl to suit your setup.
What the script does:
With mailman set up properly, all mail to your list domain, i.e. lists.domain.com, will go to the mailman user. instead of piping mail directly to the qmail-to-mailman.py script, this wrapper reads in the mail, writes it to a tempfile and parses the header.
The tempfile is cat'd out to qmail-to-mailman.py and then to maillist.php with the contents of the "To" field as the argument to maillist.php.
Disclaimer:
This script works well for me, but it may not suit your needs. It is also incredibly simplistic. It does almost no error checking and it does not provide any safety nets. Do NOT try to use this if you do not know what you are doing. Incorrect use of this script can lead to mail loss No guaratees, etc. etc. Use at your own risk. Enjoy
mailwrapper.pl:
#!/path/to/perl -w
use strict;
use File::Temp qw/ tempfile tempdir /;
use Mail::Internet;
File::Temp->safe_level( File::Temp::HIGH );
my $debug = 0;
my $dir = tempdir( CLEANUP => 1 );
my ($fh, $filename) = tempfile( DIR => $dir, SUFFIX => '.ml' );
my $rmail;
my $out;
# read in the mail
while (<>)
{
$rmail .= $_;
}
# dump mail into the tempfile
print $fh $rmail;
my $head = Mail::Header->new( [ split /\n/, $rmail ] );
# our list name
my $list = $head->get("To");
# "debug" output file
open(DEB, '>>/tmp/mailwrapperdebug') unless $debug == 0;
# almost impossible for a mail to be less than 100 bytes by the time it gets here
if(length($rmail) > 100)
{
# CHANGE PATHS IN THESE NEXT 2 LINES
$out = `cat $filename | /path/to/python /path/to/qmail-to-mailman.py`;
$out .= `cat $filename | /path/to/php /path/to/maillist.php $list`;
}
else
{
$out = "ERR: received mail is only " . length($rmail) . " bytes long";
}
print DEB $out unless $debug == 0;
[Updated on: Fri, 07 January 2005 02:57] Report message to a moderator
|
|
|