Skip to content

Commit d26aaef

Browse files
author
Menno Finlay-Smits
committed
Don't assume capabilities have been cached when sending literals
_send_literal was assuming that _cached_capabilites was populated when checking for LITERAL+ but this isn't guaranteed. has_capability is now used to check for LITERAL+. This will populate the capabilities cache if it hasn't been already. Fixes #560
1 parent 25e665d commit d26aaef

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

imapclient/imapclient.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,6 +1675,10 @@ def _raw_command(self, command, args, uid=True):
16751675
"""
16761676
command = command.upper()
16771677

1678+
# Check for LITERAL+ now because if capabilities haven't been cached
1679+
# yet, we can't call CAPABILITY while sending another command.
1680+
has_literal_plus = self.has_capability("LITERAL+")
1681+
16781682
if isinstance(args, tuple):
16791683
args = list(args)
16801684
if not isinstance(args, list):
@@ -1702,7 +1706,7 @@ def _raw_command(self, command, args, uid=True):
17021706
# Now send the (unquoted) literal
17031707
if isinstance(item, _quoted):
17041708
item = item.original
1705-
self._send_literal(tag, item)
1709+
self._send_literal(tag, item, has_literal_plus)
17061710
if not is_last:
17071711
self._imap.send(b" ")
17081712
else:
@@ -1717,9 +1721,9 @@ def _raw_command(self, command, args, uid=True):
17171721

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

1720-
def _send_literal(self, tag, item):
1724+
def _send_literal(self, tag, item, has_literal_plus):
17211725
"""Send a single literal for the command with *tag*."""
1722-
if b"LITERAL+" in self._cached_capabilities:
1726+
if has_literal_plus:
17231727
out = b" {" + str(len(item)).encode("ascii") + b"+}\r\n" + item
17241728
logger.debug("> %s", debug_trunc(out, 64))
17251729
self._imap.send(out)

0 commit comments

Comments
 (0)