4 from _typeshed import Self
5 from socket import socket as _socket
6 from ssl import SSLContext, SSLSocket
7 from types import TracebackType
8 from typing import IO, Any, Callable, List, Pattern, Tuple, Type, Union
9 from typing_extensions import Literal
11 # TODO: Commands should use their actual return types, not this type alias.
12 # E.g. Tuple[Literal["OK"], List[bytes]]
13 _CommandResults = Tuple[str, List[Any]]
15 _AnyResponseData = Union[List[None], List[Union[bytes, Tuple[bytes, bytes]]]]
17 _list = list # conflicts with a method named "list"
20 error: Type[Exception]
21 abort: Type[Exception]
22 readonly: Type[Exception]
23 mustquote: Pattern[str]
27 tagged_commands: dict[bytes, _list[bytes] | None]
28 untagged_responses: dict[str, _list[bytes | tuple[bytes, bytes]]]
29 continuation_response: str
35 capabilities: tuple[str]
37 if sys.version_info >= (3, 9):
38 def __init__(self, host: str = ..., port: int = ..., timeout: float | None = ...) -> None: ...
39 def open(self, host: str = ..., port: int = ..., timeout: float | None = ...) -> None: ...
41 def __init__(self, host: str = ..., port: int = ...) -> None: ...
42 def open(self, host: str = ..., port: int = ...) -> None: ...
43 def __getattr__(self, attr: str) -> Any: ...
47 file: IO[str] | IO[bytes]
48 def read(self, size: int) -> bytes: ...
49 def readline(self) -> bytes: ...
50 def send(self, data: bytes) -> None: ...
51 def shutdown(self) -> None: ...
52 def socket(self) -> _socket: ...
53 def recent(self) -> _CommandResults: ...
54 def response(self, code: str) -> _CommandResults: ...
55 def append(self, mailbox: str, flags: str, date_time: str, message: str) -> str: ...
56 def authenticate(self, mechanism: str, authobject: Callable[[bytes], bytes | None]) -> tuple[str, str]: ...
57 def capability(self) -> _CommandResults: ...
58 def check(self) -> _CommandResults: ...
59 def close(self) -> _CommandResults: ...
60 def copy(self, message_set: str, new_mailbox: str) -> _CommandResults: ...
61 def create(self, mailbox: str) -> _CommandResults: ...
62 def delete(self, mailbox: str) -> _CommandResults: ...
63 def deleteacl(self, mailbox: str, who: str) -> _CommandResults: ...
64 def enable(self, capability: str) -> _CommandResults: ...
65 def __enter__(self: Self) -> Self: ...
66 def __exit__(self, t: Type[BaseException] | None, v: BaseException | None, tb: TracebackType | None) -> None: ...
67 def expunge(self) -> _CommandResults: ...
68 def fetch(self, message_set: str, message_parts: str) -> tuple[str, _AnyResponseData]: ...
69 def getacl(self, mailbox: str) -> _CommandResults: ...
70 def getannotation(self, mailbox: str, entry: str, attribute: str) -> _CommandResults: ...
71 def getquota(self, root: str) -> _CommandResults: ...
72 def getquotaroot(self, mailbox: str) -> _CommandResults: ...
73 def list(self, directory: str = ..., pattern: str = ...) -> tuple[str, _AnyResponseData]: ...
74 def login(self, user: str, password: str) -> tuple[Literal["OK"], _list[bytes]]: ...
75 def login_cram_md5(self, user: str, password: str) -> _CommandResults: ...
76 def logout(self) -> tuple[str, _AnyResponseData]: ...
77 def lsub(self, directory: str = ..., pattern: str = ...) -> _CommandResults: ...
78 def myrights(self, mailbox: str) -> _CommandResults: ...
79 def namespace(self) -> _CommandResults: ...
80 def noop(self) -> tuple[str, _list[bytes]]: ...
81 def partial(self, message_num: str, message_part: str, start: str, length: str) -> _CommandResults: ...
82 def proxyauth(self, user: str) -> _CommandResults: ...
83 def rename(self, oldmailbox: str, newmailbox: str) -> _CommandResults: ...
84 def search(self, charset: str | None, *criteria: str) -> _CommandResults: ...
85 def select(self, mailbox: str = ..., readonly: bool = ...) -> tuple[str, _list[bytes | None]]: ...
86 def setacl(self, mailbox: str, who: str, what: str) -> _CommandResults: ...
87 def setannotation(self, *args: str) -> _CommandResults: ...
88 def setquota(self, root: str, limits: str) -> _CommandResults: ...
89 def sort(self, sort_criteria: str, charset: str, *search_criteria: str) -> _CommandResults: ...
90 def starttls(self, ssl_context: Any | None = ...) -> tuple[Literal["OK"], _list[None]]: ...
91 def status(self, mailbox: str, names: str) -> _CommandResults: ...
92 def store(self, message_set: str, command: str, flags: str) -> _CommandResults: ...
93 def subscribe(self, mailbox: str) -> _CommandResults: ...
94 def thread(self, threading_algorithm: str, charset: str, *search_criteria: str) -> _CommandResults: ...
95 def uid(self, command: str, *args: str) -> _CommandResults: ...
96 def unsubscribe(self, mailbox: str) -> _CommandResults: ...
97 if sys.version_info >= (3, 9):
98 def unselect(self) -> _CommandResults: ...
99 def xatom(self, name: str, *args: str) -> _CommandResults: ...
100 def print_log(self) -> None: ...
102 class IMAP4_SSL(IMAP4):
105 if sys.version_info >= (3, 9):
110 keyfile: str | None = ...,
111 certfile: str | None = ...,
112 ssl_context: SSLContext | None = ...,
113 timeout: float | None = ...,
120 keyfile: str | None = ...,
121 certfile: str | None = ...,
122 ssl_context: SSLContext | None = ...,
129 if sys.version_info >= (3, 9):
130 def open(self, host: str = ..., port: int | None = ..., timeout: float | None = ...) -> None: ...
132 def open(self, host: str = ..., port: int | None = ...) -> None: ...
133 def read(self, size: int) -> bytes: ...
134 def readline(self) -> bytes: ...
135 def send(self, data: bytes) -> None: ...
136 def shutdown(self) -> None: ...
137 def socket(self) -> _socket: ...
138 def ssl(self) -> SSLSocket: ...
140 class IMAP4_stream(IMAP4):
142 def __init__(self, command: str) -> None: ...
147 process: subprocess.Popen[bytes]
150 if sys.version_info >= (3, 9):
151 def open(self, host: str | None = ..., port: int | None = ..., timeout: float | None = ...) -> None: ...
153 def open(self, host: str | None = ..., port: int | None = ...) -> None: ...
154 def read(self, size: int) -> bytes: ...
155 def readline(self) -> bytes: ...
156 def send(self, data: bytes) -> None: ...
157 def shutdown(self) -> None: ...
159 class _Authenticator:
160 mech: Callable[[bytes], bytes]
161 def __init__(self, mechinst: Callable[[bytes], bytes]) -> None: ...
162 def process(self, data: str) -> str: ...
163 def encode(self, inp: bytes) -> str: ...
164 def decode(self, inp: str) -> bytes: ...
166 def Internaldate2tuple(resp: str) -> time.struct_time: ...
167 def Int2AP(num: int) -> str: ...
168 def ParseFlags(resp: str) -> tuple[str]: ...
169 def Time2Internaldate(date_time: float | time.struct_time | str) -> str: ...