Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Made Command class __repr__ method more robust #99

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading