summaryrefslogtreecommitdiffstats
path: root/Lib/smtplib.py
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2011-07-19 01:38:54 (GMT)
committerR David Murray <rdmurray@bitdance.com>2011-07-19 01:38:54 (GMT)
commit4634676cec29def3c70cf84ba00e6d7586bbaab7 (patch)
tree40accb2a94ade7fbca47667ca5f48d8dfb74cded /Lib/smtplib.py
parentae4a78b0a8f1c280eee19018d7988063a34d1821 (diff)
downloadcpython-4634676cec29def3c70cf84ba00e6d7586bbaab7.zip
cpython-4634676cec29def3c70cf84ba00e6d7586bbaab7.tar.gz
cpython-4634676cec29def3c70cf84ba00e6d7586bbaab7.tar.bz2
#7484: no more <> around addresses in VRFY or EXPN
The RFC doesn't say that they are allowed; apparently many mailers accept them, but not postfix. Contributions to this patch were made by Felipe Cruz and Catalin Iacob. The changeset also adds additional indirect tests for quoteaddr (null address and IDNA-encoded address).
Diffstat (limited to 'Lib/smtplib.py')
-rw-r--r--Lib/smtplib.py11
1 files changed, 9 insertions, 2 deletions
diff --git a/Lib/smtplib.py b/Lib/smtplib.py
index 9080e4a..7b97a6a 100644
--- a/Lib/smtplib.py
+++ b/Lib/smtplib.py
@@ -152,6 +152,13 @@ def quoteaddr(addr):
else:
return "<%s>" % m
+def _addr_only(addrstring):
+ displayname, addr = email.utils.parseaddr(addrstring)
+ if (displayname, addr) == ('', ''):
+ # parseaddr couldn't parse it, so use it as is.
+ return addrstring
+ return addr
+
# Legacy method kept for backward compatibility.
def quotedata(data):
"""Quote data for email.
@@ -514,14 +521,14 @@ class SMTP:
def verify(self, address):
"""SMTP 'verify' command -- checks for address validity."""
- self.putcmd("vrfy", quoteaddr(address))
+ self.putcmd("vrfy", _addr_only(address))
return self.getreply()
# a.k.a.
vrfy = verify
def expn(self, address):
"""SMTP 'expn' command -- expands a mailing list."""
- self.putcmd("expn", quoteaddr(address))
+ self.putcmd("expn", _addr_only(address))
return self.getreply()
# some useful methods