procmail
[Top] [All Lists]

Re: formail -D like option to limit mailbox size

1996-03-15 08:15:34
David wrote this recipe about a month ago for limiting a mailbox size, i.e.
removing messages if the mailbox is over some size. After studying it
at length I have several questions, interspersed through the recipe.

  :0
  * conditions
  { FOLDERNAME=wherever
    LOCKFILE=$FOLDERNAME.lock # needs regional lockfile
    MAXLETTERS=put_your_number_here

    :0c
    $FOLDERNAME

Everything is understandable up to here.

  # XTRAIN includes the incoming letter:
    XTRAIN=`formail -I'From x' -z -x'From ' -s < $FOLDERNAME`

What I believe the above line does is insert a "From x" header into each
message, and then extract what is after the "From " (which is x) from
each message and put all of them in XTRAIN. In effect, this counts
the number of messages in the mailbox. Is this right?

    :0hicw

Why do we generate a carbon copy here, this is the only recipe that
we want this message to operate on. Also why do we wait for the exitcode
of the command, it seems we don't do anything with it?

    * 1^1 XTRAIN ?? x
    * $ -$MAXLETTERS^0
    { EXCESS = $=

I am going to make EXCESS a static number, say 50, where MAXLETTERS is 75.
This will hopefully not tax the mail server as much, such as for every
message over 75.

What I believe the lines above did is generate a score of how many x's are
in XTRAIN (i.e. how many messages are in FOLDERNAME), subtract MAXLETTERS
from it, then if positive do what is inside the braces.


      :0fwi
      | formail +$EXCESS -s < $FOLDERNAME

This skips EXCESS messages from FOLDERNAME. Why not only feed the header
to the pipe, wouldn't this help because we don't do anything with the
input coming from procmail? We don't need the whole message right?

      
      :0r
      | cat > $FOLDERNAME
    }

We have the r flag, because formail already made sure the mail ends with an
empty line.


    :0h
    /dev/null

I have no idea why this is here. The processing is done, correct?


    LOCKFILE # just in case of fall-through
  }


Here is the recipe again if you want to see it in unedited form:


  :0
  * conditions
  { FOLDERNAME=wherever
    LOCKFILE=$FOLDERNAME.lock # needs regional lockfile
    MAXLETTERS=put_your_number_here

    :0c
    $FOLDERNAME

  # XTRAIN includes the incoming letter:
    XTRAIN=`formail -I'From x' -z -x'From ' -s < $FOLDERNAME`

    :0hicw
    * 1^1 XTRAIN ?? x
    * $ -$MAXLETTERS^0
    { EXCESS = $=

      :0fwi
      | formail +$EXCESS -s < $FOLDERNAME
      
      :0r
      | cat > $FOLDERNAME
    }

    :0h
    /dev/null

    LOCKFILE # just in case of fall-through
  }


Thanks for any help.

Mark Bynum
bynum(_at_)cs(_dot_)fsu(_dot_)edu

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