From: Frank Brehm Date: Fri, 12 Apr 2024 12:07:00 +0000 (+0200) Subject: Adding property relay_address to class lib/pp_admintools/postfix_chain.py X-Git-Url: https://git.uhu-banane.net/?a=commitdiff_plain;h=f67bd5f751a85fb70589acccd7f6d98d4ba99398;p=pixelpark%2Fpp-admin-tools.git Adding property relay_address to class lib/pp_admintools/postfix_chain.py --- diff --git a/lib/pp_admintools/postfix_chain.py b/lib/pp_admintools/postfix_chain.py index afd07ab..8adee52 100644 --- a/lib/pp_admintools/postfix_chain.py +++ b/lib/pp_admintools/postfix_chain.py @@ -41,7 +41,7 @@ except ImportError: _ = XLATOR.gettext ngettext = XLATOR.ngettext -__version__ = '0.8.3' +__version__ = '0.9.0' LOG = logging.getLogger(__name__) @@ -250,6 +250,8 @@ class DeliverAction(FbGenericBaseObject): re_remote_id = re.compile(pat_remote_id, re.IGNORECASE) + re_relay_address = re.compile(r'\[(?P[^\]]+)\]') + # ------------------------------------------------------------------------- def __init__(self, **kwargs): """Initialize this object.""" @@ -431,6 +433,30 @@ class DeliverAction(FbGenericBaseObject): return self._relay = val + # ----------------------------------------------------------- + @property + def relay_address(self): + """Return the IP address of an existing relay for SMTP.""" + if not self.relay: + return None + + m = self.re_relay_address.search(self.relay) + if not m: + # Did not found IP address in SMTP relay. + return None + + try: + addr = ipaddress.ip_address(m['addr']) + except ValueError as e: + msg = _('Could not interprete relay address {a!r}: {e}').format(a=m['addr'], e=e) + if self.warn_on_parse_error: + LOG.warn(msg) + else: + LOG.debug(msg) + return None + + return addr + # ----------------------------------------------------------- @property def remote_id(self): @@ -717,6 +743,9 @@ class DeliverAction(FbGenericBaseObject): # Catch all res[attrib] = value + if not exportable: + res['relay_address'] = self.relay_address + return res # -------------------------------------------------------------------------