1
0
mirror of https://github.com/Mailu/Mailu.git synced 2025-01-16 02:46:44 +02:00

only parse it once

This commit is contained in:
Florent Daigniere 2021-11-08 09:23:24 +01:00
parent f9373eacab
commit b68033eb43
2 changed files with 2 additions and 1 deletions

View File

@ -156,6 +156,7 @@ class ConfigManager(dict):
self.config['PERMANENT_SESSION_LIFETIME'] = timedelta(hours=int(self.config['SESSION_LIFETIME']))
hostnames = [host.strip() for host in self.config['HOSTNAMES'].split(',')]
self.config['AUTH_RATELIMIT_EXEMPTION'] = set(ipaddress.ip_network(cidr, False) for cidr in (cidr.strip() for cidr in self.config['AUTH_RATELIMIT_EXEMPTION'].split(',')) if cidr)
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]
# update the app config itself

View File

@ -149,7 +149,7 @@ def postfix_sender_login(sender):
def postfix_sender_rate(sender):
""" Rate limit outbound emails per sender login
"""
if sender in [s for s in flask.current_app.config.get('MESSAGE_RATELIMIT_EXEMPTION', '').lower().replace(' ', '').split(',') if s]:
if sender in flask.current_app.config['MESSAGE_RATELIMIT_EXEMPTION']:
flask.abort(404)
user = models.User.get(sender) or flask.abort(404)
return flask.abort(404) if user.sender_limiter.hit() else flask.jsonify("450 4.2.1 You are sending too many emails too fast.")