From 9bbc1b9a61236793089b31447cf2a3286dbc1c0d Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Tue, 24 Mar 2015 16:32:36 -0300 Subject: Refactor lastuid and register wrapper on SYNC_DONE -- Issue #334 --- service/pixelated/adapter/soledad/soledad_facade_mixin.py | 6 ++++-- service/pixelated/config/app_factory.py | 4 ++++ 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'service') diff --git a/service/pixelated/adapter/soledad/soledad_facade_mixin.py b/service/pixelated/adapter/soledad/soledad_facade_mixin.py index 280fc81e..761ef1e2 100644 --- a/service/pixelated/adapter/soledad/soledad_facade_mixin.py +++ b/service/pixelated/adapter/soledad/soledad_facade_mixin.py @@ -59,8 +59,10 @@ class SoledadDbFacadeMixin(object): def get_mbox(self, mbox): return self.soledad.get_from_index('by-type-and-mbox', 'mbox', mbox) if mbox else [] - def get_lastuid(self, mbox_doc): - return mbox_doc.content['lastuid'] + def get_lastuid(self, mbox): + if isinstance(mbox, str): + mbox = self.get_mbox(mbox)[0] + return mbox.content['lastuid'] def get_search_index_masterkey(self): return self.soledad.get_from_index('by-type', 'index_key') diff --git a/service/pixelated/config/app_factory.py b/service/pixelated/config/app_factory.py index f20b1229..5dcf60cb 100644 --- a/service/pixelated/config/app_factory.py +++ b/service/pixelated/config/app_factory.py @@ -39,6 +39,7 @@ from leap.common.events import ( events_pb2 as proto ) from twisted.web.server import Site +from .welcome_mail import check_welcome_mail_wrapper CREATE_KEYS_IF_KEYS_DONT_EXISTS_CALLBACK = 12345 @@ -117,6 +118,9 @@ def init_app(app, leap_home, leap_session): search_engine=search_engine, mail_service=mail_service)) + register(signal=proto.SOLEDAD_DONE_DATA_SYNC, + callback=check_welcome_mail_wrapper(pixelated_mailboxes.inbox())) + register(signal=proto.SOLEDAD_DONE_DATA_SYNC, uid=CREATE_KEYS_IF_KEYS_DONT_EXISTS_CALLBACK, callback=look_for_user_key_and_create_if_cant_find(leap_session)) -- cgit v1.2.3 From f5b405b3d89e144f574e0b7501d67f7f471d5eeb Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Tue, 24 Mar 2015 16:31:24 -0300 Subject: Unit tests, integration tests and welcome mail -- Issue #334 --- service/pixelated/config/welcome_mail.py | 48 +++++++++++++++++++++++++++ service/test/integration/test_welcome_mail.py | 35 +++++++++++++++++++ service/test/unit/config/test_welcome_mail.py | 32 ++++++++++++++++++ 3 files changed, 115 insertions(+) create mode 100644 service/pixelated/config/welcome_mail.py create mode 100644 service/test/integration/test_welcome_mail.py create mode 100644 service/test/unit/config/test_welcome_mail.py (limited to 'service') diff --git a/service/pixelated/config/welcome_mail.py b/service/pixelated/config/welcome_mail.py new file mode 100644 index 00000000..236c4331 --- /dev/null +++ b/service/pixelated/config/welcome_mail.py @@ -0,0 +1,48 @@ +# +# Copyright (c) 2014 ThoughtWorks, Inc. +# +# Pixelated is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pixelated is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Pixelated. If not, see . +import os +from pixelated.adapter.model.mail import InputMail +from pixelated.support.date import iso_now +from email import message_from_file +from email.MIMEMultipart import MIMEMultipart + + +def check_welcome_mail(mailbox): + if mailbox.fresh: + welcome_mail = build_welcome_mail() + mailbox.add(welcome_mail) + + +def build_welcome_mail(): + current_path = os.path.dirname(os.path.abspath(__file__)) + with open(os.path.join(current_path, '..', 'assets', 'welcome.mail')) as mail_template_file: + mail_template = message_from_file(mail_template_file) + welcome_mail = InputMail() + welcome_mail.headers['To'] = InputMail.FROM_EMAIL_ADDRESS + welcome_mail.headers['Subject'] = mail_template['Subject'] + welcome_mail.headers['Date'] = iso_now() + welcome_mail._mime = MIMEMultipart() + for payload in mail_template.get_payload(): + welcome_mail._mime.attach(payload) + if payload.get_content_type() == 'text/plain': + welcome_mail.body = payload.as_string() + return welcome_mail + + +def check_welcome_mail_wrapper(mailbox): + def wrapper(*args, **kwargs): + check_welcome_mail(mailbox) + return wrapper diff --git a/service/test/integration/test_welcome_mail.py b/service/test/integration/test_welcome_mail.py new file mode 100644 index 00000000..ed37f50e --- /dev/null +++ b/service/test/integration/test_welcome_mail.py @@ -0,0 +1,35 @@ +# +# Copyright (c) 2014 ThoughtWorks, Inc. +# +# Pixelated is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pixelated is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Pixelated. If not, see . + +from test.support.integration import SoledadTestBase +from pixelated.config.welcome_mail import check_welcome_mail + + +class TestWelcomeMail(SoledadTestBase): + + def test_that_a_fresh_INBOX_will_receive_a_welcome_mail_only_once(self): + inbox = self.mailboxes.inbox() + check_welcome_mail(inbox) # adds a mail + check_welcome_mail(inbox) # should not repeat + + inbox_mails = self.get_mails_by_tag('inbox') + self.assertEquals(1, len(inbox_mails)) + + self.delete_mail(inbox_mails[0].ident) + check_welcome_mail(inbox) # it is empty, but not fresh anymore + + inbox_mails = self.get_mails_by_tag('inbox') + self.assertEquals(0, len(inbox_mails)) diff --git a/service/test/unit/config/test_welcome_mail.py b/service/test/unit/config/test_welcome_mail.py new file mode 100644 index 00000000..3971c73f --- /dev/null +++ b/service/test/unit/config/test_welcome_mail.py @@ -0,0 +1,32 @@ +# +# Copyright (c) 2014 ThoughtWorks, Inc. +# +# Pixelated is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pixelated is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Pixelated. If not, see . +import unittest + +from pixelated.config.welcome_mail import build_welcome_mail +from pixelated.adapter.model.mail import InputMail + + +class WelcomeMailTest(unittest.TestCase): + + def test_build_plain_welcome_mail(self): + user_address = InputMail.FROM_EMAIL_ADDRESS = 'welcomed@user' + mail = build_welcome_mail() + self.assertEquals(user_address, mail.to) + self.assertEquals('Welcome to Pixelated Mail', mail.headers['Subject']) + self.assertIn('How to use it', mail.body) + self.assertIn('text/plain', mail._mime.as_string()) + self.assertIn('text/html', mail._mime.as_string()) + self.assertTrue(mail.headers['Date']) -- cgit v1.2.3 From 25fdeb10ab73c30f9064b0ffb399faf6d12837d7 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Tue, 24 Mar 2015 16:30:01 -0300 Subject: Adds a welcome mail template -- Issue #334 --- service/pixelated/assets/welcome.mail | 53 +++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 service/pixelated/assets/welcome.mail (limited to 'service') diff --git a/service/pixelated/assets/welcome.mail b/service/pixelated/assets/welcome.mail new file mode 100644 index 00000000..81c855db --- /dev/null +++ b/service/pixelated/assets/welcome.mail @@ -0,0 +1,53 @@ +From: Pixelated Team +Date: Sat, 21 Mar 2015 19:30:09 -0300 +Subject: Welcome to Pixelated Mail +To: Replace +Content-Type: multipart/alternative; boundary=000boundary000 + +--000boundary000 +Content-Type: text/plain; charset=UTF-8 + +Welcome to Pixelated Mail a modern email with encryption. Pixelated Mail is an open source project that aims to provide secure email on the browser with all the functionality we've come to expect of a modern email client. + +How to use it +Pixelated Mail should provide functionality that is similar to what you've come to expect of your email software. To the left, you will find a navigation bar that provides access to all your mailboxes and tags. Clicking on them will load the corresponding messages on the middle pane - the mail list. Clicking on a message will load it on this pane, but you know it already! + +To compose a message look for the big blue button on the top left. You can add tags to received messages by clicking on the "+" sign under the message subject. You can also find the encryption status of messages just above the sender/recipient information. + +A bit more about Pixelated +Pixelated is an open source project licensed under AGPL 3.0. It is composed of 3 main parts, the User Agent (what you are using right now), the Dispatcher (what allows you to log in with different accounts to the same instance) and the Platform (which provides the email service you will use to send and receive messages - the server behind the @ sign on your new mail address). You can learn more by visiting https://pixelated-project.org/. + +Enjoy your secure messaging! + +--000boundary000 +Content-Type: text/html; charset=UTF-8 +Content-Transfer-Encoding: quoted-printable + +Welcome to Pixelated Mail a modern email with encryption. Pixelated Mail is= + an open source project that aims to provide secure email on the browser wi= +th all the functionality we've come to expect of a modern email client. + +How to use it +Pixelated Mail should provide functionality that is similar to what you've = +come to expect of your email software. To the left, you will find a navigat= +ion bar that provides access to all your mailboxes and tags. Clicking on th= +em will load the corresponding messages on the middle pane - the mail list.= + Clicking on a message will load it on this pane, but you know it already! + +To compose a message look for the big blue button on the top left. You can = +add tags to received messages by clicking on the "+" sign under the message= + subject. You can also find the encryption status of messages just above th= +e sender/recipient information. + +A bit more about Pixelated +Pixelated is an open source project licensed under AGPL 3.0. It is composed= + of 3 main parts, the User Agent (what you are using right now), the Dispat= +cher (what allows you to log in with different accounts to the same instanc= +e) and the Platform (which provides the email service you will use to send = +and receive messages - the server behind the @ sign on your new mail addres= +s). You can learn more by visiting https://pixelated-project.org/. + +Enjoy your secure messaging! + +--000boundary000-- -- cgit v1.2.3 From 5634839779d5ba751742b3b99d1bb867efe98fe9 Mon Sep 17 00:00:00 2001 From: Victor Shyba Date: Wed, 1 Apr 2015 19:03:05 -0300 Subject: Adds text explaining encryption status --Issue #334 --- service/pixelated/assets/welcome.mail | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'service') diff --git a/service/pixelated/assets/welcome.mail b/service/pixelated/assets/welcome.mail index 81c855db..3bdde998 100644 --- a/service/pixelated/assets/welcome.mail +++ b/service/pixelated/assets/welcome.mail @@ -17,6 +17,11 @@ To compose a message look for the big blue button on the top left. You can add t A bit more about Pixelated Pixelated is an open source project licensed under AGPL 3.0. It is composed of 3 main parts, the User Agent (what you are using right now), the Dispatcher (what allows you to log in with different accounts to the same instance) and the Platform (which provides the email service you will use to send and receive messages - the server behind the @ sign on your new mail address). You can learn more by visiting https://pixelated-project.org/. +About this message and understanding examples of message status +This message was not encrypted, in other words, it could have been read by others at some point during transmission. +However you can check the authenticity of this message, because the message has a certified sender. +Whether it is green, it means that the text you are reading has not changed on the way until delivered to you. + Enjoy your secure messaging! --000boundary000 @@ -48,6 +53,12 @@ and receive messages - the server behind the @ sign on your new mail addres= s). You can learn more by visiting https://pixelated-project.org/. +About this message and understanding examples of message status +This message was not encrypted, in other words, it could have been read by others at some point during transmission. +However you can check the authenticity of this message, because the message has a certified sender. +Whether it is green, it means that the text you are reading has not changed on the way until delivered to you. + + Enjoy your secure messaging! --000boundary000-- -- cgit v1.2.3