SUMMARY: mail utility for selectively deleting messages from /var/mail

From: Craig Raskin (
Date: Mon May 05 1997 - 21:16:41 CDT

On Mon, 5 May 1997, Craig Raskin wrote:

> Does anyone know of any command line utilites which can be used for
> mass deleting mail messages based on the From line or the Message-Id? The
> main use would be for deleting spam from a mail spool.

I should have been more clear in the message, but my question was what to
do after the spam makes it through your filters. We are already running
procmail w/ filters as well as sendmail rules. It is impossible to catch
everything so I was wondering how would be the best way to clean up the
mess left behind.

I think the best solution to the problem is a program called, "junkmail"
which was posted to comp.sources.unix ages ago (Volume 5)! I have made the
source available at:

It might not be for everyone but seams to be able to do everything I need.
It can not delete messages based on Message-Id but I might end up hacking
the source so it can.

The most popular solution was to use procmail/formail as a filtering
agent. The man page for procmail.1 gives the following information:

     Procmail can also be invoked to postprocess an already
     filled system mailbox. This can be useful if you don't want
     to or can't use a $HOME/.forward file (in which case the
     following script could periodically be called from within
     cron(1), or whenever you start reading mail):



          if cd $HOME &&
           test -s $ORGMAIL &&
           lockfile -r0 -l1024 .newmail.lock 2>/dev/null
            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
          exit 0

The main problem with this solution is it is rather slow. For one mailbox
this isn't a problem but if you have to delete mail from 1000+ mailboxes,
it could be rather time consuming.

Summaries follow:


Umm, with procmail you can change the filter rules, then re-run the
mailbox back through procmail on the command line, to refilter the
results... I've had to do it once or twice when disk space problems
caused procmail to not work.


Yes, there is such a thing. Check Volume 5 of the comp.sources.unix
archive for "junkmail", something that I worked on back in 1983.
It should do the trick for you.


Here we use "sortmail" on a Solaris 2.4 system. You will find below where
I got it and some parts of the man pages...

---------- begin ----------
Host (
Last updated 08:29 10 Feb 1995
    Location: /archive/usenet/sources/comp.sources.unix/volume28


I don't know of one but it would be a cool thing to come up with. I might
give it a try with perl or awk. If I come up with one, I'll post it to
the list. In the mean time, you might try what I'm doing. Go to and get the latest hacks for the file.
I am currently using the spam blocker and it works great.


Look for "procmail", it can be used by an individual user or on the system

It would be nice to have a database of "SPAM signatures", strings to look
for to filter well known spams. MAKE MONEY FAST and $$$ come to mind....


thanks to:

Stephen Harris
Rich Kulawiec
Claude Charest
Brian Wells
Reto Lichtensteiger
Lewis E. Wolfgang
Rasana Atreya
Karl E. Vogel

Craig Raskin, "The optimist proclaims that we live
Unix System Administrator in the best of all possible worlds,
10F, 171 Roosevelt Road, Section 3 and the pessimist fears that this
Taipei, Taiwan is true." -- James Branch Cabell

This archive was generated by hypermail 2.1.2 : Fri Sep 28 2001 - 23:11:54 CDT