From fa24aaf94af1dd8b4ead48d6518d3770a60d1211 Mon Sep 17 00:00:00 2001 From: Patrick Maia Date: Wed, 12 Nov 2014 16:39:21 +0000 Subject: Card #30 - fixes bug that was preventing attachment download --- service/pixelated/controllers/attachments_controller.py | 8 ++++---- service/test/support/integration_helper.py | 2 +- web-ui/app/templates/mails/full_view.hbs | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/service/pixelated/controllers/attachments_controller.py b/service/pixelated/controllers/attachments_controller.py index 4965f166..d6d2f5e7 100644 --- a/service/pixelated/controllers/attachments_controller.py +++ b/service/pixelated/controllers/attachments_controller.py @@ -16,7 +16,6 @@ import io import re - from twisted.protocols.basic import FileSender from twisted.python.log import err @@ -27,11 +26,12 @@ class AttachmentsController: self.querier = querier def attachment(self, request, attachment_id): - encoding = request.args.get('encoding') + encoding = request.args.get('encoding', [None])[0] + filename = request.args.get('filename', [attachment_id])[0] attachment = self.querier.attachment(attachment_id, encoding) - content_type = self._extract_mimetype(attachment['content-type']) - request.setHeader('Content-Type', content_type) + 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) diff --git a/service/test/support/integration_helper.py b/service/test/support/integration_helper.py index 36d297d6..0411abea 100644 --- a/service/test/support/integration_helper.py +++ b/service/test/support/integration_helper.py @@ -186,7 +186,7 @@ class SoledadTestBase: def get_attachment(self, ident, encoding): request = requestMock(path='/attachment/' + ident) request.args = { - 'encoding': encoding + 'encoding': [encoding] } _render(self.resource, request) return request.getWrittenData() diff --git a/web-ui/app/templates/mails/full_view.hbs b/web-ui/app/templates/mails/full_view.hbs index 46a55318..4cdf25b9 100644 --- a/web-ui/app/templates/mails/full_view.hbs +++ b/web-ui/app/templates/mails/full_view.hbs @@ -73,7 +73,7 @@ -- cgit v1.2.3