]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Bugfixing
authorFrank Brehm <frank@brehm-online.com>
Thu, 31 Mar 2022 10:16:24 +0000 (12:16 +0200)
committerFrank Brehm <frank@brehm-online.com>
Thu, 31 Mar 2022 10:16:24 +0000 (12:16 +0200)
lib/pp_admintools/mail_app.py
lib/pp_admintools/mail_config.py

index a7fdb0ec99c9661e8791844c6b7e19597905c61c..0af08bfe21151e4b50a6d0462b777f15c835f261 100644 (file)
@@ -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)
         )
 
     # -------------------------------------------------------------------------
index 0bb8eae93f9cdebe93fc95ff4c646daa7f9b5f48..2daf9c98c8d4b23724b10a48661ca365804c7bd8 100644 (file)
@@ -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