from ..handler.pflogparse import PostfixLogfileParser
from ..xlate import XLATOR
-__version__ = '0.4.1'
+__version__ = '0.5.0'
LOG = logging.getLogger(__name__)
_ = XLATOR.gettext
def _collect_results(self):
self.empty_line()
- self.debug(_('Collecting results ...'))
+ LOG.debug(_('Collecting results ...'))
for postfix_id in self.pflogparser.chain:
continue
# Client address is not an ipaddress
- if isinstance(chain.client_addr, ipaddress._BaseAddress):
+ if chain.client_addr:
+ if not isinstance(chain.client_addr, ipaddress._BaseAddress):
+ continue
+
+ if not self._is_local_client(chain):
+ # Not from our network originating
continue
- local_client = False
- if chain.client_addr:
- for net in self.local_networks:
- if chain.client_addr in net:
- local_client = True
- break
-
- if local_client:
- for except_src in self.except_sources:
- if chain.client_addr == except_src:
- local_client = False
- else:
- # from pickup ...
- local_client = True
+ if not self._has_extern_rcpt(chain):
+ # remaining in our network
+ continue
+
+ loghost = chain.host
+
+ if loghost not in self.per_domain:
+ self.per_domain[loghost] = {}
+
+ if domain not in self.per_domain[loghost]:
+ self.per_domain[loghost][domain] = 0
+
+ self.per_domain[loghost][domain] += 1
+
+ # -------------------------------------------------------------------------
+ def _is_local_client(self, chain):
+
+ if not chain.client_addr:
+ # from pickup ...
+ return True
+
+ is_local_client = False
+ for net in self.local_networks:
+ if chain.client_addr in net:
+ is_local_client = True
- # Not from our network originating
- if not local_client:
+ if not is_local_client:
+ return False
+
+ for except_src in self.except_sources:
+ if chain.client_addr == except_src:
+ is_local_client = False
+ break
+
+ return is_local_client
+
+ # -------------------------------------------------------------------------
+ def _has_extern_rcpt(self, chain):
+
+ has_extern_rcpt = False
+
+ for action in chain.deliver_actions:
+ if action.command != 'smtp':
continue
+ relay_address = action.relay_address
+ if not relay_address:
+ continue
+
+ local_rcpt = False
+ for net in self.local_networks:
+ if relay_address in net:
+ local_rcpt = True
+ break
+
+ if not local_rcpt:
+ has_extern_rcpt = True
+ break
+
+ return has_extern_rcpt
+
# -------------------------------------------------------------------------
def _run(self):
self.pflogparser.evaluate_logfiles(self.logfiles)
+ self._collect_results()
+ if self.verbose > 1:
+ LOG.debug(_('Results per domain:') + '\n' + pp(self.per_domain))
+
# =============================================================================
if __name__ == '__main__':