# Third party modules
from fb_tools.common import pp
+from fb_tools.mailaddress import MailAddress
# Own modules
from . import BaseDPXApplication
from ..handler.pflogparse import PostfixLogfileParser
from ..xlate import XLATOR
-__version__ = '0.3.1'
+__version__ = '0.4.0'
LOG = logging.getLogger(__name__)
_ = XLATOR.gettext
default_logdir = Path('/var/log')
default_logfile_pattern = 'maillog*'
+ re_mail_domain = re.compile(r'.*@')
+
local_networks = [
ipaddress.ip_network('10.0.0.0/8'),
ipaddress.ip_network('172.16.0.0/12'),
self.logfile_pattern = self.default_logfile_pattern
self.logfiles = []
+ self.per_domain = {}
+
self.show_address_results = False
desc1 = _(
self._eval_given_logfiles()
else:
self._eval_default_logfiles()
- self._sort_sogfiles()
+ self._sort_logfiles()
# -------------------------------------------------------------------------
def _eval_given_logfiles(self):
LOG.warn(_('File {!r} is not a regular file.').format(str(f)))
# -------------------------------------------------------------------------
- def _sort_sogfiles(self):
+ def _sort_logfiles(self):
if self.verbose > 1:
LOG.debug(_('Sorting logfiles ...'))
for logfile in logfiles_left:
self.logfiles.append(logfile)
+ # -------------------------------------------------------------------------
+ def _collect_results(self):
+
+ self.empty_line()
+ self.debug(_('Collecting results ...'))
+
+ for postfix_id in self.pflogparser.chain:
+
+ chain = self.pflogparser.chain[postfix_id]
+
+ # Did not come from smtpd or pickup
+ if not chain.client_addr and not chain.pickup_from:
+ continue
+
+ # No From-address - Bounce. Forget it
+ if not chain.from_address:
+ continue
+
+ domain = ''
+ if isinstance(chain.from_address, MailAddress):
+ domain = chain.from_address.domain
+ else:
+ domain = self.re_mail_domain.sub('', chain.from_address)
+
+ # No domain found
+ if not domain:
+ continue
+
+ # Client address is not an ipaddress
+ if isinstance(chain.client_addr, ipaddress._BaseAddress):
+ 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
+
+ # Not from our network originating
+ if not local_client:
+ continue
+
# -------------------------------------------------------------------------
def _run(self):