procmail
[Top] [All Lists]

Re: Counting Messages (was Re: limit messages per box)

1998-07-22 10:50:35
On Wed, 22 Jul 1998, Colin J. Raven wrote:

Where could this statement be inserted? That sounds daft, but I suppose it
would go into the .procmailrc? Also *where* would the echo appear, at the
login prompt? (Pine already announces how many messages reside in the

[As Era points out, you can really get away with just
"grep '^From '", normally.]

Hm.  Depends what you want it to do.  :)

For example, you might have the following in your .procmailrc

--
NUMM=`grep -c '^From ' ${MAIL}`
X=`expr ${NUMM} % 50`

:0
* X ?? ^0
* ! NUMM ?? ^0
LOG="Oh uh!  I've gotten another 50 messages!  I now have ${NUMM}"
--

Of course, that won't work unless you empty all the messages from
your mailbox everytime you empty one message.

Or, for more fun,

--
:0 h
* NUMM ?? ....
* ! ^FROM_DAEMON
* ! ^X-Loop: colin(_at_)raven(_dot_)com
| ( formail -r -A"Precedence: junk" \
        -A"X-Loop: colin(_at_)raven(_dot_)com" ; \
        echo "Sorry, I already have >1000 messages to read" ) | \
        $SENDMAIL -t
--

which is basically copied from procmailex(5).  :)

Or, something which actually has some real usefulness for people
constantly running short on their quota space for mail
(potentially expandning the amount of mail they can store by 4X).

[This incidentally also addresses the original poster who
complained that he was ran low on space whenever he didn't read
messages for ~2 days.]

--
# You may want to lock $MAIL now too, to keep things cleaner.  Of
# course, gzipping-mail.lock becomes redundant, then.
:0
? lockfile -r 0 gzipping-mail.lock
{
        # Must recalc $X and $NUMM (locking issues, again :)
        NUMM=`grep -c '^From ' ${MAIL}`
        X=`expr ${NUMM} % 50`

        :0
        * X ?? ^0
        * ! NUMM ?? ^0
        {
                # Time to gzip our mail...
                :0
                ? lockfile -ml
                | ( gzip -c ${MAIL} > mail.gz.`ls mail.gz.* | wc -l`

                j=`cp /dev/null ${MAIL}`
                j=`lockfile -mu`
        }
        j=`rm -f gzipping-mail.lock`
}
--

Actually, there's no reason you couldn't put all the gzipped mail
into one big .gz file into separate numbered files.  Actually,
the only reason to keep any of the messages ungzipped is merely
for convenience.  For extra fun, write a script that
automatically moves mail back into $MAIL as messages are deleted
from $MAIL.  :)

I'm sure there've been other .procmails posted to the -list that
also gzip mail, and they've probably been tested more, but...

Standard caveats: All untested, don't copy without examing first,
especially that last one, which has more subtle locking than the
others.

If you want it to print how many new messages you have everytime
you login to your shell account, then you would just put the grep
in your .profile or .login, as appropriate.  However, that's no
longer related to procmail.  :)


-- 
This .sig is not innovative, witty, or profund.

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