Skip site navigation (1)Skip section navigation (2)
Date:      19 Feb 2003 20:23:06 -0800
From:      Ken McGlothlen <mcglk@artlogix.com>
To:        Dragoncrest <dragoncrest@voyager.net>
Cc:        freebsd-questions@FreeBSD.ORG
Subject:   Re: Removing emails from an email file automatically.
Message-ID:  <868ywb4m39.fsf@ralf.artlogix.com>
In-Reply-To: <4.2.0.58.20030219224303.00971230@pop.voyager.net>
References:  <4.2.0.58.20030219224303.00971230@pop.voyager.net>

next in thread | previous in thread | raw e-mail | index | archive | help
Dragoncrest <dragoncrest@voyager.net> writes:

| Is there a simple way to remove a single email from a mail file using an
| automated script of some kind?

Well, it's better to remove them on their way in, with a tool like procmail.

I do have a set of tools I wrote to help one person get out from under his
rather substantial spamload.  I don't know if they'll help, but they might give
you some ideas.  Note that these are not exhaustively written; they're just
very, very cheap hacks that could be improved on.  Needless to say, they're all
intended to be run as root (unless you're working on your own mailbox).

The first is "fromn," which gives you a numbered "from":

        #!/bin/sh

        from -f $1 | cat -n

For example (dates slightly elided)

        $ fromn /var/mail/mcglk
             1  From bounce-stellaawards-967752@lyris.net  Feb 19 20:02:46 2003
             2  From owner-freebsd-questions@FreeBSD.ORG  Feb 19 20:05:46 2003
             3  From nobody@devnull.spamcop.net  Feb 19 20:05:57 2003
             4  From owner-freebsd-questions@FreeBSD.ORG  Feb 19 20:06:08 2003
             5  From owner-freebsd-questions@FreeBSD.ORG  Feb 19 20:06:21 2003
             6  From owner-freebsd-ports@FreeBSD.ORG  Feb 19 20:06:31 2003
             7  From owner-freebsd-questions@FreeBSD.ORG  Feb 19 20:06:57 2003
             8  From mcglk@artlogix.com  Feb 19 20:08:42 2003
        $ _

The second tool I have is "headers"

        #!/bin/sh

        skip=`dc -e "$2 1 - p"`
        formail +"$skip" -1 -s < $1 | formail -X ""

This allows me to see the headers of any particular message without violating
the privacy of the body of the message.  For example:

        $ headers /var/mail/mcglk 2
        From nobody@devnull.spamcop.net  Wed Feb 19 20:05:57 2003
        Return-Path: <nobody@devnull.spamcop.net>
        Delivered-To: mcglk@artlogix.com
        Received: from shagrat.julianhaight.com (shagrat.julianhaight.com
          [216.127.43.86])
                by c3po.artlogix.com (Postfix) with SMTP id 1D8331AA07
                for <mcglk@artlogix.com>; Wed, 19 Feb 2003 20:05:57 -0800 (PST)
        Received: (qmail 13946 invoked from network);
          20 Feb 2003 03:59:44 -0000
        Received: from localhost (HELO spamcop.net) (127.0.0.1)
          by shagrat.julianhaight.com with SMTP; 20 Feb 2003 03:59:44 -0000
        From: SpamCop AutoResponder <nobody@devnull.spamcop.net>
        To: mcglk@artlogix.com
        Subject: SpamCop has accepted 1 email for processing
        Date: Thu, 20 Feb 2003 03:59:44 GMT
        Message-ID: <spamid64707343@admin.spamcop.net>
        In-Reply-To: <200302200357.TAA40662@itchy.serv.net>
        References: <200302200357.TAA40662@itchy.serv.net>
        $ _

If I really need to delete a message at this point, I can use /usr/bin/mail to
delete the message by the message number.

Still, much better to use procmail so you don't have to do any of this stuff in
the first place if at all possible.

| Can I setup something that will search a mail file, find a given sender, and
| then just nuke the message without hurting the mail file?

In theory.  Take a look at the manpages for formail (if you have procmail
installed), which can extract headers from specific messages.


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?868ywb4m39.fsf>