Merge pull request #1939 from k9mail/GH-1936_add_support_for_delimiter_value_nil

Add support for delimiter value NIL in LIST responses
This commit is contained in:
cketti 2017-01-04 07:31:00 +01:00 committed by GitHub
commit b7adc5e574
4 changed files with 38 additions and 5 deletions

View file

@ -194,8 +194,7 @@ class ImapResponseParser {
expect(' ');
parseList(response, '(', ')');
expect(' ');
//TODO: Add support for NIL
String delimiter = parseQuoted();
String delimiter = parseQuotedOrNil();
response.add(delimiter);
expect(' ');
String name = parseString();
@ -418,6 +417,22 @@ class ImapResponseParser {
throw new IOException("parseQuoted(): end of stream reached");
}
private String parseQuotedOrNil() throws IOException {
int peek = inputStream.peek();
if (peek == '"') {
return parseQuoted();
} else {
parseNil();
return null;
}
}
private void parseNil() throws IOException {
expect('N');
expect('I');
expect('L');
}
private String readStringUntil(char end) throws IOException {
StringBuilder sb = new StringBuilder();

View file

@ -5,6 +5,8 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import android.support.annotation.Nullable;
import static com.fsck.k9.mail.store.imap.ImapResponseParser.equalsIgnoreCase;
class ListResponse {
@ -52,9 +54,8 @@ class ListResponse {
return null;
}
//TODO: Add support for NIL. Needs modifications in ImapResponseParser
String hierarchyDelimiter = response.getString(2);
if (hierarchyDelimiter.length() != 1) {
if (hierarchyDelimiter != null && hierarchyDelimiter.length() != 1) {
return null;
}
@ -93,6 +94,7 @@ class ListResponse {
return false;
}
@Nullable
public String getHierarchyDelimiter() {
return hierarchyDelimiter;
}

View file

@ -397,6 +397,20 @@ public class ImapResponseParserTest {
assertEquals("TAG", responseTwo.getTag());
}
@Test
public void readResponse_withListResponseContainingNil() throws Exception {
ImapResponseParser parser = createParser("* LIST (\\NoInferiors) NIL INBOX\r\n");
ImapResponse response = parser.readResponse();
assertEquals(4, response.size());
assertEquals("LIST", response.get(0));
assertEquals(1, response.getList(1).size());
assertEquals("\\NoInferiors", response.getList(1).getString(0));
assertEquals(null, response.get(2));
assertEquals("INBOX", response.get(3));
}
@Test
public void readResponse_withListAsFirstToken_shouldThrow() throws Exception {
ImapResponseParser parser = createParser("* [1 2] 3\r\n");

View file

@ -20,15 +20,17 @@ public class ListResponseTest {
createImapResponse("* LIST () \"/\" blurdybloop"),
createImapResponse("* LIST (\\Noselect) \"/\" foo"),
createImapResponse("* LIST () \"/\" foo/bar"),
createImapResponse("* LIST (\\NoInferiors) NIL INBOX"),
createImapResponse("X OK LIST completed")
);
List<ListResponse> result = ListResponse.parseList(responses);
assertEquals(3, result.size());
assertEquals(4, result.size());
assertListResponseEquals(noAttributes(), "/", "blurdybloop", result.get(0));
assertListResponseEquals(singletonList("\\Noselect"), "/", "foo", result.get(1));
assertListResponseEquals(noAttributes(), "/", "foo/bar", result.get(2));
assertListResponseEquals(singletonList("\\NoInferiors"), null, "INBOX", result.get(3));
}
@Test