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

Make email parsing more robust #9523

Merged
merged 2 commits into from
Apr 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 2 additions & 8 deletions superset/utils/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import json
import logging
import os
import re
import signal
import smtplib
import tempfile
Expand Down Expand Up @@ -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()]


Expand Down
11 changes: 11 additions & 0 deletions tests/utils_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
datetime_f,
format_timedelta,
get_iterable,
get_email_address_list,
get_or_create_db,
get_since_until,
get_stacktrace,
Expand Down Expand Up @@ -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"],
)