diff options
-rw-r--r-- | tools/mail-scan.c | 60 |
1 files changed, 31 insertions, 29 deletions
diff --git a/tools/mail-scan.c b/tools/mail-scan.c index 3749945..8e0f267 100644 --- a/tools/mail-scan.c +++ b/tools/mail-scan.c @@ -168,6 +168,7 @@ public: } else { key = init; } + //xx cerr << "watcher key: " << key << " val: " << val << endl; } }; @@ -240,7 +241,7 @@ int main(int _argc, const char** _argv){ string boundary("x-xx-x"); int msgsize(0); int foundsome_infile(0); - for (;;){ // loop over all records in file + for (;;){ // loop over all records in this file if (inheads) { list<string> Header; string line; @@ -264,44 +265,45 @@ int main(int _argc, const char** _argv){ } if (Header.front().length() == 0) { inheads = 0; + continue; // blank line needs no further processing + } + string headword; // the first thing on the line, e.g. "Subject" + string rest; + string header; + if (!multi) header = join(" ", Header); + else header = join("\n", Header); + size_t where = header.find(":"); + if (where != string::npos) { + headword = header.substr(0, where); + rest = ltrim(header.substr(1+where)); } - else { - string headword; // the first thing on the line, e.g. "Subject" - string rest; - string header; - if (!multi) header = join(" ", Header); - else header = join("\n", Header); - size_t where = header.find(":"); - if (where != string::npos) { - headword = header.substr(0, where); - rest = ltrim(header.substr(1+where)); - } // temporary? FIXME? lowercase - headword = toLower(headword); - rest = toLower(rest); - for (list<watcher>::const_iterator ptr = watchword.begin(); - ptr != watchword.end(); ptr++) { - 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; - didprint++; - } + headword = toLower(headword); + rest = toLower(rest); + for (list<watcher>::const_iterator ptr = watchword.begin(); + ptr != watchword.end(); ptr++) { + 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; + didprint++; } } } } +// only show file once, even if there might have been multiple matches: + if (fname_only && didprint) break; } else { // not in header break; } - } + } // end loop over matching records in this file if (vflag && !foundsome_infile) { cout << foundsome_infile << " ... " << *file << endl; |