summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorVictor Shyba <victor.shyba@gmail.com>2015-04-08 18:24:21 -0300
committerVictor Shyba <victor.shyba@gmail.com>2015-04-08 18:24:21 -0300
commit497488499fcf870df762919e42862ca6b52a0028 (patch)
treed76c154940678e30372853c13bd275ebf67708f8 /service
parent58e22319f1926d5441cb7b69451bfa91d30fa03a (diff)
parent5634839779d5ba751742b3b99d1bb867efe98fe9 (diff)
Merge pull request #358 from pixelated-project/shybamaster
Welcome email
Diffstat (limited to 'service')
-rw-r--r--service/pixelated/adapter/soledad/soledad_facade_mixin.py6
-rw-r--r--service/pixelated/assets/welcome.mail64
-rw-r--r--service/pixelated/config/app_factory.py4
-rw-r--r--service/pixelated/config/welcome_mail.py48
-rw-r--r--service/test/integration/test_welcome_mail.py35
-rw-r--r--service/test/unit/config/test_welcome_mail.py32
6 files changed, 187 insertions, 2 deletions
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/assets/welcome.mail b/service/pixelated/assets/welcome.mail
new file mode 100644
index 00000000..3bdde998
--- /dev/null
+++ b/service/pixelated/assets/welcome.mail
@@ -0,0 +1,64 @@
+From: Pixelated Team <pixelated-team@pixelated-project.org>
+Date: Sat, 21 Mar 2015 19:30:09 -0300
+Subject: Welcome to Pixelated Mail
+To: Replace <will.be@the.user>
+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/.
+
+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
+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.
+
+<b>How to use it</b>
+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.
+
+<b>A bit more about Pixelated</b>
+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 <a src=3D"https://pixelated-project.org/=
+">https://pixelated-project.org/</a>.
+
+<b>About this message and understanding examples of message status</b>
+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--
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))
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 <http://www.gnu.org/licenses/>.
+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 <http://www.gnu.org/licenses/>.
+
+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 <http://www.gnu.org/licenses/>.
+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'])