Changeset View
Changeset View
Standalone View
Standalone View
apps/kolab_guam/src/rules/kolab_guam_rule_filter_groupware.erl
Show All 25 Lines | |||||
applies(_ConnectionDetails, Buffer, State) -> | applies(_ConnectionDetails, Buffer, State) -> | ||||
{ _Tag, Command, Data } = eimap_utils:split_command_into_components(Buffer), | { _Tag, Command, Data } = eimap_utils:split_command_into_components(Buffer), | ||||
%lager:debug("********** Checking ...~n Command: ~s ~s", [Command, Data]), | %lager:debug("********** Checking ...~n Command: ~s ~s", [Command, Data]), | ||||
{ apply_if_id_matches(Command, Data), State }. | { apply_if_id_matches(Command, Data), State }. | ||||
apply_to_client_message(ImapSession, Buffer, State) -> | apply_to_client_message(ImapSession, Buffer, State) -> | ||||
{ Tag, Command, Data } = eimap_utils:split_command_into_components(Buffer), | { Tag, Command, Data } = eimap_utils:split_command_into_components(Buffer), | ||||
{ Active, StateTag }= | { Active, StateTag }= | ||||
if Command =:= <<"LIST">>; Command =:= <<"list">>; Command =:= <<"XLIST">>; Command =:= <<"xlist">> -> | if Command =:= <<"LIST">>; | ||||
case binary:match(Data, <<"\"*\"">>) of | Command =:= <<"list">>; | ||||
Command =:= <<"XLIST">>; | |||||
Command =:= <<"xlist">>; | |||||
Command =:= <<"LSUB">>; | |||||
Command =:= <<"lsub">> -> | |||||
case binary:match(Data, <<"*">>) of | |||||
nomatch -> { false, <<>> }; | nomatch -> { false, <<>> }; | ||||
_ -> | _ -> | ||||
fetch_metadata(ImapSession, State), | fetch_metadata(ImapSession, State), | ||||
{ true, Tag } | { true, Tag } | ||||
end; | end; | ||||
true -> { false, <<>> } | true -> { false, <<>> } | ||||
end, | end, | ||||
%lager:info("Client sent: ~s ~s ~p", [Command, Data, Active]), | %lager:info("Client sent: ~s ~s ~p", [Command, Data, Active]), | ||||
Show All 16 Lines | |||||
fetch_metadata(ImapSession, #state{ blacklist = undefined }) -> | fetch_metadata(ImapSession, #state{ blacklist = undefined }) -> | ||||
eimap:get_folder_metadata(ImapSession, self(), { rule_data, ?MODULE, blacklist }, "*", ["/shared/vendor/kolab/folder-type"]); | eimap:get_folder_metadata(ImapSession, self(), { rule_data, ?MODULE, blacklist }, "*", ["/shared/vendor/kolab/folder-type"]); | ||||
fetch_metadata(_ImapSession, _State) -> ok. | fetch_metadata(_ImapSession, _State) -> ok. | ||||
apply_if_id_matches(<<"LIST">>, _Data) -> | apply_if_id_matches(<<"LIST">>, _Data) -> | ||||
true; | true; | ||||
apply_if_id_matches(<<"XLIST">>, _Data) -> | apply_if_id_matches(<<"XLIST">>, _Data) -> | ||||
true; | true; | ||||
apply_if_id_matches(<<"LSUB">>, _Data) -> | |||||
true; | |||||
apply_if_id_matches(<<"list">>, _Data) -> | apply_if_id_matches(<<"list">>, _Data) -> | ||||
true; | true; | ||||
apply_if_id_matches(<<"xlist">>, _Data) -> | apply_if_id_matches(<<"xlist">>, _Data) -> | ||||
true; | true; | ||||
apply_if_id_matches(<<"lsub">>, _Data) -> | |||||
true; | |||||
apply_if_id_matches(<<"ID">>, Data) -> | apply_if_id_matches(<<"ID">>, Data) -> | ||||
apply_if_found_kolab(binary:match(Data, <<"/Kolab">>)); | apply_if_found_kolab(binary:match(Data, <<"/Kolab">>)); | ||||
apply_if_id_matches(_Command, _Data) -> notyet. | apply_if_id_matches(_Command, _Data) -> notyet. | ||||
apply_if_found_kolab(nomatch) -> true; | apply_if_found_kolab(nomatch) -> true; | ||||
apply_if_found_kolab(_) -> false. | apply_if_found_kolab(_) -> false. | ||||
filter_folders(<<>>, State) -> | filter_folders(<<>>, State) -> | ||||
{ <<>>, State#state{ active = true } }; | { <<>>, State#state{ active = true } }; | ||||
filter_folders(Buffer, #state{ last_chunk = LeftOvers } = State) -> | filter_folders(Buffer, #state{ last_chunk = LeftOvers } = State) -> | ||||
FullBuffer = <<LeftOvers/binary, Buffer/binary>>, | FullBuffer = <<LeftOvers/binary, Buffer/binary>>, | ||||
{ FullLinesBuffer, LastChunk } = eimap_utils:only_full_lines(FullBuffer), | { FullLinesBuffer, LastChunk } = eimap_utils:only_full_lines(FullBuffer), | ||||
ListResponses = binary:split(FullLinesBuffer, <<"\r\n">>, [ global ]), | ListResponses = binary:split(FullLinesBuffer, <<"\r\n">>, [ global ]), | ||||
{ Response, More } = filter_folders(State, ListResponses, { <<>>, true }), | { Response, More } = filter_folders(State, ListResponses, { <<>>, true }), | ||||
%io:format("Filtered ... ~p~n", [Response]), | %io:format("Filtered ... ~p~n", [Response]), | ||||
{ <<Response/binary, "\r\n">>, State#state { active = More, last_chunk = LastChunk } }. | { <<Response/binary, "\r\n">>, State#state { active = More, last_chunk = LastChunk } }. | ||||
filter_folders(_State, [], Return) -> Return; | filter_folders(_State, [], Return) -> Return; | ||||
filter_folders(_State, _Folders, { Acc, false }) -> { Acc, false }; | filter_folders(_State, _Folders, { Acc, false }) -> { Acc, false }; | ||||
filter_folders(State, [Unfiltered|Folders], { Acc, _More }) -> filter_folders(State, Folders, filter_folder(State, Unfiltered, Acc)). | filter_folders(State, [Unfiltered|Folders], { Acc, _More }) -> filter_folders(State, Folders, filter_folder(State, Unfiltered, Acc)). | ||||
filter_folder(_State, <<>>, Acc) -> { Acc, true }; | filter_folder(_State, <<>>, Acc) -> { Acc, true }; | ||||
filter_folder(State, <<"* LIST ", Details/binary>> = Response, Acc) -> { filter_on_details(State, Response, Acc, Details), true }; | filter_folder(State, <<"* LIST ", Details/binary>> = Response, Acc) -> { filter_on_details(State, Response, Acc, Details), true }; | ||||
filter_folder(State, <<"* XLIST ", Details/binary>> = Response, Acc) -> { filter_on_details(State, Response, Acc, Details), true }; | filter_folder(State, <<"* XLIST ", Details/binary>> = Response, Acc) -> { filter_on_details(State, Response, Acc, Details), true }; | ||||
filter_folder(State, <<"* LSUB ", Details/binary>> = Response, Acc) -> { filter_on_details(State, Response, Acc, Details), true }; | |||||
filter_folder(#state{ tag = Tag }, Response, Acc) -> | filter_folder(#state{ tag = Tag }, Response, Acc) -> | ||||
HasMore = | HasMore = | ||||
case byte_size(Tag) =< byte_size(Response) of | case byte_size(Tag) =< byte_size(Response) of | ||||
true -> | true -> | ||||
case binary:match(Response, Tag, [{ scope, { 0, byte_size(Tag) } }]) of | case binary:match(Response, Tag, [{ scope, { 0, byte_size(Tag) } }]) of | ||||
nomatch -> true; | nomatch -> true; | ||||
_ -> false % we have found our closing tag! | _ -> false % we have found our closing tag! | ||||
end; | end; | ||||
Show All 36 Lines |