3 * _| || |_/ ___| ___ _ __ _ __ ___ | |
4 * |_ .. _\___ \ / _ \ '_ \| '_ \ / _ \| |
5 * |_ _|___) | __/ |_) | |_) | (_) |_|
6 * |_||_| |____/ \___| .__/| .__/ \___/(_)
11 * Copyright (C) The #Seppo contributors. All rights reserved.
13 * This program is free software: you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation, either version 3 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
27 (* https://datatracker.ietf.org/doc/html/rfc7565 *)
33 assert ("acct" |> String.equal
scheme);
54 let make ~local ~domain
() =
62 Printf.sprintf
"%s @%s@%s" __LOC__ local domain
66 let rx_scheme = scheme ^
{|:\
|@|}
67 let rx_user = {|[^
@: ]+|}
68 let rx_host = {|[^
:/\?#
]+|}
69 let rx'
= {|^\
(|} ^
rx_scheme ^
{|\
)?\
(|} ^
rx_user ^
{|\
)@\
(|} ^
rx_host ^
{|\
)$
|}
70 let rx = rx'
|> Str.regexp
73 if not
(Str.string_match
rx s
0)
74 then Error
("doesn't match /" ^
rx' ^
"/")
77 ~local
:(Str.matched_group
2 s
)
78 ~domain
:(Str.matched_group
3 s
)
81 let to_string ?
(prefix
= scheme ^
":") (T u
) =
82 Printf.sprintf
"%s%s@%s"
84 (u
|> Uri.user
|> Option.value ~default
:"")
85 (u
|> Uri.host
|> Option.value ~default
:"")
87 let pp_hum ppf uri
= Format.pp_print_string ppf
(to_string ~prefix
:"@" uri
)