diff --git a/gettor/services/email/sendmail.py b/gettor/services/email/sendmail.py index 754fb5bf2963987c419991b854f4698f03401291..4d908b331e6244b12ab36c525ad4b67f953ce61c 100644 --- a/gettor/services/email/sendmail.py +++ b/gettor/services/email/sendmail.py @@ -98,11 +98,21 @@ class Sendmail(object): requireTransportSecurity=True ).addCallback(self.sendmail_callback).addErrback(self.sendmail_errback) - - def build_help_body_message(self): - body_msg = strings._("help_body_intro") - body_msg += strings._("help_body_paragraph") + def build_locale_string(self, locales): + locale_string = "" + for locale in locales: + locale_string += "\t" + locale[0] + "\n" + return locale_string + + def build_help_body_message(self, locale_string): + body_msg = strings._("body_intro") + body_msg += strings._("help_body_intro") body_msg += strings._("help_body_support") + body_msg += "\twindows\n\tlinux\n\tosx\n\n" + body_msg += strings._("help_body_respond") + body_msg += strings._("help_body_locale") + body_msg += locale_string + "\n" + body_msg += strings._("help_body_example").format("Windows", "Arabic", "windows ar") return body_msg @@ -112,7 +122,7 @@ class Sendmail(object): Build the links strings """ - link_msg = None + link_msg = "" for link in links: provider = link[5] @@ -122,11 +132,9 @@ class Sendmail(object): file = link[7] sig_url = url + ".asc" - link_str = "Tor Browser {} for {}-{}-{} ({}): {}\n".format( - version, platform, locale, arch, provider, url - ) + link_str = "\t{}: {}\n".format(provider, url) - link_str += "Signature file: {}\n".format(sig_url) + link_str += "\tSignature file: {}\n".format(sig_url) link_msg = "{}\n{}".format(link_msg, link_str) @@ -134,13 +142,26 @@ class Sendmail(object): def build_body_message(self, link_msg, platform, file): - body_msg = strings._("links_body_platform").format(platform) - body_msg += strings._("links_body_links").format(link_msg) - body_msg += strings._("links_body_archive") + signature_strings = { + "windows":"links_body_windows", + "linux":"links_body_linux", + "osx":"links_body_osx" + } + signature_cmds = { + "windows":"gpgv --keyring .\\tor.keyring Downloads\\{0}.asc Downloads\\{0}", + "linux":"gpgv --keyring ./tor.keyring ~/Downloads/{}{{.asc,}}", + "osx":"gpgv --keyring ./tor.keyring ~/Downloads/{}{{.asc,}}" + } + body_msg = strings._("body_intro") + body_msg += strings._("links_body_platform").format(platform) + body_msg += strings._("links_body_step1").format(link_msg) + body_msg += strings._("links_body_archive").format(file) body_msg += strings._("links_body_internet_archive") body_msg += strings._("links_body_google_drive") - body_msg += strings._("links_body_download_filename").format(file) - body_msg += strings._("links_body_ending") + body_msg += strings._("links_body_step2") + body_msg += strings._(signature_strings[platform]) + body_msg += strings._("links_body_all").format(signature_cmds[platform].format(file)) + body_msg += strings._("links_body_step3") return body_msg @@ -176,8 +197,10 @@ class Sendmail(object): hid.hexdigest() ) ) + locales = yield self.conn.get_locales() + locale_string = self.build_locale_string(locales) - body_msg = self.build_help_body_message() + body_msg = self.build_help_body_message(locale_string) yield self.sendmail( email_addr=id, diff --git a/share/locale/en.json b/share/locale/en.json index dba30479d04d0091e4e596a10bfae2563d83210f..8737d51c8634dccb53d7b21b5baeecdca1067161 100644 --- a/share/locale/en.json +++ b/share/locale/en.json @@ -1,15 +1,22 @@ { + "body_intro": "This is an automated email response from GetTor.\n\n", "links_body_platform": "You requested Tor Browser for {}.\n\n", - "links_body_links": "You will need only one of the links below to download the bundle. If a link does not work for you, try the next one.\n\n{}\n\n", - "links_body_archive": "Should you have issues with any of the links above you can access the following archives:\n\n", - "links_body_internet_archive": "- Internet Archive: https://archive.org/details/@gettor\n\n", - "links_body_google_drive": "- Google Drive folder: https://drive.google.com/open?id=13CADQTsCwrGsIID09YQbNz2DfRMUoxUU\n\n", - "links_body_download_filename": "Download the file: {}\n\n", - "links_body_ending": "\n--\nGetTor", + "links_body_step1": "Step 1: Download Tor Browser\n\n\tFirst, try downloading Tor Browser from either GitLab or GitHub:\n\n{}\n\n", + "links_body_archive": "\tIf you cannot download Tor Browser from GitLab or GitHub,\n\ttry downloading the file {}\n\tfrom the following archives:\n\n", + "links_body_internet_archive": "\tInternet Archive: https://archive.org/details/@gettor\n\n", + "links_body_google_drive": "\tGoogle Drive folder: https://drive.google.com/open?id=13CADQTsCwrGsIID09YQbNz2DfRMUoxUU\n\n", + "links_body_step2": "Step 2: Verify the signature (Optional)\n\n\tVerifying the signature ensures that a certain package was generated by its\n\tdevelopers, and has not been tampered with. This email provides links to signature\n\tfiles that have the same name as the Tor Browser file, but end with \".asc\" instead.\n\n", + "links_body_all":"\tThe Tor Browser team signs Tor Browser releases. Import the Tor Browser Developers\n\tsigning key (0xEF6E286DDA85EA2A4BA7DE684E2C6E8793298290):\n\n\t\tgpg --auto-key-locate nodefault,wkd --locate-keys torbrowser@torproject.org\n\n\tThis should show you something like:\n\n\t\tgpg: key 4E2C6E8793298290: public key \"Tor Browser Developers (signing key) \" imported\n\t\tgpg: Total number processed: 1\n\t\tgpg: imported: 1\n\t\tpub rsa4096 2014-12-15 [C] [expires: 2020-08-24]\n\t\t EF6E286DDA85EA2A4BA7DE684E2C6E8793298290\n\t\tuid [ unknown] Tor Browser Developers (signing key) \n\t\tsub rsa4096 2018-05-26 [S] [expires: 2020-09-12]\n\n\tAfter importing the key, you can save it to a file (identifying it by fingerprint here):\n\n\t\tgpg --output ./tor.keyring --export 0xEF6E286DDA85EA2A4BA7DE684E2C6E8793298290\n\n\tNext, you will need to download the corresponding \".asc\" signature file and verify it\n\twith the command:\n\n\t\t{}\n\n\tThe result of the command should produce something like this:\n\n\t\tgpgv: Signature made 07/08/19 04:03:49 Pacific Daylight Time\n\t\tgpgv: using RSA key EB774491D9FF06E2\n\t\tgpgv: Good signature from \"Tor Browser Developers (signing key) \"\n\n", + "links_body_windows":"\tIf you run Windows, download Gpg4win and run its installer. In order to verify the\n\tsignature you will need to type a few commands in windows command-line, cmd.exe.\n\n", + "links_body_osx":"\tIf you are using macOS, you can install GPGTools. In order to verify the signature\n\tyou will need to type a few commands in the Terminal (under \"Applications\").\n\n", + "links_body_linux":"\tIf you are using GNU/Linux, then you probably already have GnuPG in your system,\n\tas most GNU/Linux distributions come with it preinstalled. In order to verify the\n\tsignature you will need to type a few commands in a terminal window.\n\n", + "links_body_step3": "Step 3: Get Bridges (Optional)\n\n\tIf you believe that Tor is blocked where you are, you can use bridges to connect\n\tto Tor. Bridges are hidden Tor relays that can circumvent censorship.\n\tTor Browser includes a list of built-in bridges, which you should try first.\n\tYou can activate built-in bridges inside of Tor Browser's settings, under the\n\t\"Tor\" menu. If built-in bridges don't work, try requesting different bridges,\n\twhich you can also do in the \"Tor\" menu inside Tor Browser's settings.\n\n", "links_subject": "[GetTor] Links for your request", - "help_body_intro": "This is how you can request a tor browser bundle link.\n\n", - "help_body_paragraph": "Send an email to: gettor@torproject.org\n\nIn the body of the email only write: .\n\n", - "help_body_support": "We only support windows, osx and linux as operating systems.\n\n", + "help_body_intro": "GetTor can send you download links for Tor Browser.\n", + "help_body_support": "Simply reply to this email and write the operating system you want to install Tor Browser on in your response. We support the following operating systems:\n\n", + "help_body_respond": "GetTor will then respond with download instructions.\n\n", + "help_body_locale": "If you want Tor Browser in a language other than English, mention one of the following language codes in your response:\n\n", + "help_body_example": "For example, if you want Tor Browser for {} in {} your email content will look like:\n\n\t{}\n\n", "help_subject": "[GetTor] Help Email", "help_debug": "Log application errors to stdout", "help_config": "Custom config file location (optional)", diff --git a/tests/test_email_service.py b/tests/test_email_service.py index 4326b9c218d7bdb3ec7066e2b38d8307fd13cce2..3803e791568a708de1e2d72cab0a2c1367f9f74b 100644 --- a/tests/test_email_service.py +++ b/tests/test_email_service.py @@ -17,18 +17,6 @@ class EmailServiceTests(unittest.TestCase): self.settings = conftests.options.parse_settings("en","tests/test.conf.json") self.sm_client = conftests.Sendmail(self.settings) self.locales = conftests.strings.get_locales() - self.links = [ - [ - "https://gitlab.com/thetorproject/gettorbrowser/raw/torbrowser-releases/TorBrowser-9.0.3-osx64_en-US.dmg", - "osx", - "en-US", - "64", - "9.0.3", - "gitlab", - "ACTIVE", - "TorBrowser-9.0.3-osx64_en-US.dmg" - ] - ] def tearDown(self): print("tearDown()") @@ -182,26 +170,38 @@ class EmailServiceTests(unittest.TestCase): self.assertEqual(request["language"], "es-AR") del ep + @pytest_twisted.inlineCallbacks def test_sent_links_message(self): ep = self.sm_client - links = self.links - link_msg, file = ep.build_link_strings(links, "osx", "en") - assert "https://gitlab.com/thetorproject/gettorbrowser/raw/torbrowser-releases/TorBrowser-9.0.3-osx64_en-US.dmg" in link_msg - assert "osx" in link_msg - - self.assertEqual("TorBrowser-9.0.3-osx64_en-US.dmg", file) - - def test_sent_body_message(self): - ep = self.sm_client - links = self.links - link_msg, file = ep.build_link_strings(links, "osx", "en") + links = yield ep.conn.get_links( + platform="osx", language="en-US", status="ACTIVE" + ) + link_msg, file = ep.build_link_strings(links, "osx", "en-US") body_msg = ep.build_body_message(link_msg, "osx", file) assert "You requested Tor Browser for osx" in body_msg + links = yield ep.conn.get_links( + platform="windows", language="en-US", status="ACTIVE" + ) + link_msg, file = ep.build_link_strings(links, "windows", "en-US") + body_msg = ep.build_body_message(link_msg, "windows", file) + assert "You requested Tor Browser for windows" in body_msg + + links = yield ep.conn.get_links( + platform="linux", language="en-US", status="ACTIVE" + ) + link_msg, file = ep.build_link_strings(links, "linux", "en-US") + body_msg = ep.build_body_message(link_msg, "linux", file) + assert "You requested Tor Browser for linux" in body_msg + + @pytest_twisted.inlineCallbacks def test_help_body_message(self): ep = self.sm_client - help_msg = ep.build_help_body_message() - assert "This is how you can request a tor browser bundle link" in help_msg + locales = yield ep.conn.get_locales() + locale_string = ep.build_locale_string(locales) + help_msg = ep.build_help_body_message(locale_string) + assert "This is an automated email response from GetTor." in help_msg + assert "\twindows\n\tlinux\n\tosx\n" in help_msg @pytest_twisted.inlineCallbacks def test_get_locales(self):