procmail
[Top] [All Lists]

Re: mail assistance please

2001-11-28 12:50:22
At 21:26 2001-11-27 -0500, Michael B. Weiner wrote:

when all i want is to take "mailbox" and split it into X number of smaller mailboxes.

If my mailbox you do mean individual messages, use:

formail -s procmail -m manageable.rc < mailbox

The -s option causes formail to _split_ the mailbox at message boundaries and pass them to procmail, which manually runs a specific rc file.

I hit the procmail list archives (like all good netizens should), which are accessible via a convenient link right on the front page of <http://www.procmail.org/>), and found the following _similar_ ruleset - which is intended to bounce a message back to sender if it _would_ overflow a defined limit. This handily presents all the "tricky" procmail bits you need - everything else is simply managing a file counter.

<http://www.rosat.mpe-garching.mpg.de/mailing-lists/procmail/2001-08/msg00127.html>


manageable.rc would be a script that takes the messages and determines if it will place them in the "current" mailbox, or a new one. I've written this off the hip just now, so pardon if it isn't optimized (from your problem description, this isn't something you're running on your regular incoming mailspool).

Move the mailbox so that it isn't being actively delivered to by some other rules (which would be bad, and if you don't understand why, stop here).

echo 0 > splitmail.count
(to set the initial counter)

Then, run the mailbox through the formail/procmail invocation shown above, using the following as the manageable.rc:

------

# because this ruleset is invoked via the above formail, we don't need to
# worry about concurrent deliveries.  If you ran this as part of a LIVE
# mailspool, additional measures would be necessary.

# uncomment these two lines if you want to examine the actions of this
# ruleset
#LOGFILE=./splitmail.log
#VERBOSE=ON

# max size (or thereabouts) for a mailbox file.
MAXSIZE=250000

# we use an external "counterfile" to hold a numeric we use for
# producing incremental mailbox filenames numbers.
MBOXNO=`cat splitmail.count`

MBOXNAME=splitmail-$MBOXNO

# this ugly bit will return 0 or the mbox size.  This is ONE line.
BOXSIZE=`[ -f $MBOXNAME ] && ls -l $MBOXNAME | while read a b c d e f; do echo $e; done || echo 0`

:0
* $ $MAXSIZE^0
* $ -$BOXSIZE^0
{
        # the boxsize doesn't exceed the max size

        # and doesn't even when the current message is factored into the size.
        :0:
        * < $=
        $MBOXNAME
}

# We got here because the mailbox size either already exceeds the max size,
# or would if we added the current message to it.  So, bump up the mbox
# counter and output the current message to a new mailbox.  If the message
# size exeeds our limit, it still gets saved, but it'll be in a mailbox all
# by itself.

# use expr to do math on the counter.  See 'man expr' (not part of procmail)
MBOXNO=`expr $MBOXNO + 1`

# output the updated counter
:0c
|echo $MBOXNO>splitmail.count

# revise mailbox filename
MBOXNAME=splitmail-$MBOXNO

# and save message.
:0:
$MBOXNAME

------

[snip - I see massive ascii-art .sigs have made a comeback.  Bummer.]

---
 Sean B. Straw / Professional Software Engineering

 Procmail disclaimer: <http://www.professional.org/procmail/disclaimer.html>
 Please DO NOT carbon me on list replies.  I'll get my copy from the list.

_______________________________________________
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>