From: Frank Brehm Date: Sun, 27 Mar 2022 13:25:49 +0000 (+0200) Subject: Adding evaluating of from address in lib/pp_admintools/mail_config.py X-Git-Tag: 0.4.1^2~36 X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=67a0a83a817bf972a23b1bea6cb200d577815dfa;p=pixelpark%2Fpp-admin-tools.git Adding evaluating of from address in lib/pp_admintools/mail_config.py --- 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):