From 9959c6a51f89e42b228e1cc1c87472d03a09693a Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Thu, 31 Mar 2022 12:16:24 +0200 Subject: [PATCH] Bugfixing --- lib/pp_admintools/mail_app.py | 23 ++++++++++++++++------- lib/pp_admintools/mail_config.py | 15 ++++++++++----- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/lib/pp_admintools/mail_app.py b/lib/pp_admintools/mail_app.py index a7fdb0e..0af08bf 100644 --- a/lib/pp_admintools/mail_app.py +++ b/lib/pp_admintools/mail_app.py @@ -41,7 +41,7 @@ from .mail_config import VALID_MAIL_METHODS from .mailaddress import MailAddress -__version__ = '0.2.3' +__version__ = '0.2.4' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -202,12 +202,23 @@ class BaseMailApplication(FbConfigApplication): mail_group = self.arg_parser.add_argument_group(_('Mailing options')) + mail_from = MailConfiguration.default_mail_from_complete + mail_method = MailConfiguration.default_mail_method + mail_server = MailConfiguration.default_mail_server + smtp_port = MailConfiguration.default_smtp_port + + if self.cfg: + mail_from = self.cfg.mail_from + mail_method = self.cfg.mail_method + mail_server = self.cfg.mail_server + smtp_port = self.cfg.smtp_port + mail_group.add_argument( '--from', '--mail-from', metavar=_("ADDRESS"), dest="mail_from", help=_( "Sender mail address for mails generated by this script. " - "Default: {!r}").format(self.cfg.mail_from), + "Default: {!r}").format(mail_from), ) mail_group.add_argument( @@ -235,7 +246,7 @@ class BaseMailApplication(FbConfigApplication): help=_( "Method for sending the mails generated by this script. " "Valid values: {v}, default: {d!r}.").format( - v=method_list, d=self.cfg.mail_method) + v=method_list, d=mail_method) ) mail_group.add_argument( @@ -243,8 +254,7 @@ class BaseMailApplication(FbConfigApplication): metavar=_("SERVER"), dest="mail_server", help=_( "Mail server for submitting generated by this script if " - "the mail method of this script is 'smtp'. Default: {!r}.").format( - self.cfg.mail_server) + "the mail method of this script is 'smtp'. Default: {!r}.").format(mail_server) ) mail_group.add_argument( @@ -253,8 +263,7 @@ class BaseMailApplication(FbConfigApplication): action=PortOptionAction, help=_( "The port to use for submitting generated by this script if " - "the mail method of this script is 'smtp'. Default: {}.").format( - self.cfg.smtp_port) + "the mail method of this script is 'smtp'. Default: {}.").format(smtp_port) ) # ------------------------------------------------------------------------- diff --git a/lib/pp_admintools/mail_config.py b/lib/pp_admintools/mail_config.py index 0bb8eae..2daf9c9 100644 --- a/lib/pp_admintools/mail_config.py +++ b/lib/pp_admintools/mail_config.py @@ -34,7 +34,7 @@ from .mailaddress import MailAddress from .xlate import XLATOR -__version__ = '0.1.5' +__version__ = '0.1.6' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -68,12 +68,15 @@ class MailConfiguration(BaseMultiConfig): default_reply_to = 'solution@pixelpark.com' default_mail_server = 'localhost' + default_smtp_port = 25 current_user_name = pwd.getpwuid(os.getuid()).pw_name current_user_gecos = pwd.getpwuid(os.getuid()).pw_gecos default_mail_from = MailAddress(current_user_name, socket.getfqdn()) + default_mail_from_complete = '{n} <{m}>'.format(n=current_user_gecos, m=default_mail_from) valid_mail_methods = VALID_MAIL_METHODS + default_mail_method = 'smtp' whitespace_re = re.compile(r'(?:[,;]+|\s*[,;]*\s+)+') @@ -96,13 +99,12 @@ class MailConfiguration(BaseMultiConfig): add_stems.append('mail') self.mail_recipients = copy.copy(self.default_mail_recipients) - self.mail_from = '{n} <{m}>'.format( - n=self.current_user_gecos, m=self.default_mail_from) + self.mail_from = self.default_mail_from_complete self.mail_cc = copy.copy(self.default_mail_cc) self.reply_to = self.default_reply_to - self.mail_method = 'smtp' + self.mail_method = default_mail_method self.mail_server = self.default_mail_server - self.smtp_port = 25 + self.smtp_port = self.default_smtp_port self._mail_cc_configured = False super(MailConfiguration, self).__init__( @@ -137,9 +139,12 @@ class MailConfiguration(BaseMultiConfig): res['default_mail_cc'] = self.default_mail_cc res['default_reply_to'] = self.default_reply_to res['default_mail_server'] = self.default_mail_server + res['default_smtp_port'] = self.default_smtp_port res['current_user_name'] = self.current_user_name res['current_user_gecos'] = self.current_user_gecos res['default_mail_from'] = self.default_mail_from + res['default_mail_from_complete'] = self.default_mail_from_complete + res['default_mail_method'] = self.default_mail_method return res -- 2.39.5