示例#1
0
def signal_handle(mode):
    outinfo(u"catch signal: %s" % mode)
    global signal_stop
    signal_stop = True

def init_queue_and_pidfile():
    global MAIL_INCHECK_QUEUE, incheck_pid_file
    if len(sys.argv) > 1:
       MAIL_INCHECK_QUEUE = sys.argv[1]
       incheck_pid_file = MAIL_INCHECK_QUEUE + '.pid'


if __name__ == "__main__":
    globals()['_DEBUG'] = common.check_debug()
    init_queue_and_pidfile()
    common.init_cfg_default()
    common.init_run_user(common.cfgDefault.get('global', 'user'))
    common.init_makedir()
    common.init_pid_file(incheck_pid_file)
    common.init_logger(MAIL_INCHECK_QUEUE, len(sys.argv) > 2, _DEBUG)
    clamav_sock = common.cfgDefault.get('clamav', 'sock')
    review_help_mode = common.cfgDefault.get('review_help', 'mode')
    init_resource()
    gevent.spawn(init_resource_routine)

    # 运行程序
    EXIT_CODE = 0
    outinfo(u"program start")
    try:
        # 设置监听信号量
        common.gevent_signal_init(signal_handle)
示例#2
0
        with open(os.path.join(rcpts_path, filename), 'wb') as f:
            f.write("\n".join(rcpttos))

        with open(os.path.join(mails_path, filename), 'wb') as f:
            f.write(data)
        log.info(
            'received %s mail: pid=%s, uid=%s, mail_from=%s, ok_rcpts=%s, body_len=%s, mail_id=%s, client_ip=%s'
            % (type, os.getpid(), uid, mailfrom, rcpttos, len(data), mail_id,
               client_ip))


if __name__ == '__main__':
    globals()['_DEBUG'] = Common.check_debug()
    #Common.init_makedir()
    Common.init_pid_file('bs_esmtpd.pid')
    Common.init_cfg_default()
    # Common.init_logger('Esmtpd', len(sys.argv) > 1, _DEBUG, user=Common.cfgDefault.get('global', 'user'))
    Common.signal_init(kill_children)

    # redis_db = get_redis_connection('default')
    redis_db = get_redis()
    auth = Authentication(connection, redis_db)
    listen_ip = Common.cfgDefault.get('esmtpd', 'listen_ip')
    listen_ports = map(
        lambda x: int(x),
        Common.cfgDefault.get('esmtpd', 'listen_port').split(','))
    timeout = int(Common.cfgDefault.get('esmtpd', 'timeout'))

    for listen_port in listen_ports:
        SMTPServer((listen_ip, listen_port),
                   ip_validator=auth.auth_by_ip,