diff options
author | Folker Bernitt <fbernitt@thoughtworks.com> | 2015-08-05 10:34:39 +0200 |
---|---|---|
committer | Folker Bernitt <fbernitt@thoughtworks.com> | 2015-08-11 17:00:32 +0200 |
commit | 908eaede72f0fd6daa8c9b1522e2b60095718623 (patch) | |
tree | ecd98527523a15e12c4b2c6a914ca993753fac72 /service/pixelated | |
parent | 579dab68cc73cd8e52b8f6feaa02a51b361c59bb (diff) |
Added mailbox name to leap mails.
Diffstat (limited to 'service/pixelated')
-rw-r--r-- | service/pixelated/adapter/mailstore/leap_mailstore.py | 27 |
1 files changed, 21 insertions, 6 deletions
diff --git a/service/pixelated/adapter/mailstore/leap_mailstore.py b/service/pixelated/adapter/mailstore/leap_mailstore.py index 60068322..7ba02519 100644 --- a/service/pixelated/adapter/mailstore/leap_mailstore.py +++ b/service/pixelated/adapter/mailstore/leap_mailstore.py @@ -23,8 +23,9 @@ from pixelated.adapter.model.mail import Mail class LeapMail(Mail): - def __init__(self, mail_id, headers=None, tags=set(), body=None): + def __init__(self, mail_id, mailbox_name, headers=None, tags=set(), body=None): self._mail_id = mail_id + self._mailbox_name = mailbox_name self.headers = headers if headers is not None else {} self._body = body self.tags = tags @@ -37,6 +38,10 @@ class LeapMail(Mail): def body(self): return self._body + @property + def mailbox_name(self): + return self._mailbox_name + def as_dict(self): return { 'header': {k.lower(): v for k, v in self.headers.items()}, @@ -94,16 +99,16 @@ class LeapMailStore(MailStore): @defer.inlineCallbacks def get_mailbox_names(self): - mbox_map = set((yield self._mailbox_uuid_to_name()).values()) + mbox_map = set((yield self._mailbox_uuid_to_name_map()).values()) defer.returnValue(mbox_map.union({'INBOX'})) @defer.inlineCallbacks - def _mailbox_uuid_to_name(self): + def _mailbox_uuid_to_name_map(self): map = {} mbox_docs = yield self.soledad.get_from_index('by-type', 'mbox') for doc in mbox_docs: - map[doc.doc_id] = doc.content.get('mbox') + map[underscore_uuid(doc.content.get('uuid'))] = doc.content.get('mbox') defer.returnValue(map) @@ -161,13 +166,23 @@ class LeapMailStore(MailStore): @defer.inlineCallbacks def _leap_message_to_leap_mail(self, mail_id, message, include_body): if include_body: - body = (yield message._wrapper.get_body(self.soledad)).raw + body = (yield message.get_wrapper().get_body(self.soledad)).raw else: body = None - mail = LeapMail(mail_id, message.get_headers(), set(message.get_tags()), body=body) + + # fetch mailbox name by mbox_uuid + 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_headers(), set(message.get_tags()), body=body) defer.returnValue(mail) + @defer.inlineCallbacks + def _mailbox_name_from_uuid(self, uuid): + map = (yield self._mailbox_uuid_to_name_map()) + defer.returnValue(map[uuid]) + def _get_or_create_mailbox(self, mailbox_name): return SoledadMailAdaptor().get_or_create_mbox(self.soledad, mailbox_name) |