[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [gettor/master] Always reply to gettor emails
commit 61afa2c544ac47f7583aa2a68c72bd7887b043b0
Author: Cecylia Bocovich <cohosh@xxxxxxxxxxxxxx>
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@xxxxxxxxxxxxxx")
+ ep.locales = ["en-US", "es-ES", "es-AR", "pt-BR", "fa"]
+ request = ep.parse("From: \"silvia [hiro]\" <hiro@xxxxxxxxxxxxxx>\n"
+ "Subject: \r\n Reply-To: hiro@xxxxxxxxxxxxxx \nTo:"
+ "gettor@xxxxxxxxxxxxxx\n\n")
+ self.assertEqual(request["language"], "en-US")
+ self.assertEqual(request["command"], "help")
+
+ request = ep.parse("From: \"silvia [hiro]\" <hiro@xxxxxxxxxxxxxx>\n"
+ "Subject: \r\n Reply-To: hiro@xxxxxxxxxxxxxx \nTo:"
+ "gettor@xxxxxxxxxxxxxx\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@xxxxxxxxxxxxxx>\n"
+ "Subject: \r\n Reply-To: hiro@xxxxxxxxxxxxxx \nTo:"
+ "gettor@xxxxxxxxxxxxxx\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@xxxxxxxxxxxxxx>\n"
+ "Subject: \r\n Reply-To: hiro@xxxxxxxxxxxxxx \nTo:"
+ "gettor@xxxxxxxxxxxxxx\n\n fa\n")
+ self.assertEqual(request["language"], "fa")
+ self.assertEqual(request["command"], "help")
+
+ request = ep.parse("From: \"silvia [hiro]\" <hiro@xxxxxxxxxxxxxx>\n"
+ "Subject: \r\n Reply-To: hiro@xxxxxxxxxxxxxx \nTo:"
+ "gettor@xxxxxxxxxxxxxx\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@xxxxxxxxxxxxxx")
ep.locales = ["en-US", "es-ES", "es-AR", "pt-BR", "fa"]
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits