summaryrefslogtreecommitdiff
path: root/src/leap/mail
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
commitefb6028e8d4096d113c565a3953919a5e30d0947 (patch)
tree05d6cde2d3cf404dbfa16af7b411d7c91bfd5118 /src/leap/mail
parente139fb997c4c482e70cea3dec10b9a2365165772 (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 'src/leap/mail')
-rw-r--r--src/leap/mail/mail.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/leap/mail/mail.py b/src/leap/mail/mail.py
index d92ff79..fd2f39a 100644
--- a/src/leap/mail/mail.py
+++ b/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):
"""