]> granicus.if.org Git - python/commitdiff
#7484: no more <> around addresses in VRFY or EXPN
authorR David Murray <rdmurray@bitdance.com>
Tue, 19 Jul 2011 01:34:04 +0000 (21:34 -0400)
committerR David Murray <rdmurray@bitdance.com>
Tue, 19 Jul 2011 01:34:04 +0000 (21:34 -0400)
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.

Lib/smtplib.py
Lib/test/test_smtplib.py
Misc/NEWS

index e3ffb37be37a777dfc19d3e7fa4903fcca219f19..f9576367f09caca2019134555ee19c3324ce90cf 100755 (executable)
@@ -149,6 +149,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
+
 def quotedata(data):
     """Quote data for email.
 
@@ -497,14 +504,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
index 42a10bee1d53da807cdaf8953e212e9f501c8798..81806c9898d530fb21e36ebb4b4ad69bd815d971 100644 (file)
@@ -330,15 +330,14 @@ class SimSMTPChannel(smtpd.SMTPChannel):
         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 @@ class SMTPSimTests(unittest.TestCase):
             self.assertEqual(smtp.vrfy(email), expected_known)
 
         u = 'nobody@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()
 
index 2ec44d9a6a71342787db721ab9dbcc52c09d9c1c..88d706c1c9fb2944d568deb6efaed763e7fd708b 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -33,6 +33,9 @@ Core and Builtins
 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.