diff --git a/apps/kolab_guam/src/rules/kolab_guam_rule_filter_groupware.erl b/apps/kolab_guam/src/rules/kolab_guam_rule_filter_groupware.erl --- a/apps/kolab_guam/src/rules/kolab_guam_rule_filter_groupware.erl +++ b/apps/kolab_guam/src/rules/kolab_guam_rule_filter_groupware.erl @@ -77,15 +77,22 @@ apply_if_found_kolab(0) -> true; apply_if_found_kolab(_) -> false. +possibly_append_newline(<<>>) -> <<>> ; +possibly_append_newline(Response) -> <> . + filter_folders(<<>>, State) -> { <<>>, State#state{ active = true } }; filter_folders(Buffer, #state{ last_chunk = LeftOvers } = State) -> + % Add the left overs from the previous buffer to the current buffer FullBuffer = <>, + % From that buffer, only take the complete lines and save off the remainder. { FullLinesBuffer, LastChunk } = eimap_utils:only_full_lines(FullBuffer), + % Create a list so we can filter the individual folders ListResponses = binary:split(FullLinesBuffer, <<"\r\n">>, [ global ]), { Response, More } = filter_folders(State, ListResponses, { <<>>, true }), %io:format("Filtered ... ~p~n", [Response]), - { <>, State#state { active = More, last_chunk = LastChunk } }. + %Note that the last list item does not contain \r\n, so that needs to be added unless we filtered the complete content. + { possibly_append_newline(Response), State#state { active = More, last_chunk = LastChunk } }. filter_folders(_State, [], Return) -> Return; filter_folders(_State, _Folders, { Acc, false }) -> { Acc, false }; diff --git a/apps/kolab_guam/test/kolab_guam_rules_SUITE.erl b/apps/kolab_guam/test/kolab_guam_rules_SUITE.erl --- a/apps/kolab_guam/test/kolab_guam_rules_SUITE.erl +++ b/apps/kolab_guam/test/kolab_guam_rules_SUITE.erl @@ -113,6 +113,17 @@ <<"\"/\" Notes\r\n* LIST (\\Subscribed) \"/\" Sent\r\n* LIST (\\Subscribed) \"/\" Spam\r\n* LIST (\\Subscribed) \"/\" Tasks\r\n* LIST (\\Subscribed) \"/\" Trash\r\n7 OK Completed (0.000 secs 15 calls)\r\n">> ], <<"* LIST (\\Noinferiors \\Subscribed) \"/\" INBOX\r\n* LIST (\\Subscribed) \"/\" Archive\r\n* LIST (\\Subscribed) \"/\" Drafts\r\n* LIST (\\Subscribed) \"/\" Sent\r\n* LIST (\\Subscribed) \"/\" Spam\r\n* LIST (\\Subscribed) \"/\" Trash\r\n7 OK Completed (0.000 secs 15 calls)\r\n">> + }, + %Filter complete packet + { + [ + {<<"Calendar">>, <<"Calendar/">>} + ], + [ + <<"* LIST (\\Subscribed \\HasChildren) \"/\" Calendar\r\n">>, + <<"7 OK Completed (0.000 secs 15 calls)\r\n">> + ], + <<"7 OK Completed (0.000 secs 15 calls)\r\n">> } ], %% setup boilerplate