mirror of
https://github.com/torproject/gettor.git
synced 2024-12-04 08:37:38 +00:00
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.
This commit is contained in:
parent
64df8b27b3
commit
61afa2c544
@ -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
|
||||
|
||||
|
||||
|
@ -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"]
|
||||
|
Loading…
Reference in New Issue
Block a user