summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2015-04-14 01:13:29 -0400
committerKali Kaneko <kali@leap.se>2015-04-28 11:33:37 -0400
commitc42e54cc707a16e4c5bde75928b1ef50593f8df8 (patch)
treece1eae48229c232f08dbed8608a592602cea536a
parent3973f50b06d5a4c0c921afb13a76a91b546880a7 (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
-rw-r--r--mail/src/leap/mail/imap/server.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/mail/src/leap/mail/imap/server.py b/mail/src/leap/mail/imap/server.py
index 3aeca54f..45da5359 100644
--- a/mail/src/leap/mail/imap/server.py
+++ b/mail/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: