Skip to content
Open
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
1 change: 1 addition & 0 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
- name: Install Poetry
uses: snok/install-poetry@v1
with:
version: 1.8.5
virtualenvs-create: true
virtualenvs-in-project: true
- name: Load cached venv
Expand Down
6 changes: 3 additions & 3 deletions aioimaplib/aioimaplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ def has_pending_idle_command(self) -> bool:
def idle_done(self) -> None:
self.send('DONE')

async def search(self, *criteria, charset: Optional[str] = 'utf-8', by_uid: bool = False) -> Response:
async def search(self, *criteria, charset: Optional[str] = None, by_uid: bool = False) -> Response:
args = ('CHARSET', charset) + criteria if charset is not None else criteria
prefix = 'UID' if by_uid else ''

Expand Down Expand Up @@ -738,10 +738,10 @@ async def logout(self) -> Response:
async def select(self, mailbox: str = 'INBOX') -> Response:
return await asyncio.wait_for(self.protocol.select(mailbox), self.timeout)

async def search(self, *criteria: str, charset: Optional[str] = 'utf-8') -> Response:
async def search(self, *criteria: str, charset: Optional[str] = None) -> Response:
return await asyncio.wait_for(self.protocol.search(*criteria, charset=charset), self.timeout)

async def uid_search(self, *criteria: str, charset: Optional[str] = 'utf-8') -> Response:
async def uid_search(self, *criteria: str, charset: Optional[str] = None) -> Response:
return await asyncio.wait_for(self.protocol.search(*criteria, by_uid=True, charset=charset), self.timeout)

async def uid(self, command: str, *criteria: str) -> Response:
Expand Down
27 changes: 27 additions & 0 deletions tests/test_aioimaplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,33 @@ async def test_search_two_messages(with_server):
assert b'1 2' == data[0]


@pytest.mark.asyncio()
async def test_search_default_charset_is_none(with_server):
"""Default charset should be None to avoid sending CHARSET which some servers reject."""
with_server.receive(Mail.create(['user']))
imap_client = await login_user_async('user', 'pass', select=True)

# Default charset=None should work (no CHARSET sent)
result, data = await imap_client.search('ALL')
assert 'OK' == result
assert b'1' == data[0]

# Explicit charset='utf-8' should still work
result, data = await imap_client.search('ALL', charset='utf-8')
assert 'OK' == result
assert b'1' == data[0]

# uid_search default charset=None should work
result, data = await imap_client.uid_search('ALL')
assert 'OK' == result
assert b'1' == data[0]

# uid_search explicit charset='utf-8' should still work
result, data = await imap_client.uid_search('ALL', charset='utf-8')
assert 'OK' == result
assert b'1' == data[0]


@pytest.mark.asyncio()
async def test_search_messages(with_server):
"""Increase compatibility with https://docs.python.org/3/library/imaplib.html#imap4-example."""
Expand Down