From fdc3a4ec2cb8e88d5a0664209daaafd1994fbf6e Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Wed, 10 Apr 2024 16:47:36 +0200 Subject: [PATCH] Evaluating info about picked up mails --- lib/pp_admintools/handler/pflogparse.py | 19 +++++++++- lib/pp_admintools/postfix_chain.py | 49 ++++++++++++++++++++++++- 2 files changed, 65 insertions(+), 3 deletions(-) diff --git a/lib/pp_admintools/handler/pflogparse.py b/lib/pp_admintools/handler/pflogparse.py index bd6bf40..5f13b7b 100644 --- a/lib/pp_admintools/handler/pflogparse.py +++ b/lib/pp_admintools/handler/pflogparse.py @@ -28,7 +28,7 @@ LOG = logging.getLogger(__name__) _ = XLATOR.gettext ngettext = XLATOR.ngettext -__version__ = '0.5.0' +__version__ = '0.5.1' # ============================================================================= @@ -72,6 +72,8 @@ class PostfixLogfileParser(HandlingObject): r'DKIM-Signature\s+field\s+added\s+\(s=(?P\S+), d=(?P\S+)\)', re.IGNORECASE) + re_pickup = re.compile(r'uid=(?P\d+)\s+from=<(?P[^>]*)>', re.IGNORECASE) + warn_on_parse_error = True deliver_commands = ( @@ -343,6 +345,21 @@ class PostfixLogfileParser(HandlingObject): LOG.debug(msg) return + if command == 'postfix/cleanup': + m = self.re_pickup.search(message) + if m: + if postfix_id in self.chain: + self.chain[postfix_id].pickup_from = m['from'] + self.chain[postfix_id].pickup_uid = m['uid'] + else: + msg = _('Did not found Postfix ID {!r} for pickup log entry.').format( + postfix_id) + if self.warn_on_parse_error: + LOG.warn(msg) + else: + LOG.debug(msg) + return + if command == 'opendkim': m = self.re_dkim.search(message) if m: diff --git a/lib/pp_admintools/postfix_chain.py b/lib/pp_admintools/postfix_chain.py index 8b67a78..ebb0a1a 100644 --- a/lib/pp_admintools/postfix_chain.py +++ b/lib/pp_admintools/postfix_chain.py @@ -41,7 +41,7 @@ except ImportError: _ = XLATOR.gettext ngettext = XLATOR.ngettext -__version__ = '0.8.0' +__version__ = '0.8.1' LOG = logging.getLogger(__name__) @@ -831,7 +831,7 @@ class PostfixLogchainInfo(FbGenericBaseObject): 'client_host', 'client_addr', 'start', 'end', 'message_id', 'postfix_id', 'ehlo', 'starttls', 'sent_quit', 'auth', 'commands', 'rcpt', 'data', 'mail', 'from_address', 'smtpd_pid', 'mailhost', 'tls_version', 'tls_cipher', 'size', 'nr_rcpt', 'finished', - 'dkim_selector', 'dkim_domain', + 'dkim_selector', 'dkim_domain', 'pickup_uid', 'pickup_from', ) # ------------------------------------------------------------------------- @@ -1250,6 +1250,51 @@ class PostfixLogchainInfo(FbGenericBaseObject): return self._message_id = val + # ----------------------------------------------------------- + @property + def pickup_from(self): + """Return the From address of a picked up mail, which was sended via sendmail.""" + return self._pickup_from + + @pickup_from.setter + def pickup_from(self, value): + if value is None: + self._pickup_from = None + return + + val = str(value).strip() + if val == '': + self._pickup_from = None + return + self._pickup_from = val + + # ----------------------------------------------------------- + @property + def pickup_uid(self): + """Return the numeric Uid of the process, which was sending a mail via sendmail..""" + return self._pickup_uid + + @pickup_uid.setter + def pickup_uid(self, value): + if value is None: + self._pickup_uid = None + return + + if isinstance(value, int): + self._pickup_uid = value + return + try: + val = int(value) + self._pickup_uid = val + except ValueError as e: + msg = _('Could not interprete the Uid of a picked up mail {a!r}: {e}').format( + a=val, e=e) + if self.warn_on_parse_error: + LOG.warn(msg) + else: + LOG.debug(msg) + self._pickup_uid = None + # ----------------------------------------------------------- @property def postfix_id(self): -- 2.39.5