procmail
[Top] [All Lists]

Re: quotas and procmail..

1999-07-01 01:14:13
On Wed, 30 Jun 1999 13:58:47 -0500 (CDT), "David W. Tamkin"
<dattier(_at_)Mcs(_dot_)Net> wrote:
Christopher Neill asked,
| anyone know a way to get procmail to spool something off to your home
| directory if you are over your quota? also, can you have procmail
| spool off files that are larger than your quota (eg, can procmail
| check the size of a message?).
The last question is easy to answer: yes. That's how "<" and ">"

(To elaborate:

    :0
    * > 5000000    # or whatever, or * $ > $QUOTA if you have that set anyway
    { EXITCODE=75 HOST }     # 75 is "temporary failure"

The action could of course be anything.)

 :0HB
 * $ -$QUOTA^0
 * $ `wc -c < ${DEFAULT:-$ORGMAIL}`^0
 * 1^1 > 1
 { DEFAULT=$HOME/bigmail }

Yes, wc can read a filename as a positional parameter, but then it repeats
the filename in its output.  That's why the input redirector (and thus a
shell) are needed in the second condition.

Since the size of the file is stored in the file system, perhaps you
could just stat(3) the file. ls(1) does this, of course, but not in a
very useful format (you have to pipe its output into awk or something
so you end up calling a shell anyhow) -- but if you have sls, that
works nicely, or otherwise you could write your own little C or Perl
program.

    :0HB
    * $ -$QUOTA^0
    * $ `sls -p '%s' ${DEFAULT:-$ORGMAIL}`^0
    * 1^1 > 1
    { $DEFAULT=$HOME/bigmail }

(Both wc and sls will produce an error messge if the file you are
trying to check on doesn't exist yet. The $ expansion [duh, that's
something one could easily have omitted from an "off top of head"
recipe, thanks for providing a good example, David!] will then return
^0 which means a number zero at beginning of line, not a scoring
condition ... this should probably be rectified if you are actually
going to use this recipe in a situation where DEFAULT might be set to
a file which doesn't exist, which isn't too usual for run-of-the-mill
mail delivery, but for other little filtering jobs, probably the norm
rather than the exception. Touching the file before this recipe is a
bit inelegant, but then a truly elegant solution might not be
available.)

The hard part is not figuring out whether you are already above quota
(and probably you could write a simple program to tell you that from
the prompt, too), but whether accepting a message would bring you
above quota, and that is something you cannot properly do from within
Procmail (because you could have some other process somewhere adding
to your disk consumption somewhere completely out of the control of
Procmail and any locking scheme). Real proper quota control has to be
done in rather tight cooperation with the kernel, i.e. using the
normal quota facilities.

Dunno where sls came from, originally found it where I work but one
source I was able to locate is a comp.sources.unix posting from 1989:
<ftp://ftp.funet.fi/pub/misc/old-hsu-archive/unsorted/8/sls.shar.gz>
I had trouble compiling this on Linux and SunOS so you might want to
look for a newer version somewhere ... there were FreeBSD package
files for this, but they didn't seem to contain actual sources.)

/* era */

Gack. Why does perl's stat just return a single-element array
containing 1? (And why did I just spend half an hour trying to provide
timing data for something that should be fairly evident, namely that
statting a big file is probably going to be cheaper than counting the
bytes in it. +And+ my timings sucked.)

-- 
.obBotBait: It shouldn't even matter whether     <http://www.iki.fi/era/>
I am a resident of the state of Washington. <http://members.xoom.com/procmail/>
 * Sign the European spam petition! <http://www.politik-digital.de/spam/en/> *

<Prev in Thread] Current Thread [Next in Thread>