From a73009734a8f795d3c1fabe3a4cfc43501010464 Mon Sep 17 00:00:00 2001 From: John Denker Date: Mon, 16 Jul 2012 15:08:28 -0700 Subject: automatically skip directories mentioned in the file-list Also, some better error messages --- tools/mail-scan.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'tools') diff --git a/tools/mail-scan.c b/tools/mail-scan.c index c2b798b..5ec2b25 100644 --- a/tools/mail-scan.c +++ b/tools/mail-scan.c @@ -15,6 +15,9 @@ #include #include +#include /* for stat() */ +#include /* stat() */ + #include /* perror */ using namespace std; @@ -182,6 +185,15 @@ int main(int _argc, const char** _argv){ for (list::const_iterator file = dofile.begin(); file != dofile.end(); file++) { + + + struct stat filestatus; + stat(file->c_str(), &filestatus ); + if (S_ISDIR(filestatus.st_mode)) { + cerr << "is directory: " << *file << endl; + continue; + } + ifstream infile; infile.open(file->c_str()); if (!infile.good()) { @@ -198,7 +210,10 @@ int main(int _argc, const char** _argv){ string line; for (;;) { // loop over all lines in this record if (infile.eof()) break; - if (infile.bad()) return 1; + if (infile.bad()) { + cerr << "mail-scan: read error on file '" << *file << "'" << endl; + return 1; + } if (getline(infile, line).fail()) continue; Header.push_back(line); msgsize += line.length()+1; -- cgit v1.2.3