summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorJefferson Stachelski <jstachel@thoughtworks.com>2015-11-13 11:19:25 -0200
committerJefferson Stachelski <jstachel@thoughtworks.com>2015-11-13 16:01:27 -0200
commitc9caf2f49ae09c7ce76022b63ed9047b37d71ffb (patch)
treedaabbf6eee077d9316088c6662999360533e0a74 /service
parentc827cebf09aa2e2faa7a5d660903dd34dda089d3 (diff)
Issue #523 - Created an archive mail button
Diffstat (limited to 'service')
-rw-r--r--service/pixelated/adapter/services/mail_service.py5
-rw-r--r--service/pixelated/resources/mails_resource.py18
2 files changed, 23 insertions, 0 deletions
diff --git a/service/pixelated/adapter/services/mail_service.py b/service/pixelated/adapter/services/mail_service.py
index 53f7615e..5485ae18 100644
--- a/service/pixelated/adapter/services/mail_service.py
+++ b/service/pixelated/adapter/services/mail_service.py
@@ -132,5 +132,10 @@ class MailService(object):
yield self.mail_store.move_mail_to_mailbox(mail_id, 'INBOX')
@defer.inlineCallbacks
+ def archive_mail(self, mail_id):
+ yield self.mail_store.add_mailbox('ARCHIVE')
+ yield self.mail_store.move_mail_to_mailbox(mail_id, 'ARCHIVE')
+
+ @defer.inlineCallbacks
def delete_permanent(self, mail_id):
yield self.mail_store.delete_mail(mail_id)
diff --git a/service/pixelated/resources/mails_resource.py b/service/pixelated/resources/mails_resource.py
index 499610de..f65041f5 100644
--- a/service/pixelated/resources/mails_resource.py
+++ b/service/pixelated/resources/mails_resource.py
@@ -94,6 +94,23 @@ class MailsRecoverResource(Resource):
return NOT_DONE_YET
+class MailsArchiveResource(Resource):
+
+ 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']
+ deferreds = []
+ for ident in idents:
+ deferreds.append(self._mail_service.archive_mail(ident))
+ d = defer.gatherResults(deferreds, consumeErrors=True)
+ d.addCallback(lambda _: respond_json_deferred({'successMessage': 'Your message was archived'}, request))
+ d.addErrback(lambda _: respond_json_deferred(None, request, status_code=500))
+ return NOT_DONE_YET
+
+
class MailsResource(Resource):
def _register_smtp_error_handler(self):
@@ -108,6 +125,7 @@ class MailsResource(Resource):
Resource.__init__(self)
self.putChild('delete', MailsDeleteResource(mail_service))
self.putChild('recover', MailsRecoverResource(mail_service))
+ self.putChild('archive', MailsArchiveResource(mail_service))
self.putChild('read', MailsReadResource(mail_service))
self.putChild('unread', MailsUnreadResource(mail_service))