]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Adding a list of Bounce Ids to the class PostfixLogchainInfo.
authorFrank Brehm <frank.brehm@pixelpark.com>
Wed, 10 Apr 2024 12:24:23 +0000 (14:24 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Wed, 10 Apr 2024 12:24:23 +0000 (14:24 +0200)
lib/pp_admintools/postfix_chain.py
test/test_20_postfix_chain.py

index 861fae7346f1a2aa4943c868b23ee56c8b1aebd4..29a033e68631e6f23567c51438a508eb10d376e4 100644 (file)
@@ -17,6 +17,7 @@ import re
 from collections.abc import Sequence
 
 # Third party modules
+from fb_tools.common import is_sequence
 from fb_tools.common import pp
 from fb_tools.common import timeinterval2delta
 from fb_tools.common import to_bool
@@ -40,7 +41,7 @@ except ImportError:
 _ = XLATOR.gettext
 ngettext = XLATOR.ngettext
 
-__version__ = '0.7.3'
+__version__ = '0.7.4'
 
 LOG = logging.getLogger(__name__)
 
@@ -814,7 +815,7 @@ class PostfixLogchainInfo(FbGenericBaseObject):
     )
 
     # -------------------------------------------------------------------------
-    def __init__(self, smtp_actions=None, **kwargs):
+    def __init__(self, smtp_actions=None, bounce_id=None, **kwargs):
         """Initialize this object."""
         for attr in self.attributes:
             priv_name = '_' + attr
@@ -826,6 +827,10 @@ class PostfixLogchainInfo(FbGenericBaseObject):
         if smtp_actions:
             self.set_smtp_actions(smtp_actions)
 
+        self.bounce_id = []
+        if bounce_id:
+            self.set_bounce_ids(bounce_id)
+
         for attr in kwargs.keys():
             if attr not in self.attributes:
                 msg = _('Unknown parameter {p!r} on calling {c}.__init__().').format(
@@ -835,7 +840,7 @@ class PostfixLogchainInfo(FbGenericBaseObject):
 
     # -------------------------------------------------------------------------
     def set_smtp_actions(self, smtp_actions):
-        """Set the array with all SMTP actions of Postfix  after address resolution."""
+        """Set the array with all SMTP actions of Postfix after address resolution."""
         self.smtp_actions = []
         if smtp_actions is None:
             return
@@ -866,6 +871,33 @@ class PostfixLogchainInfo(FbGenericBaseObject):
             c=action.__class__.__name__, w='SmtpAction', a=action)
         raise TypeError(msg)
 
+    # -------------------------------------------------------------------------
+    def add_bounce_id(self, bounce_id):
+        """Append the given Bounce-Id to the list of Bounce-Ids."""
+        if bounce_id is None:
+            msg = _('You may not append a None value as a Bounce Id.')
+            raise TypeError(msg)
+
+        bid = str(bounce_id).strip()
+        if bid == '':
+            msg = _('You may not append an empty value as a Bounce Id.')
+            raise ValueError(msg)
+
+        self.bounce_id.append(bid)
+
+    # -------------------------------------------------------------------------
+    def set_bounce_ids(self, bounce_ids):
+        """Set the array with all Bounce-Ids."""
+        self.bounce_id = []
+        if bounce_ids is None:
+            return
+
+        if not is_sequence(bounce_ids):
+            bounce_ids = [bounce_ids]
+
+        for bounce_id in bounce_ids:
+            self.add_bounce_id(bounce_id)
+
     # -----------------------------------------------------------
     @property
     def auth(self):
@@ -1483,6 +1515,12 @@ class PostfixLogchainInfo(FbGenericBaseObject):
             for action in self.smtp_actions:
                 res['smtp_actions'].append(action.as_dict(short=short))
 
+        res['bounce_id'] = None
+        if self.bounce_id or not exportable:
+            res['bounce_id'] = []
+            for bounce_id in self.bounce_id:
+                res['bounce_id'].append(bounce_id)
+
         # Non init properties
         if not exportable:
             res['duration'] = self.duration
index 0cef47a3a0b0b230b74fe1bd308e86d3a531bff4..3080f8f80068d60e2e574d0eb96f283bd9f4fbe5 100755 (executable)
@@ -238,6 +238,7 @@ class TestPostfixChain(PpAdminToolsTestcase):
         }
 
         chain = PostfixLogchainInfo(
+            bounce_id='873C9300005D',
             client_host='mail.uhu-banane.de',
             client_addr='188.34.187.246',
             start='2024-03-15T17:24:52.816303+01:00',