]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Evaluating info about picked up mails
authorFrank Brehm <frank.brehm@pixelpark.com>
Wed, 10 Apr 2024 14:47:36 +0000 (16:47 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Wed, 10 Apr 2024 14:47:36 +0000 (16:47 +0200)
lib/pp_admintools/handler/pflogparse.py
lib/pp_admintools/postfix_chain.py

index bd6bf400a5eae2c0aebbdd5d3e5f937349725b98..5f13b7be0425b5a64905b9717c9726499b0b4788 100644 (file)
@@ -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<selector>\S+), d=(?P<domain>\S+)\)',
         re.IGNORECASE)
 
+    re_pickup = re.compile(r'uid=(?P<uid>\d+)\s+from=<(?P<from>[^>]*)>', 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:
index 8b67a78d2fcd6ea1276636a55eb8ea86e96e9297..ebb0a1a917c7dabc9cb2017b9d03525b0edc08bc 100644 (file)
@@ -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):