summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--service/pixelated/adapter/mailstore/leap_mailstore.py10
-rw-r--r--service/pixelated/adapter/services/draft_service.py21
-rw-r--r--service/pixelated/adapter/services/mail_service.py20
-rw-r--r--service/pixelated/config/services.py6
-rw-r--r--service/test/integration/test_mark_as_read_unread.py33
-rw-r--r--service/test/support/integration/app_test_client.py2
-rw-r--r--service/test/unit/adapter/test_draft_service.py15
7 files changed, 62 insertions, 45 deletions
diff --git a/service/pixelated/adapter/mailstore/leap_mailstore.py b/service/pixelated/adapter/mailstore/leap_mailstore.py
index 049af9ee..9261f877 100644
--- a/service/pixelated/adapter/mailstore/leap_mailstore.py
+++ b/service/pixelated/adapter/mailstore/leap_mailstore.py
@@ -29,8 +29,8 @@ class LeapMail(Mail):
self._mailbox_name = mailbox_name
self._headers = headers if headers is not None else {}
self._body = body
- self.tags = tags
- self._flags = flags
+ self.tags = set(tags) # TODO test that asserts copy
+ self._flags = set(flags) # TODO test that asserts copy
@property
def headers(self):
@@ -77,6 +77,7 @@ class LeapMail(Mail):
'header': {k.lower(): v for k, v in self.headers.items()},
'ident': self._mail_id,
'tags': self.tags,
+ 'status': list(self.status),
'body': self._body
}
@@ -113,7 +114,8 @@ class LeapMailStore(MailStore):
def update_mail(self, mail):
message = yield self._fetch_msg_from_soledad(mail.mail_id)
message.get_wrapper().set_tags(tuple(mail.tags))
- self._update_mail(message)
+ message.get_wrapper().set_flags(tuple(mail.flags))
+ yield self._update_mail(message) # TODO assert this is yielded (otherwise asynchronous)
@defer.inlineCallbacks
def all_mails(self):
@@ -206,7 +208,7 @@ class LeapMailStore(MailStore):
mbox_uuid = message.get_wrapper().fdoc.mbox_uuid
mbox_name = yield self._mailbox_name_from_uuid(mbox_uuid)
- mail = LeapMail(mail_id, mbox_name, message.get_wrapper().hdoc.headers, set(message.get_tags()), body=body)
+ mail = LeapMail(mail_id, mbox_name, message.get_wrapper().hdoc.headers, set(message.get_tags()), set(message.get_flags()), body=body) # TODO assert flags are passed on
defer.returnValue(mail)
diff --git a/service/pixelated/adapter/services/draft_service.py b/service/pixelated/adapter/services/draft_service.py
index 5a0ee5f3..c3a14928 100644
--- a/service/pixelated/adapter/services/draft_service.py
+++ b/service/pixelated/adapter/services/draft_service.py
@@ -17,18 +17,23 @@ from twisted.internet import defer
class DraftService(object):
- __slots__ = '_mailboxes'
+ __slots__ = '_mail_store'
- def __init__(self, mailboxes):
- self._mailboxes = mailboxes
+ def __init__(self, mail_store):
+ self._mail_store = mail_store
@defer.inlineCallbacks
def create_draft(self, input_mail):
- pixelated_mail = yield (yield self._mailboxes.drafts).add(input_mail)
- defer.returnValue(pixelated_mail)
+ mail = yield self._mail_store.add_mail('DRAFTS', input_mail.raw)
+ defer.returnValue(mail)
+ # pixelated_mail = yield (yield self._mailboxes.drafts).add(input_mail)
+ # defer.returnValue(pixelated_mail)
@defer.inlineCallbacks
def update_draft(self, ident, input_mail):
- pixelated_mail = yield self.create_draft(input_mail)
- yield (yield self._mailboxes.drafts).remove(ident)
- defer.returnValue(pixelated_mail)
+ new_draft = yield self.create_draft(input_mail)
+ yield self._mail_store.delete_mail(ident)
+ defer.returnValue(new_draft)
+ # pixelated_mail = yield self.create_draft(input_mail)
+ # yield (yield self._mailboxes.drafts).remove(ident)
+ # defer.returnValue(pixelated_mail)
diff --git a/service/pixelated/adapter/services/mail_service.py b/service/pixelated/adapter/services/mail_service.py
index 6b011e11..1d161958 100644
--- a/service/pixelated/adapter/services/mail_service.py
+++ b/service/pixelated/adapter/services/mail_service.py
@@ -15,6 +15,7 @@
# along with Pixelated. If not, see <http://www.gnu.org/licenses/>.
from twisted.internet import defer
from pixelated.adapter.model.mail import InputMail
+from pixelated.adapter.model.status import Status
from pixelated.adapter.services.tag_service import extract_reserved_tags
@@ -77,7 +78,11 @@ class MailService(object):
@defer.inlineCallbacks
def mail_exists(self, mail_id):
- defer.returnValue(not(not((yield self.querier.get_header_by_chash(mail_id)))))
+ try:
+ mail = yield self.mail_store.get_mail(mail_id)
+ defer.returnValue(mail is not None)
+ except Exception, e:
+ defer.returnValue(False)
@defer.inlineCallbacks
def send_mail(self, content_dict):
@@ -91,20 +96,21 @@ class MailService(object):
@defer.inlineCallbacks
def move_to_sent(self, last_draft_ident, mail):
if last_draft_ident:
- yield (yield self.mailboxes.drafts).remove(last_draft_ident)
- defer.returnValue((yield (yield self.mailboxes.sent).add(mail)))
+ yield self.mail_store.delete_mail(last_draft_ident)
+ sent_mail = yield self.mail_store.add_mail('SENT', mail.raw)
+ defer.returnValue(sent_mail)
@defer.inlineCallbacks
def mark_as_read(self, mail_id):
mail = yield self.mail(mail_id)
- yield mail.mark_as_read()
- self.search_engine.index_mail(mail)
+ mail.flags.add(Status.SEEN)
+ yield self.mail_store.update_mail(mail)
@defer.inlineCallbacks
def mark_as_unread(self, mail_id):
mail = yield self.mail(mail_id)
- yield mail.mark_as_unread()
- self.search_engine.index_mail(mail)
+ mail.flags.remove(Status.SEEN)
+ yield self.mail_store.update_mail(mail)
@defer.inlineCallbacks
def delete_mail(self, mail_id):
diff --git a/service/pixelated/config/services.py b/service/pixelated/config/services.py
index 63208489..cc8da83b 100644
--- a/service/pixelated/config/services.py
+++ b/service/pixelated/config/services.py
@@ -40,7 +40,7 @@ class Services(object):
pixelated_mailboxes)
self.keymanager = leap_session.nicknym
- self.draft_service = self.setup_draft_service(pixelated_mailboxes)
+ self.draft_service = self.setup_draft_service(leap_session.mail_store)
yield self.post_setup(soledad_querier, leap_session)
@@ -77,5 +77,5 @@ class Services(object):
soledad_querier,
search_engine))
- def setup_draft_service(self, pixelated_mailboxes):
- return DraftService(pixelated_mailboxes)
+ def setup_draft_service(self, mail_store):
+ return DraftService(mail_store)
diff --git a/service/test/integration/test_mark_as_read_unread.py b/service/test/integration/test_mark_as_read_unread.py
index b2249b54..48879e4a 100644
--- a/service/test/integration/test_mark_as_read_unread.py
+++ b/service/test/integration/test_mark_as_read_unread.py
@@ -25,35 +25,37 @@ class MarkAsReadUnreadTest(SoledadTestBase):
@defer.inlineCallbacks
def test_mark_single_as_read(self):
input_mail = MailBuilder().build_input_mail()
- yield self.add_mail_to_inbox(input_mail)
+ mail = yield self.add_mail_to_inbox(input_mail)
mails = yield self.get_mails_by_tag('inbox')
self.assertNotIn('read', mails[0].status)
- yield self.mark_many_as_read([input_mail.ident])
+ yield self.mark_many_as_read([mail.ident])
mails = yield self.get_mails_by_tag('inbox')
self.assertIn('read', mails[0].status)
@defer.inlineCallbacks
def test_mark_single_as_unread(self):
- input_mail = MailBuilder().with_status([Status.SEEN]).build_input_mail()
- yield self.add_mail_to_inbox(input_mail)
+ input_mail = MailBuilder().build_input_mail()
+ mail = yield self.add_mail_to_inbox(input_mail)
+ yield self.mark_many_as_read([mail.ident])
- yield self.mark_many_as_unread([input_mail.ident])
- mail = (yield self.get_mails_by_tag('inbox'))[0]
+ yield self.mark_many_as_unread([mail.ident])
+ result = (yield self.get_mails_by_tag('inbox'))[0]
- self.assertNotIn('read', mail.status)
+ self.assertNotIn('read', result.status)
@defer.inlineCallbacks
def test_mark_many_mails_as_unread(self):
input_mail = MailBuilder().with_status([Status.SEEN]).build_input_mail()
input_mail2 = MailBuilder().with_status([Status.SEEN]).build_input_mail()
- yield self.add_mail_to_inbox(input_mail)
- yield self.add_mail_to_inbox(input_mail2)
+ mail1 = yield self.add_mail_to_inbox(input_mail)
+ mail2 = yield self.add_mail_to_inbox(input_mail2)
+ yield self.mark_many_as_read([mail1.ident, mail2.ident])
- yield self.mark_many_as_unread([input_mail.ident, input_mail2.ident])
+ yield self.mark_many_as_unread([mail1.ident, mail2.ident])
mails = yield self.get_mails_by_tag('inbox')
@@ -73,7 +75,7 @@ class MarkAsReadUnreadTest(SoledadTestBase):
self.assertNotIn('read', mails[0].status)
self.assertNotIn('read', mails[1].status)
- yield self.mark_many_as_read([input_mail.ident, input_mail2.ident])
+ yield self.mark_many_as_read([mails[0].ident, mails[1].ident])
mails = yield self.get_mails_by_tag('inbox')
@@ -82,11 +84,12 @@ class MarkAsReadUnreadTest(SoledadTestBase):
@defer.inlineCallbacks
def test_mark_mixed_status_as_read(self):
- input_mail = MailBuilder().build_input_mail()
- input_mail2 = MailBuilder().with_status([Status.SEEN]).build_input_mail()
+ input_mail = MailBuilder().with_subject('first').build_input_mail()
+ input_mail2 = MailBuilder().with_subject('second').build_input_mail()
yield self.add_mail_to_inbox(input_mail)
- yield self.add_mail_to_inbox(input_mail2)
+ mail2 = yield self.add_mail_to_inbox(input_mail2)
+ yield self.mark_many_as_read([mail2.ident])
mails = yield self.get_mails_by_tag('inbox')
@@ -95,7 +98,7 @@ class MarkAsReadUnreadTest(SoledadTestBase):
self.assertEquals(1, len(unread_mails))
self.assertEquals(1, len(read_mails))
- yield self.mark_many_as_read([input_mail.ident, input_mail2.ident])
+ yield self.mark_many_as_read([mails[0].ident, mails[1].ident])
mails = yield self.get_mails_by_tag('inbox')
diff --git a/service/test/support/integration/app_test_client.py b/service/test/support/integration/app_test_client.py
index ee305c69..31ffcd77 100644
--- a/service/test/support/integration/app_test_client.py
+++ b/service/test/support/integration/app_test_client.py
@@ -78,7 +78,7 @@ class AppTestClient(object):
self.account = IMAPAccount(self.ACCOUNT, self.soledad, account_ready_cb)
yield account_ready_cb
self.mailboxes = Mailboxes(self.account, self.mail_store, self.soledad_querier, self.search_engine)
- self.draft_service = DraftService(self.mailboxes)
+ self.draft_service = DraftService(self.mail_store)
self.mail_service = self._create_mail_service(self.mailboxes, self.mail_sender, self.mail_store, self.soledad_querier, self.search_engine)
mails = yield self.mail_service.all_mails()
diff --git a/service/test/unit/adapter/test_draft_service.py b/service/test/unit/adapter/test_draft_service.py
index 79eca5f6..c2b7cd93 100644
--- a/service/test/unit/adapter/test_draft_service.py
+++ b/service/test/unit/adapter/test_draft_service.py
@@ -1,4 +1,6 @@
import unittest
+from twisted.internet import defer
+from pixelated.adapter.mailstore.leap_mailstore import LeapMail
from pixelated.adapter.model.mail import InputMail
from pixelated.adapter.services.draft_service import DraftService
@@ -10,21 +12,20 @@ class DraftServiceTest(unittest.TestCase):
def setUp(self):
self.mailboxes = mock()
- self.drafts_mailbox = mock()
- self.draft_service = DraftService(self.mailboxes)
- self.mailboxes.drafts = self.drafts_mailbox
+ self.mail_store = mock()
+ self.draft_service = DraftService(self.mail_store)
def test_add_draft(self):
mail = InputMail()
self.draft_service.create_draft(mail)
- verify(self.drafts_mailbox).add(mail)
+ verify(self.mail_store).add_mail('DRAFTS', mail.raw)
def test_update_draft(self):
mail = InputMail.from_dict(test_helper.mail_dict())
- when(self.drafts_mailbox).add(mail).thenReturn(mail)
+ when(self.mail_store).add_mail('DRAFTS', mail.raw).thenReturn(defer.succeed(LeapMail('id', 'DRAFTS')))
self.draft_service.update_draft(mail.ident, mail)
- inorder.verify(self.drafts_mailbox).add(mail)
- inorder.verify(self.drafts_mailbox).remove(mail.ident)
+ inorder.verify(self.mail_store).add_mail('DRAFTS', mail.raw)
+ inorder.verify(self.mail_store).delete_mail(mail.ident)