procmail
[Top] [All Lists]

Re: force maximum mailbox size limit

2000-11-07 14:22:52
Stuart Clark posted,

| I am interested in testing the size of the mailbox itself, not the incoming 
| message.
| If the mailbox exceeds a certain size (40MB) then an error will be sent and 
| the mailbox will not be appended to.
| 
| My testing.rc file has:
| 
| MAILBOX_=`echo ${LOGNAME} | sed 
| 's/^\(.\)\(.\)\(.*\)$/\/var\/spool\/mail\/\1\/\2\/\1\2\3/'`

If you give sed a different separator, that will be immeasurably more legible:

  MAILBOX_=`echo $LOGNAME | sed 's-^\(.\)\(.\).*-/var/spool/mail/\1/\2/&-`

and in fact we don't have to tell sed to replace the rest of the name with
itself:

  MAILBOX_=`echo $LOGNAME | sed 's-^\(.\)\(.\)-/var/spool/mail/\1/\2/\1\2-`

or we could even do it all within procmail instead of stabbing ourselves with
all those forks:

  :0
  * LOGNAME ?? ^^\/.
  { INITIAL=$MATCH }

  :0
  * LOGNAME ?? ^^.\/.
  { SECOND=$MATCH }
  :0E
  { SECOND=: }

  MAILBOX_=/var/spool/mail/$INITIAL/$SECOND/$LOGNAME

| MAILBOX_SIZE_=`ls -l ${MAILBOX_} | awk '{print $5}'`

Icker, icker.  You're running a shell, ls, and a big binary like awk for
something a shell and wc can do:

  MAILBOX_SIZE_=`wc -c < $MAILBOX_`

or you can even work around the shell call and run only wc:

  MAILBOX_SIZE_REPORT_=`wc -c $MAILBOX_`

  :0
  * MAILBOX_SIZE_REPORT_ ?? ^^ *\/[0-9]+
  { MAILBOX_SIZE_=$MATCH }

| How can I do a conditional test, not on the header or body, but on the 
| variable ${MAILBOX_SIZE_}, then reject the message if ${MAILBOX_SIZE_} is 
| greater than 40000000 bytes?

  :0 # positive difference means box is already bigger than forty million bytes
  * $ $MAILBOX_SIZE_^0
  * -40000000^0
  { rejection routine goes here }

Note that this tests the size of the box without the current message; if the
box has exactly 40000000 bytes and you get any size message in, it will be
accepted.  If you want to test based on the size that the box would be if
the message were added to it, add the size of the current message before
comparing to 40000000:

  :0 # positive difference means box would get bigger than forty million bytes
  * $ $MAILBOX_SIZE_^0
  * 1^1 >1
  * -40000000^0
  { rejection routine goes here }

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