From 272a641adacfd9605dae4be17bf87c19252e7d09 Mon Sep 17 00:00:00 2001 From: John Denker Date: Mon, 4 Aug 2014 10:43:14 -0700 Subject: better help msg; better behavior for -addr mode --- tools/mail-scan.c | 49 +++++++++++++++++++++++++++---------------------- 1 file changed, 27 insertions(+), 22 deletions(-) (limited to 'tools') diff --git a/tools/mail-scan.c b/tools/mail-scan.c index 0ed7465..1047683 100644 --- a/tools/mail-scan.c +++ b/tools/mail-scan.c @@ -1,22 +1,5 @@ /////////////////// -// skrewt.c -// -// scrutinize email -// - -// Hint: -// mail-scan +from * | iconv -c \... -// | sed 's/.*@//;s/>$//' | sort | uniq -c | sort -nr > some-junk.from-count -// -// Also: -// grep score=[34] /home/user/Maildir/new/* -l | xargs mail-scan +From | blacklist-update -// Then: -// grep score=[34] /home/user/Maildir/new/* -l | xargs mv-to -i /home/user/Maildir/spam/ - -///////////// -// Another hint: using the "-addr" feature: -// mail-scan +x-spam.*:score=[234] /home/jean/Maildir/spam/* -l | \.... -// xargs mail-scan +from -addr | sort | uniq -c | sort -nr | head -20 +// mail-scan.c #include #include /* for exit() */ @@ -50,8 +33,20 @@ void usage(const int sts){ " -addr assume field contains somebody ; print just foo@bar.com\n" "\n" "\n" -" Messages containing the string '-please-bounce-this-' will be rejected.\n" -" Messages with no date will be rejected.\n" +" Hint:\n" +" mail-scan +from * | iconv -c ...\n" +" | sed 's/.*@//;s/>$//' | sort | uniq -c | sort -nr > some-junk.from-count\n" +"\n" +" Also:\n" +" grep score=[34] /home/user/Maildir/new/* -l | \\\n" +" xargs mail-scan +From | blacklist-update\n" +" Then:\n" +" grep score=[34] /home/user/Maildir/new/* -l | \\\n" +" xargs mv-to -i /home/user/Maildir/spam/\n" + +" Another hint: using the '-addr' feature:\n" +" mail-scan +x-spam.*:score=[234] /home/jean/Maildir/spam/* -l | \\\n" +" xargs mail-scan +from -addr | sort | uniq -c | sort -nr | head -20\n" ; exit(sts); } @@ -122,7 +117,8 @@ int main(int _argc, const char** _argv){ int maxlines(0); int fname_only(0); int addr_mode(0); - boost::regex addr_filter(string("<.*@(.*)>"), boost::regex_constants::icase); + boost::regex host_filter(string("<.*@(.*)>"), boost::regex_constants::icase); + boost::regex addr_filter(string("<(.*@.*)>"), boost::regex_constants::icase); while (argc) { string arg(*argv); argv++; argc--; @@ -248,7 +244,16 @@ int main(int _argc, const char** _argv){ if (boost::regex_search(header, matches, addr_filter)){ cout << string(matches[1].first, matches[1].second) << endl; } else { - cerr << "no match, ignoring: " << header << endl; + string hdr(header); + size_t where = hdr.find(':'); + if (where != string::npos) { + hdr = ltrim(hdr.substr(1+where)); + } else { + // DUBIOUS: print the whole thing + cerr << "Warning, expected a ':', didn't see it" + << endl; + } + cout << hdr << endl; } didprint++; if (maxlines && didprint >= maxlines) goto endfile; -- cgit v1.2.3