diff --git a/app/email_utils.py b/app/email_utils.py index 1904fd3b..e1759ca6 100644 --- a/app/email_utils.py +++ b/app/email_utils.py @@ -1321,4 +1321,9 @@ def parse_full_address(full_address) -> (str, str): full_address: EmailAddress = address.parse(full_address) if full_address is None: raise ValueError + + # address.parse can also parse an URL and return UrlAddress + if type(full_address) is not EmailAddress: + raise ValueError + return full_address.display_name, full_address.address diff --git a/tests/test_email_utils.py b/tests/test_email_utils.py index bd4aac38..8c9a4c8b 100644 --- a/tests/test_email_utils.py +++ b/tests/test_email_utils.py @@ -3,6 +3,7 @@ import os from email.message import EmailMessage import arrow +import pytest from app.config import MAX_ALERT_24H, EMAIL_DOMAIN, BOUNCE_EMAIL, ROOT_DIR from app.db import Session @@ -134,6 +135,9 @@ def test_parse_full_address(): "abcd@gmail.com", ) + with pytest.raises(ValueError): + parse_full_address("https://ab.cd") + def test_send_email_with_rate_control(flask_client): user = User.create(