Solved

Filtering Mail with Perl

Posted on 1998-10-20
3
195 Views
Last Modified: 2010-03-04
What I am needing to do is install a script onto a UNIX system that will allow all of the e-mail coming to my address to be filtered based on the from address or the subject.  I want the mail to either be deleted, forwarded, or have nothing happen to each message - based on what I specify.  Do you know of any way I can do this, or know of a program that will do this?  Your help would be greatly appreciated!
0
Comment
Question by:jeikenb
  • 2
3 Comments
 
LVL 5

Accepted Solution

by:
b2pi earned 200 total points
ID: 1205554
procmail will do all of this, as well as much more.  In fact, chances are it's already on your system, and your system directory is checked for a .procmailrc each time you get mail.  Try

man procmail

and then

man procmailrc

Warning: procmail recipes are non-trivial, but have nothing to do with perl.
0
 

Author Comment

by:jeikenb
ID: 1205555
Thanks for the suggestion, but it doesn't work on my system.  We are running BSDI 3.1 and I can't find anything in regards to procmail on the server.  Do you have any other suggestions?
0
 
LVL 5

Expert Comment

by:b2pi
ID: 1205556
I find it very surprising that bsdi doesn't include procmail, or
something with equivalent (superset) functionality.

( BTW, most of this info is from the procmail man file)

In any case, if you download and install procmail (say, in ~/bin), and
then put the following in your .forward file

|IFS=' '&&p=/ms/dist/aurora/bin/procmail&&test -f $p&&exec $p
-Yf-||exit 75 #YOUR_USERNAME

(note, that's all on one line, and your .forward _must_ be
world-readable).

Finally, if you don't have .forward functionality, get a new system
administrator. OK, try that again.  If you don't have .forward
functionality, you can run procmail manually or from a cron job via
the following script:

#!/bin/sh

ORGMAIL=/var/spool/mail/$LOGNAME

if cd $HOME &&
    test -s $ORGMAIL &&
    lockfile -r0 -l1024 .newmail.lock 2>/dev/null
then
    trap "rm -f .newmail.lock" 1 2 3 13 15
    umask 077
    lockfile -l1024 -ml
    cat $ORGMAIL >>.newmail &&
    cat /dev/null >$ORGMAIL
    lockfile -mu
    formail -s procmail <.newmail &&
    rm -f .newmail
    rm -f .newmail.lock
fi
exit 0

0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question