示例#1
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"], job["msgfiles"])
        if not msgfile:
            raise OSError("Message not found")
        processor = PQM(msgfile, isdir, debug=asbool(config["debug"]))
        if job["release"]:
            # Mem zapping protection
            check_mem(job, logger)
            release(processor, job, result, logger)
        if job["learn"]:
            # Mem zapping protection
            check_mem(job, logger)
            learn(processor, job, result, logger)
        if job["todelete"]:
            delete(processor, job, result, logger)
        return result
    except OSError, exception:
        process_exception(exception, result, job, logger)
        return result
示例#2
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'],
                                            job['msgfiles'])
        if not msgfile:
            raise OSError('Message not found')
        processor = PQM(msgfile, isdir, debug=asbool(config['debug']))
        if job['release']:
            # Mem zapping protection
            check_mem(job, logger)
            release(processor, job, result, logger)
        if job['learn']:
            # Mem zapping protection
            check_mem(job, logger)
            learn(processor, job, result, logger)
        if job['todelete']:
            delete(processor, job, result, logger)
        return result
    except OSError, exception:
        process_exception(exception, result, job, logger)
        return result
示例#3
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
示例#4
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
示例#5
0
def preview_msg(messageid, date, msgfiles, attachid=None, imgid=None, allowimgs=None):
    "Preview message"
    logger = preview_msg.get_logger()
    try:
        msgfile, _ = search_quarantine(date, messageid, msgfiles)
        previewer = PreviewMessage(msgfile)

        if attachid:
            logger.info(
                "Download attachment: %(attachid)s of " "message: %(id)s", dict(id=messageid, attachid=attachid)
            )
            return previewer.attachment(attachid)
        if imgid:
            logger.info("Image access: %(img)s", dict(img=imgid))
            return previewer.img(imgid)
        logger.info("Preview of message: %(id)s", dict(id=messageid))
        return previewer.preview()
    except IOError, error:
        logger.info("Accessing message: %(id)s, Failed: %(error)s", dict(id=messageid, error=error))
        return {}
示例#6
0
def preview_msg(messageid, date, attachid=None, imgid=None, allowimgs=None):
    "Preview message"
    logger = preview_msg.get_logger()
    try:
        msgfile, isdir = search_quarantine(date, messageid)
        previewer = PreviewMessage(msgfile)

        if attachid:
            logger.info(
                "Download attachment: %(attachid)s of "
                "message: %(id)s", dict(id=messageid, attachid=attachid))
            return previewer.attachment(attachid)
        if imgid:
            logger.info("Image access: %(img)s", dict(img=imgid))
            return previewer.img(imgid)
        logger.info("Preview of message: %(id)s", dict(id=messageid))
        return previewer.preview()
    except TypeError, error:
        logger.info("Accessing message: %(id)s, Failed: %(error)s",
                    dict(id=messageid, error=error))
        return {}
示例#7
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
示例#8
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