From 0de9d8dc31298921f7272d74cdd3c5d4217b5841 Mon Sep 17 00:00:00 2001 From: Duda Dornelles Date: Thu, 16 Oct 2014 13:53:16 +0200 Subject: decreasing count on tag and tag shortcut when email is read. we were decreasing only tags that were also in the read mail, but we have also to look at the mailbox and compare that to the tags in the case of default tags #95 --- service/pixelated/adapter/mail.py | 7 ++++++- service/pixelated/adapter/mail_service.py | 3 ++- service/pixelated/controllers/mails_controller.py | 7 ++++--- service/test/unit/adapter/mail_test.py | 24 ++++++++++++++++++++++- 4 files changed, 35 insertions(+), 6 deletions(-) (limited to 'service') diff --git a/service/pixelated/adapter/mail.py b/service/pixelated/adapter/mail.py index 513a07d8..5cafa36a 100644 --- a/service/pixelated/adapter/mail.py +++ b/service/pixelated/adapter/mail.py @@ -51,6 +51,10 @@ class Mail: def flags(self): return self.fdoc.content.get('flags') + @property + def mailbox_name(self): + return self.fdoc.content.get('mbox') + @property def _mime_multipart(self): if self._mime: @@ -75,7 +79,8 @@ class Mail: 'tags': list(self.tags), 'status': list(self.status), 'security_casing': {}, - 'body': self.body + 'body': self.body, + 'mailbox': self.mailbox_name.lower() } diff --git a/service/pixelated/adapter/mail_service.py b/service/pixelated/adapter/mail_service.py index e908feb7..cc03ab3a 100644 --- a/service/pixelated/adapter/mail_service.py +++ b/service/pixelated/adapter/mail_service.py @@ -35,7 +35,8 @@ class MailService: if len(reserved_words): raise ValueError('None of the following words can be used as tags: ' + ' '.join(reserved_words)) mail = self.mail(mail_id) - return mail.update_tags(set(new_tags)) + mail.update_tags(set(new_tags)) + return mail def mail(self, mail_id): return self.mailboxes.mail(mail_id) diff --git a/service/pixelated/controllers/mails_controller.py b/service/pixelated/controllers/mails_controller.py index 6bd2fe99..f6414f27 100644 --- a/service/pixelated/controllers/mails_controller.py +++ b/service/pixelated/controllers/mails_controller.py @@ -92,11 +92,12 @@ class MailsController: def mail_tags(self, mail_id): new_tags = map(lambda tag: tag.lower(), request.get_json()['newtags']) try: - tags = self._mail_service.update_tags(mail_id, new_tags) - self._search_engine.index_mail(self._mail_service.mail(mail_id)) + self._mail_service.update_tags(mail_id, new_tags) + mail = self._mail_service.mail(mail_id) + self._search_engine.index_mail(mail) except ValueError as ve: return respond_json(ve.message, 403) - return respond_json(list(tags)) + return respond_json(mail.as_dict()) def update_draft(self): _mail = InputMail.from_dict(request.json) diff --git a/service/test/unit/adapter/mail_test.py b/service/test/unit/adapter/mail_test.py index 20038e96..94578a05 100644 --- a/service/test/unit/adapter/mail_test.py +++ b/service/test/unit/adapter/mail_test.py @@ -19,10 +19,10 @@ import pixelated.support.date from pixelated.adapter.mail import PixelatedMail, InputMail from mockito import * from test.support import test_helper +import dateutil.parser as dateparser class TestPixelatedMail(unittest.TestCase): - def setUp(self): self.querier = mock() @@ -68,6 +68,28 @@ class TestPixelatedMail(unittest.TestCase): self.assertEquals(mail.fdoc.content['flags'], []) + def test_as_dict(self): + fdoc, hdoc, bdoc = test_helper.leap_mail(flags=['\\Recent']) + hdoc.content['headers']['Subject'] = 'The subject' + hdoc.content['headers']['From'] = 'me@pixelated.org' + + mail = PixelatedMail.from_soledad(fdoc, hdoc, bdoc, soledad_querier=self.querier) + + _dict = mail.as_dict() + + self.assertEquals(_dict, {'body': 'body', + 'header': { + 'date': dateparser.parse(hdoc.content['date']).isoformat(), + 'from': 'me@pixelated.org', + 'subject': 'The subject' + }, + 'ident': 'chash', + 'mailbox': 'inbox', + 'security_casing': {}, + 'status': ['recent'], + 'tags': []} + ) + class InputMailTest(unittest.TestCase): mail_dict = lambda x: { -- cgit v1.2.3