From 56f4d4c89456e13e8d9558dcb7b679dab7e02c5e Mon Sep 17 00:00:00 2001 From: TheLegend875 Date: Fri, 28 Dec 2018 21:03:57 +0100 Subject: [PATCH] fixed auto-forward --- core/admin/mailu/models.py | 2 +- core/admin/mailu/ui/forms.py | 12 +++++++++--- core/admin/mailu/ui/views/users.py | 8 +++++++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/core/admin/mailu/models.py b/core/admin/mailu/models.py index a3fc15a4..30a2ed64 100644 --- a/core/admin/mailu/models.py +++ b/core/admin/mailu/models.py @@ -72,7 +72,7 @@ class CommaSeparatedList(db.TypeDecorator): return ",".join(value) def process_result_value(self, value, dialect): - return filter(bool, value.split(",")) if value else [] + return list(filter(bool, value.split(","))) if value else [] class JSONEncoded(db.TypeDecorator): diff --git a/core/admin/mailu/ui/forms.py b/core/admin/mailu/ui/forms.py index 40a56a82..ac4f0e19 100644 --- a/core/admin/mailu/ui/forms.py +++ b/core/admin/mailu/ui/forms.py @@ -32,6 +32,14 @@ class DestinationField(fields.SelectMultipleField): if not self.validator.match(item): raise validators.ValidationError(_('Invalid email address.')) +class MultipleEmailAddressesVerify(object): + def __init__(self,message=_('Invalid email address.')): + self.message = message + + def __call__(self, form, field): + pattern = re.compile(r'^([_a-z0-9\-]+)(\.[_a-z0-9\-]+)*@([a-z0-9\-]{2,}\.)*([a-z]{2,4})(,([_a-z0-9\-]+)(\.[_a-z0-9\-]+)*@([a-z0-9\-]{2,}\.)*([a-z]{2,4}))*$') + if not pattern.match(field.data.replace(" ", "")): + raise validators.ValidationError(self.message) class ConfirmationForm(flask_wtf.FlaskForm): submit = fields.SubmitField(_('Confirm')) @@ -101,9 +109,7 @@ class UserSettingsForm(flask_wtf.FlaskForm): spam_threshold = fields_.IntegerSliderField(_('Spam filter tolerance')) forward_enabled = fields.BooleanField(_('Enable forwarding')) forward_keep = fields.BooleanField(_('Keep a copy of the emails')) - forward_destination = fields.StringField( - _('Destination'), [validators.Optional(), validators.Email()] - ) + forward_destination = fields.StringField(_('Destination'), [validators.Optional(), MultipleEmailAddressesVerify()]) submit = fields.SubmitField(_('Save settings')) diff --git a/core/admin/mailu/ui/views/users.py b/core/admin/mailu/ui/views/users.py index 51dfdc13..4cbe7a97 100644 --- a/core/admin/mailu/ui/views/users.py +++ b/core/admin/mailu/ui/views/users.py @@ -7,7 +7,6 @@ import flask_login import wtforms import wtforms_components - @ui.route('/user/list/', methods=['GET']) @access.domain_admin(models.Domain, 'domain_name') def user_list(domain_name): @@ -92,9 +91,16 @@ def user_settings(user_email): user_email_or_current = user_email or flask_login.current_user.email user = models.User.query.get(user_email_or_current) or flask.abort(404) form = forms.UserSettingsForm(obj=user) + if isinstance(form.forward_destination.data,str): + data = form.forward_destination.data.replace(" ","").split(",") + else: + data = form.forward_destination.data + form.forward_destination.data = ", ".join(data) if form.validate_on_submit(): + form.forward_destination.data = form.forward_destination.data.replace(" ","").split(",") form.populate_obj(user) models.db.session.commit() + form.forward_destination.data = ", ".join(form.forward_destination.data) flask.flash('Settings updated for %s' % user) if user_email: return flask.redirect(