def quoteaddr(addr):
    m = (None, None)
    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
    elif m is None:
        # the sender wants an empty return address
        return "<>"
    else:
        return "<%s>" % m
Quote a subset of the email addresses defined by RFC 821.
dataset/ETHPy150Open deanhiller/databus/webapp/play1.3.x/python/Lib/smtplib.py/quoteaddr