summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Hammerl <fhammerl@thoughtworks.com>2016-02-10 17:27:15 +0100
committerFelix Hammerl <fhammerl@thoughtworks.com>2016-02-10 17:29:58 +0100
commitdac74cc8cabdc5e3ad0e90fc9aff3b6beedc964f (patch)
tree0adfef86e8ecebf18608d2c9aa7c995efe5f8f7f
parentcf6adf149d2356400e611b019353f431a032d88e (diff)
Fix Issue #596: Provide correct content-type
Provide the proper content-type Quote filename due to Firefox bug https://bugzilla.mozilla.org/show_bug.cgi?id=221028
-rw-r--r--service/pixelated/resources/attachments_resource.py5
-rw-r--r--service/test/integration/test_retrieve_attachment.py12
-rw-r--r--service/test/support/integration/app_test_client.py9
-rw-r--r--web-ui/app/templates/mails/full_view.hbs2
4 files changed, 20 insertions, 8 deletions
diff --git a/service/pixelated/resources/attachments_resource.py b/service/pixelated/resources/attachments_resource.py
index 249d268a..086f6e4e 100644
--- a/service/pixelated/resources/attachments_resource.py
+++ b/service/pixelated/resources/attachments_resource.py
@@ -46,8 +46,9 @@ class AttachmentResource(Resource):
encoding = request.args.get('encoding', [None])[0]
filename = request.args.get('filename', [self.attachment_id])[0]
- request.setHeader(b'Content-Type', b'application/force-download')
- request.setHeader(b'Content-Disposition', bytes('attachment; filename=' + filename))
+ content_type = request.args.get('content_type', ['application/octet-stream'])[0]
+ request.setHeader(b'Content-Type', content_type)
+ request.setHeader(b'Content-Disposition', bytes('attachment; filename="' + filename + '"'))
d = self._send_attachment(encoding, filename, request)
d.addErrback(error_handler)
diff --git a/service/test/integration/test_retrieve_attachment.py b/service/test/integration/test_retrieve_attachment.py
index 7de03c59..4aaeadc2 100644
--- a/service/test/integration/test_retrieve_attachment.py
+++ b/service/test/integration/test_retrieve_attachment.py
@@ -27,22 +27,28 @@ from test.support.integration.soledad_test_base import SoledadTestBase
class RetrieveAttachmentTest(SoledadTestBase):
-
@defer.inlineCallbacks
def test_attachment_content_is_retrieved(self):
attachment_id, input_mail = self._create_mail_with_attachment()
yield self.mail_store.add_mail('INBOX', input_mail.as_string())
- attachment, req = yield self.get_attachment(attachment_id, 'base64')
+ requested_filename = "file name with space"
+ expected_content_type = 'text/plain'
+ expected_content_disposition = 'attachment; filename="file name with space"'
+
+ attachment, req = yield self.get_attachment(attachment_id, 'base64', filename=requested_filename, content_type=expected_content_type)
self.assertEqual(200, req.code)
self.assertEquals('pretend to be binary attachment data', attachment)
+ self.assertEquals(expected_content_disposition, req.outgoingHeaders['content-disposition'])
+ self.assertEquals(expected_content_type, req.outgoingHeaders['content-type'])
def _create_mail_with_attachment(self):
input_mail = MIMEMultipart()
input_mail.attach(MIMEText(u'a utf8 message', _charset='utf-8'))
attachment = MIMEApplication('pretend to be binary attachment data')
- attachment.add_header('Content-Disposition', 'attachment', filename='filename.txt')
+ attachment.add_header('Content-Disposition', 'attachment', filename='file name.txt')
+ attachment.add_header('Content-Type', 'text/plain')
input_mail.attach(attachment)
attachment_id = 'B5B4ED80AC3B894523D72E375DACAA2FC6606C18EDF680FE95903086C8B5E14A'
return attachment_id, input_mail
diff --git a/service/test/support/integration/app_test_client.py b/service/test/support/integration/app_test_client.py
index 99f4ebc7..8ab58397 100644
--- a/service/test/support/integration/app_test_client.py
+++ b/service/test/support/integration/app_test_client.py
@@ -322,8 +322,13 @@ class AppTestClient(object):
defer.returnValue(mails)
@defer.inlineCallbacks
- def get_attachment(self, ident, encoding):
- deferred_result, req = self.get("/attachment/%s" % ident, {'encoding': [encoding]}, as_json=False)
+ def get_attachment(self, ident, encoding, filename=None, content_type=None):
+ params = {'encoding': [encoding]}
+ if filename:
+ params['filename'] = [filename]
+ if content_type:
+ params['content_type'] = [content_type]
+ deferred_result, req = self.get("/attachment/%s" % ident, params, as_json=False)
res = yield deferred_result
defer.returnValue((res, req))
diff --git a/web-ui/app/templates/mails/full_view.hbs b/web-ui/app/templates/mails/full_view.hbs
index cf797ce6..f9ec084a 100644
--- a/web-ui/app/templates/mails/full_view.hbs
+++ b/web-ui/app/templates/mails/full_view.hbs
@@ -73,7 +73,7 @@
<ul>
{{#each attachments }}
<li>
- <a href="/attachment/{{ this.ident }}?encoding={{ this.encoding }}&filename={{ this.name }}">{{ this.name }} ({{ formatSize this.size}})<i class="fa fa-arrow-down download-icon"></i></a>
+ <a href="/attachment/{{ this.ident }}?content_type={{ this.content-type }}&encoding={{ this.encoding }}&filename={{ this.name }}">{{ this.name }} ({{ formatSize this.size}})<i class="fa fa-arrow-down download-icon"></i></a>
</li>
{{/each }}
</ul>