summaryrefslogtreecommitdiff
path: root/sqmail-4.3.07/src/hfield.c
blob: 2376e1f07eb1d7fcebf599d15ac8484d06671bb9 (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#include "hfield.h"

static char *(hname[]) = {
  "unknown-header"
, "sender"
, "from"
, "reply-to"
, "to"
, "cc"
, "bcc"
, "date"
, "message-id"
, "subject"
, "resent-sender"
, "resent-from"
, "resent-reply-to"
, "resent-to"
, "resent-cc"
, "resent-bcc"
, "resent-date"
, "resent-message-id"
, "return-receipt-to"
, "errors-to"
, "apparently-to"
, "received"
, "return-path"
, "delivered-to"
, "content-length"
, "content-type"
, "content-transfer-encoding"
, "notice-requested-upon-delivery-to"
, "mail-followup-to"
, 0
};

static int hmatch( char *s,int len,char *t)
{
  int i;
  char ch;

  for (i = 0; (ch = t[i]); ++i) {
    if (i >= len) return 0;
    if (ch != s[i]) {
      if (ch == '-') return 0;
      if (ch - 32 != s[i]) return 0;
    }
  }
  for (;;) {
    if (i >= len) return 0;
    ch = s[i];
    if (ch == ':') return 1;
    if ((ch != ' ') && (ch != '\t')) return 0;
    ++i;
  }
}

int hfield_known(char *s,int len)
{
  int i;
  char *t;

  for (i = 1; (t = hname[i]); ++i)
    if (hmatch(s,len,t))
      return i;
 
 return 0;
}

int hfield_valid(char *s,int len)
{
  int i;
  int j;
  char ch;

  for (j = 0; j < len; ++j)
    if (s[j] == ':') break;

  if (j >= len) return 0;
  
  while (j) {
    ch = s[j - 1];
    if ((ch != ' ') && (ch != '\t'))
      break;
    --j;
  }
  if (!j) return 0;

  for (i = 0; i < j; ++i) {
    ch = s[i];
    if (ch <= 32) return 0;
    if (ch >= 127) return 0;
   }
  return 1;
}

unsigned int hfield_skipname(char *s,int len)
{
  int i;
  char ch;

  for (i = 0; i < len; ++i)
    if (s[i] == ':') break;

  if (i < len) ++i;
     while (i < len) {
       ch = s[i];
       if ((ch != '\t') && (ch != '\n') && (ch != '\r') && (ch != ' '))
         break;
        ++i;
     }

  return i;
}