From 6c884f74b018b987f95f0259f701ea9fec09d1a3 Mon Sep 17 00:00:00 2001 From: Alexandre Pretto Nunes Date: Thu, 11 Sep 2014 17:39:30 -0300 Subject: Mark mails as read --- service/pixelated/adapter/pixelated_mail.py | 9 ++++++--- service/pixelated/adapter/pixelated_mailbox.py | 8 ++++---- service/pixelated/adapter/status.py | 8 ++++++-- service/test/adapter/pixelated_mail_test.py | 9 +++++---- 4 files changed, 21 insertions(+), 13 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 diff --git a/service/test/adapter/pixelated_mail_test.py b/service/test/adapter/pixelated_mail_test.py index 67922893..e364f7a9 100644 --- a/service/test/adapter/pixelated_mail_test.py +++ b/service/test/adapter/pixelated_mail_test.py @@ -17,6 +17,7 @@ import unittest import pixelated.support.date from pixelated.adapter.pixelated_mail import PixelatedMail +from pixelated.adapter.pixelated_mail import Status import test_helper @@ -62,7 +63,7 @@ class TestPixelatedMail(unittest.TestCase): self.assertEqual(mail.headers['bcc'], ['bcc@pixelated.org', 'anotherbcc@pixelated.org']) self.assertEqual(mail.headers['subject'], 'Oi') self.assertEqual(mail.ident, '') - self.assertEqual(mail.tags, ['sent']) + self.assertEqual(mail.tags, set(['sent'])) self.assertEqual(mail.body, 'Este \xe9 o corpo') def test_from_dict_adds_current_date(self): @@ -113,8 +114,8 @@ class TestPixelatedMail(unittest.TestCase): self.assertEquals(pixelated_mail.headers['cc'], ["nlima@example.com", "Duda Dornelles "]) def test_mark_as_read(self): - mail = PixelatedMail.from_dict(self.mail_dict) + mail = PixelatedMail.from_leap_mail(test_helper.leap_mail(flags=[])) - mail.mark_as_read() + read_mail = mail.mark_as_read() - self.assertIn("read", mail.status) + self.assertEquals(mail.leap_mail.setFlags.call_args[0], (('\\Seen',), 1)) -- cgit v1.2.3