From 82860d0f8013742ae3d1d8be9d17b78dc55c59b9 Mon Sep 17 00:00:00 2001 From: enginefeeder101 Date: Wed, 8 Jun 2022 17:13:38 +0200 Subject: [PATCH] Moved parsing environment variable to global application config dictionary Per requested changes added the ``DEFAULT_SPAM_THRESHOLD`` to the main application configuration dictionary in ``configuration.py`` and updated ``models.py`` accordingly. No error handling is added, as that was not required. --- core/admin/mailu/configuration.py | 2 ++ core/admin/mailu/models.py | 3 +-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/core/admin/mailu/configuration.py b/core/admin/mailu/configuration.py index 912a0204..f1bb2283 100644 --- a/core/admin/mailu/configuration.py +++ b/core/admin/mailu/configuration.py @@ -75,6 +75,7 @@ DEFAULT_CONFIG = { 'SESSION_COOKIE_SECURE': True, 'CREDENTIAL_ROUNDS': 12, 'TZ': 'Etc/UTC', + 'DEFAULT_SPAM_THRESHOLD': 80, # Host settings 'HOST_IMAP': 'imap', 'HOST_LMTP': 'imap:2525', @@ -163,6 +164,7 @@ class ConfigManager: self.config['MESSAGE_RATELIMIT_EXEMPTION'] = set([s for s in self.config['MESSAGE_RATELIMIT_EXEMPTION'].lower().replace(' ', '').split(',') if s]) self.config['HOSTNAMES'] = ','.join(hostnames) self.config['HOSTNAME'] = hostnames[0] + self.config['DEFAULT_SPAM_THRESHOLD'] = int(self.config['DEFAULT_SPAM_THRESHOLD']) # update the app config app.config.update(self.config) diff --git a/core/admin/mailu/models.py b/core/admin/mailu/models.py index 6e277fe3..3722003c 100644 --- a/core/admin/mailu/models.py +++ b/core/admin/mailu/models.py @@ -509,8 +509,7 @@ class User(Base, Email): displayed_name = db.Column(db.String(160), nullable=False, default='') spam_enabled = db.Column(db.Boolean, nullable=False, default=True) spam_mark_as_read = db.Column(db.Boolean, nullable=False, default=True) - spam_threshold = db.Column(db.Integer, nullable=False, - default=int(os.environ.get('DEFAULT_SPAM_THRESHOLD', 80))) + spam_threshold = db.Column(db.Integer, nullable=False, default=app.config['DEFAULT_SPAM_THRESHOLD']) # Flask-login attributes is_authenticated = True