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
_ = XLATOR.gettext
ngettext = XLATOR.ngettext
-__version__ = '0.7.3'
+__version__ = '0.7.4'
LOG = logging.getLogger(__name__)
)
# -------------------------------------------------------------------------
- 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
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(
# -------------------------------------------------------------------------
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
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):
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