diff options
author | Kali Kaneko <kali@leap.se> | 2015-04-14 01:13:29 -0400 |
---|---|---|
committer | Kali Kaneko <kali@leap.se> | 2015-04-28 11:33:37 -0400 |
commit | 154e1aa347bb9ee0a9ed9abd60ed703a81cce017 (patch) | |
tree | c270c0143c6d4b9ca7d9fc7e2c1287e5d7e9eecf /src/leap | |
parent | d64fb189cc7c05272e0558085740efd8df2598dd (diff) |
[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
Diffstat (limited to 'src/leap')
-rw-r--r-- | src/leap/mail/imap/server.py | 19 |
1 files changed, 18 insertions, 1 deletions
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: |