summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Denker <jsd@av8n.com>2012-07-16 17:11:37 -0700
committerJohn Denker <jsd@av8n.com>2012-07-16 17:11:37 -0700
commitad0a329eed2f913ffa2b8c786b07ea688c9c5b61 (patch)
tree4adc5ce8143327ce12b30831e81bcbba25b5aaf5
parentc347d77edbad50abdc1229a07097601a75ce13c3 (diff)
scan for +keyword:value (not just keyword)
-rw-r--r--tools/mail-scan.c48
1 files changed, 40 insertions, 8 deletions
diff --git a/tools/mail-scan.c b/tools/mail-scan.c
index 56b3806..c70a1de 100644
--- a/tools/mail-scan.c
+++ b/tools/mail-scan.c
@@ -150,6 +150,25 @@ string join(const string sep, list<string> stuff){
return rslt;
}
+class watcher {
+public:
+ string key;
+ string val;
+
+ watcher(const string init)
+ : key(""), val("")
+ {
+ size_t where = init.find(":");
+ if (where != string::npos) {
+ key = init.substr(0, where);
+ val = init.substr(1+where);
+ } else {
+ key = init;
+ }
+ }
+};
+
+
////////////////////////////////////////////////////////////
int main(int _argc, const char** _argv){
//// pid_t pid = getpid();
@@ -160,10 +179,11 @@ int main(int _argc, const char** _argv){
string progname(*argv); argv++; argc--;
int maxsize(1000000);
- list<string> watchword;
+ list<watcher> watchword;
list<string> dofile;
int vflag(0);
int multi(0);
+ int fname_only(0);
while (argc) {
string arg(*argv); argv++; argc--;
@@ -174,6 +194,9 @@ int main(int _argc, const char** _argv){
if (prefix(arg, "-verify")){
vflag++;
continue;
+ } else if (prefix(arg, "-l")){
+ fname_only++;
+ continue;
} else if (prefix(arg, "-multi")){
multi++;
continue;
@@ -192,7 +215,6 @@ int main(int _argc, const char** _argv){
for (list<string>::const_iterator file = dofile.begin();
file != dofile.end(); file++) {
-
struct stat filestatus;
stat(file->c_str(), &filestatus );
if (S_ISDIR(filestatus.st_mode)) {
@@ -236,7 +258,7 @@ int main(int _argc, const char** _argv){
inheads = 0;
}
else {
- string headword;
+ string headword; // the first thing on the line, e.g. "Subject"
string rest;
string header;
if (!multi) header = join(" ", Header);
@@ -246,13 +268,23 @@ int main(int _argc, const char** _argv){
headword = header.substr(0, where);
rest = ltrim(header.substr(1+where));
}
+// temporary? FIXME? lowercase
headword = toLower(headword);
- for (list<string>::const_iterator ptr = watchword.begin();
+ rest = toLower(rest);
+ for (list<watcher>::const_iterator ptr = watchword.begin();
ptr != watchword.end(); ptr++) {
- if (headword == toLower(*ptr)) {
- foundsome_infile++;
- if (!vflag) cout // << foundsome_infile << " "
- << *file << " :: " << header << endl;
+ if (headword == toLower(ptr->key)) {
+ // here if match as to keyword; check for match as to value
+ if (ptr->val.length()==0
+ || 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;
+ }
+ }
}
}
}