def do_change_user_delivery_email(user_profile: UserProfile, new_email: str) -> None:
    delete_user_profile_caches([user_profile])
    user_profile.delivery_email = new_email
    if user_profile.email_address_is_realm_public():
        user_profile.email = new_email
        user_profile.save(update_fields=['email', 'delivery_email'])
    else:
        user_profile.save(update_fields=['delivery_email'])
    payload = dict(user_id=user_profile.id, delivery_email=new_email)
    event = dict(type='realm_user', op='update', person=payload)
    send_event(user_profile.realm, event, [user_profile.id])
    if (user_profile.avatar_source == UserProfile.AVATAR_FROM_GRAVATAR):
        notify_avatar_url_change(user_profile)
    if user_profile.email_address_is_realm_public():
        send_user_email_update_event(user_profile)
    event_time = timezone_now()
    RealmAuditLog.objects.create(realm=user_profile.realm, acting_user=user_profile, modified_user=user_profile, event_type=RealmAuditLog.USER_EMAIL_CHANGED, event_time=event_time)
def do_change_user_delivery_email(user_profile: UserProfile, new_email: str) -> None:
    delete_user_profile_caches([user_profile])
    user_profile.delivery_email = new_email
    if user_profile.email_address_is_realm_public():
        user_profile.email = new_email
        user_profile.save(update_fields=['email', 'delivery_email'])
    else:
        user_profile.save(update_fields=['delivery_email'])
    payload = dict(user_id=user_profile.id, delivery_email=new_email)
    event = dict(type='realm_user', op='update', person=payload)
    send_event(user_profile.realm, event, [user_profile.id])
    if (user_profile.avatar_source == UserProfile.AVATAR_FROM_GRAVATAR):
        notify_avatar_url_change(user_profile)
    if user_profile.email_address_is_realm_public():
        send_user_email_update_event(user_profile)
    event_time = timezone_now()
    RealmAuditLog.objects.create(realm=user_profile.realm, acting_user=user_profile, modified_user=user_profile, event_type=RealmAuditLog.USER_EMAIL_CHANGED, event_time=event_time)