aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/Twisted/py3/twisted/mail/imap4.py
diff options
context:
space:
mode:
authorrobot-piglet <robot-piglet@yandex-team.com>2024-12-17 12:07:28 +0300
committerrobot-piglet <robot-piglet@yandex-team.com>2024-12-17 12:18:43 +0300
commit48bd5f88777f4dc94fd41a7dd22808ed639b985d (patch)
tree6a899d7cc8bd632073408198260a93d76f99ef32 /contrib/python/Twisted/py3/twisted/mail/imap4.py
parent3e05dc5f5c47aa8d220db7b5508cfbd4a0d8919f (diff)
downloadydb-48bd5f88777f4dc94fd41a7dd22808ed639b985d.tar.gz
Intermediate changes
commit_hash:3786c4fc65af12274eea45a3ef9de6050e262ac0
Diffstat (limited to 'contrib/python/Twisted/py3/twisted/mail/imap4.py')
-rw-r--r--contrib/python/Twisted/py3/twisted/mail/imap4.py25
1 files changed, 21 insertions, 4 deletions
diff --git a/contrib/python/Twisted/py3/twisted/mail/imap4.py b/contrib/python/Twisted/py3/twisted/mail/imap4.py
index 9a9f140795..f38d094f89 100644
--- a/contrib/python/Twisted/py3/twisted/mail/imap4.py
+++ b/contrib/python/Twisted/py3/twisted/mail/imap4.py
@@ -28,7 +28,7 @@ import uuid
from base64 import decodebytes, encodebytes
from io import BytesIO
from itertools import chain
-from typing import Any, List, cast
+from typing import Any, List, Optional, cast
from zope.interface import implementer
@@ -2205,7 +2205,7 @@ class IMAP4Server(basic.LineReceiver, policies.TimeoutMixin):
hdrs = _formatHeaders(msg.getHeaders(True))
_w(part.__bytes__() + b" " + _literal(hdrs))
elif part.empty:
- _w(part.__bytes__() + b" ")
+ _w(part.getBytes(length=msg.getSize()) + b" ")
_f()
if part.part:
return FileProducer(msg.getBodyFile()).beginProducing(self.transport)
@@ -5691,7 +5691,14 @@ class _FetchParser:
def __str__(self) -> str:
return self.__bytes__().decode("ascii")
- def __bytes__(self) -> bytes:
+ def getBytes(self, length: Optional[int] = None) -> bytes:
+ """
+ Prepare the initial command response for a Fetch BODY request.
+ Interpret the Fetch request from the client and return the
+ appropriate response based on RFC 3501.
+ This is not the body itself of the response, merely the section
+ of the first response line that describes the body part.
+ """
base = b"BODY"
part = b""
separator = b""
@@ -5711,9 +5718,19 @@ class _FetchParser:
elif self.empty:
base += b"[" + part + b"]"
if self.partialBegin is not None:
- base += b"<%d.%d>" % (self.partialBegin, self.partialLength) # type: ignore[unreachable]
+ if length is None or length > self.partialLength: # type: ignore[unreachable]
+ base += b"<%d.%d>" % (self.partialBegin, self.partialLength)
+ else:
+ # IMAP4rev1 says that if the partial length is greater than
+ # the length of the data, the server should send the entire
+ # data., with a "0" as the partial length
+ # https://datatracker.ietf.org/doc/html/rfc3501#section-6.4.5
+ base += b"<0>"
return base
+ def __bytes__(self) -> bytes:
+ return self.getBytes()
+
class BodyStructure:
type = "bodystructure"
__str__ = lambda self: "bodystructure"