[Python-checkins] cpython (2.7): #7484: no more <> around addresses in VRFY or EXPN

r.david.murray python-checkins at python.org
Tue Jul 19 03:43:50 CEST 2011


http://hg.python.org/cpython/rev/c4d884d5d86c
changeset:   71417:c4d884d5d86c
branch:      2.7
user:        R David Murray <rdmurray at bitdance.com>
date:        Mon Jul 18 21:34:04 2011 -0400
summary:
  #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.

files:
  Lib/smtplib.py           |  11 +++++++++--
  Lib/test/test_smtplib.py |  11 +++++------
  Misc/NEWS                |   3 +++
  3 files changed, 17 insertions(+), 8 deletions(-)


diff --git a/Lib/smtplib.py b/Lib/smtplib.py
--- a/Lib/smtplib.py
+++ b/Lib/smtplib.py
@@ -149,6 +149,13 @@
     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
+
 def quotedata(data):
     """Quote data for email.
 
@@ -497,14 +504,14 @@
 
     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
diff --git a/Lib/test/test_smtplib.py b/Lib/test/test_smtplib.py
--- a/Lib/test/test_smtplib.py
+++ b/Lib/test/test_smtplib.py
@@ -330,15 +330,14 @@
         self.push(resp)
 
     def smtp_VRFY(self, arg):
-        raw_addr = email.utils.parseaddr(arg)[1]
-        quoted_addr = smtplib.quoteaddr(arg)
-        if raw_addr in sim_users:
-            self.push('250 %s %s' % (sim_users[raw_addr], quoted_addr))
+        # For max compatibility smtplib should be sending the raw address.
+        if arg in sim_users:
+            self.push('250 %s %s' % (sim_users[arg], smtplib.quoteaddr(arg)))
         else:
             self.push('550 No such user: %s' % arg)
 
     def smtp_EXPN(self, arg):
-        list_name = email.utils.parseaddr(arg)[1].lower()
+        list_name = arg.lower()
         if list_name in sim_lists:
             user_list = sim_lists[list_name]
             for n, user_email in enumerate(user_list):
@@ -454,7 +453,7 @@
             self.assertEqual(smtp.vrfy(email), expected_known)
 
         u = 'nobody at nowhere.com'
-        expected_unknown = (550, 'No such user: %s' % smtplib.quoteaddr(u))
+        expected_unknown = (550, 'No such user: %s' % u)
         self.assertEqual(smtp.vrfy(u), expected_unknown)
         smtp.quit()
 
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -33,6 +33,9 @@
 Library
 -------
 
+- Issue #7484: smtplib no longer puts <> around addresses in VRFY and EXPN
+  commands; they aren't required and in fact postfix doesn't support that form.
+
 - Issue #11603: Fix a crash when __str__ is rebound as __repr__.  Patch by
   Andreas Stührk.
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list