summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorPeter Schneider-Kamp <nowonder@nowonder.de>2000-08-10 14:02:23 (GMT)
committerPeter Schneider-Kamp <nowonder@nowonder.de>2000-08-10 14:02:23 (GMT)
commit7bc82bb1f0ce5c841382587839c218b6cc63e1ff (patch)
treeca6da4b4bc429215b87d4618a22bbd7d9c6c3e8e /Lib
parent10e1bf2f64b77f3a71157c72de19265870cdeb5f (diff)
downloadcpython-7bc82bb1f0ce5c841382587839c218b6cc63e1ff.zip
cpython-7bc82bb1f0ce5c841382587839c218b6cc63e1ff.tar.gz
cpython-7bc82bb1f0ce5c841382587839c218b6cc63e1ff.tar.bz2
add better algorithm to get fully qualified domain name for localhost
in smtplib.ehlo() and smtplib.helo(). closes patch #101103 closes bug #110935
Diffstat (limited to 'Lib')
-rwxr-xr-xLib/smtplib.py38
1 files changed, 21 insertions, 17 deletions
diff --git a/Lib/smtplib.py b/Lib/smtplib.py
index e5f0b03..f898a2f 100755
--- a/Lib/smtplib.py
+++ b/Lib/smtplib.py
@@ -98,7 +98,6 @@ class SMTPRecipientsRefused(SMTPException):
self.args = ( recipients,)
-
class SMTPDataError(SMTPResponseException):
"""The SMTP server didn't accept the data."""
@@ -108,6 +107,7 @@ class SMTPConnectError(SMTPResponseException):
class SMTPHeloError(SMTPResponseException):
"""The server refused our HELO reply."""
+
def quoteaddr(addr):
"""Quote a subset of the email addresses defined by RFC 821.
@@ -133,6 +133,24 @@ def quotedata(data):
return re.sub(r'(?m)^\.', '..',
re.sub(r'(?:\r\n|\n|\r(?!\n))', CRLF, data))
+def _get_fqdn_hostname(name):
+ name = string.strip(name)
+ if len(name) == 0:
+ name = socket.gethostname()
+ 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:
+ name = hostname
+ return name
+
+
class SMTP:
"""This class manages a connection to an SMTP or ESMTP server.
SMTP Objects:
@@ -288,14 +306,7 @@ class SMTP:
Hostname to send for this command defaults to the FQDN of the local
host.
"""
- name=string.strip(name)
- if len(name)==0:
- name = socket.gethostname()
- try:
- name = socket.gethostbyaddr(name)[0]
- except socket.error:
- pass
- self.putcmd("helo",name)
+ self.putcmd("helo", _get_fqdn_hostname(name))
(code,msg)=self.getreply()
self.helo_resp=msg
return (code,msg)
@@ -305,14 +316,7 @@ class SMTP:
Hostname to send for this command defaults to the FQDN of the local
host.
"""
- name=string.strip(name)
- if len(name)==0:
- name = socket.gethostname()
- try:
- name = socket.gethostbyaddr(name)[0]
- except socket.error:
- pass
- self.putcmd("ehlo",name)
+ self.putcmd("ehlo", _get_fqdn_hostname(name))
(code,msg)=self.getreply()
# According to RFC1869 some (badly written)
# MTA's will disconnect on an ehlo. Toss an exception if