summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorJohn Denker <jsd@av8n.com>2012-07-17 14:33:26 -0700
committerJohn Denker <jsd@av8n.com>2012-07-29 15:32:33 -0700
commitcbbd45a9700a660bcc4e2f762f5004c2aa2b1078 (patch)
tree708e309e08ba79023ac540c5d706f6b0fe5b3137 /tools
parent40c8c828972af044b7628b2c167093f78353fcdd (diff)
implement "-addr" option in mail-scan
Diffstat (limited to 'tools')
-rw-r--r--tools/mail-scan.c51
-rw-r--r--tools/makefile3
2 files changed, 45 insertions, 9 deletions
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 <iostream>
#include <stdlib.h> /* for exit() */
#include <string>
@@ -25,6 +31,8 @@
#include <sys/stat.h> /* stat() */
#include <stdio.h> /* perror */
+#include <boost/regex.hpp>
+////#include <boost/lexical_cast.hpp>
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/