From 154e1aa347bb9ee0a9ed9abd60ed703a81cce017 Mon Sep 17 00:00:00 2001 From: Kali Kaneko Date: Tue, 14 Apr 2015 01:13:29 -0400 Subject: [feature] implement substring body fetch Current twisted implementation correctly parses partial fetches using substrings by use of angle brackets (see section 6.4.5 of imap rfc), but no use is made of the requested substring in the spew_body method. this commit minimally implements conformance to the substring request, although further boundary checks should be made (ie, checking whether the starting octet is beyond the end of the text). Resolves: #6841 Releases: 0.4.0 --- src/leap/mail/imap/server.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/leap/mail/imap/server.py b/src/leap/mail/imap/server.py index 3aeca54..45da535 100644 --- a/src/leap/mail/imap/server.py +++ b/src/leap/mail/imap/server.py @@ -17,6 +17,7 @@ """ LEAP IMAP4 Server Implementation. """ +import StringIO from copy import copy from twisted import cred @@ -136,7 +137,23 @@ class LEAPIMAPServer(imap4.IMAP4Server): _w(str(part) + ' ') _f() if part.part: - return imap4.FileProducer(msg.getBodyFile() + # PATCHED ############################################# + # implement partial FETCH + # TODO implement boundary checks + # TODO see if there's a more efficient way, without + # copying the original content into a new buffer. + fd = msg.getBodyFile() + begin = getattr(part, "partialBegin", None) + _len = getattr(part, "partialLength", None) + if begin is not None and _len is not None: + _fd = StringIO.StringIO() + fd.seek(part.partialBegin) + _fd.write(fd.read(part.partialLength)) + _fd.seek(0) + else: + _fd = fd + return imap4.FileProducer(_fd + # END PATCHED #########################3 ).beginProducing(self.transport ) else: -- cgit v1.2.3