diff -r c9e9142d82d6 Lib/smtplib.py --- a/Lib/smtplib.py Mon Apr 11 08:43:52 2011 +0100 +++ b/Lib/smtplib.py Tue Apr 12 12:17:14 2011 -0300 @@ -132,24 +132,31 @@ combination provided. """ -def quoteaddr(addr): +def quoteaddr(addr, clean=False): """Quote a subset of the email addresses defined by RFC 821. - Should be able to handle anything email.utils.parseaddr can handle. + Should be able to handle anything rfc822.parseaddr can handle. + + The default return format is "", when clean + is True, the format is "some@email.org" """ m = (None, None) try: m = email.utils.parseaddr(addr)[1] except AttributeError: pass + if clean: + fmt = "%s" + else: + fmt = "<%s>" if m == (None, None): # Indicates parse failure or AttributeError # something weird here.. punt -ddm - return "<%s>" % addr + return fmt % addr elif m is None: # the sender wants an empty return address - return "<>" + return fmt % "" else: - return "<%s>" % m + return fmt % m # Legacy method kept for backward compatibility. def quotedata(data): @@ -526,7 +533,7 @@ def verify(self, address): """SMTP 'verify' command -- checks for address validity.""" - self.putcmd("vrfy", quoteaddr(address)) + self.putcmd("vrfy", quoteaddr(address, clean=True)) return self.getreply() # a.k.a. vrfy = verify diff -r c9e9142d82d6 Lib/test/test_smtplib.py --- a/Lib/test/test_smtplib.py Mon Apr 11 08:43:52 2011 +0100 +++ b/Lib/test/test_smtplib.py Tue Apr 12 12:17:14 2011 -0300 @@ -583,7 +583,7 @@ u = 'nobody@nowhere.com' expected_unknown = (550, ('No such user: %s' - % smtplib.quoteaddr(u)).encode('ascii')) + % smtplib.quoteaddr(u, clean=True)).encode('ascii')) self.assertEqual(smtp.vrfy(u), expected_unknown) smtp.quit()