3353: Fix email forwarding when set from the UI r=mergify[bot] a=nextgens

## What type of PR?

bug-fix

## What does this PR do?

Fix email forwarding when set from the UI

### Related issue(s)
- closes #3352 
- closes #3349 

## Prerequisites
Before we can consider review and merge, please make sure the following list is done and checked.
If an entry in not applicable, you can check it or remove it from the list.

- [ ] In case of feature or enhancement: documentation updated accordingly
- [x] Unless it's docs or a minor change: add [changelog](https://mailu.io/master/contributors/workflow.html#changelog) entry file.


Co-authored-by: Florent Daigniere <nextgens@freenetproject.org>
This commit is contained in:
bors-mailu[bot]
2024-07-30 11:02:43 +00:00
committed by GitHub
3 changed files with 10 additions and 7 deletions

View File

@@ -93,11 +93,11 @@ def user_settings(user_email):
form = forms.UserSettingsForm(obj=user) form = forms.UserSettingsForm(obj=user)
utils.formatCSVField(form.forward_destination) utils.formatCSVField(form.forward_destination)
if form.validate_on_submit(): if form.validate_on_submit():
if form.forward_enabled.data and (form.forward_destination.data in ['', None] or type(form.forward_destination.data) is list): user.forward_enabled = bool(flask.request.form.get('forward_enabled', False))
if user.forward_enabled and not form.forward_destination.data:
flask.flash('Destination email address is missing', 'error') flask.flash('Destination email address is missing', 'error')
user.forward_enabled = True return flask.redirect(
return flask.render_template('user/settings.html', form=form, user=user) flask.url_for('.user_settings', user_email=user_email))
if form.forward_enabled.data:
form.forward_destination.data = form.forward_destination.data.replace(" ","").split(",") form.forward_destination.data = form.forward_destination.data.replace(" ","").split(",")
form.populate_obj(user) form.populate_obj(user)
models.db.session.commit() models.db.session.commit()
@@ -107,8 +107,9 @@ def user_settings(user_email):
return flask.redirect( return flask.redirect(
flask.url_for('.user_list', domain_name=user.domain.name)) flask.url_for('.user_list', domain_name=user.domain.name))
elif form.is_submitted() and not form.validate(): elif form.is_submitted() and not form.validate():
user.forward_enabled = form.forward_enabled.data flask.flash('Error validating the form', 'error')
return flask.render_template('user/settings.html', form=form, user=user) return flask.redirect(
flask.url_for('.user_settings', user_email=user_email))
return flask.render_template('user/settings.html', form=form, user=user) return flask.render_template('user/settings.html', form=form, user=user)
def _process_password_change(form, user_email): def _process_password_change(form, user_email):

View File

@@ -532,6 +532,7 @@ def isBadOrPwned(form):
def formatCSVField(field): def formatCSVField(field):
if not field.data: if not field.data:
field.data = ''
return return
if isinstance(field.data,str): if isinstance(field.data,str):
data = field.data.replace(" ","").split(",") data = field.data.replace(" ","").split(",")

View File

@@ -0,0 +1 @@
Fix email-forwarding when set from the web interface