Commit caa658d0 authored by Thomas Wouters's avatar Thomas Wouters

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.
parent 56221a7c
......@@ -136,6 +136,8 @@ and \var{ipaddrlist} is a list of IP addresses for the same interface
on the same host (most likely containing only a single address).
To find the fully qualified domain name, check \var{hostname} and the
items of \var{aliaslist} for an entry containing at least one period.
An implementation of this algorithm can be found in the module
\module{smtplib} in form of the \function{make_fqdn()} function.
\end{funcdesc}
\begin{funcdesc}{getprotobyname}{protocolname}
......
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment