ldap imap refactored version 1