summaryrefslogtreecommitdiff
path: root/tools/libskrewt.h
blob: 00a8d90f4c8df22533c691555b0985211518edfb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include <string>
#include <vector>
#include <iostream>
#include "sepofra.h"
#include "qq_exit_codes.h"              // a bit of a kludge

extern std::string progid;

#define test_state_macro \
foo(untested)  \
foo(pass)   \
foo(neutral)    \
foo(fail)

// expand the codes to make some <const int> names:
#define foo(name) name,
typedef enum {
  test_state_macro
} test_state;
#undef foo

class name_tester {
public:
  std::string name;          // typically a FQDN
  test_state spf;
  test_state map2ip;
  name_tester() : name(""), spf(untested), map2ip(untested)
  {}
};

class xstr {
public:
  int err;
  std::string str;
  xstr() : err(1), str("") {}
  xstr(const int foo, const std::string bar) : err(foo), str(bar) {}
};

class skrewt{
public:
  std::string received_from;         // envelope HELO among other things
    name_tester proximta_HELO;
    name_tester proximta_rDNS;
    int         proximta_rDNS_flagged;
    std::string proximta_IP;
    std::string proximta_AuthUser;
    SPF_result_t spf_result;
  name_tester return_path;           // envelope MAIL FROM
  std::string boundary;
  std::string to;
  std::string from;
  std::string subject;
  std::string date;
  std::string message_id;
  std::string content_type;
  std::list<std::string> delivered_to;
  int msgsize;
  int saw_blank_line;
  int recno;
  int maxsize;
  int strictness;
  std::string note;
  int mid_required;
  std::vector<std::string> headerbuf;
  std::vector<std::string> bigbuf;
  xstr lookahead;
  std::map<test_state,std::string> decode_test_state;

  skrewt();       // constructor
  xstr getRecord(std::istream& xin);
  xstr getLine(std::istream& xin);
  int headers(std::istream& xin);
  int dump_bigbuf(std::ostream& xout);
  int interstage();
  int body(std::istream& xin, std::ostream& xout);
  int krunch_rfrom();
};

void parse_content(const std::string type_spec_line,
        std::string &maintype, std::string &boundary);

void exeunt(const int sts);
void maybe_exeunt(const int sts, const int really);