ispcomm Wrote:I missed something: When external mail arrives for a forwarded account do you count the size * 2 ? That is... 1MB arrives and 1MB leaves to the forwarded account. 2MB total for this email should be added to the domain.
This is the Test case 4 example. Final count is mail_size * 2 so it's ok with my last patch.
ispcomm Wrote:I'll try to propose a simpler solution for amavis-on case. It assumes that deliveries to amavis will be on consecutive lines (probably true 99% of the time):
This may work, I don't really know if this is true 99% of the time or just 80% or whatever though.
ispcomm Wrote:-) Count all deliveries to 127.0.0.1, but skip consecutive lines of the same value (i.e. the multiple recipients of the same mail).
Hmm... just piping the awk's output through "uniq" may work here
ispcomm Wrote:-) Ignore all virtuals (they were accounted for on step 1).
Last patch version does just this (only if amavis is on, of course).
ispcomm Wrote:-) Count all other SMTP traffic, mapping every destination address to the domain that forwarded it.
Outgoing (forwarded) deliveries have no info about the original recipient, as in test case 4 (second smtp):
Code:
2008-06-19 08:17:35 me@external.dmn redir@dmn.tld test.server.tld 127.0.0.1 SMTP - 1 778303
2008-06-19 08:17:35 me@external.dmn me@external.dmn test.server.tld mx.external.dmn SMTP - 1 778674
There is no easy way of reverse-mapping "me@external.dmn" to "redir@dmn.tld" (it may seem easy here, but there could be some more deliveries between those lines). We would probably need to modify maillogconvert in order to do it...
ispcomm Wrote:Another issue: What happens when a delivery is deferred?
Deferred deliveries are filtered out by maillogconvert. As my current approach doesn't use any context info (no "same as last line" nor reverse-mappings or queue id tracking), the traffic will be properly accounted when the delivery is done correctly. The only problem in this regard is that incoming traffic may never be accounted if a mail sent to a forwarded address is undeliverable, but it's not a common case (why would someone redirect an account they own to one that doesn't work?).
Actually, my solution isn't that complicated. The relevant logic lies on those lines (virtual deliveries are stripped out before by awk, so both solutions would be the same in this regard):
Code:
+ if ((!exists $main::smtp_traffic{$smtp_from_domain}) && (!exists $main::smtp_traffic{$smtp_to_domain})) {
+ next;
+ }
+ if (exists($forwarders_table{$smtp_to_mail})) {
+ $extra_size = $traffic_size / $forwarders_table{$smtp_to_mail};
+ $main::smtp_traffic{$smtp_to_domain} += $extra_size;
+ }
So 7 lines of logic that may be further reduced to 6 (I only use $external_size var to debug, it should be removed in a final version patch). Could you implement the reverse-mapping that easily?