summaryrefslogtreecommitdiff
path: root/tools/ward.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/ward.c')
-rw-r--r--tools/ward.c112
1 files changed, 13 insertions, 99 deletions
diff --git a/tools/ward.c b/tools/ward.c
index 277fd76..19d9d02 100644
--- a/tools/ward.c
+++ b/tools/ward.c
@@ -71,91 +71,6 @@ Received: from ip68-231-191-153.tc.ph.cox.net (HELO asclepias.av8n.net) (smtp@68
/home/jsd/Maildir/cur/1342363199.24320.cloud:2,
#endif
-int skrewt::headers(){
- //xxxx cerr << progid << " begins" << endl;
- for (;;){ // outer loop over all records in the header
- if (cin.eof()) break;
- if (cin.bad()) return 1;
-
- string line;
-// on fail, go back to top of outer loop and check for eof versus bad
- if (getline(cin, line).fail()) continue;
- msgsize += line.length()+1;
- if (msgsize > maxsize) {
- cerr << progid << " rejection: bigger than " << maxsize << endl;
- exeunt(ex_spam);
- }
- cout << line << endl;
- bigbuf.push_back(line);
- string headrec = noCR(line); // for a folded record, this is the first line
-
- for (;;) { // inner loop to build a multi-line record e.g. folded record:
- if (cin.eof()) break;
- if (cin.bad()) return 1;
- char ch;
- if (cin.get(ch).fail()) continue;
- cin.putback(ch);
- if (ch != ' ' && ch != '\t') break;
- string line;
-// on fail, go back to top of inner loop and check for eof versus bad
- if (getline(cin, line).fail()) continue;
- msgsize += line.length()+1;
- if (msgsize > maxsize) {
- cerr << progid << " rejection: bigger than " << maxsize << endl;
- exeunt(ex_spam);
- }
- cout << line << endl;
- bigbuf.push_back(line);
- headrec += "\n" + noCR(line);
- }
-// here with a fully assembled header record
-// headrec (unlike line) contains no DOS CR characters
- int len = headrec.length();
- if (len == 0) {
- saw_blank_line = 1;
- break; // no more headers in this message
- }
-
-// here if it's a header line
- string headword;
- string rest;
- size_t where = headrec.find(":");
- if (where != string::npos) {
- headword = headrec.substr(0, where);
- rest = ltrim(headrec.substr(1+where));
- }
- headword = toLower(headword);
- if (0){
- } else if (headword == "from") {
- from = rest;
- } else if (headword == "to") {
- to = rest;
- } else if (headword == "return-path") {
- return_path = rest;
- } else if (headword == "message-id") {
- message_id = rest;
- } else if (headword == "received") {
- if (!received_from.length() && prefix("from ", rest)){
- received_from = rest;
- }
- } else if (headword == "date") {
- date = rest;
- } else if (headword == "subject") {
- subject = rest;
- } else if (headword == "content-type") {
- content_type = rest;
- } else if (headword == "delivered-to") {
- delivered_to = rest;
- }
- //xxxx cout << headrec.length() << " ... ";
- recno++;
- if (0) if (recno <= 6) cerr << progid << "#" << recno
- << " " << headrec << endl;
- }
- return 0;
-}
-
-
////////////////////////////////////////////////////////////
int main(int _argc, const char** _argv){
@@ -171,23 +86,20 @@ int main(int _argc, const char** _argv){
skrewt mysk;
- while (argc) {
- string arg(*argv); argv++; argc--;
+ argParser ARGS(argc, argv);
+ try {while (ARGS.size()) {
+ string arg = ARGS.next();
if (arg.substr(0,2) == "--") arg = arg.substr(1);
- if (prefix(arg, "-help")) {
+ if (ARGS.prefix("-help")) {
usage(0);
}
if (0) {
- } else if (prefix(arg, "-mid-required")) {
+ } else if (ARGS.prefix("-mid-required")) {
mysk.mid_required++;
- } else if (prefix(arg, "-error-exit")) {
+ } else if (ARGS.prefix("-error-exit")) {
mysk.error_exit++;
- } else if (prefix(arg, "-maxsize")) {
- if (!argc) {
- cerr << "Option -maxsize requires an argument" << endl;
- exit(ex_usage);
- }
- mysk.maxsize = atoi(*argv); argv++; argc--;
+ } else if (ARGS.prefix("-maxsize", 1)) {
+ mysk.maxsize = atoi(ARGS.shift().c_str());
} else if (arg.substr(0,1) == "-") {
cerr << "Unrecognized option '" << arg << "'" << endl;
cerr << "For help, try: " << progname << " -help" << endl;
@@ -197,9 +109,12 @@ int main(int _argc, const char** _argv){
cerr << "For help, try: " << progname << " -help" << endl;
exit(ex_usage);
}
+ }}
+ catch (int) {
+ exit(ex_usage);
}
- int rslt = mysk.headers();
+ int rslt = mysk.headers(cin, cout);
if (rslt) return rslt;
// Headers are done.
@@ -208,7 +123,6 @@ int main(int _argc, const char** _argv){
rslt = mysk.interstage();
if (rslt) return rslt;
- rslt = mysk.body();
+ rslt = mysk.body(cin, cout);
return rslt;
-
}