[plug] Mail Filtering

Anthony J. Breeds-Taurima tony at cantech.net.au
Thu Aug 1 10:14:30 WST 2002


On Wed, 31 Jul 2002, I am the LinuxAlien wrote:

> I have an account at UCC. I was wondering if I could set up some kind of 
> filter so that i if receive an email from 'callen at corpus.wa.edu.au' with 
> 'registered_names.txt' attached, it copys 'registered_names.txt' to my 
> ~/public-html directory and replaces the version there. There will be about 
> one email a day and it wont have to be added to the old file, just replace 
> it in it entirety.

If the 'registered_names.txt' is inline ass opposed to attached then
sonething like this should work.
--------
#!/usr/bin/perl

#read the _whole_ file from stdin into $_;
undef $/;
$_=<STDIN>;

#get rid of the email headers
# headers are seperated from the body of the message by a blank line.
s/^.*?\n\n//gs;

open(DATA, ">public_html/registered_names.txt") or 
	die "failed to open public_html/registered_names.txt: $!\n";
print DATA $_;
close(DATA);
--------

Then in ~/.procmailrc do something like:
---
:0
* ^From:.*callen at corpus.wa.edu.au
| /path/to/script
---

This is insecure as anyone can forge a fromline and thus overwrite the
registered_users.txt file, but it should give you some pointers.

If the file simply _must_ be attached then you should be able to use 
mimencode to get at the actuall data.

#include <http://thor.cantech.net.au/~tony/stddisclaimer.h>

Yours Tony

   Jan 22-25 2003           Linux.Conf.AU            http://linux.conf.au/
		  The Australian Linux Technical Conference!



More information about the plug mailing list