]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Adding evaluating of from address in lib/pp_admintools/mail_config.py
authorFrank Brehm <frank@brehm-online.com>
Sun, 27 Mar 2022 13:25:49 +0000 (15:25 +0200)
committerFrank Brehm <frank@brehm-online.com>
Sun, 27 Mar 2022 13:25:49 +0000 (15:25 +0200)
lib/pp_admintools/mail_config.py

index eb9e69dc33a20c89aac1f634f5b027fef0d32237..10c011edfe2644169b49a3d95f00569348936129 100644 (file)
@@ -31,7 +31,7 @@ from .mailaddress import MailAddress
 
 from .xlate import XLATOR
 
-__version__ = '0.1.1'
+__version__ = '0.1.2'
 LOG = logging.getLogger(__name__)
 
 _ = XLATOR.gettext
@@ -169,6 +169,7 @@ class MailConfiguration(BaseMultiConfig):
             msg = _("Evaluating config section {!r}:").format(section_name)
             LOG.debug(msg + '\n' + pp(section))
 
+        self._eval_mail_from(section_name, section)
         self._eval_mail_rcpt(section_name, section)
         self._eval_mail_cc(section_name, section)
         self._eval_mail_reply_to(section_name, section)
@@ -191,6 +192,28 @@ class MailConfiguration(BaseMultiConfig):
 
         return result
 
+    # -------------------------------------------------------------------------
+    def _eval_mail_from(self, section_name, section):
+
+        re_from = re.compile(r'^\s*(mail[_-]?)?from\s*$', re.IGNORECASE)
+
+        for key in section.keys():
+            if not re_from.search(key):
+                continue
+
+            val = section[key]
+
+            if is_sequence(val):
+                if not len(val):
+                    continue
+                val = val[0]
+
+            if MailAddress.valid_address(val):
+                self.mail_from = val
+            else:
+                msg = _("Found invalid {what} {addr!r} in configuration.")
+                LOG.error(msg.format(what=_("from address"), addr=val))
+
     # -------------------------------------------------------------------------
     def _eval_mail_rcpt(self, section_name, section):