Skip to content

Commit

Permalink
added flags and internaldate capabilites for MULTIAPPEND
Browse files Browse the repository at this point in the history
  • Loading branch information
d70-t authored and mjs committed Jan 25, 2022
1 parent 843dc07 commit 05dbfb4
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
13 changes: 12 additions & 1 deletion imapclient/imapclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -1429,7 +1429,18 @@ def multiappend(self, folder, msgs):
Returns the APPEND response from the server.
"""
msgs = [_literal(to_bytes(m)) for m in msgs]
def chunks():
for m in msgs:
if isinstance(m, dict):
if "flags" in m:
yield to_bytes(seq_to_parenstr(m["flags"]))
if "date" in m:
yield to_bytes('"%s"' % datetime_to_INTERNALDATE(m["date"]))
yield _literal(to_bytes(m["msg"]))
else:
yield _literal(to_bytes(m))

msgs = list(chunks())

return self._raw_command(
b"APPEND",
Expand Down
42 changes: 42 additions & 0 deletions tests/test_imapclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,35 @@ def test_multiappend(self):
b"APPEND", [b'"foobar"', b"msg1", b"msg2"], uid=False
)

def test_multiappend_with_flags_and_internaldate(self):
self.client._cached_capabilities = (b"MULTIAPPEND",)
self.client._raw_command = Mock()
self.client.multiappend("foobar", [
{
"msg": "msg1",
"flags": ["FLAG", "WAVE"],
"date": datetime(2009, 4, 5, 11, 0, 5, 0, FixedOffset(2 * 60)),
},
{
"msg": "msg2",
"flags": ["FLAG", "WAVE"],
},
{
"msg": "msg3",
"date": datetime(2009, 4, 5, 11, 0, 5, 0, FixedOffset(2 * 60)),
}])

self.client._raw_command.assert_called_once_with(
b"APPEND", [b'"foobar"',
b'(FLAG WAVE)',
b'"05-Apr-2009 11:00:05 +0200"',
_literal(b"msg1"),
b'(FLAG WAVE)',
_literal(b"msg2"),
b'"05-Apr-2009 11:00:05 +0200"',
_literal(b"msg3")], uid=False
)


class TestAclMethods(IMAPClientTest):
def setUp(self):
Expand Down Expand Up @@ -976,6 +1005,19 @@ def test_literal_plus(self):
b"tag APPEND {1+}\r\n" b"\xff {5+}\r\n" b"hello\r\n",
)

def test_literal_plus_multiple_literals(self):
self.client._cached_capabilities = (b"LITERAL+",)

typ, data = self.client._raw_command(
b"APPEND", [b"\xff", _literal(b"hello"), b"TEXT", _literal(b"test")], uid=False
)
self.assertEqual(typ, "OK")
self.assertEqual(data, ["done"])
self.assertEqual(
self.client._imap.sent,
b"tag APPEND {1+}\r\n" b"\xff {5+}\r\n" b"hello" b" TEXT {4+}\r\n" b"test\r\n",
)

def test_complex(self):
self.check(
b"search",
Expand Down

0 comments on commit 05dbfb4

Please sign in to comment.