Add type stubs for socket and ssl modules; update MicromailClient to remove type ignores
This commit is contained in:
parent
77d4da5900
commit
ddbf910f34
4 changed files with 264 additions and 7 deletions
17
micromail.py
17
micromail.py
|
@ -68,7 +68,7 @@ class MicromailClient:
|
|||
print("Connected to server.")
|
||||
|
||||
if self.ssl:
|
||||
self.socket = ssl.wrap_socket(self.socket) # type: ignore
|
||||
self.socket = ssl.wrap_socket(self.socket)
|
||||
|
||||
self.read_res(code=220)
|
||||
self.features = self.ehlo()
|
||||
|
@ -114,7 +114,7 @@ class MicromailClient:
|
|||
|
||||
if isinstance(data, str):
|
||||
data = data.encode()
|
||||
n = self.socket.write(data) # type: ignore
|
||||
n = self.socket.write(data)
|
||||
if n != len(data):
|
||||
print(f"Failure writing data <{data.decode()}>: not all bytes written")
|
||||
|
||||
|
@ -137,14 +137,14 @@ class MicromailClient:
|
|||
response = []
|
||||
next = True
|
||||
while next:
|
||||
r_code = int(self.socket.read(3)) # type: ignore
|
||||
next = self.socket.read(1) == b"-" # type: ignore
|
||||
response.append(self.socket.readline().strip().decode()) # type: ignore
|
||||
r_code = int(self.socket.read(3))
|
||||
next = self.socket.read(1) == b"-"
|
||||
response.append(self.socket.readline().strip().decode())
|
||||
|
||||
if isinstance(code, int):
|
||||
code = [code]
|
||||
if code != [] and r_code not in code:
|
||||
raise SMTPError(cmd, r_code, b" ".join(response).decode())
|
||||
raise SMTPError(cmd, r_code, " ".join(response))
|
||||
return r_code, response
|
||||
|
||||
def ehlo(self) -> list[str]:
|
||||
|
@ -152,8 +152,11 @@ class MicromailClient:
|
|||
return res
|
||||
|
||||
def start_starttls(self) -> None:
|
||||
if self.socket is None:
|
||||
raise NoSocketError
|
||||
|
||||
self.send_command("STARTTLS", code=220)
|
||||
self.socket = ssl.wrap_socket(self.socket) # type: ignore
|
||||
self.socket = ssl.wrap_socket(self.socket)
|
||||
|
||||
def new_message(self, to: str | list[str], sender: str | None = None) -> None:
|
||||
self.send_command("RSET", code=250)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue