Solved

Filtering Mail with Perl

Posted on 1998-10-20
3
165 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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

763 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now