@Test public void getUidFromMessageId_withoutMessageIdHeader_shouldReturnNull() throws Exception { ImapFolder folder = createFolder("Folder"); ImapMessage message = createImapMessage("2"); when(message.getHeader("Message-ID")).thenReturn(new String[0]); String uid = folder.getUidFromMessageId(message); assertNull(uid); }
@Override public String getUidFromMessageId(Message message) throws MessagingException { try { String[] messageIdHeader = message.getHeader("Message-ID"); if (messageIdHeader.length == 0) { if (K9MailLib.isDebug()) { Timber.d("Did not get a message-id in order to search for UID for %s", getLogId()); } return null; } String messageId = messageIdHeader[0]; if (K9MailLib.isDebug()) { Timber.d("Looking for UID for message with message-id %s for %s", messageId, getLogId()); } String command = String.format("UID SEARCH HEADER MESSAGE-ID %s", ImapUtility.encodeString(messageId)); List<ImapResponse> responses = executeSimpleCommand(command); for (ImapResponse response : responses) { if (response.getTag() == null && ImapResponseParser.equalsIgnoreCase(response.get(0), "SEARCH") && response.size() > 1) { return response.getString(1); } } return null; } catch (IOException ioe) { throw new MessagingException("Could not find UID for message based on Message-ID", ioe); } }
ImapFolder extends Folder<ImapMessage> { @Override public String getUidFromMessageId(Message message) throws MessagingException { try { String[] messageIdHeader = message.getHeader("Message-ID"); if (messageIdHeader.length == 0) { if (K9MailLib.isDebug()) { Timber.d("Did not get a message-id in order to search for UID for %s", getLogId()); } return null; } String messageId = messageIdHeader[0]; if (K9MailLib.isDebug()) { Timber.d("Looking for UID for message with message-id %s for %s", messageId, getLogId()); } String command = String.format("UID SEARCH HEADER MESSAGE-ID %s", ImapUtility.encodeString(messageId)); List<ImapResponse> responses = executeSimpleCommand(command); for (ImapResponse response : responses) { if (response.getTag() == null && ImapResponseParser.equalsIgnoreCase(response.get(0), "SEARCH") && response.size() > 1) { return response.getString(1); } } return null; } catch (IOException ioe) { throw new MessagingException("Could not find UID for message based on Message-ID", ioe); } } }
ImapFolder extends Folder<ImapMessage> { @Override public String getUidFromMessageId(Message message) throws MessagingException { try { String[] messageIdHeader = message.getHeader("Message-ID"); if (messageIdHeader.length == 0) { if (K9MailLib.isDebug()) { Timber.d("Did not get a message-id in order to search for UID for %s", getLogId()); } return null; } String messageId = messageIdHeader[0]; if (K9MailLib.isDebug()) { Timber.d("Looking for UID for message with message-id %s for %s", messageId, getLogId()); } String command = String.format("UID SEARCH HEADER MESSAGE-ID %s", ImapUtility.encodeString(messageId)); List<ImapResponse> responses = executeSimpleCommand(command); for (ImapResponse response : responses) { if (response.getTag() == null && ImapResponseParser.equalsIgnoreCase(response.get(0), "SEARCH") && response.size() > 1) { return response.getString(1); } } return null; } catch (IOException ioe) { throw new MessagingException("Could not find UID for message based on Message-ID", ioe); } } ImapFolder(ImapStore store, String id);   ImapFolder(ImapStore store, String id, FolderNameCodec folderNameCodec); }
ImapFolder extends Folder<ImapMessage> { @Override public String getUidFromMessageId(Message message) throws MessagingException { try { String[] messageIdHeader = message.getHeader("Message-ID"); if (messageIdHeader.length == 0) { if (K9MailLib.isDebug()) { Timber.d("Did not get a message-id in order to search for UID for %s", getLogId()); } return null; } String messageId = messageIdHeader[0]; if (K9MailLib.isDebug()) { Timber.d("Looking for UID for message with message-id %s for %s", messageId, getLogId()); } String command = String.format("UID SEARCH HEADER MESSAGE-ID %s", ImapUtility.encodeString(messageId)); List<ImapResponse> responses = executeSimpleCommand(command); for (ImapResponse response : responses) { if (response.getTag() == null && ImapResponseParser.equalsIgnoreCase(response.get(0), "SEARCH") && response.size() > 1) { return response.getString(1); } } return null; } catch (IOException ioe) { throw new MessagingException("Could not find UID for message based on Message-ID", ioe); } } ImapFolder(ImapStore store, String id);   ImapFolder(ImapStore store, String id, FolderNameCodec folderNameCodec); @Override void open(int mode); @Override boolean isOpen(); @Override int getMode(); @Override void close(); @Override String getId(); @Override String getParentId(); @Override String getName(); @Override boolean exists(); @Override boolean canHaveSubFolders(); @Override boolean create(FolderType type); @Override Map<String, String> copyMessages(List<? extends Message> messages, Folder folder); @Override Map<String, String> moveMessages(List<? extends Message> messages, Folder folder); @Override void delete(List<? extends Message> messages, String trashFolderName); @Override int getMessageCount(); @Override int getUnreadMessageCount(); @Override int getFlaggedMessageCount(); @Override void delete(boolean recurse); @Override ImapMessage getMessage(String uid); @Override List<ImapMessage> getMessages(int start, int end, Date earliestDate,
            MessageRetrievalListener<ImapMessage> listener); @Override boolean areMoreMessagesAvailable(int indexOfOldestMessage, Date earliestDate); @Override void fetch(List<ImapMessage> messages, FetchProfile fetchProfile,
            MessageRetrievalListener<ImapMessage> listener); @Override void fetchPart(Message message, Part part, MessageRetrievalListener<Message> listener,
            BodyFactory bodyFactory); @Override Map<String, String> appendMessages(List<? extends Message> messages); @Override String getUidFromMessageId(Message message); @Override void expunge(); @Override void setFlags(Set<Flag> flags, boolean value); @Override String getNewPushState(String oldSerializedPushState, Message message); @Override void setFlags(List<? extends Message> messages, final Set<Flag> flags, boolean value); @Override boolean equals(Object other); @Override int hashCode(); @Override List<ImapMessage> search(final String queryString, final Set<Flag> requiredFlags,
            final Set<Flag> forbiddenFlags); }
ImapFolder extends Folder<ImapMessage> { @Override public String getUidFromMessageId(Message message) throws MessagingException { try { String[] messageIdHeader = message.getHeader("Message-ID"); if (messageIdHeader.length == 0) { if (K9MailLib.isDebug()) { Timber.d("Did not get a message-id in order to search for UID for %s", getLogId()); } return null; } String messageId = messageIdHeader[0]; if (K9MailLib.isDebug()) { Timber.d("Looking for UID for message with message-id %s for %s", messageId, getLogId()); } String command = String.format("UID SEARCH HEADER MESSAGE-ID %s", ImapUtility.encodeString(messageId)); List<ImapResponse> responses = executeSimpleCommand(command); for (ImapResponse response : responses) { if (response.getTag() == null && ImapResponseParser.equalsIgnoreCase(response.get(0), "SEARCH") && response.size() > 1) { return response.getString(1); } } return null; } catch (IOException ioe) { throw new MessagingException("Could not find UID for message based on Message-ID", ioe); } } ImapFolder(ImapStore store, String id);   ImapFolder(ImapStore store, String id, FolderNameCodec folderNameCodec); @Override void open(int mode); @Override boolean isOpen(); @Override int getMode(); @Override void close(); @Override String getId(); @Override String getParentId(); @Override String getName(); @Override boolean exists(); @Override boolean canHaveSubFolders(); @Override boolean create(FolderType type); @Override Map<String, String> copyMessages(List<? extends Message> messages, Folder folder); @Override Map<String, String> moveMessages(List<? extends Message> messages, Folder folder); @Override void delete(List<? extends Message> messages, String trashFolderName); @Override int getMessageCount(); @Override int getUnreadMessageCount(); @Override int getFlaggedMessageCount(); @Override void delete(boolean recurse); @Override ImapMessage getMessage(String uid); @Override List<ImapMessage> getMessages(int start, int end, Date earliestDate,
            MessageRetrievalListener<ImapMessage> listener); @Override boolean areMoreMessagesAvailable(int indexOfOldestMessage, Date earliestDate); @Override void fetch(List<ImapMessage> messages, FetchProfile fetchProfile,
            MessageRetrievalListener<ImapMessage> listener); @Override void fetchPart(Message message, Part part, MessageRetrievalListener<Message> listener,
            BodyFactory bodyFactory); @Override Map<String, String> appendMessages(List<? extends Message> messages); @Override String getUidFromMessageId(Message message); @Override void expunge(); @Override void setFlags(Set<Flag> flags, boolean value); @Override String getNewPushState(String oldSerializedPushState, Message message); @Override void setFlags(List<? extends Message> messages, final Set<Flag> flags, boolean value); @Override boolean equals(Object other); @Override int hashCode(); @Override List<ImapMessage> search(final String queryString, final Set<Flag> requiredFlags,
            final Set<Flag> forbiddenFlags);  }