From f8e3fd5f843f107d84d99034e80b5261d11b0a3a Mon Sep 17 00:00:00 2001
From: bogdan kyryliuk <bogdankyryliuk@dropbox.com>
Date: Mon, 13 Apr 2020 20:30:18 -0700
Subject: [PATCH 1/2] Make email parsing more robust

---
 superset/utils/core.py | 10 ++--------
 tests/utils_tests.py   | 11 +++++++++++
 2 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/superset/utils/core.py b/superset/utils/core.py
index e72c8ccabd8b6..0349aa5e38210 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(",|\n|\t| |;", 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"],
+        )

From 4ebcbdda3c2a9c660d9b2ebe02392e98efcdf438 Mon Sep 17 00:00:00 2001
From: bogdan kyryliuk <bogdankyryliuk@dropbox.com>
Date: Tue, 14 Apr 2020 13:55:07 -0700
Subject: [PATCH 2/2] Address comment

---
 superset/utils/core.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/superset/utils/core.py b/superset/utils/core.py
index 0349aa5e38210..524b8e20c0f8c 100644
--- a/superset/utils/core.py
+++ b/superset/utils/core.py
@@ -780,7 +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):
-        address_string_list = re.split(",|\n|\t| |;", address_string)
+        address_string_list = re.split(",|\s|;", address_string)
     return [x.strip() for x in address_string_list if x.strip()]