summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tools/skrewt.c150
1 files changed, 92 insertions, 58 deletions
diff --git a/tools/skrewt.c b/tools/skrewt.c
index 6749a01..8c9beba 100644
--- a/tools/skrewt.c
+++ b/tools/skrewt.c
@@ -178,65 +178,36 @@ string join(const string sep, const list<string> stuff){
return rslt;
}
-////////////////////////////////////////////////////////////
-int main(int _argc, const char** _argv){
-//// pid_t pid = getpid();
-//// cout << pid << endl;
-//// cout << getpgid(pid) << endl;
- int argc(_argc);
- const char **argv(_argv);
- {
- progname = *argv++; argc--;
- mypid = getpid();
- stringstream binder;
- binder << basename(progname) << "[" << mypid << "]";
- progid = binder.str();
- }
-
- int maxsize(1000*1000);
- int error_exit(0);
- int mid_required(0);
-
- while (argc) {
- string arg(*argv); argv++; argc--;
- if (arg.substr(0,2) == "--") arg = arg.substr(1);
- if (prefix(arg, "-help")) {
- usage(0);
- }
- if (0) {
- } else if (prefix(arg, "-mid-required")) {
- mid_required++;
- } else if (prefix(arg, "-error-exit")) {
- error_exit++;
- } else if (prefix(arg, "-maxsize")) {
- if (!argc) {
- cerr << "Option -maxsize requires an argument" << endl;
- exit(ex_usage);
- }
- maxsize = atoi(*argv); argv++; argc--;
- } else if (arg.substr(0,1) == "-") {
- cerr << "Unrecognized option '" << arg << "'" << endl;
- cerr << "For help, try: " << progname << " -help" << endl;
- exit(ex_usage);
- } else {
- cerr << "Extraneous verbiage '" << arg << "'" << endl;
- cerr << "For help, try: " << progname << " -help" << endl;
- exit(ex_usage);
- }
- }
-
- int saw_blank_line(0);
- string boundary("x-xx-x");
+class skrewt{
+public:
+ string boundary;
string to;
string from;
string subject;
string date;
string message_id;
string content_type;
- int msgsize(0);
+ int msgsize;
vector<string> bigbuf;
- int recno(0);
+ int saw_blank_line;
+ int recno;
+
+ int maxsize;
+ int error_exit;
+ int mid_required;
+
+ // constructor
+ skrewt()
+ : boundary("x-xx-x"), msgsize(0), saw_blank_line(0), recno(0),
+ maxsize(1000*1000), error_exit(0), mid_required(0)
+ {}
+
+ int headers();
+ int interstage();
+ int body();
+};
+int skrewt::headers(){
//xxxx cerr << progid << " begins" << endl;
for (;;){ // outer loop over all records in the header
if (cin.eof()) break;
@@ -309,12 +280,13 @@ int main(int _argc, const char** _argv){
if (0) if (recno <= 6) cerr << progid << "#" << recno
<< " " << headrec << endl;
}
+ return 0;
+}
+
+int skrewt::interstage(){
if (saw_blank_line) {/* ignore */}
cerr << progid <<" Mid '" << message_id << "'" << endl;
-// Headers are done.
-// Do some early-stage thinking.
-
list<string> badnews;
if (subject.find("-please-bounce-this-") != string::npos) {
@@ -338,7 +310,10 @@ int main(int _argc, const char** _argv){
exeunt(ex_spam);
}
}
+ return 0;
+}
+int skrewt::body(){
string main_contype;
if (content_type.length())
parse_content(content_type, main_contype, boundary);
@@ -397,10 +372,69 @@ int main(int _argc, const char** _argv){
}
if (0) cerr << "textlines: " << textlines << endl;
- if (1 && !textlines) {
- cerr << progid << " rejection: no text" << endl;
-// maybe_exeunt(ex_spam, error_exit);
+ if (!textlines) {
+ cerr << progid << " rejection: no text: " << error_exit << endl;
+ maybe_exeunt(ex_spam, error_exit);
}
cerr << progid << " normal completion" << endl;
- exit(ex_good);
+ return(ex_good);
+}
+
+////////////////////////////////////////////////////////////
+int main(int _argc, const char** _argv){
+//// pid_t pid = getpid();
+//// cout << pid << endl;
+//// cout << getpgid(pid) << endl;
+ int argc(_argc);
+ const char **argv(_argv);
+ {
+ progname = *argv++; argc--;
+ mypid = getpid();
+ stringstream binder;
+ binder << basename(progname) << "[" << mypid << "]";
+ progid = binder.str();
+ }
+
+ skrewt mysk;
+
+ while (argc) {
+ string arg(*argv); argv++; argc--;
+ if (arg.substr(0,2) == "--") arg = arg.substr(1);
+ if (prefix(arg, "-help")) {
+ usage(0);
+ }
+ if (0) {
+ } else if (prefix(arg, "-mid-required")) {
+ mysk.mid_required++;
+ } else if (prefix(arg, "-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 (arg.substr(0,1) == "-") {
+ cerr << "Unrecognized option '" << arg << "'" << endl;
+ cerr << "For help, try: " << progname << " -help" << endl;
+ exit(ex_usage);
+ } else {
+ cerr << "Extraneous verbiage '" << arg << "'" << endl;
+ cerr << "For help, try: " << progname << " -help" << endl;
+ exit(ex_usage);
+ }
+ }
+
+ int rslt = mysk.headers();
+ if (rslt) return rslt;
+
+// Headers are done.
+// Do some early-stage thinking.
+
+ rslt = mysk.interstage();
+ if (rslt) return rslt;
+
+ rslt = mysk.body();
+ return rslt;
+
}