diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2007-03-09 15:35:55 +0000 |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2007-03-09 15:35:55 +0000 |
commit | 1190a38d336ad65f505b00b9057e0f136f777115 (patch) | |
tree | 011dcb63aa49369edf5db8ea1f51e43d16e8dabf /Lib/smtplib.py | |
parent | fd61107e7a24af2cc25a3a7abbdb82656fbe9335 (diff) | |
download | cpython-git-1190a38d336ad65f505b00b9057e0f136f777115.tar.gz |
Patch #957003: Implement smtplib.LMTP.
Diffstat (limited to 'Lib/smtplib.py')
-rwxr-xr-x | Lib/smtplib.py | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/Lib/smtplib.py b/Lib/smtplib.py index a5c82a8523..5f70b10ddd 100755 --- a/Lib/smtplib.py +++ b/Lib/smtplib.py @@ -226,6 +226,7 @@ class SMTP: debuglevel = 0 file = None helo_resp = None + ehlo_msg = "ehlo" ehlo_resp = None does_esmtp = 0 @@ -401,7 +402,7 @@ class SMTP: host. """ self.esmtp_features = {} - self.putcmd("ehlo", name or self.local_hostname) + self.putcmd(self.ehlo_msg, name or self.local_hostname) (code,msg)=self.getreply() # According to RFC1869 some (badly written) # MTA's will disconnect on an ehlo. Toss an exception if @@ -746,6 +747,50 @@ class SMTP_SSL(SMTP): self.sock = SSLFakeSocket(self.sock, sslobj) self.file = SSLFakeFile(sslobj) +# +# LMTP extension +# +LMTP_PORT = 2003 + +class LMTP(SMTP): + """LMTP - Local Mail Transfer Protocol + + The LMTP protocol, which is very similar to ESMTP, is heavily based + on the standard SMTP client. It's common to use Unix sockets for LMTP, + so our connect() method must support that as well as a regular + host:port server. To specify a Unix socket, you must use an absolute + path as the host, starting with a '/'. + + Authentication is supported, using the regular SMTP mechanism. When + using a Unix socket, LMTP generally don't support or require any + authentication, but your mileage might vary.""" + + ehlo_msg = "lhlo" + + def __init__(self, host = '', port = LMTP_PORT, local_hostname = None): + """Initialize a new instance.""" + SMTP.__init__(self, host, port, local_hostname) + + def connect(self, host='localhost', port = 0): + """Connect to the LMTP daemon, on either a Unix or a TCP socket.""" + if host[0] == '/': + try: + self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) + self.sock.connect(host) + except socket.error, msg: + if self.debuglevel > 0: print 'connect fail:', host + if self.sock: + self.sock.close() + self.sock = None + if not self.sock: + raise socket.error, msg + (code, msg) = self.getreply() + if self.debuglevel > 0: print "connect:", msg + return (code, msg) + else: + return SMTP.connect(self, host, port) + + # Test the sendmail method, which tests most of the others. # Note: This always sends to localhost. if __name__ == '__main__': |