From cbbd45a9700a660bcc4e2f762f5004c2aa2b1078 Mon Sep 17 00:00:00 2001 From: John Denker Date: Tue, 17 Jul 2012 14:33:26 -0700 Subject: implement "-addr" option in mail-scan --- tools/mail-scan.c | 51 ++++++++++++++++++++++++++++++++++++++++++--------- tools/makefile | 3 +++ 2 files changed, 45 insertions(+), 9 deletions(-) (limited to 'tools') diff --git a/tools/mail-scan.c b/tools/mail-scan.c index 0d7f722..9e79ff9 100644 --- a/tools/mail-scan.c +++ b/tools/mail-scan.c @@ -13,6 +13,12 @@ // Then: // grep score=[34] /home/user/Maildir/new/* -l | xargs mv-to -i /home/user/Maildir/spam/ +///////////// +// Another hint: using the "-addr" feature: +// grep score=[234] /home/user/Maildir/spam/* -l | \... +// xargs mail-scan +from -addr | sort | uniq -c | sort -nr | head | blacklist-update -bare + + #include #include /* for exit() */ #include @@ -25,6 +31,8 @@ #include /* stat() */ #include /* perror */ +#include +////#include using namespace std; @@ -157,6 +165,8 @@ class watcher { public: string key; string val; + boost::regex valrx; + boost::regex keyrx; watcher(const string init) : key(""), val("") @@ -168,6 +178,8 @@ public: } else { key = init; } + keyrx = boost::regex(key, boost::regex_constants::icase); + valrx = boost::regex(val, boost::regex_constants::icase); //xx cerr << "watcher key: " << key << " val: " << val << endl; } }; @@ -189,6 +201,8 @@ int main(int _argc, const char** _argv){ int group_flag(0); int multi(0); int fname_only(0); + int addr_mode(0); + boost::regex addr_filter(string("<.*@(.*)>"), boost::regex_constants::icase); while (argc) { string arg(*argv); argv++; argc--; @@ -196,16 +210,19 @@ int main(int _argc, const char** _argv){ if (prefix(arg, "-help")) { usage(0); } - if (prefix(arg, "-vert")){ + if (prefix(arg, "-vert" /* short */)){ vflag++; continue; - } if (prefix(arg, "-group")){ + } if (prefix(arg, "-group" /* short */)){ group_flag++; continue; - } else if (prefix(arg, "-l")){ + } else if (prefix(arg, "-l" /* short */)){ fname_only++; continue; - } else if (prefix(arg, "-multi")){ + } else if (prefix(arg, "-address" /* long */)){ + addr_mode++; + continue; + } else if (prefix(arg, "-multi" /* long */)){ multi++; continue; } else if (arg.substr(0,1) == "-") { @@ -288,11 +305,27 @@ int main(int _argc, const char** _argv){ || rest.find(toLower(ptr->val)) != string::npos) { foundsome_infile++; if (!vflag) { - // << foundsome_infile << " " ; (number of occurrences) - cout << *file; - if (!fname_only) cout << " :: " << header; - cout << endl; - didprint++; + if (!addr_mode){ + // << foundsome_infile << " " ; (number of occurrences) + cout << *file; + if (!fname_only) { + cout << " :: " << header; + } + cout << endl; + didprint++; + } else /* addr_mode */{ + boost::smatch matches; +//// boost::match_flag_type flg; +//// boost::regex_search(header, matches, addr_filter); +//// boost::regex_search(header.begin(), header.end(), matches, addr_filter, flg); +/// boost::regex_search(header, matches, addr_filter); + if (boost::regex_search(header, matches, addr_filter)){ + cout << string(matches[1].first, matches[1].second) << endl; + } else { + cerr << "no match, ignoring: " << header << endl; + } + didprint++; + } } } } diff --git a/tools/makefile b/tools/makefile index 7f5dcef..e092702 100644 --- a/tools/makefile +++ b/tools/makefile @@ -14,6 +14,9 @@ progs = pido hi-q skrewt hi-test mail-scan all: $(progs) +mail-scan: mail-scan.o + $(CC) $< -lboost_regex -o $@ + install: install $(progs) /var/qmail/bin/ cp filters.conf aufilters.conf /var/qmail/control/ -- cgit v1.2.3