diff options
Diffstat (limited to 'service/pixelated/controllers')
-rw-r--r-- | service/pixelated/controllers/__init__.py | 41 | ||||
-rw-r--r-- | service/pixelated/controllers/attachments_controller.py | 49 | ||||
-rw-r--r-- | service/pixelated/controllers/contacts_controller.py | 31 | ||||
-rw-r--r-- | service/pixelated/controllers/features_controller.py | 32 | ||||
-rw-r--r-- | service/pixelated/controllers/home_controller.py | 42 | ||||
-rw-r--r-- | service/pixelated/controllers/mails_controller.py | 124 | ||||
-rw-r--r-- | service/pixelated/controllers/sync_info_controller.py | 41 | ||||
-rw-r--r-- | service/pixelated/controllers/tags_controller.py | 33 |
8 files changed, 0 insertions, 393 deletions
diff --git a/service/pixelated/controllers/__init__.py b/service/pixelated/controllers/__init__.py deleted file mode 100644 index 6bc8e7c2..00000000 --- a/service/pixelated/controllers/__init__.py +++ /dev/null @@ -1,41 +0,0 @@ -# -# 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/>. - - -def respond_json(entity, request, status_code=200): - json_response = json.dumps(entity) - request.responseHeaders.addRawHeader(b"content-type", b"application/json") - request.code = status_code - return json_response - - -def respond_json_deferred(entity, request, status_code=200): - json_response = json.dumps(entity) - request.responseHeaders.addRawHeader(b"content-type", b"application/json") - request.code = status_code - request.write(json_response) - request.finish() - - -import json - -from home_controller import HomeController -from mails_controller import MailsController -from tags_controller import TagsController -from features_controller import FeaturesController -from sync_info_controller import SyncInfoController -from attachments_controller import AttachmentsController -from contacts_controller import ContactsController diff --git a/service/pixelated/controllers/attachments_controller.py b/service/pixelated/controllers/attachments_controller.py deleted file mode 100644 index b3fed903..00000000 --- a/service/pixelated/controllers/attachments_controller.py +++ /dev/null @@ -1,49 +0,0 @@ -# -# 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 io - -import re -from twisted.protocols.basic import FileSender -from twisted.python.log import err - - -class AttachmentsController: - - def __init__(self, querier): - self.querier = querier - - def attachment(self, request, attachment_id): - encoding = request.args.get('encoding', [None])[0] - filename = request.args.get('filename', [attachment_id])[0] - attachment = self.querier.attachment(attachment_id, encoding) - - request.setHeader(b'Content-Type', b'application/force-download') - request.setHeader(b'Content-Disposition', bytes('attachment; filename=' + filename)) - bytes_io = io.BytesIO(attachment['content']) - d = FileSender().beginFileTransfer(bytes_io, request) - - def cbFinished(ignored): - bytes_io.close() - request.finish() - - d.addErrback(err).addCallback(cbFinished) - - return d - - def _extract_mimetype(self, content_type): - match = re.compile('([A-Za-z-]+\/[A-Za-z-]+)').search(content_type) - return match.group(1) diff --git a/service/pixelated/controllers/contacts_controller.py b/service/pixelated/controllers/contacts_controller.py deleted file mode 100644 index 5825b563..00000000 --- a/service/pixelated/controllers/contacts_controller.py +++ /dev/null @@ -1,31 +0,0 @@ -# -# 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/>. - -from pixelated.controllers import respond_json_deferred -from twisted.internet.threads import deferToThread - - -class ContactsController: - - def __init__(self, search_engine): - self._search_engine = search_engine - - def contacts(self, request): - query = request.args.get('q', [''])[0] - d = deferToThread(lambda: self._search_engine.contacts(query)) - d.addCallback(lambda tags: respond_json_deferred(tags, request)) - - return d diff --git a/service/pixelated/controllers/features_controller.py b/service/pixelated/controllers/features_controller.py deleted file mode 100644 index b91aa183..00000000 --- a/service/pixelated/controllers/features_controller.py +++ /dev/null @@ -1,32 +0,0 @@ -# -# 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/>. - -from pixelated.controllers import respond_json -import os - - -class FeaturesController: - DISABLED_FEATURES = ['draftReply', 'encryptionStatus'] - - def __init__(self): - pass - - def features(self, request): - try: - disabled_features = {'logout': os.environ['DISPATCHER_LOGOUT_URL']} - except KeyError: - disabled_features = {} - return respond_json({'disabled_features': self.DISABLED_FEATURES, 'dispatcher_features': disabled_features}, request) diff --git a/service/pixelated/controllers/home_controller.py b/service/pixelated/controllers/home_controller.py deleted file mode 100644 index ccdad197..00000000 --- a/service/pixelated/controllers/home_controller.py +++ /dev/null @@ -1,42 +0,0 @@ -# -# 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 os - -from twisted.web.static import File - - -class HomeController: - def __init__(self): - self.static_folder = self._get_static_folder() - pass - - def _get_static_folder(self): - - static_folder = os.path.abspath(os.path.join(os.path.abspath(__file__), "..", "..", "..", "web-ui", "app")) - # this is a workaround for packaging - if not os.path.exists(static_folder): - static_folder = os.path.abspath( - os.path.join(os.path.abspath(__file__), "..", "..", "..", "..", "web-ui", "app")) - if not os.path.exists(static_folder): - static_folder = os.path.join('/', 'usr', 'share', 'pixelated-user-agent') - return static_folder - - def home(self, request): - request_type = request.requestHeaders.getRawHeaders('accept')[0].split(',')[0] - response_type = request_type if request_type else "text/html" - - request.setHeader('Content-Type', response_type) - return File('%s/' % self.static_folder, defaultType=response_type) diff --git a/service/pixelated/controllers/mails_controller.py b/service/pixelated/controllers/mails_controller.py deleted file mode 100644 index fb9c9adc..00000000 --- a/service/pixelated/controllers/mails_controller.py +++ /dev/null @@ -1,124 +0,0 @@ -# -# 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 json - -from pixelated.adapter.model.mail import InputMail -from pixelated.controllers import respond_json - - -class MailsController: - - def __init__(self, mail_service, draft_service, search_engine): - self._mail_service = mail_service - self._draft_service = draft_service - self._search_engine = search_engine - - def mails(self, request): - mail_ids, total = self._search_engine.search(request.args.get('q')[0], request.args.get('w')[0], request.args.get('p')[0]) - mails = self._mail_service.mails(mail_ids) - - response = { - "stats": { - "total": total, - }, - "mails": [mail.as_dict() for mail in mails] - } - - return json.dumps(response) - - def mail(self, request, mail_id): - mail = self._mail_service.mail(mail_id) - return respond_json(mail.as_dict(), request) - - def mark_many_mail_unread(self, request): - content_dict = json.load(request.content) - idents = content_dict.get('idents') - for ident in idents: - mail = self._mail_service.mark_as_unread(ident) - self._search_engine.index_mail(mail) - return "" - - def mark_many_mail_read(self, request): - content_dict = json.load(request.content) - idents = content_dict.get('idents') - for ident in idents: - mail = self._mail_service.mark_as_read(ident) - self._search_engine.index_mail(mail) - return "" - - def _delete_mail(self, mail_id): - mail = self._mail_service.mail(mail_id) - if mail.mailbox_name == 'TRASH': - self._mail_service.delete_permanent(mail_id) - self._search_engine.remove_from_index(mail_id) - else: - trashed_mail = self._mail_service.delete_mail(mail_id) - self._search_engine.index_mail(trashed_mail) - - def delete_mail(self, request, mail_id): - self._delete_mail(mail_id) - return respond_json(None, request) - - def delete_mails(self, request): - idents = json.loads(request.content.read())['idents'] - for ident in idents: - self._delete_mail(ident) - return respond_json(None, request) - - def send_mail(self, request): - try: - content_dict = json.loads(request.content.read()) - _mail = InputMail.from_dict(content_dict) - draft_id = content_dict.get('ident') - if draft_id: - self._search_engine.remove_from_index(draft_id) - _mail = self._mail_service.send(draft_id, _mail) - self._search_engine.index_mail(_mail) - - return respond_json(_mail.as_dict(), request) - except Exception as error: - return respond_json({'message': self._format_exception(error)}, request, status_code=422) - - def mail_tags(self, request, mail_id): - content_dict = json.loads(request.content.read()) - new_tags = map(lambda tag: tag.lower(), content_dict['newtags']) - try: - 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, request, 403) - return respond_json(mail.as_dict(), request) - - def update_draft(self, request): - content_dict = json.loads(request.content.read()) - _mail = InputMail.from_dict(content_dict) - draft_id = content_dict.get('ident') - - if draft_id: - if not self._mail_service.mail_exists(draft_id): - return respond_json("", request, status_code=422) - pixelated_mail = self._draft_service.update_draft(draft_id, _mail) - self._search_engine.remove_from_index(draft_id) - else: - pixelated_mail = self._draft_service.create_draft(_mail) - self._search_engine.index_mail(pixelated_mail) - return respond_json({'ident': pixelated_mail.ident}, request) - - def _format_exception(self, exception): - exception_info = map(str, list(exception.args)) - return '\n'.join(exception_info) diff --git a/service/pixelated/controllers/sync_info_controller.py b/service/pixelated/controllers/sync_info_controller.py deleted file mode 100644 index 50e53852..00000000 --- a/service/pixelated/controllers/sync_info_controller.py +++ /dev/null @@ -1,41 +0,0 @@ -# -# 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/>. -from pixelated.controllers import respond_json - - -class SyncInfoController: - def __init__(self): - self.current = 0 - self.total = 0 - - def _get_progress(self): - if self.total == 0: - return 0 - return self.current / float(self.total) - - def set_sync_info(self, soledad_sync_status): - self.current, self.total = map(int, soledad_sync_status.content.split('/')) - - def sync_info(self, request): - _sync_info = { - 'is_syncing': self.current != self.total, - 'count': { - 'current': self.current, - 'total': self.total, - 'progress': self._get_progress() - } - } - return respond_json(_sync_info, request) diff --git a/service/pixelated/controllers/tags_controller.py b/service/pixelated/controllers/tags_controller.py deleted file mode 100644 index b6741dcc..00000000 --- a/service/pixelated/controllers/tags_controller.py +++ /dev/null @@ -1,33 +0,0 @@ -# -# 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/>. - -from pixelated.controllers import respond_json_deferred -from twisted.internet.threads import deferToThread - - -class TagsController: - - def __init__(self, search_engine): - self._search_engine = search_engine - - def tags(self, request): - query = request.args.get('q', [''])[0] - skip_default_tags = request.args.get('skipDefaultTags', [False])[0] - - d = deferToThread(lambda: self._search_engine.tags(query=query, skip_default_tags=skip_default_tags)) - d.addCallback(lambda tags: respond_json_deferred(tags, request)) - - return d |