-module(gleambox). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([get_body/1, get_headers/1]). -spec get_body(binary()) -> binary(). get_body(Mboxcontents) -> _pipe = Mboxcontents, _pipe@1 = gleam@string:split_once(_pipe, <<"\n\n"/utf8>>), _pipe@2 = gleam@result:unwrap(_pipe@1, {<<""/utf8>>, <<""/utf8>>}), gleam@pair:second(_pipe@2). -spec get_header_dict(binary()) -> {binary(), binary()}. get_header_dict(S) -> _pipe = S, _pipe@1 = gleam@string:split_once(_pipe, <<": "/utf8>>), gleam@result:unwrap(_pipe@1, {<<""/utf8>>, <<""/utf8>>}). -spec remove_dead_space(binary(), binary()) -> binary(). remove_dead_space(Acc, Matched_content) -> _assert_subject = gleam@regex:from_string(<<"\\s+"/utf8>>), {ok, Dead_space} = case _assert_subject of {ok, _} -> _assert_subject; _assert_fail -> erlang:error(#{gleam_error => let_assert, message => <<"Assertion pattern match failed"/utf8>>, value => _assert_fail, module => <<"gleambox"/utf8>>, function => <<"remove_dead_space"/utf8>>, line => 51}) end, _pipe = Matched_content, _pipe@1 = gleam@regex:split(Dead_space, _pipe), _pipe@2 = gleam@string:join(_pipe@1, <<" "/utf8>>), gleam@string:replace(Acc, Matched_content, _pipe@2). -spec fix_multiline_values(binary()) -> binary(). fix_multiline_values(S) -> _assert_subject = gleam@regex:compile( <<": [^\n]+\n\\s+[^\n]+$"/utf8>>, {options, true, true} ), {ok, Multi_line_value} = case _assert_subject of {ok, _} -> _assert_subject; _assert_fail -> erlang:error(#{gleam_error => let_assert, message => <<"Assertion pattern match failed"/utf8>>, value => _assert_fail, module => <<"gleambox"/utf8>>, function => <<"fix_multiline_values"/utf8>>, line => 39}) end, _pipe = S, _pipe@1 = gleam@regex:scan(Multi_line_value, _pipe), _pipe@2 = gleam@list:map( _pipe@1, fun(Match) -> erlang:element(2, Match) end ), _pipe@3 = gleam@list:scan(_pipe@2, S, fun remove_dead_space/2), _pipe@4 = gleam@list:first(_pipe@3), gleam@result:unwrap(_pipe@4, <<"bar"/utf8>>). -spec get_headers(binary()) -> gleam@dict:dict(binary(), binary()). get_headers(Mboxcontents) -> _pipe = Mboxcontents, _pipe@1 = gleam@string:split_once(_pipe, <<"\n\n"/utf8>>), _pipe@2 = gleam@result:unwrap(_pipe@1, {<<""/utf8>>, <<""/utf8>>}), _pipe@3 = gleam@pair:first(_pipe@2), _pipe@4 = fix_multiline_values(_pipe@3), _pipe@5 = gleam@string:split(_pipe@4, <<"\n"/utf8>>), _pipe@6 = gleam@list:map(_pipe@5, fun get_header_dict/1), maps:from_list(_pipe@6).