예제 #1
0
    def handle_folder(self, cr, uid, ids, connection, folder, context=None):
        '''Return ids of objects matched'''

        matched_object_ids = []

        for this in self.browse(cr, uid, ids, context=context):
            logger.info('start checking for emails in %s server %s',
                        folder.path, this.name)

            match_algorithm = folder.get_algorithm()

            if connection.select(folder.path)[0] != 'OK':
                logger.error(
                    'Could not open mailbox %s on %s' % (
                    folder.path, this.server))
                connection.select()
                continue
            result, msgids = this.get_msgids(connection)
            if result != 'OK':
                logger.error(
                    'Could not search mailbox %s on %s' % (
                    folder.path, this.server))
                continue

            for msgid in msgids[0].split():
                matched_object_ids += this.apply_matching(
                        connection, folder, msgid, match_algorithm)

            logger.info('finished checking for emails in %s server %s',
                        folder.path, this.name)

        return matched_object_ids
예제 #2
0
    def apply_matching(self,
                       cr,
                       uid,
                       ids,
                       connection,
                       folder,
                       msgid,
                       match_algorithm,
                       context=None):
        '''Return ids of objects matched'''

        matched_object_ids = []

        for this in self.browse(cr, uid, ids, context=context):
            result, msgdata = connection.fetch(msgid, '(RFC822)')

            if result != 'OK':
                logger.error('Could not fetch %s in %s on %s', msgid,
                             folder.path, this.server)
                continue

            mail_message = self.pool.get('mail.thread').message_parse(
                cr,
                uid,
                msgdata[0][1],
                save_original=this.original,
                context=context)

            if self.pool.get('mail.message').search(
                    cr, uid,
                [('message_id', '=', mail_message['message_id'])]):
                continue

            found_ids = match_algorithm.search_matches(cr, uid, folder,
                                                       mail_message,
                                                       msgdata[0][1])

            if found_ids and (len(found_ids) == 1 or folder.match_first):
                try:
                    cr.execute('savepoint apply_matching')
                    match_algorithm.handle_match(cr, uid, connection,
                                                 found_ids[0], folder,
                                                 mail_message, msgdata[0][1],
                                                 msgid, context)
                    cr.execute('release savepoint apply_matching')
                    matched_object_ids += found_ids[:1]
                except Exception:
                    cr.execute('rollback to savepoint apply_matching')
                    logger.exception("Failed to fetch mail %s from %s", msgid,
                                     this.name)
            elif folder.flag_nonmatching:
                connection.store(msgid, '+FLAGS', '\\FLAGGED')

        return matched_object_ids
예제 #3
0
    def apply_matching(self, cr, uid, ids, connection, folder, msgid,
                       match_algorithm, context=None):
        '''Return ids of objects matched'''

        matched_object_ids = []

        for this in self.browse(cr, uid, ids, context=context):
            result, msgdata = connection.fetch(msgid, '(RFC822)')

            if result != 'OK':
                logger.error(
                    'Could not fetch %s in %s on %s' % (msgid, folder.path, this.server))
                continue

            mail_message = self.pool.get('mail.thread').message_parse(
                cr, uid, msgdata[0][1], save_original=this.original,
                context=context)

            if self.pool.get('mail.message').search(
                cr, uid, [
                    ('message_id', '=', mail_message['message_id'])]):
                continue

            found_ids = match_algorithm.search_matches(
                cr, uid, folder,
                mail_message, msgdata[0][1])

            if found_ids and (len(found_ids) == 1 or
                              folder.match_first):
                try:
                    cr.execute('savepoint apply_matching')
                    match_algorithm.handle_match(
                        cr, uid, connection,
                        found_ids[0], folder, mail_message,
                        msgdata[0][1], msgid, context)
                    cr.execute('release savepoint apply_matching')
                    matched_object_ids += found_ids[:1]
                except Exception:
                    cr.execute('rollback to savepoint apply_matching')
                    logger.exception(
                        "Failed to fetch mail %s from %s",
                        msgid, this.name)
            elif folder.flag_nonmatching:
                connection.store(msgid, '+FLAGS', '\\FLAGGED')

        return matched_object_ids