summaryrefslogtreecommitdiff
path: root/Lib/smtplib.py
diff options
context:
space:
mode:
authorThomas Wouters <thomas@python.org>2000-08-15 19:30:36 +0000
committerThomas Wouters <thomas@python.org>2000-08-15 19:30:36 +0000
commitd29aa30ff9cf0e1485f3d0e32801cb1b3f9c71ce (patch)
treec38ad5bd90a411c30fea52e0ab96a03d838c1a12 /Lib/smtplib.py
parent8abba5dd03a31dc7f6382783c1baa32d1cd9e00a (diff)
downloadcpython-d29aa30ff9cf0e1485f3d0e32801cb1b3f9c71ce.tar.gz
Apply SF patch #101151, by Peter S-K, which fixes smtplib's passing of the
'helo' and 'ehlo' message, and exports the 'make_fqdn' function. This function should be moved to socket.py, if that module ever gets a Python wrapper.
Diffstat (limited to 'Lib/smtplib.py')
-rwxr-xr-xLib/smtplib.py40
1 files changed, 27 insertions, 13 deletions
diff --git a/Lib/smtplib.py b/Lib/smtplib.py
index f898a2fe1e..f00f30ba41 100755
--- a/Lib/smtplib.py
+++ b/Lib/smtplib.py
@@ -133,21 +133,29 @@ def quotedata(data):
return re.sub(r'(?m)^\.', '..',
re.sub(r'(?:\r\n|\n|\r(?!\n))', CRLF, data))
-def _get_fqdn_hostname(name):
+def make_fqdn(name = ''):
+ """Get fully qualified domain name from name.
+
+ An empty argument is interpreted as meaning the local host.
+
+ First the hostname returned by socket.gethostbyaddr()
+ is checked, then possibly existing aliases. In case
+ no FQDN is available, hostname is returned.
+ """
name = string.strip(name)
if len(name) == 0:
name = socket.gethostname()
- try:
- hostname, aliases, ipaddrs = socket.gethostbyaddr(name)
- except socket.error:
- pass
+ try:
+ hostname, aliases, ipaddrs = socket.gethostbyaddr(name)
+ except socket.error:
+ pass
+ else:
+ aliases.insert(0, hostname)
+ for name in aliases:
+ if '.' in name:
+ break
else:
- aliases.insert(0, hostname)
- for name in aliases:
- if '.' in name:
- break
- else:
- name = hostname
+ name = hostname
return name
@@ -306,7 +314,10 @@ class SMTP:
Hostname to send for this command defaults to the FQDN of the local
host.
"""
- self.putcmd("helo", _get_fqdn_hostname(name))
+ if name:
+ self.putcmd("helo", name)
+ else:
+ self.putcmd("helo", make_fqdn())
(code,msg)=self.getreply()
self.helo_resp=msg
return (code,msg)
@@ -316,7 +327,10 @@ class SMTP:
Hostname to send for this command defaults to the FQDN of the local
host.
"""
- self.putcmd("ehlo", _get_fqdn_hostname(name))
+ if name:
+ self.putcmd("ehlo", name)
+ else:
+ self.putcmd("ehlo", make_fqdn())
(code,msg)=self.getreply()
# According to RFC1869 some (badly written)
# MTA's will disconnect on an ehlo. Toss an exception if