From 59c7b8e91b57fef326a0b63efc9f9ad7b0aee855 Mon Sep 17 00:00:00 2001
From: Frank Brehm <frank.brehm@pixelpark.com>
Date: Wed, 20 Mar 2024 18:00:04 +0100
Subject: [PATCH] Adding property mailhost to PostfixLogchainInfo

---
 lib/pp_admintools/postfix_chain.py | 28 +++++++++++++++++++++++++---
 test/test_20_postfix_chain.py      |  1 +
 2 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/lib/pp_admintools/postfix_chain.py b/lib/pp_admintools/postfix_chain.py
index fdb96eb..87036c9 100644
--- a/lib/pp_admintools/postfix_chain.py
+++ b/lib/pp_admintools/postfix_chain.py
@@ -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
diff --git a/test/test_20_postfix_chain.py b/test/test_20_postfix_chain.py
index f814c66..f4f0710 100755
--- a/test/test_20_postfix_chain.py
+++ b/test/test_20_postfix_chain.py
@@ -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))
-- 
2.39.5