procmail
[Top] [All Lists]

Re: counting message size from two different relays

2004-02-24 09:02:46
At 13:46 2004-02-24 +0100, Michael Meltzer wrote:
We get our mails for the company from two different mail relays.
How can I count the incoming message size for each mail relay separately ?

Probably the best way would simply be to write a script to parse the (SMTP) mail log file. Procmail is only going to see the messages which are for local delivery, and even then, there's aliases which deliver to files or forward, as well as users running a .forward which will bypass the /etc/procmailrc (which is the logical location to implement a procmail-based message size filter).


If you keep those (IMO, significant) issues in mind, then the following may be workable:

[/etc/procmailrc]

# modify relay expression accordingly
# non-delivery recipe, so no 'c'opy necessary
# note that counting bytes isn't particularly efficient, but if you want to
# do that, it's probably a lot more so than writing a copy of the data to
# get the logabstract associated with the relay
:0
* ^Received: from \/(first_relay|second_relay)
* 1^1 B ?? > 1
* 1^1 H ?? > 1
{
        # assignment to a named variable is necessary because scored variable
        # doesn't survive to shell.
        PM_SCORE=$=
        # Two spaces at beginning, and a TAB between $MATCH and $PM_SCORE
        IGNORE=`echo "  Folder: $MATCH  $PM_SCORE" >> stats.log
}

This will produce a log excerpt in the same format that "mailstat" parses for, which means that you can take that stats.log and process it:

        mailstat < stats.log

Go ahead and try this with some saved messages (try it in a sandbox -- see my .sig)

---
 Sean B. Straw / Professional Software Engineering

 Procmail disclaimer: <http://www.professional.org/procmail/disclaimer.html>
 Please DO NOT carbon me on list replies.  I'll get my copy from the list.


_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail