Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't assume capabilities have been cached when sending literals #569

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions imapclient/imapclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -1675,6 +1675,10 @@ def _raw_command(self, command, args, uid=True):
"""
command = command.upper()

# Check for LITERAL+ now because if capabilities haven't been cached
# yet, we can't call CAPABILITY while sending another command.
has_literal_plus = self.has_capability("LITERAL+")

if isinstance(args, tuple):
args = list(args)
if not isinstance(args, list):
Expand Down Expand Up @@ -1702,7 +1706,7 @@ def _raw_command(self, command, args, uid=True):
# Now send the (unquoted) literal
if isinstance(item, _quoted):
item = item.original
self._send_literal(tag, item)
self._send_literal(tag, item, has_literal_plus)
if not is_last:
self._imap.send(b" ")
else:
Expand All @@ -1717,9 +1721,9 @@ def _raw_command(self, command, args, uid=True):

return self._imap._command_complete(to_unicode(command), tag)

def _send_literal(self, tag, item):
def _send_literal(self, tag, item, has_literal_plus):
"""Send a single literal for the command with *tag*."""
if b"LITERAL+" in self._cached_capabilities:
if has_literal_plus:
out = b" {" + str(len(item)).encode("ascii") + b"+}\r\n" + item
logger.debug("> %s", debug_trunc(out, 64))
self._imap.send(out)
Expand Down
Loading