diff options
Diffstat (limited to 'service/pixelated')
-rw-r--r-- | service/pixelated/adapter/mailstore/leap_mailstore.py | 18 | ||||
-rw-r--r-- | service/pixelated/adapter/model/mail.py | 4 | ||||
-rw-r--r-- | service/pixelated/adapter/search/__init__.py | 6 | ||||
-rw-r--r-- | service/pixelated/config/services.py | 6 |
4 files changed, 30 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')) diff --git a/service/pixelated/config/services.py b/service/pixelated/config/services.py index 73678ccc..63208489 100644 --- a/service/pixelated/config/services.py +++ b/service/pixelated/config/services.py @@ -1,3 +1,4 @@ +from pixelated.adapter.mailstore.searchable_mailstore import SearchableMailStore from pixelated.adapter.services.mail_service import MailService from pixelated.adapter.model.mail import InputMail from pixelated.adapter.services.mail_sender import MailSender @@ -23,6 +24,8 @@ class Services(object): leap_home, soledad_querier) + self.wrap_mail_store_with_indexing_mail_store(leap_session) + pixelated_mailboxes = Mailboxes( leap_session.account, leap_session.soledad_session.soledad, @@ -41,6 +44,9 @@ class Services(object): yield self.post_setup(soledad_querier, leap_session) + def wrap_mail_store_with_indexing_mail_store(self, leap_session): + leap_session.mail_store = SearchableMailStore(leap_session.mail_store, self.search_engine) + @defer.inlineCallbacks def post_setup(self, soledad_querier, leap_session): self.search_engine.index_mails( |