def METHOD_NAME(
    user: User, new_email: str, with_confirmation: bool
) -> None:
    if not is_valid_email(new_email):
        raise InvalidEmailException('valid email must be provided')
    if user.email == new_email:
        raise InvalidEmailException(
            'new email must be different than current email'
        )
    if with_confirmation:
        user.email_to_confirm = new_email
        user.confirmation_token = secrets.token_urlsafe(30)
    else:
        user.email = new_email