Skip to content

Commit

Permalink
Added a test to show the incompatibility and fixed the code to make i…
Browse files Browse the repository at this point in the history
…t pass
  • Loading branch information
BrentWilkins authored and bamthomas committed Dec 13, 2023
1 parent bf51f58 commit 692b1e2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
9 changes: 5 additions & 4 deletions aioimaplib/aioimaplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,16 @@ 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()

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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 12 additions & 0 deletions aioimaplib/tests/test_aioimaplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit 692b1e2

Please sign in to comment.