procmail
[Top] [All Lists]

Re: formail -D like option to limit mailbox size

1996-02-10 15:48:00
Mark Bynum asked,

| I subscribe to a freebsd mailing list which gets about a hundred messages
| a day (I have gotten 6 in the last 10 minutes). I was wondering is there
| a way using formail (or some other program) to keep say the last n messages?
| What would happen is that I get a new message and I already have n messages,
| then it will add the current message while removing the first one.

We discussed this at some length about a year ago.  No, formail -D has
nothing to do with it, because we aren't looking for duplicated data.

The procmailex(5) man page has an example for how to handle his if you save
the messages to [individual files in] a directory.  If you save them to a
folder, it's more complicated but still possible.

One major question is whether you are saving new messages to the beginning
or the end of the folder.  Putting the new message at the beginning is harder
than putting it at the end but then it's easier to trim the old messages out.

If you're adding at the end:

  :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
  }

It's analogous if you're putting the new messages at the top:

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

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

    :0fw
    * 1^1 XTRAIN ?? x
    * $ -$MAXLETTERS^0
    * 1^0
    | cat - $FOLDERNAME | formail -$MAXLETTERS -s

  # If your cat does not grok lone hyphens, use
  # | ( cat ; cat $FOLDERNAME ) | formail -${MAXLETTERS}s
    
    :0Efw
    | cat - $FOLDERNAME

  # Again, if your cat does not grok lone hyphens, use
  # | cat ; cat $FOLDERNAME

    :0r
    | cat > $FOLDERNAME
    :0Eh
    /dev/null

    LOCKFILE # just in case of fall-through
  }

<Prev in Thread] Current Thread [Next in Thread>
  • Re: formail -D like option to limit mailbox size, David W. Tamkin <=