Solved

Filtering Mail with Perl

Posted on 1998-10-20
3
187 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

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 …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

776 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