示例#1
0
def release_message(messageid, date, from_addr, to_addr, msgfiles):
    "Release message"
    logger = release_message.get_logger()
    msgfile, isdir = search_quarantine(date, messageid, msgfiles)
    if not msgfile:
        return dict(success=False, error="Message not found")

    processor = PQM(msgfile, isdir, debug=asbool(config["debug"]))
    if processor.release(from_addr, to_addr):
        logger.info("Message: %(id)s released to: %(addrs)s", dict(id=messageid, addrs=",".join(to_addr)))
        retdict = dict(success=True, error="")
    else:
        logger.info("Message: %(id)s release failed", dict(id=messageid))
        retdict = dict(success=False, error=" ".join(processor.errors))
        processor.reset_errors()
    return retdict
示例#2
0
def release_message(messageid, date, from_addr, to_addr, msgfiles):
    "Release message"
    logger = release_message.get_logger()
    msgfile, isdir = search_quarantine(date, messageid, msgfiles)
    if not msgfile:
        return dict(success=False, error='Message not found')

    processor = PQM(msgfile, isdir, debug=asbool(config['debug']))
    if processor.release(from_addr, to_addr):
        logger.info("Message: %(id)s released to: %(addrs)s",
                    dict(id=messageid, addrs=','.join(to_addr)))
        retdict = dict(success=True, error='')
    else:
        logger.info("Message: %(id)s release failed", dict(id=messageid))
        retdict = dict(success=False, error=' '.join(processor.errors))
        processor.reset_errors()
    return retdict
示例#3
0
def process_message(job, logger):
    "Process a quarantined message"
    result = dict(message_id=job['message_id'],
                  mid=job['mid'],
                  date=job['date'],
                  from_address=job['from_address'],
                  to_address=job['to_address'],
                  release=None,
                  learn=None,
                  delete=None,
                  errors=[])
    try:
        msgfile, isdir = search_quarantine(job['date'], job['message_id'])
        if not msgfile:
            raise OSError('Message not found')
        processor = PQM(msgfile, isdir, debug=asbool(config['debug']))
        if job['release']:
            if job['from_address']:
                if job['use_alt']:
                    to_addrs = job['altrecipients'].split(',')
                else:
                    to_addrs = job['to_address'].split(',')
                #result['to_address'] = to_addrs
                result['release'] = processor.release(job['from_address'],
                                                      to_addrs)
                if not result['release']:
                    error = ' '.join(processor.errors)
                    result['errors'].append(('release', error))
                    processor.reset_errors()
                else:
                    logger.info(
                        "Message: %(msgid)s released to: %(to)s",
                        dict(msgid=job['message_id'], to=', '.join(to_addrs)))
            else:
                result['release'] = False
                error = 'The sender address is empty'
                result['errors'].append(('release', error))
                logger.info(
                    "Message: %(msgid)s release failed with "
                    "error: %(error)s",
                    dict(msgid=job['message_id'], error=error))
        if job['learn']:
            result['learn'] = processor.learn(job['salearn_as'])
            if not result['learn']:
                error = ' '.join(processor.errors)
                result['errors'].append(('learn', error))
                processor.reset_errors()
                logger.info(
                    "Message: %(msgid)s learning failed with "
                    "error: %(error)s",
                    dict(msgid=job['message_id'], error=error))
            else:
                logger.info(
                    "Message: %(msgid)s learnt as %(learn)s",
                    dict(msgid=job['message_id'], learn=job['salearn_as']))
        if job['todelete']:
            result['delete'] = processor.delete()
            if not result['delete']:
                error = ' '.join(processor.errors)
                result['errors'].append(('delete', error))
                processor.reset_errors()
                logger.info(
                    "Message: %(msgid)s deleting failed with "
                    "error: %(error)s",
                    dict(msgid=job['message_id'], error=error))
            else:
                logger.info("Message: %(msgid)s deleted from quarantine",
                            dict(msgid=job['message_id']))
                sql = Message.__table__\
                            .update()\
                            .where(Message.messageid == job['message_id'])\
                            .values(isquarantined=0)
                Session.bind.execute(sql)
                # Session.close()
        return result
    except OSError, exception:
        for action in ['release', 'learn', 'todelete']:
            if job[action]:
                if action == 'todelete':
                    action = 'delete'
                result[action] = False
                result['errors'].append((action, str(exception)))
                logger.info(
                    "Message: %(msgid)s %(task)s failed with "
                    "error: %(error)s",
                    dict(msgid=job['message_id'],
                         task=task,
                         error=str(exception)))
        return result
示例#4
0
文件: messages.py 项目: aureg/baruwa2
def process_message(job, logger):
    "Process a quarantined message"
    result = dict(message_id=job['message_id'],
                    mid=job['mid'],
                    date=job['date'],
                    from_address=job['from_address'],
                    to_address=job['to_address'],
                    release=None,
                    learn=None,
                    delete=None,
                    errors=[])
    try:
        msgfile, isdir = search_quarantine(job['date'], job['message_id'])
        if not msgfile:
            raise OSError('Message not found')
        processor = PQM(msgfile, isdir, debug=asbool(config['debug']))
        if job['release']:
            if job['from_address']:
                if job['use_alt']:
                    to_addrs = job['altrecipients'].split(',')
                else:
                    to_addrs = job['to_address'].split(',')
                #result['to_address'] = to_addrs
                result['release'] = processor.release(job['from_address'],
                                                                to_addrs)
                if not result['release']:
                    error = ' '.join(processor.errors)
                    result['errors'].append(('release', error))
                    processor.reset_errors()
                else:
                    logger.info("Message: %(msgid)s released to: %(to)s",
                                dict(msgid=job['message_id'],
                                to=', '.join(to_addrs)))
            else:
                result['release'] = False
                error = 'The sender address is empty'
                result['errors'].append(('release', error))
                logger.info("Message: %(msgid)s release failed with "
                            "error: %(error)s", dict(msgid=job['message_id'],
                            error=error))
        if job['learn']:
            result['learn'] = processor.learn(job['salearn_as'])
            if not result['learn']:
                error = ' '.join(processor.errors)
                result['errors'].append(('learn', error))
                processor.reset_errors()
                logger.info("Message: %(msgid)s learning failed with "
                            "error: %(error)s", dict(msgid=job['message_id'],
                            error=error))
            else:
                logger.info("Message: %(msgid)s learnt as %(learn)s",
                            dict(msgid=job['message_id'],
                            learn=job['salearn_as']))
        if job['todelete']:
            result['delete'] = processor.delete()
            if not result['delete']:
                error = ' '.join(processor.errors)
                result['errors'].append(('delete', error))
                processor.reset_errors()
                logger.info("Message: %(msgid)s deleting failed with "
                            "error: %(error)s", dict(msgid=job['message_id'],
                            error=error))
            else:
                logger.info("Message: %(msgid)s deleted from quarantine",
                dict(msgid=job['message_id']))
                sql = Message.__table__\
                            .update()\
                            .where(Message.messageid == job['message_id'])\
                            .values(isquarantined=0)
                Session.bind.execute(sql)
                # Session.close()
        return result
    except OSError, exception:
        for action in ['release', 'learn', 'todelete']:
            if job[action]:
                if action == 'todelete':
                    action = 'delete'
                result[action] = False
                result['errors'].append((action, str(exception)))
                logger.info("Message: %(msgid)s %(task)s failed with "
                            "error: %(error)s", dict(msgid=job['message_id'],
                            task=task, error=str(exception)))
        return result