From 10112b7d862f5d2d24b6c295e08c4ebd73d54ee2 Mon Sep 17 00:00:00 2001 From: Patrick Maia and Victor Shyba Date: Mon, 8 Sep 2014 08:26:52 +0000 Subject: \#72 - adds tag with the name of the mailbox on all mails that does not have it during mails fetch --- service/pixelated/adapter/pixelated_mailbox.py | 12 ++++++++++-- service/test/adapter/pixelated_mailbox_test.py | 9 +++++++++ service/test/adapter/test_helper.py | 3 ++- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/service/pixelated/adapter/pixelated_mailbox.py b/service/pixelated/adapter/pixelated_mailbox.py index 2723dfc1..1a17926a 100644 --- a/service/pixelated/adapter/pixelated_mailbox.py +++ b/service/pixelated/adapter/pixelated_mailbox.py @@ -40,8 +40,16 @@ class PixelatedMailbox: def mails(self): mails = self.leap_mailbox.messages or [] - mails = [PixelatedMail.from_leap_mail(mail) for mail in mails] - return mails + result = [] + mailbox_name = self.leap_mailbox.mbox + for mail in mails: + pixelated_mail = PixelatedMail.from_leap_mail(mail) + if not pixelated_mail.has_tag(mailbox_name): + new_tags = set([mailbox_name.lower()]) + pixelated_mail.update_tags(new_tags.union(pixelated_mail.tags)) + self.notify_tags_updated(new_tags, [], pixelated_mail.ident) + result.append(pixelated_mail) + return result def mails_by_tags(self, tags): if 'all' in tags: diff --git a/service/test/adapter/pixelated_mailbox_test.py b/service/test/adapter/pixelated_mailbox_test.py index 72e6141d..9bc65de0 100644 --- a/service/test/adapter/pixelated_mailbox_test.py +++ b/service/test/adapter/pixelated_mailbox_test.py @@ -57,6 +57,15 @@ class TestPixelatedMailbox(unittest.TestCase): self.assertEquals(1, mailbox.tag_index.get('inbox').total) self.assertIsNone(mailbox.tag_index.get('one_tag')) + def test_mailbox_tag_is_added_when_new_mail_arrives(self): + mail_one = test_helper.leap_mail(uid=0) + + leap_mailbox = test_helper.leap_mailbox(messages=[mail_one], mailbox_name='SENT') + mailbox = PixelatedMailbox(leap_mailbox, self.db_file_path) + + mail = mailbox.mail(0) + self.assertIn('sent', mail.tags) + def test_index_is_initialized_with_mail_tags_if_empty(self): mail_one = test_helper.leap_mail(uid=0, extra_headers={'X-Tags': ['tag_1']}) mail_two = test_helper.leap_mail(uid=1, extra_headers={'X-Tags': ['tag_2']}) diff --git a/service/test/adapter/test_helper.py b/service/test/adapter/test_helper.py index 7bf19a42..a904a041 100644 --- a/service/test/adapter/test_helper.py +++ b/service/test/adapter/test_helper.py @@ -49,6 +49,7 @@ def leap_mail(uid=0, flags=LEAP_FLAGS, headers=DEFAULT_HEADERS, extra_headers={} hdoc=Mock(content={'headers': headers})) -def leap_mailbox(messages=[leap_mail(uid=6)]): +def leap_mailbox(messages=[leap_mail(uid=6)], mailbox_name='INBOX'): return Mock(_get_mbox_doc=Mock(return_value=None), + mbox=mailbox_name, messages=messages) -- cgit v1.2.3