Index: Lib/smtplib.py =================================================================== --- Lib/smtplib.py (revision 77056) +++ Lib/smtplib.py (working copy) @@ -128,24 +128,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) + if clean: + fmt = "%s" + else: + fmt = "<%s>" try: m = email.utils.parseaddr(addr)[1] except AttributeError: pass if m == (None, None): # Indicates parse failure or AttributeError - # something weird here.. punt -ddm - return "<%s>" % addr + # something weird here.. punt -ddmg + return fmt % addr elif m is None: # the sender wants an empty return address - return "<>" + return fmt % '' else: - return "<%s>" % m + return fmt % m def quotedata(data): """Quote data for email. @@ -488,7 +495,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 Index: Lib/test/test_smtplib.py =================================================================== --- Lib/test/test_smtplib.py (revision 77056) +++ Lib/test/test_smtplib.py (working copy) @@ -447,7 +447,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()