@Test public void parse_withResponseTextListTooShort_shouldReturnNull() throws Exception { ImapResponse imapResponse = createImapResponse("x OK [A B C] Success"); CopyUidResponse result = CopyUidResponse.parse(imapResponse); assertNull(result); }
public static CopyUidResponse parse(ImapResponse response) { if (!response.isTagged() || response.size() < 2 || !equalsIgnoreCase(response.get(0), Responses.OK) || !response.isList(1)) { return null; } ImapList responseTextList = response.getList(1); if (responseTextList.size() < 4 || !equalsIgnoreCase(responseTextList.get(0), Responses.COPYUID) || !responseTextList.isString(1) || !responseTextList.isString(2) || !responseTextList.isString(3)) { return null; } List<String> sourceUids = getImapSequenceValues(responseTextList.getString(2)); List<String> destinationUids = getImapSequenceValues(responseTextList.getString(3)); int size = sourceUids.size(); if (size == 0 || size != destinationUids.size()) { return null; } Map<String, String> uidMapping = new HashMap<>(size); for (int i = 0; i < size; i++) { String sourceUid = sourceUids.get(i); String destinationUid = destinationUids.get(i); uidMapping.put(sourceUid, destinationUid); } return new CopyUidResponse(uidMapping); }
CopyUidResponse { public static CopyUidResponse parse(ImapResponse response) { if (!response.isTagged() || response.size() < 2 || !equalsIgnoreCase(response.get(0), Responses.OK) || !response.isList(1)) { return null; } ImapList responseTextList = response.getList(1); if (responseTextList.size() < 4 || !equalsIgnoreCase(responseTextList.get(0), Responses.COPYUID) || !responseTextList.isString(1) || !responseTextList.isString(2) || !responseTextList.isString(3)) { return null; } List<String> sourceUids = getImapSequenceValues(responseTextList.getString(2)); List<String> destinationUids = getImapSequenceValues(responseTextList.getString(3)); int size = sourceUids.size(); if (size == 0 || size != destinationUids.size()) { return null; } Map<String, String> uidMapping = new HashMap<>(size); for (int i = 0; i < size; i++) { String sourceUid = sourceUids.get(i); String destinationUid = destinationUids.get(i); uidMapping.put(sourceUid, destinationUid); } return new CopyUidResponse(uidMapping); } }
CopyUidResponse { public static CopyUidResponse parse(ImapResponse response) { if (!response.isTagged() || response.size() < 2 || !equalsIgnoreCase(response.get(0), Responses.OK) || !response.isList(1)) { return null; } ImapList responseTextList = response.getList(1); if (responseTextList.size() < 4 || !equalsIgnoreCase(responseTextList.get(0), Responses.COPYUID) || !responseTextList.isString(1) || !responseTextList.isString(2) || !responseTextList.isString(3)) { return null; } List<String> sourceUids = getImapSequenceValues(responseTextList.getString(2)); List<String> destinationUids = getImapSequenceValues(responseTextList.getString(3)); int size = sourceUids.size(); if (size == 0 || size != destinationUids.size()) { return null; } Map<String, String> uidMapping = new HashMap<>(size); for (int i = 0; i < size; i++) { String sourceUid = sourceUids.get(i); String destinationUid = destinationUids.get(i); uidMapping.put(sourceUid, destinationUid); } return new CopyUidResponse(uidMapping); } private  CopyUidResponse(Map<String, String> uidMapping); }
CopyUidResponse { public static CopyUidResponse parse(ImapResponse response) { if (!response.isTagged() || response.size() < 2 || !equalsIgnoreCase(response.get(0), Responses.OK) || !response.isList(1)) { return null; } ImapList responseTextList = response.getList(1); if (responseTextList.size() < 4 || !equalsIgnoreCase(responseTextList.get(0), Responses.COPYUID) || !responseTextList.isString(1) || !responseTextList.isString(2) || !responseTextList.isString(3)) { return null; } List<String> sourceUids = getImapSequenceValues(responseTextList.getString(2)); List<String> destinationUids = getImapSequenceValues(responseTextList.getString(3)); int size = sourceUids.size(); if (size == 0 || size != destinationUids.size()) { return null; } Map<String, String> uidMapping = new HashMap<>(size); for (int i = 0; i < size; i++) { String sourceUid = sourceUids.get(i); String destinationUid = destinationUids.get(i); uidMapping.put(sourceUid, destinationUid); } return new CopyUidResponse(uidMapping); } private  CopyUidResponse(Map<String, String> uidMapping); static CopyUidResponse parse(ImapResponse response); Map<String, String> getUidMapping(); }
CopyUidResponse { public static CopyUidResponse parse(ImapResponse response) { if (!response.isTagged() || response.size() < 2 || !equalsIgnoreCase(response.get(0), Responses.OK) || !response.isList(1)) { return null; } ImapList responseTextList = response.getList(1); if (responseTextList.size() < 4 || !equalsIgnoreCase(responseTextList.get(0), Responses.COPYUID) || !responseTextList.isString(1) || !responseTextList.isString(2) || !responseTextList.isString(3)) { return null; } List<String> sourceUids = getImapSequenceValues(responseTextList.getString(2)); List<String> destinationUids = getImapSequenceValues(responseTextList.getString(3)); int size = sourceUids.size(); if (size == 0 || size != destinationUids.size()) { return null; } Map<String, String> uidMapping = new HashMap<>(size); for (int i = 0; i < size; i++) { String sourceUid = sourceUids.get(i); String destinationUid = destinationUids.get(i); uidMapping.put(sourceUid, destinationUid); } return new CopyUidResponse(uidMapping); } private  CopyUidResponse(Map<String, String> uidMapping); static CopyUidResponse parse(ImapResponse response); Map<String, String> getUidMapping();  }