def quoteaddr(addr):
    """
    Turn an email address, possibly with realname part etc, into
    a form suitable for and SMTP envelope.
    """

    if isinstance(addr, Address):
        return b'<' + bytes(addr) + b'>'

    if isinstance(addr, bytes):
        addr = addr.decode('ascii')

    res = parseaddr(addr)

    if res == (None, None):
        # It didn't parse, use it as-is
        return  b'<' + bytes(addr) + b'>'
    else:
        return  b'<' + res[1].encode('ascii') + b'>'

    Turn an email address, possibly with realname part etc, into
    a form suitable for and SMTP envelope.
    
stackoverflow/venv/lib/python3.6/site-packages/twisted/mail/smtp.py