procmail
[Top] [All Lists]

Re: rotate mailbox based on size?

2003-12-28 20:05:10
Nuno had asked,

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

Gary replied,

Might be difficult to do in procmail, directly.

If you consider any fork of any other program to be doing it indirectly, then it's impossible to do "directly" by that interpretation. But it can be triggered by procmail without use of cron.

If $SHELL is something sh-compatible and not csh-ish,

TRAP='case "$LASTFOLDER" in
*freebsd*) if test `wc -c < "$LASTFOLDER"` -ge 1048576
 then lockfile "$LASTFOLDER$LOCKEXT"
  mv -f "$LASTFOLDER" "$LASTFOLDER.old"
  rm -f "$LASTFOLDER$LOCKEXT"
 fi ;;
esac'

Just hope that the particular folder doesn't get flooded, or you'll be filling up those one-meg boxes very fast and clobbering old ones before you get to read them. You might want to come up with a naming system based on date and time so that you won't lose old mail too soon.

Since it is tested once per message, you won't have the problem of cutting in the middle of a message.

Now, that rotates when a mailbox reaches or exceeds one megabyte; if you want to keep them from going over one meg, you have to test the total size of the existing folder plus the pending message before storing it there. So we check for that before delivery, not afterward with TRAP:

 :0
 * condition[s] to establish that this is a message from a freebsd list
 * additional condition[s] to extract $MATCH if not already determined
 {
  LOCKFILE="$MATCH$LOCKEXT" # needs regional lockfile

  :0ic # size of this message + size folder already is > 1 MB?
  * 1^1 HB ??  > 1
  * $ `wc -c < "$MATCH"`^0
  * -1048576
  | mv -f "$MATCH" "$MATCH.old"

  :0 # regional lockfile is in effect
  "$MATCH"

  LOCKFILE # in case of fall-through
 }


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