'Login and return an IMAP connection.'

def _login(self):

    import imaplib
    try:
        connection = imaplib.IMAP4_SSL(self._server, self._port)
        connection.login(self._user, self._password)
        return connection
    except imaplib.IMAP4.error:
        _LOGGER.error('Failed    to    login    to    %s.', self._server)
        return False
