procmail
[Top] [All Lists]

Re: Re-filtering....

2001-01-08 15:38:57
Bennett Todd <bet(_at_)rahul(_dot_)net> writes:
Re-filtering email is easy. Just move the mail you want to refilter
aside --- so the input to this process is no longer a possible
output destination of procmail --- then pipe the messages one at a
time into procmail.

With mbox format, you can pipe the old (moved) mbox through
"formail -s procmail"; for Maildir format you can hit the Maildir
with "find . -type f|xargs -l procmail". Once you're satisfied with
how the messages have been re-filed, you can delete the moved-aside
copy.

Whoops, you just tried to use each message as an rcfile!  The other
problem with the find command is that there can be non-message files in
the top maildir directory (the qmail pop daemon uses a couple, I think).

Instead, I would recommend a shell script, ala:

        #!/bin/sh

        maildir=$1

        if test ! -d $maildir ||
           test ! -d $maildir/new ||
           test ! -d $maildir/cur
        then
            echo "$0: $maildir doesn't appear to be a maildir mailbox" >&2
            exit 1
        fi

        cd $maildir

        # A unique looking suffix to avoid problem if you accidentially
        # run two copies of this script at the same time
        suffix=`uname -n`.$$

        if test -e "new.$suffix" || test -e "cur.$suffix"
        then
            echo "$0: collision generating a unique name!  Help!" >&2
            exit 2
        fi

        # Move the current subdirs out of the way and create new ones
        # Ignore mkdir errors in case some other process 
        mv new "new.$suffix"
        mv cur "cur.$suffix"
        mkdir new old 2>/dev/null

        for file in "new.$suffix"/* "cur.$suffix"/*
        do
                test -f "$file" || continue
                procmail < "$file"
        done

        rm -rf "new.$suffix" "cur.$suffix"



PS. I would be grateful for an idea of client-independent purging of
mailboxes, let's say, messages older than 14 days would be deleted....

For Maildir, that's awfully easy:

      find maildir-name -type f -mtime +14|perl -lne unlink


find maildir-name/new maildir-name/cur -type f -mtime +14 -print0 |
        perl -n0e unlink

If your find command has the -maxdepth option (GNU, BSD) then I would
suggest adding "-maxdepth 1" to the find command, just in case someone
creates a meaning for subdirectories of maildir/new or maildir/cur.


Philip Guenther
Procmail Maintainer
_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

<Prev in Thread] Current Thread [Next in Thread>