@Test public void parse_withoutPermanentFlagsList_shouldReturnNull() throws Exception { ImapResponse response = createImapResponse("* OK [PERMANENTFLAGS none]"); PermanentFlagsResponse result = PermanentFlagsResponse.parse(response); assertNull(result); }
public static PermanentFlagsResponse parse(ImapResponse response) { if (response.isTagged() || !equalsIgnoreCase(response.get(0), Responses.OK) || !response.isList(1)) { return null; } ImapList responseTextList = response.getList(1); if (responseTextList.size() < 2 || !equalsIgnoreCase(responseTextList.get(0), Responses.PERMANENTFLAGS) || !responseTextList.isList(1)) { return null; } ImapList permanentFlagsList = responseTextList.getList(1); int size = permanentFlagsList.size(); Set<Flag> flags = new HashSet<>(size); boolean canCreateKeywords = false; for (int i = 0; i < size; i++) { if (!permanentFlagsList.isString(i)) { return null; } String flag = permanentFlagsList.getString(i); String compareFlag = flag.toLowerCase(Locale.US); switch (compareFlag) { case "\\deleted": { flags.add(Flag.DELETED); break; } case "\\answered": { flags.add(Flag.ANSWERED); break; } case "\\seen": { flags.add(Flag.SEEN); break; } case "\\flagged": { flags.add(Flag.FLAGGED); break; } case "$forwarded": { flags.add(Flag.FORWARDED); break; } case "\\*": { canCreateKeywords = true; break; } } } return new PermanentFlagsResponse(flags, canCreateKeywords); }
PermanentFlagsResponse { public static PermanentFlagsResponse parse(ImapResponse response) { if (response.isTagged() || !equalsIgnoreCase(response.get(0), Responses.OK) || !response.isList(1)) { return null; } ImapList responseTextList = response.getList(1); if (responseTextList.size() < 2 || !equalsIgnoreCase(responseTextList.get(0), Responses.PERMANENTFLAGS) || !responseTextList.isList(1)) { return null; } ImapList permanentFlagsList = responseTextList.getList(1); int size = permanentFlagsList.size(); Set<Flag> flags = new HashSet<>(size); boolean canCreateKeywords = false; for (int i = 0; i < size; i++) { if (!permanentFlagsList.isString(i)) { return null; } String flag = permanentFlagsList.getString(i); String compareFlag = flag.toLowerCase(Locale.US); switch (compareFlag) { case "\\deleted": { flags.add(Flag.DELETED); break; } case "\\answered": { flags.add(Flag.ANSWERED); break; } case "\\seen": { flags.add(Flag.SEEN); break; } case "\\flagged": { flags.add(Flag.FLAGGED); break; } case "$forwarded": { flags.add(Flag.FORWARDED); break; } case "\\*": { canCreateKeywords = true; break; } } } return new PermanentFlagsResponse(flags, canCreateKeywords); } }
PermanentFlagsResponse { public static PermanentFlagsResponse parse(ImapResponse response) { if (response.isTagged() || !equalsIgnoreCase(response.get(0), Responses.OK) || !response.isList(1)) { return null; } ImapList responseTextList = response.getList(1); if (responseTextList.size() < 2 || !equalsIgnoreCase(responseTextList.get(0), Responses.PERMANENTFLAGS) || !responseTextList.isList(1)) { return null; } ImapList permanentFlagsList = responseTextList.getList(1); int size = permanentFlagsList.size(); Set<Flag> flags = new HashSet<>(size); boolean canCreateKeywords = false; for (int i = 0; i < size; i++) { if (!permanentFlagsList.isString(i)) { return null; } String flag = permanentFlagsList.getString(i); String compareFlag = flag.toLowerCase(Locale.US); switch (compareFlag) { case "\\deleted": { flags.add(Flag.DELETED); break; } case "\\answered": { flags.add(Flag.ANSWERED); break; } case "\\seen": { flags.add(Flag.SEEN); break; } case "\\flagged": { flags.add(Flag.FLAGGED); break; } case "$forwarded": { flags.add(Flag.FORWARDED); break; } case "\\*": { canCreateKeywords = true; break; } } } return new PermanentFlagsResponse(flags, canCreateKeywords); } private  PermanentFlagsResponse(Set<Flag> flags, boolean canCreateKeywords); }
PermanentFlagsResponse { public static PermanentFlagsResponse parse(ImapResponse response) { if (response.isTagged() || !equalsIgnoreCase(response.get(0), Responses.OK) || !response.isList(1)) { return null; } ImapList responseTextList = response.getList(1); if (responseTextList.size() < 2 || !equalsIgnoreCase(responseTextList.get(0), Responses.PERMANENTFLAGS) || !responseTextList.isList(1)) { return null; } ImapList permanentFlagsList = responseTextList.getList(1); int size = permanentFlagsList.size(); Set<Flag> flags = new HashSet<>(size); boolean canCreateKeywords = false; for (int i = 0; i < size; i++) { if (!permanentFlagsList.isString(i)) { return null; } String flag = permanentFlagsList.getString(i); String compareFlag = flag.toLowerCase(Locale.US); switch (compareFlag) { case "\\deleted": { flags.add(Flag.DELETED); break; } case "\\answered": { flags.add(Flag.ANSWERED); break; } case "\\seen": { flags.add(Flag.SEEN); break; } case "\\flagged": { flags.add(Flag.FLAGGED); break; } case "$forwarded": { flags.add(Flag.FORWARDED); break; } case "\\*": { canCreateKeywords = true; break; } } } return new PermanentFlagsResponse(flags, canCreateKeywords); } private  PermanentFlagsResponse(Set<Flag> flags, boolean canCreateKeywords); static PermanentFlagsResponse parse(ImapResponse response); Set<Flag> getFlags(); boolean canCreateKeywords(); }
PermanentFlagsResponse { public static PermanentFlagsResponse parse(ImapResponse response) { if (response.isTagged() || !equalsIgnoreCase(response.get(0), Responses.OK) || !response.isList(1)) { return null; } ImapList responseTextList = response.getList(1); if (responseTextList.size() < 2 || !equalsIgnoreCase(responseTextList.get(0), Responses.PERMANENTFLAGS) || !responseTextList.isList(1)) { return null; } ImapList permanentFlagsList = responseTextList.getList(1); int size = permanentFlagsList.size(); Set<Flag> flags = new HashSet<>(size); boolean canCreateKeywords = false; for (int i = 0; i < size; i++) { if (!permanentFlagsList.isString(i)) { return null; } String flag = permanentFlagsList.getString(i); String compareFlag = flag.toLowerCase(Locale.US); switch (compareFlag) { case "\\deleted": { flags.add(Flag.DELETED); break; } case "\\answered": { flags.add(Flag.ANSWERED); break; } case "\\seen": { flags.add(Flag.SEEN); break; } case "\\flagged": { flags.add(Flag.FLAGGED); break; } case "$forwarded": { flags.add(Flag.FORWARDED); break; } case "\\*": { canCreateKeywords = true; break; } } } return new PermanentFlagsResponse(flags, canCreateKeywords); } private  PermanentFlagsResponse(Set<Flag> flags, boolean canCreateKeywords); static PermanentFlagsResponse parse(ImapResponse response); Set<Flag> getFlags(); boolean canCreateKeywords();  }