Date: Wed, 17 Aug 2005 20:17:22 +0300 From: Giorgos Keramidas <keramida@ceid.upatras.gr> To: Matt Juszczak <matt@atopia.net> Cc: freebsd-questions@freebsd.org Subject: Re: OT: Removal of old 14+ mail from mbox-based mail spool (not maildir) Message-ID: <20050817171722.GB1295@flame.pc> In-Reply-To: <43035EB3.7080300@atopia.net> References: <43034EA2.4000206@atopia.net> <43035504.4020300@daleco.biz> <43035EB3.7080300@atopia.net>
next in thread | previous in thread | raw e-mail | index | archive | help
On 2005-08-17 11:58, Matt Juszczak <matt@atopia.net> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20050817171722.GB1295>
