summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorRafael Lisboa <rafaelzlisboa@gmail.com>2015-04-27 12:35:02 -0300
committerRafael Lisboa <rafaelzlisboa@gmail.com>2015-04-27 12:35:02 -0300
commit9234ef399cac44dcdc8dab11c20dd162953e447c (patch)
treebbc3c618a245b903f99c1c41fa726062ead55ebf /service
parent5cc53a2ac0b47a05423ed9e4a64e24a3a9994a58 (diff)
parent6617b24ae00490cf86282147b732cfa31de127fb (diff)
Merge pull request #373 from roberto/master
Allow user to move emails from trash to inbox
Diffstat (limited to 'service')
-rw-r--r--service/pixelated/adapter/services/mail_service.py5
-rw-r--r--service/pixelated/adapter/services/mailboxes.py8
-rw-r--r--service/pixelated/resources/mails_resource.py15
-rw-r--r--service/test/unit/adapter/test_mail_service.py10
-rw-r--r--service/test/unit/adapter/test_mailboxes.py40
5 files changed, 77 insertions, 1 deletions
diff --git a/service/pixelated/adapter/services/mail_service.py b/service/pixelated/adapter/services/mail_service.py
index 03889f82..656bb4bc 100644
--- a/service/pixelated/adapter/services/mail_service.py
+++ b/service/pixelated/adapter/services/mail_service.py
@@ -97,6 +97,11 @@ class MailService(object):
trashed_mail = self.mailboxes.move_to_trash(mail_id)
self.search_engine.index_mail(trashed_mail)
+ def recover_mail(self, mail_id):
+ mail = self.mail(mail_id)
+ recovered_mail = self.mailboxes.move_to_inbox(mail_id)
+ self.search_engine.index_mail(recovered_mail)
+
def delete_permanent(self, mail_id):
mail = self.mail(mail_id)
self.search_engine.remove_from_index(mail_id)
diff --git a/service/pixelated/adapter/services/mailboxes.py b/service/pixelated/adapter/services/mailboxes.py
index a7a3a591..e9fe6ce5 100644
--- a/service/pixelated/adapter/services/mailboxes.py
+++ b/service/pixelated/adapter/services/mailboxes.py
@@ -49,8 +49,14 @@ class Mailboxes(object):
return [self._create_or_get(leap_mailbox_name) for leap_mailbox_name in self.account.mailboxes]
def move_to_trash(self, mail_id):
+ return self._move_to(mail_id, self.trash())
+
+ def move_to_inbox(self, mail_id):
+ return self._move_to(mail_id, self.inbox())
+
+ def _move_to(self, mail_id, mailbox):
mail = self.querier.mail(mail_id)
- mail.set_mailbox(self.trash().mailbox_name)
+ mail.set_mailbox(mailbox.mailbox_name)
mail.save()
return mail
diff --git a/service/pixelated/resources/mails_resource.py b/service/pixelated/resources/mails_resource.py
index c057031a..3822abd3 100644
--- a/service/pixelated/resources/mails_resource.py
+++ b/service/pixelated/resources/mails_resource.py
@@ -53,6 +53,20 @@ class MailsDeleteResource(Resource):
return respond_json(None, request)
+class MailsRecoverResource(Resource):
+ isLeaf = True
+
+ def __init__(self, mail_service):
+ Resource.__init__(self)
+ self._mail_service = mail_service
+
+ def render_POST(self, request):
+ idents = json.loads(request.content.read())['idents']
+ for ident in idents:
+ self._mail_service.recover_mail(ident)
+ return respond_json(None, request)
+
+
class MailsResource(Resource):
def _register_smtp_error_handler(self):
@@ -66,6 +80,7 @@ class MailsResource(Resource):
def __init__(self, mail_service, draft_service):
Resource.__init__(self)
self.putChild('delete', MailsDeleteResource(mail_service))
+ self.putChild('recover', MailsRecoverResource(mail_service))
self.putChild('read', MailsReadResource(mail_service))
self.putChild('unread', MailsUnreadResource(mail_service))
diff --git a/service/test/unit/adapter/test_mail_service.py b/service/test/unit/adapter/test_mail_service.py
index 34fec708..f4b89f57 100644
--- a/service/test/unit/adapter/test_mail_service.py
+++ b/service/test/unit/adapter/test_mail_service.py
@@ -101,3 +101,13 @@ class TestMailService(unittest.TestCase):
self.mail_service.delete_mail(1)
verify(self.mailboxes).move_to_trash(1)
+
+ def test_recover_mail(self):
+ mail_to_recover = PixelatedMail.from_soledad(*leap_mail(), soledad_querier=None)
+ when(self.mail_service).mail(1).thenReturn(mail_to_recover)
+ when(self.mailboxes).move_to_inbox(1).thenReturn(mail_to_recover)
+
+ self.mail_service.recover_mail(1)
+
+ verify(self.mailboxes).move_to_inbox(1)
+ verify(self.search_engine).index_mail(mail_to_recover)
diff --git a/service/test/unit/adapter/test_mailboxes.py b/service/test/unit/adapter/test_mailboxes.py
new file mode 100644
index 00000000..5b4548eb
--- /dev/null
+++ b/service/test/unit/adapter/test_mailboxes.py
@@ -0,0 +1,40 @@
+#
+# 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 pixelated.adapter.model.mail import PixelatedMail
+from pixelated.adapter.services.mailboxes import Mailboxes
+from mockito import mock, when, verify
+from test.support import test_helper
+from mock import MagicMock
+
+
+class PixelatedMailboxesTest(unittest.TestCase):
+ def setUp(self):
+ self.querier = mock()
+ self.search_engine = mock()
+ self.account = MagicMock()
+ self.mailboxes = Mailboxes(self.account, self.querier, self.search_engine)
+
+ def test_move_to_inbox(self):
+ mail = PixelatedMail.from_soledad(*test_helper.leap_mail(), soledad_querier=self.querier)
+ when(self.querier).mail(1).thenReturn(mail)
+ when(mail).save().thenReturn(None)
+
+ mail.set_mailbox('TRASH')
+ recovered_mail = self.mailboxes.move_to_inbox(1)
+ self.assertEquals('INBOX', recovered_mail.mailbox_name)
+ verify(mail).save()