commit 61afa2c544ac47f7583aa2a68c72bd7887b043b0 Author: Cecylia Bocovich cohosh@torproject.org Date: Fri Mar 6 14:07:45 2020 -0500
Always reply to gettor emails
This fixes a bug where improperly formatted emails were not receiving gettor replies. We should always reply to emails and default to sending a help message if the request was invalid.
This also prioritizes sending links if both a valid links request and the word help were sent. Several tests were added. --- gettor/parse/email.py | 6 ++++-- tests/test_email_service.py | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-)
diff --git a/gettor/parse/email.py b/gettor/parse/email.py index a08f8ca..38bc120 100644 --- a/gettor/parse/email.py +++ b/gettor/parse/email.py @@ -127,9 +127,8 @@ class EmailParser(object): if word.lower() in self.platforms: request["command"] = "links" request["platform"] = word.lower() - if word.lower() == "help": + if (not request["command"]) and word.lower() == "help": request["command"] = "help" - break return request
def build_request(self, msg_str, norm_addr): @@ -155,6 +154,9 @@ class EmailParser(object): if not request["language"]: request["language"] = "en-US"
+ if not request["command"]: + request["command"] = "help" + return request
diff --git a/tests/test_email_service.py b/tests/test_email_service.py index d064aa1..45278bc 100644 --- a/tests/test_email_service.py +++ b/tests/test_email_service.py @@ -88,6 +88,41 @@ class EmailServiceTests(unittest.TestCase): self.assertEqual(check, False) del ep
+ def test_email_parser(self): + ep = conftests.EmailParser(self.settings, "gettor@torproject.org") + ep.locales = ["en-US", "es-ES", "es-AR", "pt-BR", "fa"] + request = ep.parse("From: "silvia [hiro]" hiro@torproject.org\n" + "Subject: \r\n Reply-To: hiro@torproject.org \nTo:" + "gettor@torproject.org\n\n") + self.assertEqual(request["language"], "en-US") + self.assertEqual(request["command"], "help") + + request = ep.parse("From: "silvia [hiro]" hiro@torproject.org\n" + "Subject: \r\n Reply-To: hiro@torproject.org \nTo:" + "gettor@torproject.org\n\n please send me tor\n") + self.assertEqual(request["language"], "en-US") + self.assertEqual(request["command"], "help") + + request = ep.parse("From: "silvia [hiro]" hiro@torproject.org\n" + "Subject: \r\n Reply-To: hiro@torproject.org \nTo:" + "gettor@torproject.org\n\nwindows\n") + self.assertEqual(request["language"], "en-US") + self.assertEqual(request["platform"], "windows") + self.assertEqual(request["command"], "links") + + request = ep.parse("From: "silvia [hiro]" hiro@torproject.org\n" + "Subject: \r\n Reply-To: hiro@torproject.org \nTo:" + "gettor@torproject.org\n\n fa\n") + self.assertEqual(request["language"], "fa") + self.assertEqual(request["command"], "help") + + request = ep.parse("From: "silvia [hiro]" hiro@torproject.org\n" + "Subject: \r\n Reply-To: hiro@torproject.org \nTo:" + "gettor@torproject.org\n\n please help me get tor for windows\n") + self.assertEqual(request["language"], "en-US") + self.assertEqual(request["command"], "links") + self.assertEqual(request["platform"], "windows") + def test_language_email_parser(self): ep = conftests.EmailParser(self.settings, "gettor@torproject.org") ep.locales = ["en-US", "es-ES", "es-AR", "pt-BR", "fa"]