private void readContinuationRequest(ImapResponseCallback callback) throws IOException { parseCommandContinuationRequest(); response = ImapResponse.newContinuationRequest(callback); skipIfSpace(); String rest = readStringUntilEndOfLine(); response.add(rest); }
private boolean isListResponse(ImapResponse response) { boolean responseTooShort = response.size() < 4; if (responseTooShort) { return false; } boolean isListResponse = equalsIgnoreCase(response.get(0), Responses.LIST); boolean hierarchyDelimiterValid = response.get(2) instanceof String; return isListResponse && hierarchyDelimiterValid; }
public static CapabilityResponse parse(List<ImapResponse> responses) { for (ImapResponse response : responses) { CapabilityResponse result; if (!response.isEmpty() && equalsIgnoreCase(response.get(0), Responses.OK) && response.isList(1)) { ImapList capabilityList = response.getList(1); result = parse(capabilityList); } else if (response.getTag() == null) { result = parse(response); } else { result = null; } if (result != null) { return result; } } return null; }
private static void parseSingleLine(ImapResponse response, List<Long> numbers) { if (response.isTagged() || response.size() < 2 || !equalsIgnoreCase(response.get(0), Responses.SEARCH)) { return; } int end = response.size(); for (int i = 1; i < end; i++) { try { long number = response.getLong(i); numbers.add(number); } catch (NumberFormatException e) { return; } } }
public static SelectOrExamineResponse parse(ImapResponse response) { if (!response.isTagged() || !equalsIgnoreCase(response.get(0), Responses.OK)) { return null; } if (!response.isList(1)) { return noOpenModeInResponse(); } ImapList responseTextList = response.getList(1); if (!responseTextList.isString(0)) { return noOpenModeInResponse(); } String responseCode = responseTextList.getString(0); if ("READ-ONLY".equalsIgnoreCase(responseCode)) { return new SelectOrExamineResponse(false); } else if ("READ-WRITE".equalsIgnoreCase(responseCode)) { return new SelectOrExamineResponse(true); } return noOpenModeInResponse(); }
@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)); }
if (response.getTag() == null) { if (response.size() > 1) { Object responseType = response.get(1); if (equalsIgnoreCase(responseType, "EXISTS") || equalsIgnoreCase(responseType, "EXPUNGE") || equalsIgnoreCase(responseType, "FETCH")) { } else if (response.isContinuationRequested()) { if (K9MailLib.isDebug()) { Timber.d("Idling %s", getLogId());
/** * Handle an untagged response that the caller doesn't care to handle themselves. */ protected void handleUntaggedResponse(ImapResponse response) { if (response.getTag() == null && response.size() > 1) { if (ImapResponseParser.equalsIgnoreCase(response.get(1), "EXISTS")) { messageCount = response.getNumber(0); if (K9MailLib.isDebug()) { Timber.d("Got untagged EXISTS with value %d for %s", messageCount, getLogId()); } } handlePossibleUidNext(response); if (ImapResponseParser.equalsIgnoreCase(response.get(1), "EXPUNGE") && messageCount > 0) { messageCount--; if (K9MailLib.isDebug()) { Timber.d("Got untagged EXPUNGE with messageCount %d for %s", messageCount, getLogId()); } } } }
public static String getAlertText(ImapResponse response) { if (response.size() < 3 || !response.isList(1)) { return null; } ImapList responseTextCode = response.getList(1); if (responseTextCode.size() != 1 || !equalsIgnoreCase(responseTextCode.get(0), ALERT_RESPONSE_CODE)) { return null; } return response.getString(2); } }
if (response.getTag() != null && !response.getTag().equalsIgnoreCase(tag)) { Timber.w("After sending tag %s, got tag response from previous command %s for %s", tag, response, logId); if (delResponse.getTag() != null || delResponse.size() < 2 || ( !equalsIgnoreCase(delResponse.get(1), Responses.EXISTS) && !equalsIgnoreCase(delResponse.get(1), Responses.EXPUNGE))) { responseIterator.remove(); if (response.getTag() == null && untaggedHandler != null) { untaggedHandler.handleAsyncUntaggedResponse(response); } while (response == null || response.getTag() == null); if (response.size() < 1 || !equalsIgnoreCase(response.get(0), Responses.OK)) { String message = "Command: " + commandToLog + "; response: " + response.toString(); throw new NegativeImapResponseException(message, responses);
private static ListResponse parseSingleLine(ImapResponse response, String commandResponse) { if (response.size() < 4 || !equalsIgnoreCase(response.get(0), commandResponse)) { return null; } // We have special support for LIST responses in ImapResponseParser so we can relax the length/type checks here List<String> attributes = extractAttributes(response); if (attributes == null) { return null; } String hierarchyDelimiter = response.getString(2); if (hierarchyDelimiter != null && hierarchyDelimiter.length() != 1) { return null; } String name = response.getString(3); return new ListResponse(attributes, hierarchyDelimiter, name); }
if (response.getTag() == null && response.size() > 1) { try { Object responseType = response.get(1); if (equalsIgnoreCase(responseType, "FETCH")) { Timber.i("Got FETCH %s", response); long msgSeq = response.getLong(0); long msgSeq = response.getLong(0); if (msgSeq <= oldMessageCount) { messageCountDelta = -1;
@Override public Object foundLiteral(ImapResponse response, FixedLengthInputStream literal) throws MessagingException, IOException { if (response.getTag() == null && ImapResponseParser.equalsIgnoreCase(response.get(1), "FETCH")) { ImapList fetchList = (ImapList)response.getKeyedValue("FETCH"); String uid = fetchList.getKeyedString("UID"); ImapMessage message = (ImapMessage) mMessageMap.get(uid); message.parse(literal); // Return placeholder object return 1; } return null; } }
response = connection.readResponse(callback); if (response.getTag() == null && ImapResponseParser.equalsIgnoreCase(response.get(1), "FETCH")) { ImapList fetchList = (ImapList) response.getKeyedValue("FETCH"); String uid = fetchList.getKeyedString("UID"); long msgSeq = response.getLong(0); if (uid != null) { try { } while (response.getTag() == null); } catch (IOException ioe) { throw ioExceptionHandler(connection, ioe);
@Test public void testFetchResponse() throws Exception { ImapResponseParser parser = createParser("* 1 FETCH (" + "UID 23 " + "INTERNALDATE \"01-Jul-2015 12:34:56 +0200\" " + "RFC822.SIZE 3456 " + "BODY[HEADER.FIELDS (date subject from)] \"<headers>\" " + "FLAGS (\\Seen))\r\n"); ImapResponse response = parser.readResponse(); assertEquals(3, response.size()); assertEquals("1", response.getString(0)); assertEquals("FETCH", response.getString(1)); assertEquals("UID", response.getList(2).getString(0)); assertEquals(23, response.getList(2).getNumber(1)); assertEquals("INTERNALDATE", response.getList(2).getString(2)); assertEquals("01-Jul-2015 12:34:56 +0200", response.getList(2).getString(3)); assertEquals("RFC822.SIZE", response.getList(2).getString(4)); assertEquals(3456, response.getList(2).getNumber(5)); assertEquals("BODY", response.getList(2).getString(6)); assertEquals(2, response.getList(2).getList(7).size()); assertEquals("HEADER.FIELDS", response.getList(2).getList(7).getString(0)); assertEquals(3, response.getList(2).getList(7).getList(1).size()); assertEquals("date", response.getList(2).getList(7).getList(1).getString(0)); assertEquals("subject", response.getList(2).getList(7).getList(1).getString(1)); assertEquals("from", response.getList(2).getList(7).getList(1).getString(2)); assertEquals("<headers>", response.getList(2).getString(8)); assertEquals("FLAGS", response.getList(2).getString(9)); assertEquals(1, response.getList(2).getList(10).size()); assertEquals("\\Seen", response.getList(2).getList(10).getString(0)); }
private void handleXOAuthUntaggedResponse(ImapResponse response) throws IOException { if (response.isString(0)) { retryXoauth2WithNewToken = XOAuth2ChallengeParser.shouldRetry(response.getString(0), settings.getHost()); } if (response.isContinuationRequested()) { outputStream.write("\r\n".getBytes()); outputStream.flush(); } }