summaryrefslogtreecommitdiff
path: root/tools/mail-scan.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/mail-scan.c')
-rw-r--r--tools/mail-scan.c27
1 files changed, 20 insertions, 7 deletions
diff --git a/tools/mail-scan.c b/tools/mail-scan.c
index 3c53b2b..5378e89 100644
--- a/tools/mail-scan.c
+++ b/tools/mail-scan.c
@@ -44,6 +44,7 @@ void usage(const int sts){
" -vert invert: print only if *no* match.\n"
" -l print filename only, not matching text.\n"
" -group print a blank line after every match.\n"
+" -max nn print at most nn records per file.\n"
" -multi print multi-line records on multiple lines\n"
" (as opposed to smashing them all onto one long line\n"
" -addr assume field contains somebody <foo@bar.com>; print just foo@bar.com\n"
@@ -183,6 +184,7 @@ int main(int _argc, const char** _argv){
int vflag(0);
int group_flag(0);
int multi(0);
+ int maxlines(0);
int fname_only(0);
int addr_mode(0);
boost::regex addr_filter(string("<.*@(.*)>"), boost::regex_constants::icase);
@@ -205,6 +207,14 @@ int main(int _argc, const char** _argv){
} else if (prefix(arg, "-address" /* long */)){
addr_mode++;
continue;
+ } else if (prefix(arg, "-max" /* long */)){
+ if (!argc){
+ cerr << "Option '" << arg << "' requires an argument" << endl;
+ cerr << "For help, try: " << progname << " -help" << endl;
+ exit(sa_usage);
+ }
+ maxlines = atoi(*argv++); argc--;
+ continue;
} else if (prefix(arg, "-multi" /* long */)){
multi++;
continue;
@@ -296,14 +306,16 @@ int main(int _argc, const char** _argv){
}
cout << endl;
didprint++;
+ if (maxlines && didprint >= maxlines) goto endfile;
} else /* addr_mode */{
- boost::smatch matches;
- 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++;
+ boost::smatch matches;
+ 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++;
+ if (maxlines && didprint >= maxlines) goto endfile;
}
}
}
@@ -316,6 +328,7 @@ int main(int _argc, const char** _argv){
break;
}
} // end loop over matching records in this file
+endfile:;;;;
if (vflag && !foundsome_infile) {
cout << *file << endl;