summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Denker <jsd@av8n.com>2014-08-04 10:43:14 -0700
committerJohn Denker <jsd@av8n.com>2014-08-04 10:43:14 -0700
commit272a641adacfd9605dae4be17bf87c19252e7d09 (patch)
tree8b336631a722c77958b8e1ad3c48e200e47d56f5
parent263a9ba17b200da3e5cf25772999335f0bffe872 (diff)
better help msg;
better behavior for -addr mode
-rw-r--r--tools/mail-scan.c49
1 files changed, 27 insertions, 22 deletions
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 <iostream>
#include <stdlib.h> /* for exit() */
@@ -50,8 +33,20 @@ void usage(const int sts){
" -addr assume field contains somebody <foo@bar.com>; 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;