Skip to content

Commit 7198239

Browse files
Menno Finlay-Smitsmjs
authored andcommitted
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 391cc6d commit 7198239

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
@@ -1677,6 +1677,10 @@ def _raw_command(self, command, args, uid=True):
16771677
"""
16781678
command = command.upper()
16791679

1680+
# Check for LITERAL+ now because if capabilities haven't been cached
1681+
# yet, we can't call CAPABILITY while sending another command.
1682+
has_literal_plus = self.has_capability("LITERAL+")
1683+
16801684
if isinstance(args, tuple):
16811685
args = list(args)
16821686
if not isinstance(args, list):
@@ -1704,7 +1708,7 @@ def _raw_command(self, command, args, uid=True):
17041708
# Now send the (unquoted) literal
17051709
if isinstance(item, _quoted):
17061710
item = item.original
1707-
self._send_literal(tag, item)
1711+
self._send_literal(tag, item, has_literal_plus)
17081712
if not is_last:
17091713
self._imap.send(b" ")
17101714
else:
@@ -1719,9 +1723,9 @@ def _raw_command(self, command, args, uid=True):
17191723

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

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

0 commit comments

Comments
 (0)