Skip to content

Commit 2a47fd9

Browse files
committed
Fix SMTPResponse.status_text type: str → bytes
smtplib.SMTP.mail/rcpt/data return (int, bytes), so status_text and the text parameter of set_status() should be bytes, not str.
1 parent f9566a6 commit 2a47fd9

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

emails/backend/response.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@ def __init__(self, exception: Exception | None = None, backend: Any = None) -> N
4141
self.rcpt_options: list[str] | None = None
4242

4343
self.status_code: int | None = None
44-
self.status_text: str | None = None
44+
self.status_text: bytes | None = None
4545
self.last_command: str | None = None
4646
self.refused_recipients: dict[str, tuple[int, bytes]] = {}
4747

48-
def set_status(self, command: str, code: int, text: str, **kwargs: Any) -> None:
48+
def set_status(self, command: str, code: int, text: bytes, **kwargs: Any) -> None:
4949
self.responses.append([command, code, text, kwargs])
5050
self.status_code = code
5151
self.status_text = text

emails/testsuite/smtp/test_smtp_response.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ def test_smtp_response_defaults():
1515

1616
def test_smtp_response_set_status():
1717
r = SMTPResponse()
18-
r.set_status('mail', 250, 'OK')
18+
r.set_status('mail', 250, b'OK')
1919
assert r.status_code == 250
20-
assert r.status_text == 'OK'
20+
assert r.status_text == b'OK'
2121
assert r.last_command == 'mail'
2222
assert len(r.responses) == 1
2323

2424

2525
def test_smtp_response_success():
2626
r = SMTPResponse()
27-
r.set_status('data', 250, 'OK')
27+
r.set_status('data', 250, b'OK')
2828
assert not r.success # _finished is False
2929
r._finished = True
3030
assert r.success

0 commit comments

Comments
 (0)