#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
+@summary: A module for providing a configuration for applications, which are sending mails.
+
@author: Frank Brehm
@contact: frank.brehm@pixelpark.com
@copyright: © 2023 by Frank Brehm, Berlin
-@summary: A module for providing a configuration for applications,
- which are sending mails
"""
from __future__ import absolute_import
# Standard module
+import copy
import logging
import re
-import copy
# Third party modules
-
-# Own modules
-
+from fb_tools import MailAddress
from fb_tools.common import is_sequence, to_bool
-
from fb_tools.multi_config import DEFAULT_ENCODING
-from fb_tools import MailAddress
-
+# Own modules
+from . import PpBaseConfiguration
+from . import PpConfigurationError
+from .. import DEFAULT_CONFIG_DIR
+from .. import MAX_PORT_NUMBER
from .. import __version__ as GLOBAL_VERSION
-from .. import MAX_PORT_NUMBER, DEFAULT_CONFIG_DIR
from .. import pp
-
-from . import PpConfigurationError, PpBaseConfiguration
-
from ..xlate import XLATOR
-__version__ = '0.2.4'
+__version__ = '0.2.5'
LOG = logging.getLogger(__name__)
_ = XLATOR.gettext
# =============================================================================
class MailConfigError(PpConfigurationError):
- """Base error class for all exceptions happened during
- execution this configured application"""
+ """Base error class for all exceptions happened during execution a configured application."""
pass
# =============================================================================
class MailConfiguration(PpBaseConfiguration):
- """
- A class for providing a configuration for an arbitrary PowerDNS Application
- and methods to read it from configuration files.
- """
+ """A class for providing a configuration for applications, which are sending mails."""
whitespace_re = re.compile(r'(?:[,;]+|\s*[,;]*\s+)+')
append_appname_to_stems=True, additional_stems=None, config_dir=DEFAULT_CONFIG_DIR,
additional_config_file=None, additional_cfgdirs=None, encoding=DEFAULT_ENCODING,
ensure_privacy=False, raise_on_error=True, use_chardet=True, initialized=False):
-
+ """Initialize the MailConfiguration object."""
add_stems = []
if additional_stems:
if is_sequence(additional_stems):
raise_on_error=raise_on_error, ensure_privacy=ensure_privacy, initialized=False,
)
- self.xmailer = "{a} (Admin Tools version {v})".format(
+ self.xmailer = '{a} (Admin Tools version {v})'.format(
a=self.appname, v=GLOBAL_VERSION)
if initialized:
# -----------------------------------------------------------
@property
def mail_cc_configured(self):
- """Should there be used LDAPS for communicating with the LDAP server?"""
+ """Return, whether cc addresses are configured."""
return self._mail_cc_configured
@mail_cc_configured.setter
# -------------------------------------------------------------------------
def as_dict(self, short=True):
"""
- Transforms the elements of the object into a dict
+ Transform the elements of the object into a dict.
@param short: don't include local properties in resulting dict.
@type short: bool
@return: structure as dict
@rtype: dict
"""
-
res = super(MailConfiguration, self).as_dict(short=short)
res['mail_cc_configured'] = self.mail_cc_configured
return res
# -------------------------------------------------------------------------
- def eval(self):
-
+ def eval(self): # noqa: A003
+ """Evaluate read configuration and storing it in object properties."""
super(MailConfiguration, self).eval()
if not self.mail_recipients:
# -------------------------------------------------------------------------
def eval_section(self, section_name):
-
+ """Evaluate a particular configuration section."""
super(MailConfiguration, self).eval_section(section_name)
sn = section_name.lower()
def _eval_mail(self, section_name, section):
if self.verbose > 2:
- msg = _("Evaluating config section {!r}:").format(section_name)
+ msg = _('Evaluating config section {!r}:').format(section_name)
LOG.debug(msg + '\n' + pp(section))
self._eval_mail_from(section_name, section)
if MailAddress.valid_address(token):
result.append(token)
else:
- msg = _("Found invalid {what} {addr!r} in configuration.")
+ msg = _('Found invalid {what} {addr!r} in configuration.')
LOG.error(msg.format(what=what, addr=token))
return result
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))
+ 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):
continue
if is_sequence(val):
for v in val:
- result = self._split_mailaddress_tokens(v, _("recipient mail address"))
+ result = self._split_mailaddress_tokens(v, _('recipient mail address'))
if result:
self.mail_recipients += result
else:
- result = self._split_mailaddress_tokens(val, _("recipient mail address"))
+ result = self._split_mailaddress_tokens(val, _('recipient mail address'))
if result:
self.mail_recipients += result
continue
if is_sequence(val):
for v in val:
- result = self._split_mailaddress_tokens(v, _("cc mail address"))
+ result = self._split_mailaddress_tokens(v, _('cc mail address'))
if result:
self.mail_cc += result
else:
- result = self._split_mailaddress_tokens(val, _("cc mail address"))
+ result = self._split_mailaddress_tokens(val, _('cc mail address'))
if result:
self.mail_cc += result
if MailAddress.valid_address(val):
self.reply_to = val
else:
- msg = _("Found invalid {what} {addr!r} in configuration.")
- LOG.error(msg.format(what=_("reply to address"), addr=val))
+ msg = _('Found invalid {what} {addr!r} in configuration.')
+ LOG.error(msg.format(what=_('reply to address'), addr=val))
# -------------------------------------------------------------------------
def _eval_mail_method(self, section_name, section):
continue
if val not in self.valid_mail_methods:
- msg = _("Found invalid mail method {!r} in configuration.")
+ msg = _('Found invalid mail method {!r} in configuration.')
LOG.error(msg.format(section[key]))
continue
try:
port = int(val)
except (ValueError, TypeError) as e:
- msg = _("Value {!r} for SMTP port is invalid:").format(val)
+ msg = _('Value {!r} for SMTP port is invalid:').format(val)
msg += ' ' + str(e)
LOG.error(msg)
continue
if port <= 0 or port > MAX_PORT_NUMBER:
- msg = _("Found invalid SMTP port number {} in configuration.").format(port)
+ msg = _('Found invalid SMTP port number {} in configuration.').format(port)
LOG.error(msg)
continue
# =============================================================================
-if __name__ == "__main__":
+if __name__ == '__main__':
pass