From 33981cf1aba48b7589fbdc685eeaa8a52ece8c4f Mon Sep 17 00:00:00 2001 From: John Denker Date: Thu, 22 Nov 2012 18:21:17 -0800 Subject: add hooks for redirecting main output --- tools/libskrewt.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 89 insertions(+), 6 deletions(-) (limited to 'tools/libskrewt.c') diff --git a/tools/libskrewt.c b/tools/libskrewt.c index 812b546..fb1cd4a 100644 --- a/tools/libskrewt.c +++ b/tools/libskrewt.c @@ -1,6 +1,5 @@ #include "libskrewt.h" #include "utils.h" -#include #include #include @@ -86,6 +85,90 @@ int skrewt::krunch_rfrom(){ return 0; } +int skrewt::headers(istream& xin, std::ostream& xout){ + //xxxx cerr << progid << " begins" << endl; + for (;;){ // outer loop over all records in the header + if (xin.eof()) break; + if (xin.bad()) return 1; + + string line; +// on fail, go back to top of outer loop and check for eof versus bad + if (getline(xin, line).fail()) continue; + msgsize += line.length()+1; + if (msgsize > maxsize) { + cerr << progid << " rejection: bigger than " << maxsize << endl; + exeunt(ex_spam); + } + xout << 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 (xin.eof()) break; + if (xin.bad()) return 1; + char ch; + if (xin.get(ch).fail()) continue; + xin.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(xin, line).fail()) continue; + msgsize += line.length()+1; + if (msgsize > maxsize) { + cerr << progid << " rejection: bigger than " << maxsize << endl; + exeunt(ex_spam); + } + xout << 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 xout << headrec.length() << " ... "; + recno++; + if (0) if (recno <= 6) cerr << progid << "#" << recno + << " " << headrec << endl; + } + return 0; +} + int skrewt::interstage(){ if (saw_blank_line) {/* ignore */} // Note that the headers are in reverse-chronological order: @@ -254,7 +337,7 @@ int skrewt::interstage(){ return 0; } -int skrewt::body(){ +int skrewt::body(std::istream& xin, std::ostream& xout){ string main_contype; if (content_type.length()) parse_content(content_type, main_contype, boundary); @@ -269,18 +352,18 @@ int skrewt::body(){ int textlines(0); for (;;){ // outer loop over all lines in the body - if (cin.eof()) break; - if (cin.bad()) return 1; + if (xin.eof()) break; + if (xin.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; + if (getline(xin, line).fail()) continue; msgsize += line.length()+1; if (msgsize > maxsize) { cerr << progid << " rejection: bigger than " << maxsize << endl; maybe_exeunt(ex_spam, error_exit); } bigbuf.push_back(line); - cout << line << endl; + xout << line << endl; if (in_subheads){ if (line == "" || line == "\r") in_subheads = 0; } -- cgit v1.2.3