procmail
[Top] [All Lists]

Re: Deleting a single e-mail from a mailbox - mbox format

2001-08-11 12:23:25
At 08:29 AM 8/9/2001, Matt Dunford wrote:
* Odhiambo Washington <wash(_at_)wananchi(_dot_)com> [010809 08:03]:
[snip]
Here's an idea.  Very, very, very untested.  Wouldn't it be funny if you
mangled 2k mailboxes?  And you would owe it all to me.. ;-)

#!/bin/bash

SPOOL=/path/to/your/mail/spool
BOXES=`ls $SPOOL`

cd $SPOOL
for mailbox in $BOXES
do
    tmpbox=/tmp/$mailbox
    mv $mailbox $tmpbox
    formail -s procmail -m rcfile <$tmpbox
    rm $tmpbox
done

Well, if you do something like that, there are some things to
watch for (aside from the fact that users may not want you "fixing"
their mail by deleting from it--I know I wouldn't!).

One is locking... unless you can assure the users aren't doing
something with the mail, and turn off mail delivery, there could
be collisions.

It's a small chance, true, but if the system crashes while you're doing
this, somebody's mail is only in /tmp and may get removed on reboot.

The loop should check for failures... if the mv is cross-partition,
running out of space is possible.  Failures are possible in the
middle of the formail deliveries too.

Another thing to watch for are file ownership, group, and permissions.
It looks like those are spool files, not folders, so procmail may well
do the right thing (but you should check).

Finally, if "rcfile" delivers nothing to $mailbox, it should be
recreated with zero size.

The last two paragraphs might be fixed by inserting after:

    mv $mailbox $tmpbox

a few lines like:
        owner=`ls -l $tmpbox | awk '{print $3}'`
        touch $mailbox
        chown $owner $mailbox
        chgrp ... $mailbox
        chmod ... $mailbox
before the formail is run.

Finally, I'd make a directory /oldmailboxes or something,
and change

    rm $tmpbox

to
        mv $tmpbox /oldmailboxes
and keep it around for a while, just in case.


It's the chances of a well-meaning admin not getting it quite right and
screwing up my mail that make me want him to NOT try and fix it.
Perhaps you (i.e., Mr. Washington) should just give your users credit
for being able to delete the mass mails themselves.

Cheers,
Stan

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