Solved

Filtering Mail with Perl

Posted on 1998-10-20
3
210 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…
Six Sigma Control Plans

691 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