postfix-log-parser 0.2.0

高性能模块化Postfix日志解析器,经3.2GB生产数据验证,SMTPD事件100%准确率
Documentation
use regex::Regex;

fn main() {
    let command_stats_regex = Regex::new(r"(?:ehlo=(\d+))?(?:\s+helo=(\d+))?(?:\s+mail=(\d+))?(?:\s+rcpt=(\d+))?(?:\s+data=(\d+))?(?:\s+bdat=(\d+))?(?:\s+quit=(\d+))?(?:\s+commands=(\d+))?").unwrap();

    let test_texts = vec![
        " ehlo=1 mail=1 rcpt=1 data=1 commands=4",
        "ehlo=1 mail=1 rcpt=1 data=1 commands=4",
        " ehlo=1 helo=0 mail=1 rcpt=1 data=1 commands=4",
    ];

    for test_text in test_texts {
        println!("\n测试文本: '{}'", test_text);

        if let Some(captures) = command_stats_regex.captures(test_text) {
            println!("匹配成功!");
            for (i, capture) in captures.iter().enumerate() {
                if let Some(cap) = capture {
                    println!("  Group {}: '{}'", i, cap.as_str());
                } else {
                    println!("  Group {}: None", i);
                }
            }
        } else {
            println!("匹配失败!");
        }
    }
}