diff --git a/Lib/smtplib.py b/Lib/smtplib.py index 7808ba01cba887f..fe55af6c065add3 100755 --- a/Lib/smtplib.py +++ b/Lib/smtplib.py @@ -41,6 +41,8 @@ # # This was modified from the Python 1.5 library HTTP lib. +from __future__ import print_function + import socket import io import re @@ -335,12 +337,14 @@ def connect(self, host='localhost', port=0, source_address=None): raise OSError("nonnumeric port") if not port: port = self.default_port - sys.audit("smtplib.connect", self, host, port) + #sys.audit("smtplib.connect", self, host, port) self.sock = self._get_socket(host, port, self.timeout) self.file = None (code, msg) = self.getreply() if self.debuglevel > 0: self._print_debug('connect:', repr(msg)) + if code == 220: + self._host = host return (code, msg) def send(self, s): @@ -353,7 +357,7 @@ def send(self, s): # should not be used, but 'data' needs to convert the string to # binary itself anyway, so that's not a problem. s = s.encode(self.command_encoding) - sys.audit("smtplib.send", self, s) + #sys.audit("smtplib.send", self, s) try: self.sock.sendall(s) except OSError: @@ -416,7 +420,7 @@ def getreply(self): errmsg = b"\n".join(resp) if self.debuglevel > 0: - self._print_debug('reply: retcode (%s); Msg: %a' % (errcode, errmsg)) + self._print_debug('reply: retcode (%s); Msg: %s' % (errcode, errmsg)) return errcode, errmsg def docmd(self, cmd, args=""): @@ -606,7 +610,7 @@ def ehlo_or_helo_if_needed(self): if not (200 <= code <= 299): raise SMTPHeloError(code, resp) - def auth(self, mechanism, authobject, *, initial_response_ok=True): + def auth(self, mechanism, authobject, initial_response_ok=True): """Authentication command - requires response processing. 'mechanism' specifies which authentication mechanism is to @@ -667,7 +671,7 @@ def auth_login(self, challenge=None): else: return self.password - def login(self, user, password, *, initial_response_ok=True): + def login(self, user, password, initial_response_ok=True): """Log in on an SMTP server that requires authentication. The arguments are: @@ -950,7 +954,7 @@ def send_message(self, msg, from_addr=None, to_addrs=None, del msg_copy['Resent-Bcc'] international = False try: - ''.join([from_addr, *to_addrs]).encode('ascii') + ''.join([from_addr, ] + to_addrs).encode('ascii') except UnicodeEncodeError: if not self.has_extn('smtputf8'): raise SMTPNotSupportedError( @@ -962,7 +966,7 @@ def send_message(self, msg, from_addr=None, to_addrs=None, if international: g = email.generator.BytesGenerator( bytesmsg, policy=msg.policy.clone(utf8=True)) - mail_options = (*mail_options, 'SMTPUTF8', 'BODY=8BITMIME') + mail_options = mail_options + ('SMTPUTF8', 'BODY=8BITMIME') else: g = email.generator.BytesGenerator(bytesmsg) g.flatten(msg_copy, linesep='\r\n') @@ -1037,9 +1041,9 @@ def __init__(self, host='', port=0, local_hostname=None, def _get_socket(self, host, port, timeout): if self.debuglevel > 0: self._print_debug('connect:', (host, port)) - new_socket = super()._get_socket(host, port, timeout) + new_socket = SMTP._get_socket(self, host, port, timeout) new_socket = self.context.wrap_socket(new_socket, - server_hostname=self._host) + server_hostname=host) return new_socket __all__.append("SMTP_SSL")