Commit 829fa9fb authored by Cecylia Bocovich's avatar Cecylia Bocovich
Browse files

Make locale parsing less eager

This will make the locale parsing more restrictive so that, for example,
sending "i like fries" will not result in the locale "fr".
parent c8e385ba
......@@ -123,16 +123,18 @@ class EmailParser(object):
if len(line.strip()) > 0 and line.strip()[0] == ">":
for word in re.split(r"\s+", line.strip()):
word = word.lower()
for locale in self.locales:
if word.lower() == locale.lower():
if word == locale.lower():
request["language"] = locale
elif (not request["language"]) and (word.lower()[:2] ==
request["language"] = locale
if word.lower() in self.platforms:
elif not request["language"]:
parts = re.split(r"[-_]", word)
if parts[0] == locale.lower()[:2]:
request["language"] = locale
if word in self.platforms:
request["command"] = "links"
request["platform"] = word.lower()
if (not request["command"]) and word.lower() == "help":
request["platform"] = word
if (not request["command"]) and word == "help":
request["command"] = "help"
return request
......@@ -213,7 +213,7 @@ class EmailServiceTests(unittest.TestCase):
def test_help_reply(self):
#Replying to GetTor Help with a valid links request should get you links
ep = conftests.EmailParser(self.settings, "")
ep.locales = ["en-US", "es-ES", "es-AR", "pt-BR", "fa"]
ep.locales = ["en-US", "es-ES", "es-AR", "pt-BR", "fa", "fr"]
request = ep.parse("From: \"silvia [hiro]\" <>\n"
"Subject: Re: [GetTor] Help Email\r\n Reply-To: \nTo:"
"\n osx en\n")
......@@ -221,6 +221,11 @@ class EmailServiceTests(unittest.TestCase):
self.assertEqual(request["language"], "en-US")
self.assertEqual(request["platform"], "osx")
request = ep.parse("From: \"silvia [hiro]\" <>\n"
"Subject: Re: [GetTor] Help Email\r\n Reply-To: \nTo:"
"\n i like french fries\n")
self.assertEqual(request["command"], "help")
request = ep.parse("From: \"silvia [hiro]\" <>\n"
"Subject: Re: [GetTor] Help Email\r\n Reply-To: \nTo:"
"\nlinux fa\n\n"
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment