From efb6028e8d4096d113c565a3953919a5e30d0947 Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Mon, 23 Mar 2015 12:57:02 -0400 Subject: [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 --- src/leap/mail/mail.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'src/leap/mail') 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): """ -- cgit v1.2.3