'Connect to IMAP'

def connect_imap(self):

    try:
        if cint(self.settings.use_ssl):
            self.imap = Timed_IMAP4_SSL(self.settings.host, timeout=frappe.conf.get(u'pop_timeout'))
        else:
            self.imap = Timed_IMAP4(self.settings.host, timeout=frappe.conf.get(u'pop_timeout'))
        self.imap.login(self.settings.username, self.settings.password)
        return True
    except _socket.error:
        frappe.msgprint(_(u'Invalid    Mail    Server.    Please    rectify    and    try    again.'))
        raise
    except Exception as e:
        frappe.msgprint(_(u'Cannot    connect:    {0}').format(str(e)))
        raise
