From f72010dfd27b0f3d2f2348785dc248693d3b04ef Mon Sep 17 00:00:00 2001 From: Brent Wilkins Date: Sun, 10 Dec 2023 00:07:26 -0700 Subject: [PATCH] Added a test to show the incompatibility and fixed the code to make it pass --- aioimaplib/aioimaplib.py | 9 +++++---- aioimaplib/tests/test_aioimaplib.py | 12 ++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/aioimaplib/aioimaplib.py b/aioimaplib/aioimaplib.py index e65257c..ed7fe0e 100644 --- a/aioimaplib/aioimaplib.py +++ b/aioimaplib/aioimaplib.py @@ -156,7 +156,7 @@ def __init__(self, name: str, tag: str, *args, prefix: str = None, untagged_resp self._timer = asyncio.Handle(lambda: None, None, self._loop) # fake timer self._set_timer() self._expected_size = 0 - + self._resp_literal_data = bytearray() self._resp_result = 'Init' self._resp_lines: List[bytes] = list() @@ -164,7 +164,8 @@ def __init__(self, name: str, tag: str, *args, prefix: str = None, untagged_resp def __repr__(self) -> str: return '{tag} {prefix}{name}{space}{args}'.format( tag=self.tag, prefix=self.prefix or '', name=self.name, - space=' ' if self.args else '', args=' '.join(self.args)) + space=' ' if self.args else '', args=' '.join(str(arg) if arg is not None else '' \ + for arg in self.args)) # for tests def __eq__(self, other): @@ -473,7 +474,7 @@ async def xoauth2(self, user: str, token: str) -> Response: """Authentication with XOAUTH2. Tested with outlook. - + Specification: https://learn.microsoft.com/en-us/exchange/client-developer/legacy-protocols/how-to-authenticate-an-imap-pop-smtp-application-by-using-oauth https://developers.google.com/gmail/imap/xoauth2-protocol @@ -787,7 +788,7 @@ async def idle_start(self, timeout: float = TWENTY_NINE_MINUTES) -> Future: if not self.has_pending_idle(): wait_for_ack.cancel() raise Abort('server returned error to IDLE command') - + def start_stop_wait_server_push(): task = asyncio.ensure_future(self.stop_wait_server_push()) self.tasks.add(task) diff --git a/aioimaplib/tests/test_aioimaplib.py b/aioimaplib/tests/test_aioimaplib.py index 0ff1625..4628c0b 100644 --- a/aioimaplib/tests/test_aioimaplib.py +++ b/aioimaplib/tests/test_aioimaplib.py @@ -471,6 +471,18 @@ async def test_search_two_messages(self): assert 'OK' == result assert b'1 2' == data[0] + async def test_search_messages(self): + """Increase compatibility with https://docs.python.org/3/library/imaplib.html#imap4-example.""" + self.imapserver.receive(Mail.create(['user'])) + self.imapserver.receive(Mail.create(['user'])) + imap_client = await self.login_user('user', 'pass', select=True) + + # E.g. typ, data = M.search(None, 'ALL') + result, data = await imap_client.search(None, 'ALL') + + assert 'OK' == result + assert b'1 2' == data[0] + async def test_uid_with_illegal_command(self): imap_client = await self.login_user('user', 'pass', select=True)