procmail
[Top] [All Lists]

RE: rotate mailbox based on size?

2003-12-28 19:11:20


-----Original Message-----
From: procmail-bounces(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
[mailto:procmail-bounces(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE]On Behalf Of 
Nuno Teixeira
Sent: Sunday, December 28, 2003 12:50 PM
To: procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
Subject: rotate mailbox based on size?



Hello to all,

I am searching for recipe that can rotate a mailbox based on mailbox
size. This is good to mailing lists.

Supose that I want to establish a limit of 1MB for each freebsd list
mailbox, and then rotate each ${MATCH} to ${MATCH}.old.


Might be difficult to do in procmail, directly. I do this sort of thing
in a daily cronjob. The main part of the (tcsh) script looks like this:

set maxmsgs=200
foreach f (*-mail)
    set lockfile = ${f}.lock
    lockfile -s 10 -r 6 $lockfile
    if ($status != 0) continue
    set nmsgs = `formail -X 'From ' -s < $f | wc -l`
    if ($nmsgs > $maxmsgs) then
        set arc = archive/${f}
        if (-e $arc) echo "" >> $arc
        @ cnt = $nmsgs - $minmsgs
        formail -$cnt -s < $f >> $arc
        formail +$cnt -s < $f > ${f}.tmp
        touch -r ${f} ${f}.tmp
        mv -f ${f}.tmp ${f}
        chmod 600 ${f} $arc
    endif
    rm -f $lockfile
end

This uses a maximum message limit rather than file size limit, because
ultimately
you'll want to make sure that you pare down the mailboxes in way that you
truncate
the mailbox at a message boundary. If you wanted to enforce a particular
file
size then you could try the following.

set max_file_size=1000000
set maxmsgs=`head --bytes=$max_file_size $f | formail -X 'From ' -s | wc -l`



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