diff options
| -rw-r--r-- | service/pixelated/adapter/mail_service.py | 3 | ||||
| -rw-r--r-- | service/pixelated/adapter/pixelated_mail.py | 7 | ||||
| -rw-r--r-- | service/pixelated/adapter/status.py | 5 | ||||
| -rw-r--r-- | service/pixelated/user_agent.py | 14 | ||||
| -rw-r--r-- | service/test/integration/mark_as_read_unread_test.py | 50 | ||||
| -rw-r--r-- | service/test/support/integration_helper.py | 11 | 
6 files changed, 88 insertions, 2 deletions
diff --git a/service/pixelated/adapter/mail_service.py b/service/pixelated/adapter/mail_service.py index ad494ac8..a6241821 100644 --- a/service/pixelated/adapter/mail_service.py +++ b/service/pixelated/adapter/mail_service.py @@ -54,6 +54,9 @@ class MailService:      def mark_as_read(self, mail_id):          return self.mail(mail_id).mark_as_read() +    def mark_as_unread(self, mail_id): +        return self.mail(mail_id).mark_as_unread() +      def tags_for_thread(self, thread):          raise NotImplementedError() diff --git a/service/pixelated/adapter/pixelated_mail.py b/service/pixelated/adapter/pixelated_mail.py index 4b207059..fabb1ab4 100644 --- a/service/pixelated/adapter/pixelated_mail.py +++ b/service/pixelated/adapter/pixelated_mail.py @@ -93,7 +93,7 @@ class InputMail:          fd[fields.MULTIPART_KEY] = True          fd[fields.RECENT_KEY] = True          fd[fields.TYPE_KEY] = fields.TYPE_FLAGS_VAL -        fd[fields.FLAGS_KEY] = ["\\Recent"] +        fd[fields.FLAGS_KEY] = Status.to_flags([status.name for status in self.status])          self._fd = fd          return fd @@ -261,6 +261,11 @@ class PixelatedMail:          self.save()          return self +    def mark_as_unread(self): +        self.fdoc.content['flags'].remove(Status.PixelatedStatus.SEEN) +        self.save() +        return self +      def mark_as_not_recent(self):          if Status.PixelatedStatus.RECENT in self.fdoc.content['flags']:              self.fdoc.content['flags'].remove(Status.PixelatedStatus.RECENT) diff --git a/service/pixelated/adapter/status.py b/service/pixelated/adapter/status.py index cd11a46f..3807359c 100644 --- a/service/pixelated/adapter/status.py +++ b/service/pixelated/adapter/status.py @@ -37,6 +37,11 @@ class Status:      def from_flags(cls, flags):          return set(cls.from_flag(flag) for flag in flags if flag in cls.LEAP_FLAGS_STATUSES.keys()) +    @classmethod +    def to_flags(cls, statuses): +        statuses_to_flags = dict(zip(cls.LEAP_FLAGS_STATUSES.values(), cls.LEAP_FLAGS_STATUSES.keys())) +        return [statuses_to_flags[status] for status in statuses] +      def __init__(self, name):          self.name = name          self.ident = name.__hash__() diff --git a/service/pixelated/user_agent.py b/service/pixelated/user_agent.py index d97d5905..04be0b90 100644 --- a/service/pixelated/user_agent.py +++ b/service/pixelated/user_agent.py @@ -166,6 +166,20 @@ def mark_mail_as_read(mail_id):      return "" +@app.route('/mail/<mail_id>/unread', methods=['POST']) +def mark_mail_as_unread(mail_id): +    mail_service.mark_as_unread(mail_id) +    return "" + + +@app.route('/mails/unread', methods=['POST']) +def mark_many_mail_unread(): +    idents = json.loads(request.form['idents']) +    for ident in idents: +        mail_service.mark_as_unread(ident) +    return "" + +  @app.route('/contacts')  def contacts():      pass diff --git a/service/test/integration/mark_as_read_unread_test.py b/service/test/integration/mark_as_read_unread_test.py new file mode 100644 index 00000000..a75e8c92 --- /dev/null +++ b/service/test/integration/mark_as_read_unread_test.py @@ -0,0 +1,50 @@ +# +# Copyright (c) 2014 ThoughtWorks, Inc. +# +# Pixelated is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Pixelated is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Pixelated. If not, see <http://www.gnu.org/licenses/>. +import unittest +from test.support.integration_helper import MailBuilder, SoledadTestBase + + +class MarkAsReadTest(unittest.TestCase, SoledadTestBase): + +    def setUp(self): +        self.setup_soledad() + +    def tearDown(self): +        self.teardown_soledad() + +    def test_mark_single_as_read(self): +        input_mail = MailBuilder().build_input_mail() +        self.add_mail_to_inbox(input_mail) + +        mails = self.get_mails_by_tag('inbox') +        self.assertFalse('read' in mails[0].status) + +        self.mark_as_read(input_mail.ident) + +        mails = self.get_mails_by_tag('inbox') +        self.assertTrue('read' in mails[0].status) + +    def test_mark_single_as_unread(self): +        input_mail = MailBuilder().with_status('read').build_input_mail() +        self.add_mail_to_inbox(input_mail) + +        mails = self.get_mails_by_tag('inbox') +        self.assertIn('read', mails[0].status) + +        self.mark_as_unread(input_mail.ident) + +        mails = self.get_mails_by_tag('inbox') +        self.assertNotIn('read', mails[0].status) diff --git a/service/test/support/integration_helper.py b/service/test/support/integration_helper.py index c9a80624..5975b9e8 100644 --- a/service/test/support/integration_helper.py +++ b/service/test/support/integration_helper.py @@ -22,6 +22,7 @@ from mock import Mock  import shutil  from pixelated.adapter.mail_service import MailService  from pixelated.adapter.search import SearchEngine +from pixelated.adapter.status import Status  from pixelated.adapter.tag_index import TagIndex  from pixelated.adapter.tag_service import TagService  from pixelated.adapter.draft_service import DraftService @@ -82,7 +83,8 @@ class MailBuilder:                  'bcc': ['recipient@bcc.com'],                  'subject': 'Hi! This the subject'              }, -            'body': "Hello,\nThis is the body of this message\n\nRegards,\n\n--\nPixelated.\n" +            'body': "Hello,\nThis is the body of this message\n\nRegards,\n\n--\nPixelated.\n", +            'status': []          }      def with_body(self, body): @@ -93,6 +95,10 @@ class MailBuilder:          self.mail['header']['subject'] = subject          return self +    def with_status(self, status): +        self.mail['status'].append(Status('read')) +        return self +      def with_ident(self, ident):          self.mail['ident'] = ident          return self @@ -166,6 +172,9 @@ class SoledadTestBase:      def mark_as_read(self, mail_ident):          self.app.post('/mail/' + mail_ident + '/read', content_type="application/json") +    def mark_as_unread(self, mail_ident): +        self.app.post('/mail/' + mail_ident + '/unread', content_type="application/json") +      def add_mail_to_inbox(self, input_mail):          mail = self.pixelated_mailboxes.inbox().add(input_mail)          self.search_engine.index_mail(mail)  | 
