Projects
Kolab:16:Enterprise
erlang-eimap
untagged-commands.patch
Log In
Username
Password
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File untagged-commands.patch of Package erlang-eimap (Revision 14)
Currently displaying revision
14
,
Show latest
diff --git a/src/eimap_utils.erl b/src/eimap_utils.erl index 163229b..230ab60 100644 --- a/src/eimap_utils.erl +++ b/src/eimap_utils.erl @@ -156,14 +156,20 @@ remove_tag_from_response(Buffer, Tag, trust) -> %% Private split_command(<<>>) -> { <<>>, <<>>, <<>> }; split_command(Buffer) -> - End = eol_found(Buffer, binary:match(Buffer, <<"\r\n">>)), + {Terminated, End} = eol_found(Buffer, binary:match(Buffer, <<"\r\n">>)), { Tag, CommandStart } = searched_in_buffer(Buffer, 0, End, binary:match(Buffer, <<" ">>, [ { scope, { 0, End } } ])), - { Command, DataStart } = searched_in_buffer(Buffer, CommandStart, End, binary:match(Buffer, <<" ">>, [ { scope, { CommandStart, End - CommandStart } } ])), - Data = binary:part(Buffer, DataStart, End - (DataStart)), - { Tag, Command, Data }. + case Terminated of + true when End == CommandStart -> + %% when we have a newline, and the tag takes the entire line, the "tag" is actually the command + {<<>>, Tag, <<>>}; + _ -> + { Command, DataStart } = searched_in_buffer(Buffer, CommandStart, End, binary:match(Buffer, <<" ">>, [ { scope, { CommandStart, End - CommandStart } } ])), + Data = binary:part(Buffer, DataStart, End - (DataStart)), + { Tag, Command, Data } + end. -eol_found(Buffer, nomatch) -> size(Buffer); -eol_found(_Buffer, { MatchStart, _MatchLength }) -> MatchStart. +eol_found(Buffer, nomatch) -> {false, size(Buffer)}; +eol_found(_Buffer, { MatchStart, _MatchLength }) -> {true, MatchStart}. searched_in_buffer(Buffer, Start, End, nomatch) -> { binary:part(Buffer, Start, End - Start), End }; searched_in_buffer(Buffer, Start, _End, { MatchStart, MatchLength } ) -> { binary:part(Buffer, Start, MatchStart - Start), MatchStart + MatchLength }. diff --git a/test/eimap_utils_tests.erl b/test/eimap_utils_tests.erl index 389be6f..81631c1 100644 --- a/test/eimap_utils_tests.erl +++ b/test/eimap_utils_tests.erl @@ -79,6 +79,7 @@ split_command_into_components_test_() -> Data = [ { { <<>>, <<>>, <<>> }, <<>> }, + { { <<>>, <<"DONE">>, <<>> }, <<"DONE\r\n">> }, { { <<".">>, <<"LIST">>, <<"\"\" \"*\"">> }, <<". LIST \"\" \"*\"">> }, { { <<"1">>, <<"STARTTLS">>, <<>> }, <<"1 STARTTLS">> }, { { <<"1">>, <<"STARTTLS">>, <<>> }, <<"1 STARTTLS\r\n">> },
Locations
Projects
Search
Status Monitor
Help
Open Build Service
OBS Manuals
API Documentation
OBS Portal
Reporting a Bug
Contact
Mailing List
Forums
Chat (IRC)
Twitter
Open Build Service (OBS)
is an
openSUSE project
.