From owner-freebsd-questions Wed Feb 19 20:20:35 2003 Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id B343537B401 for ; Wed, 19 Feb 2003 20:20:32 -0800 (PST) Received: from c3po.artlogix.com (s01.artlogix.com [216.231.46.16]) by mx1.FreeBSD.org (Postfix) with ESMTP id DD05243F3F for ; Wed, 19 Feb 2003 20:20:31 -0800 (PST) (envelope-from mcglk@artlogix.com) Received: from ralf.artlogix.com.artlogix.com (unknown [192.168.0.3]) by c3po.artlogix.com (Postfix) with ESMTP id D87761A9CC; Wed, 19 Feb 2003 20:21:46 -0800 (PST) To: Dragoncrest Cc: freebsd-questions@FreeBSD.ORG Subject: Re: Removing emails from an email file automatically. References: <4.2.0.58.20030219224303.00971230@pop.voyager.net> From: Ken McGlothlen Date: 19 Feb 2003 20:23:06 -0800 In-Reply-To: <4.2.0.58.20030219224303.00971230@pop.voyager.net> Message-ID: <868ywb4m39.fsf@ralf.artlogix.com> Lines: 74 User-Agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.1 (Cuyahoga Valley) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Dragoncrest 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: 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 ; 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 To: mcglk@artlogix.com Subject: SpamCop has accepted 1 email for processing Date: Thu, 20 Feb 2003 03:59:44 GMT Message-ID: 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