'Read the next email from the email server.'

def read_next(self):

    import imaplib
    try:
        self.connection.select()
        if (not self._unread_ids):
            search = 'SINCE    {0:%d-%b-%Y}'.format(datetime.date.today())
            if (self._last_id is not None):
                search = 'UID    {}:*'.format(self._last_id)
            (_, data) = self.connection.uid('search', None, search)
            self._unread_ids = deque(data[0].split())
        while self._unread_ids:
            message_uid = self._unread_ids.popleft()
            if ((self._last_id is None) or (int(message_uid) > self._last_id)):
                self._last_id = int(message_uid)
                return self._fetch_message(message_uid)
    except imaplib.IMAP4.error:
        _LOGGER.info('Connection    to    %s    lost,    attempting    to    reconnect', self._server)
        try:
            self.connect()
        except imaplib.IMAP4.error:
            _LOGGER.error('Failed    to    reconnect')
