diff options
author | Patrick Maia <patrickjourdanmaia@gmail.com> | 2014-08-14 16:38:19 -0300 |
---|---|---|
committer | Patrick Maia <patrickjourdanmaia@gmail.com> | 2014-08-14 16:46:20 -0300 |
commit | 33cd5cbb6f023f281c5b146d9cf0ccdba4d53e22 (patch) | |
tree | 0f9308ac7e5e675870781e2dddcf54416e066657 /service | |
parent | 7f3a740a2b4366ea97bc08b99ab9b969f8aedb01 (diff) |
Persisting new tags to email (using workaround for now because LeapMessage.set_flags is not working)
Diffstat (limited to 'service')
-rw-r--r-- | service/app/adapter/mail_service.py | 12 | ||||
-rw-r--r-- | service/test/adapter/mail_service_test.py | 3 |
2 files changed, 13 insertions, 2 deletions
diff --git a/service/app/adapter/mail_service.py b/service/app/adapter/mail_service.py index 32238973..a11825e0 100644 --- a/service/app/adapter/mail_service.py +++ b/service/app/adapter/mail_service.py @@ -1,6 +1,7 @@ import traceback import sys import os +from twisted.internet import defer from app.bitmask_libraries.config import LeapConfig from app.bitmask_libraries.provider import LeapProvider from app.bitmask_libraries.session import LeapSessionFactory @@ -36,13 +37,22 @@ class MailService: def update_tags(self, mail_id, new_tags): mail = self.mail(mail_id) new_tags = mail.update_tags(new_tags) + self._update_flags(new_tags, mail_id) self._update_tag_list(new_tags) - return mail + return new_tags def _update_tag_list(self, tags): for tag in tags: self.tags.add(tag) + def _update_flags(self, new_tags, mail_id): + new_tags_flag_name = ['tag_'+tag.name for tag in new_tags] + self.set_flags(mail_id, new_tags_flag_name) + + def set_flags(self, mail_id, new_tags_flag_name): + observer = defer.Deferred() + self.mailbox.messages.set_flags(self.mailbox, [mail_id], tuple(new_tags_flag_name), 1, observer) + def mail(self, mail_id): for message in self.mailbox.messages: if message.getUID() == int(mail_id): diff --git a/service/test/adapter/mail_service_test.py b/service/test/adapter/mail_service_test.py index 7b70ac9b..5a085ef3 100644 --- a/service/test/adapter/mail_service_test.py +++ b/service/test/adapter/mail_service_test.py @@ -25,7 +25,8 @@ class TestMailService(unittest.TestCase): "body": "teste" } - def test_custom_tags_get_created_if_not_exists(self): + @patch.object(MailService, 'set_flags', return_value=None) + def test_custom_tags_get_created_if_not_exists(self, setFlags): MailService._open_leap_session = lambda self: None MailService.mailbox = Mock(messages=[test_helper.leap_mail(uid=6)]) MailService.account = Mock(return_value=MagicMock()) |