summaryrefslogtreecommitdiff
path: root/service/pixelated/adapter/mailstore/leap_mailstore.py
diff options
context:
space:
mode:
authorFolker Bernitt <fbernitt@thoughtworks.com>2015-07-23 16:33:32 +0200
committerFolker Bernitt <fbernitt@thoughtworks.com>2015-08-11 17:00:27 +0200
commit4de9e17f4cd1f597251552408080c1a82c45720f (patch)
treed64b9a2f8d2823991d18157a9f5107a4614c5700 /service/pixelated/adapter/mailstore/leap_mailstore.py
parent23f0aafe4490b4126af6c8e12aaa340170f042c6 (diff)
Added to_dict and get_mails to mail storage.
Diffstat (limited to 'service/pixelated/adapter/mailstore/leap_mailstore.py')
-rw-r--r--service/pixelated/adapter/mailstore/leap_mailstore.py25
1 files changed, 21 insertions, 4 deletions
diff --git a/service/pixelated/adapter/mailstore/leap_mailstore.py b/service/pixelated/adapter/mailstore/leap_mailstore.py
index 9d41c988..a39f4eae 100644
--- a/service/pixelated/adapter/mailstore/leap_mailstore.py
+++ b/service/pixelated/adapter/mailstore/leap_mailstore.py
@@ -23,14 +23,24 @@ from pixelated.adapter.model.mail import Mail
class LeapMail(Mail):
- def __init__(self, headers, body=None):
+ def __init__(self, mail_id, headers, tags=tuple(), body=None):
+ self._mail_id = mail_id
self.headers = headers
self._body = body
+ self._tags = tags
@property
def body(self):
return self._body
+ def as_dict(self):
+ return {
+ 'header': {k.lower(): v for k, v in self.headers.items()},
+ 'ident': self._mail_id,
+ 'tags': self._tags,
+ }
+
+
class LeapMailStore(MailStore):
__slots__ = ('account', 'soledad')
@@ -43,10 +53,17 @@ class LeapMailStore(MailStore):
try:
message = yield SoledadMailAdaptor().get_msg_from_mdoc_id(Message, self.soledad, mail_id)
- defer.returnValue(self._leap_message_to_leap_mail(message))
+ defer.returnValue(self._leap_message_to_leap_mail(mail_id, message))
except AttributeError:
defer.returnValue(None)
- def _leap_message_to_leap_mail(self, message):
- return LeapMail(message.get_headers())
+ def get_mails(self, mail_ids):
+ deferreds = []
+ for mail_id in mail_ids:
+ deferreds.append(self.get_mail(mail_id))
+
+ return defer.gatherResults(deferreds, consumeErrors=True)
+
+ def _leap_message_to_leap_mail(self, mail_id, message):
+ return LeapMail(mail_id, message.get_headers(), message.get_tags())