summaryrefslogtreecommitdiff
path: root/mail/src/leap
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2015-03-23 12:57:02 -0400
committerKali Kaneko <kali@leap.se>2015-03-23 14:45:45 -0400
commit822385e16b4f0f7a7d74905984bc4b4d76d187be (patch)
tree01a630c0d55df618797bc7ea7200c5cfa52fd8e1 /mail/src/leap
parent62a02b3b1e14afcbec82d3fca2f906ca6dd38715 (diff)
[bug] report the correct size for mime parts
The MIME size is the size of the body, w/o counting the headers. Releases: 0.4.0
Diffstat (limited to 'mail/src/leap')
-rw-r--r--mail/src/leap/mail/mail.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/mail/src/leap/mail/mail.py b/mail/src/leap/mail/mail.py
index d92ff793..fd2f39ab 100644
--- a/mail/src/leap/mail/mail.py
+++ b/mail/src/leap/mail/mail.py
@@ -135,7 +135,15 @@ class MessagePart(object):
self._index = index
def get_size(self):
- return self._pmap['size']
+ """
+ Size of the body, in octets.
+ """
+ total = self._pmap['size']
+ _h = self.get_headers()
+ headers = len(
+ '\n'.join(["%s: %s" % (k, v) for k, v in dict(_h).items()]))
+ # have to subtract 2 blank lines
+ return total - headers - 2
def get_body_file(self):
payload = ""
@@ -148,6 +156,7 @@ class MessagePart(object):
raise NotImplementedError
if payload:
payload = _encode_payload(payload)
+
return _write_and_rewind(payload)
def get_headers(self):
@@ -252,9 +261,10 @@ class Message(object):
def get_size(self):
"""
- Size, in octets.
+ Size of the whole message, in octets (including headers).
"""
- return self._wrapper.fdoc.size
+ total = self._wrapper.fdoc.size
+ return total
def is_multipart(self):
"""