summaryrefslogtreecommitdiff
path: root/service/pixelated/adapter/mailstore/leap_mailstore.py
diff options
context:
space:
mode:
authorNavaL <mnandri@thoughtworks.com>2016-01-07 18:12:50 +0100
committerNavaL <mnandri@thoughtworks.com>2016-01-11 16:56:29 +0100
commitf07aa46453a311010dad3218689891f91f76e3fc (patch)
treef17a21831c3d54ce629adfaf5ac7b55e5c1d7725 /service/pixelated/adapter/mailstore/leap_mailstore.py
parente10e43968e2a4a8ef3ef84fd7ff7e741af5e40b0 (diff)
matching POST response and GET of an attachment -- API specification
Issue #548
Diffstat (limited to 'service/pixelated/adapter/mailstore/leap_mailstore.py')
-rw-r--r--service/pixelated/adapter/mailstore/leap_mailstore.py20
1 files changed, 11 insertions, 9 deletions
diff --git a/service/pixelated/adapter/mailstore/leap_mailstore.py b/service/pixelated/adapter/mailstore/leap_mailstore.py
index 10aad0b3..3539b498 100644
--- a/service/pixelated/adapter/mailstore/leap_mailstore.py
+++ b/service/pixelated/adapter/mailstore/leap_mailstore.py
@@ -29,10 +29,12 @@ from pixelated.support.functional import to_unicode
class AttachmentInfo(object):
- def __init__(self, ident, name, encoding):
- self.ident = ident
- self.name = name
- self.encoding = encoding
+ def __init__(self, part_map, headers):
+ self.ident = part_map['phash']
+ 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)
def __repr__(self):
return 'AttachmentInfo[%s, %s, %s]' % (self.ident, self.name, self.encoding)
@@ -40,6 +42,9 @@ class AttachmentInfo(object):
def __str__(self):
return 'AttachmentInfo[%s, %s, %s]' % (self.ident, self.name, self.encoding)
+ def as_dict(self):
+ return {'ident': self.ident, 'name': self.name, 'encoding': self.encoding, 'size': self.size, 'content-type': self.ctype}
+
class LeapMail(Mail):
@@ -140,7 +145,7 @@ class LeapMail(Mail):
'textPlainBody': self._body,
'replying': self._replying_dict(),
'mailbox': self._mailbox_name.lower(),
- 'attachments': [{'ident': attachment.ident, 'name': attachment.name, 'encoding': attachment.encoding} for attachment in self._attachments]
+ 'attachments': [attachment.as_dict() for attachment in self._attachments]
}
def _replying_dict(self):
@@ -403,11 +408,8 @@ class LeapMailStore(MailStore):
for nr, part_map in part_maps.items():
if 'headers' in part_map and 'phash' in part_map:
headers = {header[0]: header[1] for header in part_map['headers']}
- phash = part_map['phash']
if self._is_attachment(part_map, headers):
- filename = _extract_filename(headers)
- encoding = headers.get('Content-Transfer-Encoding', None)
- result.append(AttachmentInfo(phash, filename, encoding))
+ result.append(AttachmentInfo(part_map, headers))
if 'part_map' in part_map:
result += self._extract_part_map(part_map['part_map'])