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

Store IMAP client task reference #115

Merged
merged 1 commit into from
Jan 13, 2025
Merged
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
5 changes: 3 additions & 2 deletions aioimaplib/aioimaplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import ssl
import sys
import time
from asyncio import BaseTransport, Future
from asyncio import BaseTransport, Future, Task
from collections import namedtuple
from copy import copy
from datetime import datetime, timezone, timedelta
Expand Down Expand Up @@ -701,6 +701,7 @@ def _find_pending_async_cmd_by_tag(self, tag: str) -> list:

class IMAP4(object):
TIMEOUT_SECONDS = 10.0
_client_task: Task

def __init__(self, host: str = '127.0.0.1', port: int = IMAP4_PORT, loop: asyncio.AbstractEventLoop = None,
timeout: float = TIMEOUT_SECONDS, conn_lost_cb: Callable[[Optional[Exception]], None] = None,
Expand All @@ -717,7 +718,7 @@ def create_client(self, host: str, port: int, loop: asyncio.AbstractEventLoop,
conn_lost_cb: Callable[[Optional[Exception]], None] = None, ssl_context: ssl.SSLContext = None) -> None:
local_loop = loop if loop is not None else get_running_loop()
self.protocol = IMAP4ClientProtocol(local_loop, conn_lost_cb)
local_loop.create_task(local_loop.create_connection(lambda: self.protocol, host, port, ssl=ssl_context))
self._client_task = local_loop.create_task(local_loop.create_connection(lambda: self.protocol, host, port, ssl=ssl_context))

def get_state(self) -> str:
return self.protocol.state
Expand Down
Loading