Skip to content

Commit

Permalink
Make email parsing more robust (#9523)
Browse files Browse the repository at this point in the history
* Make email parsing more robust

* Address comment

Co-authored-by: bogdan kyryliuk <bogdankyryliuk@dropbox.com>
  • Loading branch information
bkyryliuk and bogdan-dbx authored Apr 15, 2020
1 parent ef5e11f commit 3574a3a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
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 @@ -783,14 +784,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"],
)

0 comments on commit 3574a3a

Please sign in to comment.