diff --git a/superset/utils/core.py b/superset/utils/core.py index e72c8ccabd8b6..524b8e20c0f8c 100644 --- a/superset/utils/core.py +++ b/superset/utils/core.py @@ -23,6 +23,7 @@ import json import logging import os +import re import signal import smtplib import tempfile @@ -779,14 +780,7 @@ def send_MIME_email(e_from, e_to, mime_msg, config, dryrun=False): def get_email_address_list(address_string: str) -> List[str]: address_string_list: List[str] = [] if isinstance(address_string, str): - if "," in address_string: - address_string_list = address_string.split(",") - elif "\n" in address_string: - address_string_list = address_string.split("\n") - elif ";" in address_string: - address_string_list = address_string.split(";") - else: - address_string_list = [address_string] + address_string_list = re.split(",|\s|;", address_string) return [x.strip() for x in address_string_list if x.strip()] diff --git a/tests/utils_tests.py b/tests/utils_tests.py index 9a5d8f6341586..70b77afeac021 100644 --- a/tests/utils_tests.py +++ b/tests/utils_tests.py @@ -40,6 +40,7 @@ datetime_f, format_timedelta, get_iterable, + get_email_address_list, get_or_create_db, get_since_until, get_stacktrace, @@ -1238,3 +1239,13 @@ def test_ssl_certificate_file_creation(self): expected_filename = hashlib.md5(ssl_certificate.encode("utf-8")).hexdigest() self.assertIn(expected_filename, path) self.assertTrue(os.path.exists(path)) + + def test_get_email_address_list(self): + self.assertEqual(get_email_address_list("a@a"), ["a@a"]) + self.assertEqual(get_email_address_list(" a@a "), ["a@a"]) + self.assertEqual(get_email_address_list("a@a\n"), ["a@a"]) + self.assertEqual(get_email_address_list(",a@a;"), ["a@a"]) + self.assertEqual( + get_email_address_list(",a@a; b@b c@c a-c@c; d@d, f@f"), + ["a@a", "b@b", "c@c", "a-c@c", "d@d", "f@f"], + )