summaryrefslogtreecommitdiffstats
path: root/Lib/smtplib.py
diff options
context:
space:
mode:
authorThomas Wouters <thomas@python.org>2000-08-15 19:30:36 (GMT)
committerThomas Wouters <thomas@python.org>2000-08-15 19:30:36 (GMT)
commitcaa658d04739875133f388d9dc470843e3870f87 (patch)
tree6ae5515668734f5e45c85f33aecfbcbe7a6062a3 /Lib/smtplib.py
parent56221a7cfa8f361f4310b63b74091766c50dd7f8 (diff)
downloadcpython-caa658d04739875133f388d9dc470843e3870f87.zip
cpython-caa658d04739875133f388d9dc470843e3870f87.tar.gz
cpython-caa658d04739875133f388d9dc470843e3870f87.tar.bz2
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 f898a2f..f00f30b 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