Changeset View
Changeset View
Standalone View
Standalone View
src/eimap_utils.erl
Show All 18 Lines | |||||
-export([ | -export([ | ||||
extract_path_from_uri/3, extract_uidset_from_uri/1, | extract_path_from_uri/3, extract_uidset_from_uri/1, | ||||
split_command_into_components/1, is_tagged_response/2, remove_tag_from_response/3, | split_command_into_components/1, is_tagged_response/2, remove_tag_from_response/3, | ||||
header_name/1, parse_flags/1, | header_name/1, parse_flags/1, | ||||
check_response_for_failure/2, | check_response_for_failure/2, | ||||
ensure_binary/1, | ensure_binary/1, | ||||
new_imap_compressors/0, | new_imap_compressors/0, | ||||
only_full_lines/1, | only_full_lines/1, | ||||
binary_to_atom/1 | binary_to_atom/1, | ||||
num_literal_continuation_bytes/1 | |||||
]). | ]). | ||||
%% Translate the folder name in to a fully qualified folder path such as it | %% Translate the folder name in to a fully qualified folder path such as it | ||||
%% would be used by a cyrus administrator. | %% would be used by a cyrus administrator. | ||||
-spec extract_path_from_uri(SharedPrefix :: binary(), HierarchyDelim :: binary, URI :: binary()) -> Path :: binary() | bad_uri. | -spec extract_path_from_uri(SharedPrefix :: binary(), HierarchyDelim :: binary, URI :: binary()) -> Path :: binary() | bad_uri. | ||||
extract_path_from_uri(SharedPrefix, HierarchyDelim, URI) when is_binary(URI) -> | extract_path_from_uri(SharedPrefix, HierarchyDelim, URI) when is_binary(URI) -> | ||||
extract_path_from_uri(SharedPrefix, HierarchyDelim, binary_to_list(URI)); | extract_path_from_uri(SharedPrefix, HierarchyDelim, binary_to_list(URI)); | ||||
extract_path_from_uri(SharedPrefix, HierarchyDelim, URI) when is_list(URI) -> | extract_path_from_uri(SharedPrefix, HierarchyDelim, URI) when is_list(URI) -> | ||||
▲ Show 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | case NoTokenLength > byte_size(Data) of | ||||
true -> ok; | true -> ok; | ||||
false -> is_no_token_found(Data, Tag, binary:match(Data, NoToken, [ { scope, { 0, NoTokenLength } } ])) | false -> is_no_token_found(Data, Tag, binary:match(Data, NoToken, [ { scope, { 0, NoTokenLength } } ])) | ||||
end. | end. | ||||
-spec split_command_into_components(Buffer :: binary()) -> { Tag :: binary(), Command :: binary(), Data :: binary() }. | -spec split_command_into_components(Buffer :: binary()) -> { Tag :: binary(), Command :: binary(), Data :: binary() }. | ||||
split_command_into_components(Buffer) when is_binary(Buffer) -> | split_command_into_components(Buffer) when is_binary(Buffer) -> | ||||
split_command(Buffer). | split_command(Buffer). | ||||
-spec is_tagged_response(Buffer :: binary(), Tag :: binary()) -> true | false. | -spec is_tagged_response(Buffer :: binary(), Tag :: binary()) -> tagged | untagged. | ||||
is_tagged_response(Buffer, Tag) -> | is_tagged_response(Buffer, Tag) -> | ||||
TagSize = size(Tag) + 1, % The extra char is a space | TagSize = size(Tag) + 1, % The extra char is a space | ||||
BufferSize = size(Buffer), | BufferSize = size(Buffer), | ||||
case | |||||
case (TagSize =< BufferSize) of | case (TagSize =< BufferSize) of | ||||
true -> <<Tag/binary, " ">> =:= binary:part(Buffer, 0, TagSize); | true -> <<Tag/binary, " ">> =:= binary:part(Buffer, 0, TagSize); | ||||
false -> false | _ -> false | ||||
end of | |||||
true -> tagged; | |||||
_ -> untagged | |||||
end. | |||||
-spec num_literal_continuation_bytes(Buffer :: binary()) -> { BufferSansContinuation :: binary(), NumberBytes :: integer() }. | |||||
num_literal_continuation_bytes(Buffer) when size(Buffer) < 4 -> | |||||
{ Buffer, 0 }; | |||||
num_literal_continuation_bytes(Buffer) -> | |||||
case binary:last(Buffer) =:= $} of | |||||
true -> number_of_bytes_in_continuation(Buffer); | |||||
false -> { Buffer, 0 } | |||||
end. | |||||
number_of_bytes_in_continuation(Buffer) -> | |||||
BufferSize = size(Buffer), | |||||
OpenBracePos = find_continuation_open_brace(Buffer, BufferSize - 3), | |||||
confirm_continuation(Buffer, OpenBracePos). | |||||
find_continuation_open_brace(_Buffer, 0) -> -1; | |||||
find_continuation_open_brace(Buffer, Pos) -> | |||||
case binary:at(Buffer, Pos) of | |||||
${ -> Pos; | |||||
_ -> find_continuation_open_brace(Buffer, Pos - 1) | |||||
end. | |||||
confirm_continuation(Buffer, -1) -> | |||||
{ Buffer, 0 }; | |||||
confirm_continuation(Buffer, OpenBracePos) -> | |||||
BufferSize = size(Buffer), | |||||
try binary_to_integer(binary:part(Buffer, OpenBracePos + 1, BufferSize - OpenBracePos - 2)) of | |||||
Result -> { binary:part(Buffer, 0, OpenBracePos), Result } | |||||
catch | |||||
_:_ -> { Buffer, 0 } | |||||
end. | end. | ||||
-spec remove_tag_from_response(Buffer :: binary(), Tag :: undefine | binary(), Check :: check | trust) -> Command :: binary(). | -spec remove_tag_from_response(Buffer :: binary(), Tag :: undefine | binary(), Check :: check | trust) -> Command :: binary(). | ||||
remove_tag_from_response(Buffer, undefined, _) -> | remove_tag_from_response(Buffer, undefined, _) -> | ||||
Buffer; | Buffer; | ||||
remove_tag_from_response(Buffer, <<>>, _) -> | remove_tag_from_response(Buffer, <<>>, _) -> | ||||
Buffer; | Buffer; | ||||
remove_tag_from_response(Buffer, Tag, check) -> | remove_tag_from_response(Buffer, Tag, check) -> | ||||
▲ Show 20 Lines • Show All 109 Lines • Show Last 20 Lines |