summaryrefslogtreecommitdiff
path: root/tools/libskrewt.c
blob: 602fdb767b4c11f90610d1dc8bd2707112e37e69 (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
84
85
86
#include "libskrewt.h"
#include "utils.h"
#include <iostream>
#include <sstream>

using namespace std;

void parse_content(const string type_spec_line,
        string &maintype, string &boundary) {
  //xxx cerr << "parser called with: " << type_spec_line << endl;
  string get_type(type_spec_line);

  size_t where = get_type.find_first_of(" \t;\n");
  string rest;
  if (where == string::npos) {
    // keep whole string
  }
  else {
    rest = get_type.substr(where+1);
    get_type = get_type.substr(0,where);
  }
  where = get_type.find("/");
  if (where == string::npos){
    maintype = "";
    cerr << "could not find / in " << get_type << endl;
  } else {
    maintype = get_type.substr(0, where);
  }

// now need to find boundary

  string srch = "boundary=";
  where = rest.find(srch);
  if (where != string::npos) {
    where += srch.length();
    boundary = rest.substr(where);
    if (boundary[0] == '"') {
      boundary = boundary.substr(1);
      where = boundary.find_first_of("\"");
    } else {
      where = boundary.find_first_of(" \t;\n");
    }
    if (where == string::npos) {
      /* do nothing, boundary=boundary as a whole */
    } else {
      boundary = boundary.substr(0, where);
    }
  } else {
    //xxxxxxx cerr << "boundary= not found in " << type_spec_line << endl;
  }
}

int skrewt::krunch_rfrom(){
  stringstream parse;
  parse.str(received_from);
  string word;
  parse >> word;
  if (word != "from") {
    cerr << progid << " bad 'Received: from' line ... '"
        << word << "'" << endl;
    return ex_syserr;
  }
  parse >> proximta_rDNS;
  parse >> word;
  if (word == "(HELO" /*)*/) {
    parse >> proximta_HELO;
    proximta_HELO = rtrim(proximta_HELO, "()");
    parse >> word;
  } else {
    proximta_HELO = proximta_rDNS;
  }
  size_t len = word.length();
  if (len<2 || word[0] != '(' || word[len-1] != ')') {
    cerr << progid << " bad 'Received: from' line ;;; '"
        << word << "'" << endl;
    return ex_syserr;
  }
  proximta_IP = word.substr(1, len-2);
  size_t where = proximta_IP.find("@");
  if (where != string::npos){
    proximta_AuthUser = proximta_IP.substr(0, where);
    proximta_IP = proximta_IP.substr(1+where);
  }

  return 0;
}