package email_message

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file rfc.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
open Core

(*
   module RFC2822 = struct
   let unfold str =
   let lexbuf = Lexing.from_string str in
   let bigbuffer = Bigbuffer.create (String.length str) in
   Lexer.field_unstructured_unfold bigbuffer lexbuf;
   Bigbuffer.contents bigbuffer
   ;;

   let fold str =
   let lexbuf = Lexing.from_string str in
   let bigbuffer = Bigbuffer.create (String.length str) in
   Lexer.field_unstructured_fold bigbuffer lexbuf;
   Bigbuffer.contents bigbuffer
   ;;

   TEST_MODULE "Folding_and_unfolding" = struct
   TEST = (fold "a\n b\nc") = " a\n b\n c"
   TEST = (fold " a\n b\nc") = " a\n b\n c"
   TEST = (fold "\ta\n b\nc") = "\ta\n b\n c"
   TEST = (unfold " a\n b\nc d") = "a b c d"
   end
   end
*)

module RFC2045 = struct
  module Token = struct
    include (Mimestring.Case_insensitive : Mimestring.S)

    let is_valid str =
      not (String.is_empty str)
      && String.for_all str ~f:(function
        | '('
        | ')'
        | '<'
        | '>'
        | '@'
        | ','
        | ';'
        | ':'
        | '\\'
        | '"'
        | '/'
        | '['
        | ']'
        | '?'
        | '=' -> false
        (* '\n', '\r', ' ' are excluded by the following: *)
        | '\033' .. '\126' -> true
        | _ -> false)
    ;;

    let is_valid_or_quote str = if is_valid str then str else Mimestring.quote str
  end
end