Improve contact manager: lowercase the contact address before adding

This commit is contained in:
Son NK 2020-04-01 20:31:47 +02:00
parent 62e028c30f
commit 7f85ec30bd
2 changed files with 7 additions and 7 deletions

View file

@ -326,7 +326,7 @@ def create_contact_route(alias_id):
if alias.user_id != user.id:
return jsonify(error="Forbidden"), 403
contact_email = data.get("contact")
contact_addr = data.get("contact").lower()
# generate a reply_email, make sure it is unique
# not use while to avoid infinite loop
@ -336,21 +336,21 @@ def create_contact_route(alias_id):
if not Contact.get_by(reply_email=reply_email):
break
_, website_email = parseaddr(contact_email)
_, contact_email = parseaddr(contact_addr)
# already been added
if Contact.get_by(alias_id=alias.id, website_email=website_email):
if Contact.get_by(alias_id=alias.id, website_email=contact_email):
return jsonify(error="Contact already added"), 409
contact = Contact.create(
user_id=alias.user_id,
alias_id=alias.id,
website_email=website_email,
website_from=contact_email,
website_email=contact_email,
website_from=contact_addr,
reply_email=reply_email,
)
LOG.d("create reverse-alias for %s %s", contact_email, alias)
LOG.d("create reverse-alias for %s %s", contact_addr, alias)
db.session.commit()
return jsonify(**serialize_contact(contact)), 201

View file

@ -68,7 +68,7 @@ def alias_contact_manager(alias_id):
if request.method == "POST":
if request.form.get("form-name") == "create":
if new_contact_form.validate():
contact_email = new_contact_form.email.data.strip()
contact_email = new_contact_form.email.data.strip().lower()
# generate a reply_email, make sure it is unique
# not use while to avoid infinite loop