Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: api crashes #2338

Merged
merged 2 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion app/api/views/alias.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,13 @@ def update_alias(alias_id):
changed = True

if "mailbox_ids" in data:
mailbox_ids = [int(m_id) for m_id in data.get("mailbox_ids")]
mailbox_ids = []
for mailbox_id in data.get("mailbox_ids"):
try:
mailbox_ids.append(int(mailbox_id))
except ValueError:
return jsonify(error="Invalid mailbox_id"), 400

cquintana92 marked this conversation as resolved.
Show resolved Hide resolved
err = set_mailboxes_for_alias(
user_id=user.id, alias=alias, mailbox_ids=mailbox_ids
)
Expand Down
24 changes: 18 additions & 6 deletions app/api/views/new_custom_alias.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from email_validator import EmailNotValidError
from flask import g
from flask import jsonify, request

Expand Down Expand Up @@ -93,12 +94,15 @@ def new_custom_alias_v2():
400,
)

alias = Alias.create(
user_id=user.id,
email=full_alias,
mailbox_id=user.default_mailbox_id,
note=note,
)
try:
alias = Alias.create(
user_id=user.id,
email=full_alias,
mailbox_id=user.default_mailbox_id,
note=note,
)
except EmailNotValidError:
return jsonify(error="Email is not valid"), 400

Session.commit()

Expand Down Expand Up @@ -154,8 +158,16 @@ def new_custom_alias_v3():
return jsonify(error="request body does not follow the required format"), 400

alias_prefix_data = data.get("alias_prefix", "") or ""

if not isinstance(alias_prefix_data, str):
return jsonify(error="request body does not follow the required format"), 400

alias_prefix = alias_prefix_data.strip().lower().replace(" ", "")
signed_suffix = data.get("signed_suffix", "") or ""

if not isinstance(signed_suffix, str):
return jsonify(error="request body does not follow the required format"), 400

signed_suffix = signed_suffix.strip()

mailbox_ids = data.get("mailbox_ids")
Expand Down
2 changes: 1 addition & 1 deletion app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1659,7 +1659,7 @@ def pgp_enabled(self) -> bool:
return False

@staticmethod
def get_custom_domain(alias_address) -> Optional["CustomDomain"]:
def get_custom_domain(alias_address: str) -> Optional["CustomDomain"]:
alias_domain = validate_email(
alias_address, check_deliverability=False, allow_smtputf8=False
).domain
Expand Down
Loading