procmail
[Top] [All Lists]

Re: counting message size from two different relays - solution ?

2004-02-27 09:53:50


Professional Software Engineering wrote:

At 18:18 2004-02-25 +0100, Michael Meltzer wrote:
[big-ole-snip - the list is archived]

FTR, speaking in general terms instead of providing concrete examples of
headers (particularly, the topmost Received: header, which is most
applicable to your query) makes it that much more difficult to compose an
accurate recipe for your specfic situation.

On my mailserver I get mail for two domains. The MX record for the first
domain points to my mailserver. The MX record for the second domain points
to a mail relay.

Which uhm, must relay it to you if you have a prayer of seeing it with
procmail on this host, so that host should be in your regexp.

Your script works fine for the latter situation but not for the former one.

Translation: every message which _isn't_ from that specific relay.  That
could be done by breaking the hostname determination out to a separate
recipe, and using an ELSE recipe after that to define a default hostname to
show for regular message.  Using my second recipe as a basis:

# you might rather anchor the second condition to the beginning of the
# variable, or prefix the match operator with a word delimiter regexp if you
# want to match multiple hosts at a given domain)
:0
* ^Received: from \/[^  ]*
* MATCH ?? ()\/(server\.tld|server2\.tld|local_host_name\.tld)
{
         RELAYHOST=$MATCH
}

# this executes only if the above did not
:0E
{
         RELAYHOST="outside mailer"
}

# Apparently, we're supposed to count the bytes on ALL messages.  Yuck.
:0
* 1^1 H ?? > 1
* 1^1 B ?? > 1
{
         PM_SCORE=$=
         IGNORE=`echo "  Folder: $RELAYHOST      $PM_SCORE" >> stats.log`
}

Grepping your mail log may prove to be a lot less process intensive in the
long run, as the message sizes and relay hosts are simply recorded in the
entries there, and I somehow doubt you really need realtime access to these
stats.

On the mailserver there is also the internal traffic which I don't want to
count or which should be summarized also separately.

Sounds like fun  Those should have the local host entry for the topmost
Received: header, so just add that to your regexp check (as I've done above).

BTW, you're aware of the sendmail program "mailstats" ?

Finally I want to summarize the size of mails comming from the mail relay
and the size of mails coming from outside directly to my server each in a
separate sum.

I think you get to deal with some of this job, or perhaps someone else here
can do this part for you.  I've got that miserable thing called "eeking out
a living" to go contend with.


Thanks for your help and sorry for the long delay.
I think I have a solution now based on your concept and according to my 
knowledge of procmail
made only a few tests.
contrary to the subject line there is one mail relay and one Mailserver and two 
domains as I posted in my last message.
maybe someone will use this or post a better solution.
that's what I have now in my /etc/procmailrc:

PATH=/usr/bin:/usr/sbin:/bin:/usr/ucb:/usr/local/procmail/bin
LOGFILE=$HOME/procmail.log
MAILDIR=/var/mail  # You'd better make sure it exists
#
# get senders domain
:0 w
{ FROMDOM=`formail -rtzxTo: | /usr/bin/sed -e 's/^.*@//'` }
:0
* FROMDOM ?? (domain1|domain2)\.de
   {
     # mail comes from intranet
     RELAYHOST=LOCAL
   }
#
:0
* ^Received: from \/[^  ]*
* MATCH ?? ()\/mailrelay\.de
{
        # Mail comes from mailrelay (addressed to the second domain)
         RELAYHOST=$MATCH
}

:0
* RELAYHOST ?? ^^^^
{
         # mail comes directly from internet to my mailserver (addressed to the 
second domain)
         RELAYHOST="extern"
}

# Apparently, we're supposed to count the bytes on ALL messages.  Yuck.
:0
* 1^1 H ?? > 1
* 1^1 B ?? > 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: $RELAYHOST      $PM_SCORE" >> 
/var/log/stats.log`
}

Michael

--
+-- Michael Meltzer -------------+-----------------------------------------+
|   AED-SICAD Aktiengesellschaft |   EMail : 
Michael(_dot_)Meltzer(_at_)aed-sicad(_dot_)de  |
|   Lilienthal-Str. 7            |   Phone : +49-89-45026-108              |
|   85579 Neubiberg              |   Fax   : +49-89-45026-113              |
+--------------------------------+-----------------------------------------+




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

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