summaryrefslogtreecommitdiff
path: root/service
diff options
context:
space:
mode:
authorNavaL <mnandri@thoughtworks.com>2016-01-08 17:52:32 +0100
committerNavaL <mnandri@thoughtworks.com>2016-01-11 16:56:29 +0100
commit64106a5d6b589616db5ddd07f383b74c66e0b39d (patch)
treec18e5338981a61bf36fb4e0244d00fd44b35214f /service
parentf07aa46453a311010dad3218689891f91f76e3fc (diff)
fixed filesize bug
Issue #573
Diffstat (limited to 'service')
-rw-r--r--service/pixelated/adapter/mailstore/leap_mailstore.py2
-rw-r--r--service/pixelated/adapter/model/mail.py2
-rw-r--r--service/test/unit/adapter/mailstore/test_leap_mail.py4
-rw-r--r--service/test/unit/adapter/mailstore/test_leap_mailstore.py6
-rw-r--r--service/test/unit/adapter/test_mail.py4
5 files changed, 9 insertions, 9 deletions
diff --git a/service/pixelated/adapter/mailstore/leap_mailstore.py b/service/pixelated/adapter/mailstore/leap_mailstore.py
index 3539b498..d550ec60 100644
--- a/service/pixelated/adapter/mailstore/leap_mailstore.py
+++ b/service/pixelated/adapter/mailstore/leap_mailstore.py
@@ -34,7 +34,7 @@ class AttachmentInfo(object):
self.name = _extract_filename(headers)
self.encoding = headers.get('Content-Transfer-Encoding', None)
self.ctype = part_map.get('ctype') or headers.get('Content-Type')
- self.size = headers.get('size', 0)
+ self.size = part_map.get('size', 0)
def __repr__(self):
return 'AttachmentInfo[%s, %s, %s]' % (self.ident, self.name, self.encoding)
diff --git a/service/pixelated/adapter/model/mail.py b/service/pixelated/adapter/model/mail.py
index 1a505481..dd2f4c0d 100644
--- a/service/pixelated/adapter/model/mail.py
+++ b/service/pixelated/adapter/model/mail.py
@@ -116,7 +116,7 @@ class Mail(object):
attachment_mime = MIMENonMultipart(major, sub)
base64_attachment_file = binascii.b2a_base64(attachment['raw'])
attachment_mime.set_payload(base64_attachment_file)
- attachment_mime['Content-Disposition'] = 'attachment; filename="%s"' % attachment['filename']
+ attachment_mime['Content-Disposition'] = 'attachment; filename="%s"' % attachment['name']
attachment_mime['Content-Transfer-Encoding'] = 'base64'
mime.attach(attachment_mime)
diff --git a/service/test/unit/adapter/mailstore/test_leap_mail.py b/service/test/unit/adapter/mailstore/test_leap_mail.py
index f883dad1..4b074082 100644
--- a/service/test/unit/adapter/mailstore/test_leap_mail.py
+++ b/service/test/unit/adapter/mailstore/test_leap_mail.py
@@ -85,9 +85,9 @@ class TestLeapMail(TestCase):
self.assertEqual(body, mail.as_dict()['body'])
def test_as_dict_with_attachments(self):
- mail = LeapMail('doc id', 'INBOX', attachments=[AttachmentInfo({'phash': 'id', 'ctype': 'text/plain'},
+ mail = LeapMail('doc id', 'INBOX', attachments=[AttachmentInfo({'phash': 'id', 'ctype': 'text/plain', 'size': 2},
{'Content-Description': 'name',
- 'Content-Transfer-Encoding': 'encoding', 'size': 2})])
+ 'Content-Transfer-Encoding': 'encoding'})])
self.assertEqual([{'ident': 'id', 'name': 'name', 'encoding': 'encoding', 'content-type': 'text/plain', 'size': 2}],
mail.as_dict()['attachments'])
diff --git a/service/test/unit/adapter/mailstore/test_leap_mailstore.py b/service/test/unit/adapter/mailstore/test_leap_mailstore.py
index 090c6b06..1eae48df 100644
--- a/service/test/unit/adapter/mailstore/test_leap_mailstore.py
+++ b/service/test/unit/adapter/mailstore/test_leap_mailstore.py
@@ -238,7 +238,7 @@ class TestLeapMailStore(TestCase):
message = yield store.add_mail('INBOX', input_mail.as_string())
- expected = [{'ident': self._cdoc_phash_from_message(mocked_message, 2), 'name': 'filename.txt', 'encoding': 'base64', 'size': 0, 'content-type': 'application/octet-stream'}]
+ expected = [{'ident': self._cdoc_phash_from_message(mocked_message, 2), 'name': 'filename.txt', 'encoding': 'base64', 'size': 197, 'content-type': 'application/octet-stream'}]
self.assertEqual(expected, message.as_dict()['attachments'])
@defer.inlineCallbacks
@@ -253,7 +253,7 @@ class TestLeapMailStore(TestCase):
message = yield store.add_mail('INBOX', input_mail.as_string())
- expected = [{'ident': self._cdoc_phash_from_message(mocked_message, 2), 'name': 'super_nice_photo.jpg', 'encoding': 'base64', 'size': 0, 'content-type': 'application/octet-stream'}]
+ expected = [{'ident': self._cdoc_phash_from_message(mocked_message, 2), 'name': 'super_nice_photo.jpg', 'encoding': 'base64', 'size': 202, 'content-type': 'application/octet-stream'}]
self.assertEqual(expected, message.as_dict()['attachments'])
@defer.inlineCallbacks
@@ -270,7 +270,7 @@ class TestLeapMailStore(TestCase):
message = yield store.add_mail('INBOX', input_mail.as_string())
- expected = [{'ident': self._cdoc_phash_from_message(mocked_message, 2), 'name': 'filename.txt', 'encoding': 'base64', 'size': 0, 'content-type': 'application/octet-stream'}]
+ expected = [{'ident': self._cdoc_phash_from_message(mocked_message, 2), 'name': 'filename.txt', 'encoding': 'base64', 'size': 197, 'content-type': 'application/octet-stream'}]
self.assertEqual(expected, message.as_dict()['attachments'])
def test_extract_attachment_filename_with_or_without_quotes(self):
diff --git a/service/test/unit/adapter/test_mail.py b/service/test/unit/adapter/test_mail.py
index 4a36bd42..6e4943fa 100644
--- a/service/test/unit/adapter/test_mail.py
+++ b/service/test/unit/adapter/test_mail.py
@@ -55,8 +55,8 @@ def multipart_mail_dict():
def with_attachment_mail_dict():
return {
- 'attachments': [{'content-type': 'text/plain', 'filename': 'ayoyo.txt', 'raw': 'Hamburg Ayoyoyooooo!!!', 'id': 'some_attachment_id'},
- {'content-type': 'text/html', 'filename': 'hello.html', 'raw': '<p>Hello html Hamburg!</p>', 'id': 'other_attachment_id'}],
+ 'attachments': [{'content-type': 'text/plain', 'name': 'ayoyo.txt', 'raw': 'Hamburg Ayoyoyooooo!!!', 'ident': 'some_attachment_id'},
+ {'content-type': 'text/html', 'name': 'hello.html', 'raw': '<p>Hello html Hamburg!</p>', 'ident': 'other_attachment_id'}],
'body': [{'content-type': 'plain', 'raw': 'Hello world!'},
{'content-type': 'html', 'raw': '<p>Hello html world!</p>'}],
'header': {