From 67a0a83a817bf972a23b1bea6cb200d577815dfa Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Sun, 27 Mar 2022 15:25:49 +0200 Subject: [PATCH] Adding evaluating of from address in lib/pp_admintools/mail_config.py --- lib/pp_admintools/mail_config.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/pp_admintools/mail_config.py b/lib/pp_admintools/mail_config.py index eb9e69d..10c011e 100644 --- a/lib/pp_admintools/mail_config.py +++ b/lib/pp_admintools/mail_config.py @@ -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): -- 2.39.5