--- Lib.orig/smtplib.py 2008-11-30 17:04:44.000000000 +0100 +++ Lib/smtplib.py 2008-11-30 16:47:02.000000000 +0100 @@ -159,30 +159,9 @@ try: import ssl + _have_ssl = True except ImportError: _have_ssl = False -else: - class SSLFakeFile: - """A fake file like object that really wraps a SSLObject. - - It only supports what is needed in smtplib. - """ - def __init__(self, sslobj): - self.sslobj = sslobj - - def readline(self): - str = "" - chr = None - while chr != "\n": - chr = self.sslobj.read(1) - if not chr: break - str += chr - return str - - def close(self): - pass - - _have_ssl = True class SMTP: """This class manages a connection to an SMTP or ESMTP server. @@ -219,6 +198,7 @@ ehlo_msg = "ehlo" ehlo_resp = None does_esmtp = 0 + default_port = SMTP_PORT def __init__(self, host='', port=0, local_hostname=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT): @@ -234,7 +214,6 @@ """ self.timeout = timeout self.esmtp_features = {} - self.default_port = SMTP_PORT if host: (code, msg) = self.connect(host, port) if code != 220: @@ -613,8 +592,9 @@ if resp == 220: if not _have_ssl: raise RuntimeError("No SSL support included in this Python") - self.sock = ssl.wrap_socket(self.sock, keyfile, certfile) - self.file = SSLFakeFile(self.sock) + self._sock=self.sock + self.sock = ssl.wrap_socket(self._sock, keyfile, certfile) + self.file = self.sock.makefile('rb') # RFC 3207: # The client MUST discard any knowledge obtained from # the server, such as the list of SMTP service extensions, @@ -721,8 +701,13 @@ self.file.close() self.file = None if self.sock: + self.sock.shutdown(socket.SHUT_RDWR) self.sock.close() self.sock = None + if hasattr(self, '_sock') and self._sock: + self._sock.shutdown(socket.SHUT_RDWR) + self._sock.close() + self._sock = None def quit(self): @@ -741,19 +726,19 @@ are also optional - they can contain a PEM formatted private key and certificate chain file for the SSL connection. """ + default_port = SMTP_SSL_PORT + def __init__(self, host='', port=0, local_hostname=None, keyfile=None, certfile=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT): self.keyfile = keyfile self.certfile = certfile SMTP.__init__(self, host, port, local_hostname, timeout) - self.default_port = SMTP_SSL_PORT def _get_socket(self, host, port, timeout): if self.debuglevel > 0: print>>stderr, 'connect:', (host, port) - self.sock = socket.create_connection((host, port), timeout) - self.sock = ssl.wrap_socket(self.sock, self.keyfile, self.certfile) - self.file = SSLFakeFile(self.sock) + self._sock = socket.create_connection((host, port), timeout) + return ssl.wrap_socket(self._sock, self.keyfile, self.certfile) __all__.append("SMTP_SSL") @@ -776,8 +761,9 @@ authentication, but your mileage might vary.""" ehlo_msg = "lhlo" + default_port = LMTP_PORT - def __init__(self, host = '', port = LMTP_PORT, local_hostname = None): + def __init__(self, host = '', port = 0, local_hostname = None): """Initialize a new instance.""" SMTP.__init__(self, host, port, local_hostname)