private void handleNamespace() throws IOException, MessagingException { List<ImapResponse> responses = executeSimpleCommand(Commands.NAMESPACE); NamespaceResponse namespaceResponse = NamespaceResponse.parse(responses); if (namespaceResponse != null) { String prefix = namespaceResponse.getPrefix(); String hierarchyDelimiter = namespaceResponse.getHierarchyDelimiter(); settings.setPathPrefix(prefix); settings.setPathDelimiter(hierarchyDelimiter); settings.setCombinedPrefix(null); if (K9MailLib.isDebug()) { Timber.d("Got path '%s' and separator '%s'", prefix, hierarchyDelimiter); } } }
@Test public void parse_withSingleItemInResponseList() throws Exception { ImapResponse imapResponse = createImapResponse("* NAMESPACE ((\"\" \"/\")) NIL NIL"); NamespaceResponse result = NamespaceResponse.parse(Collections.singletonList(imapResponse)); assertNotNull(result); assertEquals("", result.getPrefix()); assertEquals("/", result.getHierarchyDelimiter()); }
@Test public void parse_withResponseList() throws Exception { ImapResponse imapResponseOne = createImapResponse("* OK"); ImapResponse imapResponseTwo = createImapResponse("* NAMESPACE ((\"INBOX\" \".\")) NIL NIL"); NamespaceResponse result = NamespaceResponse.parse(Arrays.asList(imapResponseOne, imapResponseTwo)); assertNotNull(result); assertEquals("INBOX", result.getPrefix()); assertEquals(".", result.getHierarchyDelimiter()); }
@Test public void parse_withProperNamespaceResponse() throws Exception { NamespaceResponse result = parse("* NAMESPACE ((\"\" \"/\")) NIL NIL"); assertNotNull(result); assertEquals("", result.getPrefix()); assertEquals("/", result.getHierarchyDelimiter()); }