]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Adding property mailhost to PostfixLogchainInfo
authorFrank Brehm <frank.brehm@pixelpark.com>
Wed, 20 Mar 2024 17:00:04 +0000 (18:00 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Wed, 20 Mar 2024 17:00:04 +0000 (18:00 +0100)
lib/pp_admintools/postfix_chain.py
test/test_20_postfix_chain.py

index fdb96eb64ccac1a3d4276bc1fff1ab905b9f76db..87036c9bf231f248946f9d949ea95a8acf827e22 100644 (file)
@@ -28,7 +28,7 @@ from .xlate import XLATOR
 _ = XLATOR.gettext
 ngettext = XLATOR.ngettext
 
-__version__ = '0.4.2'
+__version__ = '0.5.0'
 
 LOG = logging.getLogger(__name__)
 
@@ -96,6 +96,7 @@ class DataPair(object):
         """Copy the current data pair into a new object."""
         return self.__class__(self.value, total=self.total)
 
+
 # =============================================================================
 class PostfixLogchainInfo(FbGenericBaseObject):
     """A class for encapsulating the information from a chain of Postfix log entries."""
@@ -114,7 +115,8 @@ class PostfixLogchainInfo(FbGenericBaseObject):
     def __init__(
             self, client_host=None, client_addr=None, start=None, end=None, message_id=None,
             postfix_id=None, ehlo=None, starttls=None, sent_quit=None, auth=None, commands=None,
-            rcpt=None, data=None, mail=None, from_address=None, to_address=None, smtpd_pid=None):
+            rcpt=None, data=None, mail=None, from_address=None, to_address=None, smtpd_pid=None,
+            mailhost=None):
         """Initialize this object."""
         self._auth = None
         self._client_addr = None
@@ -133,6 +135,7 @@ class PostfixLogchainInfo(FbGenericBaseObject):
         self._start = None
         self._starttls = None
         self._to_address = None
+        self._mailhost = None
 
         self.auth = auth
         self.client_addr = client_addr
@@ -144,6 +147,7 @@ class PostfixLogchainInfo(FbGenericBaseObject):
         self.from_address = from_address
         self.message_id = message_id
         self.mail = mail
+        self.mailhost = mailhost
         self.postfix_id = postfix_id
         self.rcpt = rcpt
         self.sent_quit = sent_quit
@@ -427,6 +431,24 @@ class PostfixLogchainInfo(FbGenericBaseObject):
         else:
             self._mail = DataPair.from_str(val)
 
+    # -----------------------------------------------------------
+    @property
+    def mailhost(self):
+        """Return the name of the mailhost, from where this logchain is originating."""
+        return self._mailhost
+
+    @mailhost.setter
+    def mailhost(self, value):
+        if value is None:
+            self._mailhost = None
+            return
+
+        val = str(value).strip()
+        if val == '':
+            self._mailhost = None
+            return
+        self._mailhost = val
+
     # -----------------------------------------------------------
     @property
     def message_id(self):
@@ -676,7 +698,7 @@ class PostfixLogchainInfo(FbGenericBaseObject):
         atribs = (
             'client_host', 'client_addr', 'start', 'end', 'message_id', 'postfix_id', 'ehlo',
             'starttls', 'sent_quit', 'auth', 'commands', 'rcpt', 'data', 'mail', 'from_address',
-            'to_address', 'smtpd_pid')
+            'to_address', 'smtpd_pid', 'mailhost')
         for attrib in atribs:
             if not hasattr(self, attrib):
                 continue
index f814c66cdb825581bcb8b37a2794ef4eef19095d..f4f0710ed54cc5a9e6c5f5d6c1830060cdb6b1b4 100755 (executable)
@@ -105,6 +105,7 @@ class TestPostfixChain(PpAdminToolsTestcase):
             from_address='frank.brehm@pixelpark.com',
             to_address='frank@brehm-online.com',
             smtpd_pid='23456',
+            mailhost='prd-mail01.pixelpark.com',
         )
         LOG.debug('PostfixLogchainInfo %r: {!r}'.format(chain))
         LOG.debug('PostfixLogchainInfo %s:\n{}'.format(chain))