From owner-freebsd-questions@FreeBSD.ORG Wed Aug 17 17:11:42 2005 Return-Path: X-Original-To: freebsd-questions@freebsd.org 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 2EFE216A41F for ; Wed, 17 Aug 2005 17:11:42 +0000 (GMT) (envelope-from keramida@ceid.upatras.gr) Received: from rosebud.otenet.gr (rosebud.otenet.gr [195.170.0.94]) by mx1.FreeBSD.org (Postfix) with ESMTP id 7DD4843D53 for ; Wed, 17 Aug 2005 17:11:40 +0000 (GMT) (envelope-from keramida@ceid.upatras.gr) Received: from flame.pc (aris.bedc.ondsl.gr [62.103.39.226]) by rosebud.otenet.gr (8.13.4/8.13.4/Debian-1) with SMTP id j7HHBbUC019717; Wed, 17 Aug 2005 20:11:37 +0300 Received: from flame.pc (flame [127.0.0.1]) by flame.pc (8.13.4/8.13.4) with ESMTP id j7HHHNW2001391; Wed, 17 Aug 2005 20:17:23 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Received: (from keramida@localhost) by flame.pc (8.13.4/8.13.4/Submit) id j7HHHMqC001390; Wed, 17 Aug 2005 20:17:22 +0300 (EEST) (envelope-from keramida@ceid.upatras.gr) Date: Wed, 17 Aug 2005 20:17:22 +0300 From: Giorgos Keramidas To: Matt Juszczak Message-ID: <20050817171722.GB1295@flame.pc> References: <43034EA2.4000206@atopia.net> <43035504.4020300@daleco.biz> <43035EB3.7080300@atopia.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <43035EB3.7080300@atopia.net> Cc: freebsd-questions@freebsd.org Subject: Re: OT: Removal of old 14+ mail from mbox-based mail spool (not maildir) X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Aug 2005 17:11:42 -0000 On 2005-08-17 11:58, Matt Juszczak wrote: > I know how to: > > 1) recursively pull each Spam folder in existance (for x in `ls > /home/*/mail/Spam`; do ....; done) > 2) Use grep and awk to pull each message and its relative data (grep the > date, parse it) > > What I'm not sure of is how to remove a message from the spool itself. > Should I just use grep and/or sed to "pull until new From header", then > remove those lines from the spool manually? > > This would be easier if I could use IMAP, because then I could use the > built-in PHP functions for imap to check dates and remove messages. > Problem is, we don't know the user's passwords (they are hashed). > > Any other ideas? Thanks! For a similar purpose (removing duplicates from a UNIX mailbox file), I use a temporary procmailrc ruleset with the -D option of formail(1) and save some of the messages of the original mailbox in a temporary file. You can do something similar, but use a properly crafted procmailrc that saves only "new enough" messages. The script I use to remove duplicates from mailboxes is: % #!/bin/sh % % if [ $# -eq 0 ]; then % echo "usage: $(basename $0) file [...]" >&2 % exit 1 % fi % % TMPDIR="${TMPDIR:-/tmp}" % export TMPDIR % % for fname in "$@" ;do % mbox=$(mktemp "${TMPDIR}/$(basename ${fname})-XXXXXX") % filter=$(mktemp "${TMPDIR}/procmailrc-XXXXXX") % msgid=$(mktemp "${TMPDIR}/msgid-XXXXXX") % % if [ X"${mbox}" = X"" ] || [ X"${filter}" = X"" ] || \ % [ X"${msgid}" = X"" ]; then % echo "$(basename $0): error: failed to create temp files." >&2 % exit 1 % fi % % echo "DEFAULT=${mbox}" > "${filter}" && \ % formail -D 32768 "${msgid}" \ % -s procmail "${filter}" < "${fname}" % if [ $? -eq 0 ] && [ -f "${mbox}" ]; then % mv "${mbox}" "${fname}" % echo "ok ${fname}" % fi % /bin/rm -f "${filter}" "${msgid}" % done You can write a similar script to filter any mailbox through any procmail ruleset, as long as you have tested the ruleset and found that it works exactly like you want it to work. - Giorgos