Changeset View
Changeset View
Standalone View
Standalone View
src/commands/eimap_command_getmetadata.erl
Show All 20 Lines | |||||
%% http://tools.ietf.org/html/rfc2342 | %% http://tools.ietf.org/html/rfc2342 | ||||
%% Public API | %% Public API | ||||
new_command({ Folder }) -> new_command({ Folder, [] }); | new_command({ Folder }) -> new_command({ Folder, [] }); | ||||
new_command({ Folder, Attributes }) when is_list(Folder) -> new_command({ list_to_binary(Folder), Attributes }); | new_command({ Folder, Attributes }) when is_list(Folder) -> new_command({ list_to_binary(Folder), Attributes }); | ||||
new_command({ Folder, Attributes }) -> new_command({ Folder, Attributes, infinity, nomax }); | new_command({ Folder, Attributes }) -> new_command({ Folder, Attributes, infinity, nomax }); | ||||
new_command({ Folder, Attributes, Depth, MaxSize }) -> | new_command({ Folder, Attributes, Depth, MaxSize }) -> | ||||
AttributesString = format_attributes(Attributes, <<>>), | AttributesString = format_attributes(Attributes, <<>>), | ||||
vanmeeuwen: Please copy/paste, omit MaxSize as a parameter, yet be all kitty-like and land on 3-4 feet.
Or… | |||||
DepthString = depth_param(Depth), | DepthString = depth_param(Depth), | ||||
MaxSizeString = maxsize_param(MaxSize), | MaxSizeString = maxsize_param(MaxSize), | ||||
Command = metadata_comand(DepthString, MaxSizeString, Folder, AttributesString), | Command = metadata_command(DepthString, MaxSizeString, Folder, AttributesString), | ||||
{ Command, multiline_response }. | { Command, multiline_response }. | ||||
process_line(<<"* METADATA ", Details/binary>>, Acc) -> | process_line(<<"* METADATA ", Details/binary>>, Acc) -> | ||||
Results = parse_folder(Details), | Results = parse_folder(Details), | ||||
[Results|Acc]; | [Results|Acc]; | ||||
process_line(_Line, Acc) -> Acc. | process_line(_Line, Acc) -> Acc. | ||||
formulate_response(Result, Data) -> eimap_command:formulate_response(Result, Data). | formulate_response(Result, Data) -> eimap_command:formulate_response(Result, Data). | ||||
%% Private API | %% Private API | ||||
depth_param(infinity) -> <<"DEPTH infinity">>; | depth_param(infinity) -> <<"DEPTH infinity">>; | ||||
depth_param(Depth) when is_integer(Depth) -> Bin = integer_to_binary(Depth), <<"DEPTH ", Bin/binary>>; | depth_param(Depth) when is_integer(Depth) -> Bin = integer_to_binary(Depth), <<"DEPTH ", Bin/binary>>; | ||||
depth_param(_) -> <<>>. | depth_param(_) -> <<>>. | ||||
maxsize_param(Size) when is_integer(Size) -> Bin = integer_to_binary(Size), <<"MAXSIZE ", Bin/binary>>; | maxsize_param(Size) when is_integer(Size) -> Bin = integer_to_binary(Size), <<"MAXSIZE ", Bin/binary>>; | ||||
maxsize_param(_) -> <<>>. | maxsize_param(_) -> <<>>. | ||||
metadata_comand(<<>>, <<>>, Folder, Attributes) -> <<"GETMETADATA \"", Folder/binary, "\"", Attributes/binary>>; | metadata_command(<<>>, <<>>, Folder, Attributes) -> <<"GETMETADATA \"", Folder/binary, "\"", Attributes/binary>>; | ||||
metadata_comand(Depth, <<>>, Folder, Attributes) -> <<"GETMETADATA (", Depth/binary, ") \"", Folder/binary, "\"", Attributes/binary>>; | metadata_command(Depth, <<>>, Folder, Attributes) -> <<"GETMETADATA (", Depth/binary, ") \"", Folder/binary, "\"", Attributes/binary>>; | ||||
metadata_comand(<<>>, MaxSize, Folder, Attributes) -> <<"GETMETADATA (", MaxSize/binary, ") \"", Folder/binary, "\"", Attributes/binary>>; | metadata_command(<<>>, MaxSize, Folder, Attributes) -> <<"GETMETADATA (", MaxSize/binary, ") \"", Folder/binary, "\"", Attributes/binary>>; | ||||
metadata_comand(Depth, MaxSize, Folder, Attributes) -> <<"GETMETADATA (", Depth/binary, " ", MaxSize/binary, ") \"", Folder/binary, "\"", Attributes/binary>>. | metadata_command(Depth, MaxSize, Folder, Attributes) -> <<"GETMETADATA (", Depth/binary, " ", MaxSize/binary, ") \"", Folder/binary, "\"", Attributes/binary>>. | ||||
format_attributes([], <<>>) -> <<>>; | format_attributes([], <<>>) -> <<>>; | ||||
format_attributes([], String) -> <<" (", String/binary, ")">>; | format_attributes([], String) -> <<" (", String/binary, ")">>; | ||||
format_attributes([Attribute|Attributes], String) -> | format_attributes([Attribute|Attributes], String) -> | ||||
AttrBin = case is_list(Attribute) of | AttrBin = case is_list(Attribute) of | ||||
true -> list_to_binary(Attribute); | true -> list_to_binary(Attribute); | ||||
false -> Attribute | false -> Attribute | ||||
end, | end, | ||||
▲ Show 20 Lines • Show All 52 Lines • Show Last 20 Lines |
Please copy/paste, omit MaxSize as a parameter, yet be all kitty-like and land on 3-4 feet.
Or, ...
insert a comment about handling this yay way rather than other way in comparison with, for example, Cyrus IMAP.