1
- # Stubs for imaplib (Python 2)
2
-
3
1
import imaplib
4
2
import subprocess
5
3
import sys
@@ -8,8 +6,16 @@ from socket import socket as _socket
8
6
from ssl import SSLSocket , SSLContext
9
7
from typing import Any , Callable , Dict , IO , List , Optional , Pattern , Text , Tuple , Type , Union
10
8
11
- CommandResults = Tuple [str , List [Any ]]
9
+ if sys .version_info >= (3 , 8 ):
10
+ from typing import Literal
11
+ else :
12
+ from typing_extensions import Literal
13
+
14
+ # TODO: Commands should use their actual return types, not this type alias.
15
+ # E.g. Tuple[Literal["OK"], List[bytes]]
16
+ _CommandResults = Tuple [str , List [Any ]]
12
17
18
+ _AnyResponseData = Union [List [None ], List [Union [bytes , Tuple [bytes , bytes ]]]]
13
19
14
20
class IMAP4 :
15
21
error : Type [Exception ] = ...
@@ -19,8 +25,8 @@ class IMAP4:
19
25
debug : int = ...
20
26
state : str = ...
21
27
literal : Optional [Text ] = ...
22
- tagged_commands : Dict [str , str ] = ...
23
- untagged_responses : Dict [str , str ] = ...
28
+ tagged_commands : Dict [bytes , Optional [ List [ bytes ]]]
29
+ untagged_responses : Dict [str , List [ Union [ bytes , Tuple [ bytes , bytes ]]]]
24
30
continuation_response : str = ...
25
31
is_readonly : bool = ...
26
32
tagnum : int = ...
@@ -41,53 +47,53 @@ class IMAP4:
41
47
def send (self , data : bytes ) -> None : ...
42
48
def shutdown (self ) -> None : ...
43
49
def socket (self ) -> _socket : ...
44
- def recent (self ) -> CommandResults : ...
45
- def response (self , code : str ) -> CommandResults : ...
50
+ def recent (self ) -> _CommandResults : ...
51
+ def response (self , code : str ) -> _CommandResults : ...
46
52
def append (self , mailbox : str , flags : str , date_time : str , message : str ) -> str : ...
47
53
def authenticate (self , mechanism : str , authobject : Callable [[bytes ], Optional [bytes ]]) -> Tuple [str , str ]: ...
48
- def capability (self ) -> CommandResults : ...
49
- def check (self ) -> CommandResults : ...
50
- def close (self ) -> CommandResults : ...
51
- def copy (self , message_set : str , new_mailbox : str ) -> CommandResults : ...
52
- def create (self , mailbox : str ) -> CommandResults : ...
53
- def delete (self , mailbox : str ) -> CommandResults : ...
54
- def deleteacl (self , mailbox : str , who : str ) -> CommandResults : ...
54
+ def capability (self ) -> _CommandResults : ...
55
+ def check (self ) -> _CommandResults : ...
56
+ def close (self ) -> _CommandResults : ...
57
+ def copy (self , message_set : str , new_mailbox : str ) -> _CommandResults : ...
58
+ def create (self , mailbox : str ) -> _CommandResults : ...
59
+ def delete (self , mailbox : str ) -> _CommandResults : ...
60
+ def deleteacl (self , mailbox : str , who : str ) -> _CommandResults : ...
55
61
if sys .version_info >= (3 , 5 ):
56
- def enable (self , capability : str ) -> CommandResults : ...
62
+ def enable (self , capability : str ) -> _CommandResults : ...
57
63
def __enter__ (self ) -> IMAP4 : ...
58
64
def __exit__ (self , * args ) -> None : ...
59
- def expunge (self ) -> CommandResults : ...
60
- def fetch (self , message_set : str , message_parts : str ) -> CommandResults : ...
61
- def getacl (self , mailbox : str ) -> CommandResults : ...
62
- def getannotation (self , mailbox : str , entry : str , attribute : str ) -> CommandResults : ...
63
- def getquota (self , root : str ) -> CommandResults : ...
64
- def getquotaroot (self , mailbox : str ) -> CommandResults : ...
65
- def list (self , directory : str = ..., pattern : str = ...) -> CommandResults : ...
66
- def login (self , user : str , password : str ) -> CommandResults : ...
67
- def login_cram_md5 (self , user : str , password : str ) -> CommandResults : ...
68
- def logout (self ) -> CommandResults : ...
69
- def lsub (self , directory : str = ..., pattern : str = ...) -> CommandResults : ...
70
- def myrights (self , mailbox : str ) -> CommandResults : ...
71
- def namespace (self ) -> CommandResults : ...
72
- def noop (self ) -> CommandResults : ...
73
- def partial (self , message_num : str , message_part : str , start : str , length : str ) -> CommandResults : ...
74
- def proxyauth (self , user : str ) -> CommandResults : ...
75
- def rename (self , oldmailbox : str , newmailbox : str ) -> CommandResults : ...
76
- def search (self , charset : Optional [str ], * criteria : str ) -> CommandResults : ...
77
- def select (self , mailbox : str = ..., readonly : bool = ...) -> CommandResults : ...
78
- def setacl (self , mailbox : str , who : str , what : str ) -> CommandResults : ...
79
- def setannotation (self , * args : str ) -> CommandResults : ...
80
- def setquota (self , root : str , limits : str ) -> CommandResults : ...
81
- def sort (self , sort_criteria : str , charset : str , * search_criteria : str ) -> CommandResults : ...
65
+ def expunge (self ) -> _CommandResults : ...
66
+ def fetch (self , message_set : str , message_parts : str ) -> Tuple [ str , _AnyResponseData ] : ...
67
+ def getacl (self , mailbox : str ) -> _CommandResults : ...
68
+ def getannotation (self , mailbox : str , entry : str , attribute : str ) -> _CommandResults : ...
69
+ def getquota (self , root : str ) -> _CommandResults : ...
70
+ def getquotaroot (self , mailbox : str ) -> _CommandResults : ...
71
+ def list (self , directory : str = ..., pattern : str = ...) -> Tuple [ str , _AnyResponseData ] : ...
72
+ def login (self , user : str , password : str ) -> Tuple [ Literal [ "OK" ], List [ bytes ]] : ...
73
+ def login_cram_md5 (self , user : str , password : str ) -> _CommandResults : ...
74
+ def logout (self ) -> Tuple [ str , _AnyResponseData ] : ...
75
+ def lsub (self , directory : str = ..., pattern : str = ...) -> _CommandResults : ...
76
+ def myrights (self , mailbox : str ) -> _CommandResults : ...
77
+ def namespace (self ) -> _CommandResults : ...
78
+ def noop (self ) -> Tuple [ str , List [ bytes ]] : ...
79
+ def partial (self , message_num : str , message_part : str , start : str , length : str ) -> _CommandResults : ...
80
+ def proxyauth (self , user : str ) -> _CommandResults : ...
81
+ def rename (self , oldmailbox : str , newmailbox : str ) -> _CommandResults : ...
82
+ def search (self , charset : Optional [str ], * criteria : str ) -> _CommandResults : ...
83
+ def select (self , mailbox : str = ..., readonly : bool = ...) -> Tuple [ str , List [ Optional [ bytes ]]] : ...
84
+ def setacl (self , mailbox : str , who : str , what : str ) -> _CommandResults : ...
85
+ def setannotation (self , * args : str ) -> _CommandResults : ...
86
+ def setquota (self , root : str , limits : str ) -> _CommandResults : ...
87
+ def sort (self , sort_criteria : str , charset : str , * search_criteria : str ) -> _CommandResults : ...
82
88
if sys .version_info >= (3 ,):
83
- def starttls (self , ssl_context : Optional [Any ] = ...) -> CommandResults : ...
84
- def status (self , mailbox : str , names : str ) -> CommandResults : ...
85
- def store (self , message_set : str , command : str , flags : str ) -> CommandResults : ...
86
- def subscribe (self , mailbox : str ) -> CommandResults : ...
87
- def thread (self , threading_algorithm : str , charset : str , * search_criteria : str ) -> CommandResults : ...
88
- def uid (self , command : str , * args : str ) -> CommandResults : ...
89
- def unsubscribe (self , mailbox : str ) -> CommandResults : ...
90
- def xatom (self , name : str , * args : str ) -> CommandResults : ...
89
+ def starttls (self , ssl_context : Optional [Any ] = ...) -> Tuple [ Literal [ "OK" ], List [ None ]] : ...
90
+ def status (self , mailbox : str , names : str ) -> _CommandResults : ...
91
+ def store (self , message_set : str , command : str , flags : str ) -> _CommandResults : ...
92
+ def subscribe (self , mailbox : str ) -> _CommandResults : ...
93
+ def thread (self , threading_algorithm : str , charset : str , * search_criteria : str ) -> _CommandResults : ...
94
+ def uid (self , command : str , * args : str ) -> _CommandResults : ...
95
+ def unsubscribe (self , mailbox : str ) -> _CommandResults : ...
96
+ def xatom (self , name : str , * args : str ) -> _CommandResults : ...
91
97
def print_log (self ) -> None : ...
92
98
93
99
class IMAP4_SSL (IMAP4 ):
0 commit comments