GitLab is used only for code review, issue tracking and project management. Canonical locations for source code are still https://gitweb.torproject.org/ https://git.torproject.org/ and git-rw.torproject.org.

Commit 0cd6443c authored by Cecylia Bocovich's avatar Cecylia Bocovich

Ensure replies to the help message will work

This commit makes some changes and adds some tests to ensure that
valid replies to the gettor help message will contain links.
Non-valid replies should still return the GetTor help message.
parent 0297dbcd
......@@ -13,6 +13,7 @@
from __future__ import absolute_import
import re
import io
import dkim
import hashlib
......@@ -117,18 +118,22 @@ class EmailParser(object):
def parse_keywords(self, text, request):
for word in re.split(r"\s+", text.strip()):
for locale in self.locales:
if word.lower() == locale.lower():
request["language"] = locale
elif (not request["language"]) and (word.lower()[:2] ==
locale.lower()[:2]):
request["language"] = locale
if word.lower() in self.platforms:
request["command"] = "links"
request["platform"] = word.lower()
if (not request["command"]) and word.lower() == "help":
request["command"] = "help"
buf = io.StringIO(text)
for line in buf:
if len(line.strip()) > 0 and line.strip()[0] == ">":
continue
for word in re.split(r"\s+", line.strip()):
for locale in self.locales:
if word.lower() == locale.lower():
request["language"] = locale
elif (not request["language"]) and (word.lower()[:2] ==
locale.lower()[:2]):
request["language"] = locale
if word.lower() in self.platforms:
request["command"] = "links"
request["platform"] = word.lower()
if (not request["command"]) and word.lower() == "help":
request["command"] = "help"
return request
def build_request(self, msg_str, norm_addr):
......
......@@ -210,6 +210,47 @@ class EmailServiceTests(unittest.TestCase):
assert "en-US" in ep.locales
del ep
def test_help_reply(self):
#Replying to GetTor Help with a valid links request should get you links
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: Re: [GetTor] Help Email\r\n Reply-To: hiro@torproject.org \nTo:"
"gettor@torproject.org\n osx en\n")
self.assertEqual(request["command"], "links")
self.assertEqual(request["language"], "en-US")
self.assertEqual(request["platform"], "osx")
request = ep.parse("From: \"silvia [hiro]\" <hiro@torproject.org>\n"
"Subject: Re: [GetTor] Help Email\r\n Reply-To: hiro@torproject.org \nTo:"
"gettor@torproject.org\nlinux fa\n\n"
"On 2020-02-10 11:54 a.m., gettor@torproject.org wrote:\n"
"> This is how you can request a tor browser bundle link.\n"
">\n"
"> Send an email to: gettor@torproject.org\n"
">\n"
"> In the body of the email only write: <operating system> <language>.\n"
">\n"
"> We only support windows, osx and linux as operating systems.\n"
">\n")
self.assertEqual(request["command"], "links")
self.assertEqual(request["language"], "fa")
self.assertEqual(request["platform"], "linux")
request = ep.parse("From: \"silvia [hiro]\" <hiro@torproject.org>\n"
"Subject: Re: [GetTor] Help Email\r\n Reply-To: hiro@torproject.org \nTo:"
"gettor@torproject.org\n"
"On 2020-02-10 11:54 a.m., gettor@torproject.org wrote:\n"
"> This is how you can request a tor browser bundle link.\n"
">\n"
"> Send an email to: gettor@torproject.org\n"
">\n"
"> In the body of the email only write: <operating system> <language>.\n"
">\n"
"> We only support windows, osx and linux as operating systems.\n"
">\n")
self.assertEqual(request["command"], "help")
if __name__ == "__main__":
unittest.main()
Markdown is supported
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