diff --git a/apps/kolab_guam/src/kolab_guam_session.erl b/apps/kolab_guam/src/kolab_guam_session.erl --- a/apps/kolab_guam/src/kolab_guam_session.erl +++ b/apps/kolab_guam/src/kolab_guam_session.erl @@ -175,36 +175,6 @@ close_socket(_ImplicitTLS, _TLS, Socket) -> gen_tcp:close(Socket). -apply_rules(ImapSession, Socket, PreprocessData, CurrentCommandSplit, UndecidedRules, ActiveRules) -> - { ModifiedData, NewSplitCommand, NewSplitResetTrigger, NewUndecidedRules, NewActiveRules, PostAction } = apply_ruleset_clientside(ImapSession, Socket, PreprocessData, CurrentCommandSplit, UndecidedRules, ActiveRules), - BufferThisData = - case PostAction of - perform_passthrough -> - eimap:passthrough_data(ImapSession, ModifiedData), - <<>>; - buffer_data -> - % Originally Aaron uses Data here, but later on this buffer is assumed to be - % already decoded, so we do have to use PreprocessData here, I think. - case binary:matches(PreprocessData, <<"\r\n">>) of - [] -> - lager:info("buffering: ~s", [PreprocessData]), - PreprocessData; - List -> - {FoundPos, _} = lists:last(List), - % I would like to have some binary:match for the last instead of the - % first occurrence; but I'm really inexperienced in erlang so I don't - % know how to solve this efficiently, so I'm using binary:matches with - % using the last element only - SplitPos = FoundPos + 2, - eimap:passthrough_data(ImapSession, binary:part(PreprocessData, 0, SplitPos)), - lager:info("sending first part: ~s", [binary:part(PreprocessData, 0, SplitPos)] ), - lager:info("buffering second part: ~s", [binary:part(PreprocessData, SplitPos, size(PreprocessData)-SplitPos)]), - binary:part(PreprocessData, SplitPos, size(PreprocessData)-SplitPos) - end - end, - { NewUndecidedRules, NewActiveRules, BufferThisData, NewSplitCommand, NewSplitResetTrigger }. - - read_line(Data) -> case binary:match(Data, <<"\r\n">>) of nomatch -> @@ -253,8 +223,15 @@ eimap:compress(ImapSession), % TODO: make optional { TLS, Socket, NewInflator, NewDeflator, UndecidedRules, ActiveRules, <<>>, undefined, undefined }; nochange -> - { NewUndecidedRules, NewActiveRules, BufferThisData, NewSplitCommand, NewSplitResetTrigger } = - apply_rules(ImapSession, Socket, Data, CurrentCommandSplit, UndecidedRules, ActiveRules), + { ModifiedData, NewSplitCommand, NewSplitResetTrigger, NewUndecidedRules, NewActiveRules, PostAction } = apply_ruleset_clientside(ImapSession, Socket, Data, CurrentCommandSplit, UndecidedRules, ActiveRules), + BufferThisData = + case PostAction of + perform_passthrough -> + eimap:passthrough_data(ImapSession, ModifiedData), + <<>>; + buffer_data -> + Data + end, { TLS, Socket, Inflator, Deflator, NewUndecidedRules, NewActiveRules, BufferThisData, NewSplitCommand, NewSplitResetTrigger } end, set_socket_active(TLSActive, CurrentSocket),