summaryrefslogtreecommitdiff
path: root/service/pixelated/adapter
diff options
context:
space:
mode:
authorFolker Bernitt <fbernitt@thoughtworks.com>2015-08-06 13:25:30 +0200
committerFolker Bernitt <fbernitt@thoughtworks.com>2015-08-11 17:00:33 +0200
commit08497951fa9aed8d28be8b2dea1aef2135f56769 (patch)
tree2c11b8c3cc71b47db62fa3cb4dce9dbe3ed22292 /service/pixelated/adapter
parentce86deeed4d4e408ddad294beec7952601345025 (diff)
Made LeapMail compatible with SearchEngine.
Diffstat (limited to 'service/pixelated/adapter')
-rw-r--r--service/pixelated/adapter/mailstore/leap_mailstore.py18
-rw-r--r--service/pixelated/adapter/model/mail.py4
-rw-r--r--service/pixelated/adapter/search/__init__.py6
3 files changed, 24 insertions, 4 deletions
diff --git a/service/pixelated/adapter/mailstore/leap_mailstore.py b/service/pixelated/adapter/mailstore/leap_mailstore.py
index 7ba02519..c3c93cc3 100644
--- a/service/pixelated/adapter/mailstore/leap_mailstore.py
+++ b/service/pixelated/adapter/mailstore/leap_mailstore.py
@@ -23,12 +23,13 @@ from pixelated.adapter.model.mail import Mail
class LeapMail(Mail):
- def __init__(self, mail_id, mailbox_name, headers=None, tags=set(), body=None):
+ def __init__(self, mail_id, mailbox_name, headers=None, tags=set(), flags=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
+ self._flags = flags
@property
def mail_id(self):
@@ -39,9 +40,24 @@ class LeapMail(Mail):
return self._body
@property
+ def flags(self):
+ return self._flags
+
+ @property
def mailbox_name(self):
return self._mailbox_name
+ @property
+ def raw(self):
+ result = ''
+ for k, v in self.headers.items():
+ result = result + '%s: %s\n' % (k, v)
+ result = result + '\n'
+ if self._body:
+ result = result + self._body
+
+ return result
+
def as_dict(self):
return {
'header': {k.lower(): v for k, v in self.headers.items()},
diff --git a/service/pixelated/adapter/model/mail.py b/service/pixelated/adapter/model/mail.py
index 498ef079..61e56f33 100644
--- a/service/pixelated/adapter/model/mail.py
+++ b/service/pixelated/adapter/model/mail.py
@@ -86,6 +86,10 @@ class Mail(object):
return self.fdoc.content.get('mbox', 'INBOX')
@property
+ def bounced(self):
+ return False
+
+ @property
def _mime_multipart(self):
if self._mime:
return self._mime
diff --git a/service/pixelated/adapter/search/__init__.py b/service/pixelated/adapter/search/__init__.py
index b8d3e7ca..759ad5ef 100644
--- a/service/pixelated/adapter/search/__init__.py
+++ b/service/pixelated/adapter/search/__init__.py
@@ -121,8 +121,8 @@ class SearchEngine(object):
def _index_mail(self, writer, mail):
mdict = mail.as_dict()
header = mdict['header']
- tags = mdict.get('tags', [])
- tags.append(mail.mailbox_name.lower())
+ tags = set(mdict.get('tags', {}))
+ tags.add(mail.mailbox_name.lower())
bounced = mail.bounced if mail.bounced else ['']
index_data = {
@@ -134,7 +134,7 @@ class SearchEngine(object):
'bcc': u','.join([h.decode('utf-8') for h in header.get('bcc', [''])]),
'tag': u','.join(unique(tags)),
'bounced': u','.join(bounced),
- 'body': unicode(mdict['textPlainBody']),
+ 'body': unicode(mdict['textPlainBody'] if 'textPlainBody' in mdict else mdict['body']),
'ident': unicode(mdict['ident']),
'flags': unicode(','.join(unique(mail.flags))),
'raw': unicode(mail.raw.decode('utf-8'))