Ejemplo n.º 1
0
    def get_new_uids(self, crispin_client):
        try:
            remote_uidnext = crispin_client.conn.folder_status(
                self.folder_name, ['UIDNEXT']).get('UIDNEXT')
        except ValueError:
            # Work around issue where ValueError is raised on parsing STATUS
            # response.
            log.warning('Error getting UIDNEXT', exc_info=True)
            remote_uidnext = None
        except imaplib.IMAP4.error as e:
            if '[NONEXISTENT]' in e.message:
                raise FolderMissingError()
            else:
                raise e
        if remote_uidnext is not None and remote_uidnext == self.uidnext:
            return
        log.info('UIDNEXT changed, checking for new UIDs',
                 remote_uidnext=remote_uidnext,
                 saved_uidnext=self.uidnext)

        crispin_client.select_folder(self.folder_name, self.uidvalidity_cb)
        with session_scope(self.namespace_id) as db_session:
            lastseenuid = common.lastseenuid(self.account_id, db_session,
                                             self.folder_id)
        latest_uids = crispin_client.conn.fetch('{}:*'.format(lastseenuid + 1),
                                                ['UID']).keys()
        new_uids = set(latest_uids) - {lastseenuid}
        if new_uids:
            for uid in sorted(new_uids):
                self.download_and_commit_uids(crispin_client, [uid])
        self.uidnext = remote_uidnext
Ejemplo n.º 2
0
    def get_new_uids(self, crispin_client):
        try:
            remote_uidnext = crispin_client.conn.folder_status(
                self.folder_name, ["UIDNEXT"]).get(b"UIDNEXT")
        except ValueError:
            # Work around issue where ValueError is raised on parsing STATUS
            # response.
            log.warning("Error getting UIDNEXT", exc_info=True)
            remote_uidnext = None
        except imaplib.IMAP4.error as e:
            # TODO: match with CrispinClient.select_folder
            message = e.args[0] if e.args else ""
            if ("[NONEXISTENT]" in message or "does not exist" in message
                    or "doesn't exist" in message):
                raise FolderMissingError()
            else:
                raise e
        if remote_uidnext is not None and remote_uidnext == self.uidnext:
            return
        log.debug(
            "UIDNEXT changed, checking for new UIDs",
            remote_uidnext=remote_uidnext,
            saved_uidnext=self.uidnext,
        )

        crispin_client.select_folder(self.folder_name, self.uidvalidity_cb)
        with session_scope(self.namespace_id) as db_session:
            lastseenuid = common.lastseenuid(self.account_id, db_session,
                                             self.folder_id)
        latest_uids = crispin_client.conn.fetch("{}:*".format(lastseenuid + 1),
                                                ["UID"]).keys()
        new_uids = set(latest_uids) - {lastseenuid}
        if new_uids:
            for uid in sorted(new_uids):
                self.download_and_commit_uids(crispin_client, [uid])
        self.uidnext = remote_uidnext
Ejemplo n.º 3
0
def raise_folder_error(*args, **kwargs):
    raise FolderMissingError()