Thanks for thinking about this meticulously. I think user_get_id_by_email() doesn't consider LDAP users, so we may have to handle this in a new function. Will do it and modify my commits.