summaryrefslogtreecommitdiff
path: root/service/pixelated/adapter
diff options
context:
space:
mode:
authorFolker Bernitt <fbernitt@thoughtworks.com>2015-08-09 22:09:08 +0200
committerFolker Bernitt <fbernitt@thoughtworks.com>2015-08-11 17:00:33 +0200
commit46ed5e1731fa0295a7f4b612457069db36bb8e64 (patch)
treef7b1d81e19f1e86d40c605910063e86feef6eb73 /service/pixelated/adapter
parent319e5e2ddd20444bb30f294a2fd08854dfaae494 (diff)
Worked on integration tests.
Diffstat (limited to 'service/pixelated/adapter')
-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
3 files changed, 32 insertions, 19 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):