diff options
author | Alexandre Pretto Nunes <anunes@thoughtworks.com> | 2014-09-11 17:39:30 -0300 |
---|---|---|
committer | Alexandre Pretto Nunes <anunes@thoughtworks.com> | 2014-09-11 17:39:30 -0300 |
commit | 6c884f74b018b987f95f0259f701ea9fec09d1a3 (patch) | |
tree | ac159bb5bf5dabd849a93c9434c584cc8fe2a101 /service/pixelated/adapter | |
parent | 332e7d54e0e4c3d71e20a9dc8d9957298e6dcb90 (diff) |
Mark mails as read
Diffstat (limited to 'service/pixelated/adapter')
-rw-r--r-- | service/pixelated/adapter/pixelated_mail.py | 9 | ||||
-rw-r--r-- | service/pixelated/adapter/pixelated_mailbox.py | 8 | ||||
-rw-r--r-- | service/pixelated/adapter/status.py | 8 |
3 files changed, 16 insertions, 9 deletions
diff --git a/service/pixelated/adapter/pixelated_mail.py b/service/pixelated/adapter/pixelated_mail.py index d39cf81e..97adc964 100644 --- a/service/pixelated/adapter/pixelated_mail.py +++ b/service/pixelated/adapter/pixelated_mail.py @@ -27,9 +27,10 @@ class PixelatedMail: pass @staticmethod - def from_leap_mail(leap_mail): + def from_leap_mail(leap_mail, leap_mail_collection=None): mail = PixelatedMail() mail.leap_mail = leap_mail + mail.leap_mail._collection = leap_mail_collection #Work around until they fix the issue of mails not having the collection set on a LeapMailbox mail.body = leap_mail.bdoc.content['raw'] mail.headers = mail._extract_headers() mail.date = PixelatedMail._get_date(mail.headers) @@ -80,7 +81,9 @@ class PixelatedMail: return added, removed def mark_as_read(self): - self.status.add("read") + self.leap_mail.setFlags((Status.PixelatedStatus.SEEN,), 1) + self.status = self._extract_status() + return self def _persist_mail_tags(self, current_tags): hdoc = self.leap_mail.hdoc @@ -136,6 +139,6 @@ def from_dict(mail_dict): mail.headers['date'] = pixelated.support.date.iso_now() mail.body = mail_dict.get('body', '') mail.ident = mail_dict.get('ident', None) - mail.tags = mail_dict.get('tags', []) + mail.tags = set(mail_dict.get('tags', [])) mail.status = set(mail_dict.get('status', [])) return mail diff --git a/service/pixelated/adapter/pixelated_mailbox.py b/service/pixelated/adapter/pixelated_mailbox.py index 06f30896..4d4d8faa 100644 --- a/service/pixelated/adapter/pixelated_mailbox.py +++ b/service/pixelated/adapter/pixelated_mailbox.py @@ -39,7 +39,7 @@ class PixelatedMailbox: mails = self.leap_mailbox.messages or [] result = [] for mail in mails: - pixelated_mail = PixelatedMail.from_leap_mail(mail) + pixelated_mail = PixelatedMail.from_leap_mail(mail, mails) self.add_mailbox_tag_if_not_there(pixelated_mail) result.append(pixelated_mail) return result @@ -50,9 +50,9 @@ class PixelatedMailbox: return [mail for mail in self.mails() if len(mail.tags.intersection(tags)) > 0] def mail(self, mail_id): - for message in self.leap_mailbox.messages: - if gen_pixelated_uid(self.leap_mailbox.mbox, message.getUID()) == mail_id: - return PixelatedMail.from_leap_mail(message) + for message in self.mails(): + if message.ident == mail_id: + return message @classmethod def create(cls, account, mailbox_name='INBOX'): diff --git a/service/pixelated/adapter/status.py b/service/pixelated/adapter/status.py index 128ccb68..96257414 100644 --- a/service/pixelated/adapter/status.py +++ b/service/pixelated/adapter/status.py @@ -17,9 +17,13 @@ class Status: + class PixelatedStatus: + SEEN = u'\\Seen' + ANSWERED = u'\\Answered' + LEAP_FLAGS_STATUSES = { - '\\Seen': 'read', - '\\Answered': 'replied' + PixelatedStatus.SEEN: 'read', + PixelatedStatus.ANSWERED: 'replied' } @classmethod |