Skip to content

Commit

Permalink
Store IMAP client task reference
Browse files Browse the repository at this point in the history
  • Loading branch information
jbouwh authored and bamthomas committed Jan 13, 2025
1 parent d7cd270 commit b5461cc
Showing 1 changed file with 3 additions and 2 deletions.
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

0 comments on commit b5461cc

Please sign in to comment.