def next(self): if self._current >= len(self._queue): self._feed_queue() res = self._queue[self._current] LOGGER.debug('Parsing mail...') try: self._parser = MailReaderFactory.get_reader_for_mail(res) self._current = self._current + 1 except Exception as ex: LOGGER.error('Error while parsing mail #%s', self._uids[self._current]) LOGGER.error('Unable to determine source of this mail (raw content follows): %s', ex) LOGGER.error('Retrieved email:\n%s', res) LOGGER.debug('-- Recovery mode --') # Add this uid to the failed list so don't retry to parse this mail anymore self._failed_uids.append(self._uids[self._current]) # Remove uid from the list so this email won't be deleted. self._uids.remove(self._uids[self._current]) # Remove mail from the queue self._queue.remove(res) LOGGER.debug('Ok. Now, try to fetch another mail...') # Try to fetch next mail one more time... return self.next() return res
def __init__(self, mail): self._parser = MailReaderFactory.get_reader_for_mail(mail)