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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
let _ = Thread.self ()
type ctx
type stat
= Continue
| Reject
| Discard
| Accept
| Tempfail
| No_reply
| Skip
| All
type flag
= ADDHDRS
| CHGHDRS
| CHGBODY
| ADDRCPT
| ADDRCPT_PAR
| DELRCPT
| QUARANTINE
| CHGFROM
| SETSYMLIST
type stage
= CONNECT
| HELO
| ENVFROM
| ENVRCPT
| DATA
| EOM
| EOH
type step
= NOCONNECT
| NOHELO
| NOMAIL
| NORCPT
| NOBODY
| NOHDRS
| NOEOH
| NR_HDR
| NOUNKNOWN
| NODATA
| SKIP
| RCPT_REJ
| NR_CONN
| NR_HELO
| NR_MAIL
| NR_RCPT
| NR_DATA
| NR_UNKN
| NR_EOH
| NR_BODY
| HDR_LEADSPC
| MDS_256K
| MDS_1M
type bytes =
(char, Bigarray.int8_unsigned_elt, Bigarray.c_layout) Bigarray.Array1.t
type filter =
{ name : string
; version : int
; flags : flag list
; connect : (ctx -> string option -> Unix.sockaddr option -> stat) option
; helo : (ctx -> string -> stat) option
; envfrom : (ctx -> string -> string list -> stat) option
; envrcpt : (ctx -> string -> string list -> stat) option
; header : (ctx -> string -> string -> stat) option
; eoh : (ctx -> stat) option
; body : (ctx -> bytes -> int -> stat) option
; eom : (ctx -> stat) option
; abort : (ctx -> stat) option
; close : (ctx -> stat) option
; unknown : (ctx -> string -> stat) option
; data : (ctx -> stat) option
; negotiate : (ctx -> flag list -> step list
-> stat * flag list * step list) option
}
exception Milter_error of string
let _ = Callback.register_exception "Milter.Milter_error" (Milter_error "")
external opensocket : bool -> unit = "caml_milter_opensocket"
external milter_register : filter -> unit = "caml_milter_register"
let maybe f = function
| None -> ()
| Some x -> f x
let register descr =
maybe (Callback.register "milter_connect") descr.connect;
maybe (Callback.register "milter_helo") descr.helo;
maybe (Callback.register "milter_envfrom") descr.envfrom;
maybe (Callback.register "milter_envrcpt") descr.envrcpt;
maybe (Callback.register "milter_header") descr.header;
maybe (Callback.register "milter_eoh") descr.eoh;
maybe (Callback.register "milter_body") descr.body;
maybe (Callback.register "milter_eom") descr.eom;
maybe (Callback.register "milter_abort") descr.abort;
maybe (Callback.register "milter_close") descr.close;
maybe (Callback.register "milter_unknown") descr.unknown;
maybe (Callback.register "milter_data") descr.data;
maybe (Callback.register "milter_negotiate") descr.negotiate;
milter_register descr
external setconn : string -> unit = "caml_milter_setconn"
external settimeout : int -> unit = "caml_milter_settimeout"
external setbacklog : int -> unit = "caml_milter_setbacklog"
external setdbg : int -> unit = "caml_milter_setdbg"
external stop : unit -> unit = "caml_milter_stop"
external main : unit -> unit = "caml_milter_main"
external getsymval : ctx -> string -> string option =
"caml_milter_getsymval"
external getpriv : ctx -> 'a option =
"caml_milter_getpriv"
external setpriv : ctx -> 'a option -> unit =
"caml_milter_setpriv"
external setreply : ctx -> string -> string option -> string option -> unit =
"caml_milter_setreply"
external setmlreply : ctx -> string -> string option -> string list -> unit =
"caml_milter_setmlreply"
external addheader : ctx -> string -> string -> unit =
"caml_milter_addheader"
external chgheader : ctx -> string -> int -> string option -> unit =
"caml_milter_chgheader"
external insheader : ctx -> int -> string -> string -> unit =
"caml_milter_insheader"
external chgfrom : ctx -> string -> string option -> unit =
"caml_milter_chgfrom"
external addrcpt : ctx -> string -> unit =
"caml_milter_addrcpt"
external addrcpt_par : ctx -> string -> string option -> unit =
"caml_milter_addrcpt_par"
external delrcpt : ctx -> string -> unit =
"caml_milter_delrcpt"
external replacebody : ctx -> bytes -> unit =
"caml_milter_replacebody"
external progress : ctx -> unit =
"caml_milter_progress"
external quarantine : ctx -> string -> unit =
"caml_milter_quarantine"
external version : unit -> int * int * int =
"caml_milter_version"
external setsymlist : ctx -> stage -> string -> unit =
"caml_milter_setsymlist"
external milter_version_code : unit -> int = "caml_milter_version_code"
let version_code =
milter_version_code ()
let empty =
{ name = ""
; version = version_code
; flags = []
; connect = None
; helo = None
; envfrom = None
; envrcpt = None
; header = None
; eoh = None
; body = None
; eom = None
; abort = None
; close = None
; unknown = None
; data = None
; negotiate = None
}