diff options
author | Victor Shyba <victor.shyba@gmail.com> | 2014-09-16 16:56:59 -0300 |
---|---|---|
committer | Victor Shyba <victor.shyba@gmail.com> | 2014-09-16 16:56:59 -0300 |
commit | eb9af89a56da8f6d4afe759c8b88eaef5d181b8e (patch) | |
tree | ed67c7352c8ce7f88762765e693d9fb5a5aa7c99 | |
parent | 8f657882334d5c0beb28217e78ca5da1a5cea415 (diff) |
#53 apply mailbox tag only on recent mail
-rw-r--r-- | service/pixelated/adapter/pixelated_mail.py | 9 | ||||
-rw-r--r-- | service/pixelated/adapter/pixelated_mailbox.py | 3 | ||||
-rw-r--r-- | service/test/adapter/pixelated_mail_test.py | 7 | ||||
-rw-r--r-- | service/test/adapter/pixelated_mailbox_test.py | 12 |
4 files changed, 27 insertions, 4 deletions
diff --git a/service/pixelated/adapter/pixelated_mail.py b/service/pixelated/adapter/pixelated_mail.py index f6e02882..c732f5a0 100644 --- a/service/pixelated/adapter/pixelated_mail.py +++ b/service/pixelated/adapter/pixelated_mail.py @@ -45,6 +45,10 @@ class PixelatedMail: return mail @property + def is_recent(self): + return Status('recent') in self.status + + @property def ident(self): return gen_pixelated_uid(self.leap_mailbox.mbox, self.leap_mail.getUID()) @@ -96,6 +100,11 @@ class PixelatedMail: self.status = self._extract_status() return self + def mark_as_not_recent(self): + self.leap_mail.setFlags((Status.PixelatedStatus.RECENT,), -1) + self.status = self._extract_status() + return self + def _persist_mail_tags(self, current_tags): hdoc = self.leap_mail.hdoc hdoc.content['headers']['X-Tags'] = json.dumps(list(current_tags)) diff --git a/service/pixelated/adapter/pixelated_mailbox.py b/service/pixelated/adapter/pixelated_mailbox.py index 34c6c97b..7d2a1fa5 100644 --- a/service/pixelated/adapter/pixelated_mailbox.py +++ b/service/pixelated/adapter/pixelated_mailbox.py @@ -35,9 +35,10 @@ class PixelatedMailbox: return self.leap_mailbox.mbox def add_mailbox_tag_if_not_there(self, pixelated_mail): - if not pixelated_mail.has_tag(self.mailbox_tag): + if not pixelated_mail.has_tag(self.mailbox_tag) and pixelated_mail.is_recent: pixelated_mail.update_tags({self.mailbox_tag}.union(pixelated_mail.tags)) self.tag_service.notify_tags_updated({self.mailbox_tag}, [], pixelated_mail.ident) + pixelated_mail.mark_as_not_recent() def mails(self): mails = self.leap_mailbox.messages or [] diff --git a/service/test/adapter/pixelated_mail_test.py b/service/test/adapter/pixelated_mail_test.py index 9eab3d2c..4292883c 100644 --- a/service/test/adapter/pixelated_mail_test.py +++ b/service/test/adapter/pixelated_mail_test.py @@ -119,3 +119,10 @@ class TestPixelatedMail(unittest.TestCase): mail.mark_as_read() self.assertEquals(mail.leap_mail.setFlags.call_args[0], (('\\Seen',), 1)) + + def test_mark_as_not_recent(self): + mail = PixelatedMail.from_leap_mail(test_helper.leap_mail(flags=[])) + + mail.mark_as_not_recent() + + self.assertEquals(mail.leap_mail.setFlags.call_args[0], (('\\Recent',), -1)) diff --git a/service/test/adapter/pixelated_mailbox_test.py b/service/test/adapter/pixelated_mailbox_test.py index 9ac4f53e..b4ddb32d 100644 --- a/service/test/adapter/pixelated_mailbox_test.py +++ b/service/test/adapter/pixelated_mailbox_test.py @@ -31,9 +31,15 @@ class TestPixelatedMailbox(unittest.TestCase): self.tag_service = mock() self.mailbox = PixelatedMailbox(leap_mailbox, self.tag_service) - def test_mailbox_tag_is_added_when_new_mail_arrives(self): - mails = self.mailbox.mails() - self.assertIn('sent', mails[0].tags) + def test_mailbox_tag_is_added_when_recent_mail_arrives(self): + recent_leap_mail = test_helper.leap_mail(uid=0, mbox='SPAM', flags=['\\Recent']) + mailbox = PixelatedMailbox(test_helper.leap_mailbox(messages=[recent_leap_mail], mailbox_name='SPAM')) + self.assertIn('spam', mailbox.mails()[0].tags) + + def test_mailbox_tag_is_ignored_for_non_recent_mail(self): + recent_leap_mail = test_helper.leap_mail(uid=0, mbox='SPAM', flags=[]) + mailbox = PixelatedMailbox(test_helper.leap_mailbox(messages=[recent_leap_mail], mailbox_name='SPAM')) + self.assertNotIn('spam', mailbox.mails()[0].tags) def test_add_message_to_mailbox(self): PixelatedMail.from_email_address = 'pixel@ted.org' |