From d2d080350381c4e55d6282782f525ed48c834280 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Wed, 10 Apr 2024 14:24:23 +0200 Subject: [PATCH] Adding a list of Bounce Ids to the class PostfixLogchainInfo. --- lib/pp_admintools/postfix_chain.py | 44 ++++++++++++++++++++++++++++-- test/test_20_postfix_chain.py | 1 + 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/lib/pp_admintools/postfix_chain.py b/lib/pp_admintools/postfix_chain.py index 861fae7..29a033e 100644 --- a/lib/pp_admintools/postfix_chain.py +++ b/lib/pp_admintools/postfix_chain.py @@ -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 diff --git a/test/test_20_postfix_chain.py b/test/test_20_postfix_chain.py index 0cef47a..3080f8f 100755 --- a/test/test_20_postfix_chain.py +++ b/test/test_20_postfix_chain.py @@ -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', -- 2.39.5