def extract_and_validate(email):
    try:
        stream_name, token = decode_email_address(email)
    except (__HOLE__, ValueError):
        raise ZulipEmailForwardError("Malformed email recipient " + email)

    if not valid_stream(stream_name, token):
        raise ZulipEmailForwardError("Bad stream token from email recipient " + email)

    return Stream.objects.get(email_token=token)
dataset/ETHPy150Open zulip/zulip/zerver/lib/email_mirror.py/extract_and_validate