]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Adding property relay_address to class lib/pp_admintools/postfix_chain.py
authorFrank Brehm <frank.brehm@pixelpark.com>
Fri, 12 Apr 2024 12:07:00 +0000 (14:07 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Fri, 12 Apr 2024 12:07:00 +0000 (14:07 +0200)
lib/pp_admintools/postfix_chain.py

index afd07abdce5e840c5f5b085e5b054db135df5e88..8adee525d87ca7f9d424f8820d5f39cdaa651969 100644 (file)
@@ -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<addr>[^\]]+)\]')
+
     # -------------------------------------------------------------------------
     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
 
     # -------------------------------------------------------------------------