[tor-commits] [gettor/master] Always reply to gettor emails

cohosh at torproject.org cohosh at torproject.org
Fri Mar 6 19:17:29 UTC 2020


commit 61afa2c544ac47f7583aa2a68c72bd7887b043b0
Author: Cecylia Bocovich <cohosh at 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 at torproject.org")
+        ep.locales = ["en-US", "es-ES", "es-AR", "pt-BR", "fa"]
+        request = ep.parse("From: \"silvia [hiro]\" <hiro at torproject.org>\n"
+                "Subject: \r\n Reply-To: hiro at torproject.org \nTo:"
+                "gettor at torproject.org\n\n")
+        self.assertEqual(request["language"], "en-US")
+        self.assertEqual(request["command"], "help")
+
+        request = ep.parse("From: \"silvia [hiro]\" <hiro at torproject.org>\n"
+                "Subject: \r\n Reply-To: hiro at torproject.org \nTo:"
+                "gettor at 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 at torproject.org>\n"
+                "Subject: \r\n Reply-To: hiro at torproject.org \nTo:"
+                "gettor at 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 at torproject.org>\n"
+                "Subject: \r\n Reply-To: hiro at torproject.org \nTo:"
+                "gettor at torproject.org\n\n fa\n")
+        self.assertEqual(request["language"], "fa")
+        self.assertEqual(request["command"], "help")
+
+        request = ep.parse("From: \"silvia [hiro]\" <hiro at torproject.org>\n"
+                "Subject: \r\n Reply-To: hiro at torproject.org \nTo:"
+                "gettor at 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 at torproject.org")
         ep.locales = ["en-US", "es-ES", "es-AR", "pt-BR", "fa"]



More information about the tor-commits mailing list