package uspf

  1. Overview
  2. Docs
SPF implementation in OCaml

Install

Dune Dependency

Authors

Maintainers

Sources

uspf-0.0.4.tbz
sha256=86f8969c795ac4ceb31e7c6f4880afaaa47764430e6f0a035343dbec1a1a4827
sha512=1b7ea0d6303bd51ebe35ca2732998d889fa8d62f676730543d9fa45673ef90d36d518fa4cbc7c4da379daa4d43aacc4cdf68907781af4d4ee397d2f1055b1c33

doc/src/uspf.unix/uspf_unix.ml.html

Source file uspf_unix.ml

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
module Unix_scheduler = Uspf.Sigs.Make (struct
  type 'a t = 'a
end)

let state =
  let open Uspf.Sigs in
  let open Unix_scheduler in
  { return = (fun x -> inj x); bind = (fun x f -> f (prj x)) }

module DNS = struct
  type t = Dns_client_unix.t
  and backend = Unix_scheduler.t

  and error =
    [ `Msg of string
    | `No_data of [ `raw ] Domain_name.t * Dns.Soa.t
    | `No_domain of [ `raw ] Domain_name.t * Dns.Soa.t ]

  let getrrecord dns response domain_name =
    Unix_scheduler.inj
    @@ Dns_client_unix.get_resource_record dns response domain_name
end

module Flow = struct
  type flow = in_channel
  and backend = Unix_scheduler.t

  let input ic tmp off len = Unix_scheduler.inj @@ input ic tmp off len
end

let ( >>| ) x f = Result.map f x

let check ?nameservers ~timeout ctx =
  let dns = Dns_client_unix.create ?nameservers ~timeout () in
  Uspf.get ~ctx state dns (module DNS) |> Unix_scheduler.prj >>| fun record ->
  Uspf.check ~ctx state dns (module DNS) record |> Unix_scheduler.prj

let extract_received_spf ?newline ic =
  Uspf.extract_received_spf ?newline ic state (module Flow)
  |> Unix_scheduler.prj
OCaml

Innovation. Community. Security.