@Test public void findPartById__withTwoTimesNestedLocalMessagePart() throws Exception { LocalBodyPart searchRoot = new LocalBodyPart(null, null, 1L, -1L); LocalMimeMessage needlePart = new LocalMimeMessage(null, null, 123L); MimeMultipart mimeMultipartInner = new MimeMultipart("boundary"); mimeMultipartInner.addBodyPart(new MimeBodyPart(needlePart)); MimeMultipart mimeMultipart = new MimeMultipart("boundary"); mimeMultipart.addBodyPart(new MimeBodyPart(mimeMultipartInner)); searchRoot.setBody(mimeMultipart); Part part = LocalStore.findPartById(searchRoot, 123L); assertSame(needlePart, part); }
static Part findPartById(Part searchRoot, long partId) { if (searchRoot instanceof LocalMessage) { LocalMessage localMessage = (LocalMessage) searchRoot; if (localMessage.getMessagePartId() == partId) { return localMessage; } } Stack<Part> partStack = new Stack<>(); partStack.add(searchRoot); while (!partStack.empty()) { Part part = partStack.pop(); if (part instanceof LocalPart) { LocalPart localBodyPart = (LocalPart) part; if (localBodyPart.getPartId() == partId) { return part; } } Body body = part.getBody(); if (body instanceof Multipart) { Multipart innerMultipart = (Multipart) body; for (BodyPart innerPart : innerMultipart.getBodyParts()) { partStack.add(innerPart); } } if (body instanceof Part) { partStack.add((Part) body); } } return null; }
LocalStore extends Store { static Part findPartById(Part searchRoot, long partId) { if (searchRoot instanceof LocalMessage) { LocalMessage localMessage = (LocalMessage) searchRoot; if (localMessage.getMessagePartId() == partId) { return localMessage; } } Stack<Part> partStack = new Stack<>(); partStack.add(searchRoot); while (!partStack.empty()) { Part part = partStack.pop(); if (part instanceof LocalPart) { LocalPart localBodyPart = (LocalPart) part; if (localBodyPart.getPartId() == partId) { return part; } } Body body = part.getBody(); if (body instanceof Multipart) { Multipart innerMultipart = (Multipart) body; for (BodyPart innerPart : innerMultipart.getBodyParts()) { partStack.add(innerPart); } } if (body instanceof Part) { partStack.add((Part) body); } } return null; } }
LocalStore extends Store { static Part findPartById(Part searchRoot, long partId) { if (searchRoot instanceof LocalMessage) { LocalMessage localMessage = (LocalMessage) searchRoot; if (localMessage.getMessagePartId() == partId) { return localMessage; } } Stack<Part> partStack = new Stack<>(); partStack.add(searchRoot); while (!partStack.empty()) { Part part = partStack.pop(); if (part instanceof LocalPart) { LocalPart localBodyPart = (LocalPart) part; if (localBodyPart.getPartId() == partId) { return part; } } Body body = part.getBody(); if (body instanceof Multipart) { Multipart innerMultipart = (Multipart) body; for (BodyPart innerPart : innerMultipart.getBodyParts()) { partStack.add(innerPart); } } if (body instanceof Part) { partStack.add((Part) body); } } return null; } private  LocalStore(final Account account, final Context context); }
LocalStore extends Store { static Part findPartById(Part searchRoot, long partId) { if (searchRoot instanceof LocalMessage) { LocalMessage localMessage = (LocalMessage) searchRoot; if (localMessage.getMessagePartId() == partId) { return localMessage; } } Stack<Part> partStack = new Stack<>(); partStack.add(searchRoot); while (!partStack.empty()) { Part part = partStack.pop(); if (part instanceof LocalPart) { LocalPart localBodyPart = (LocalPart) part; if (localBodyPart.getPartId() == partId) { return part; } } Body body = part.getBody(); if (body instanceof Multipart) { Multipart innerMultipart = (Multipart) body; for (BodyPart innerPart : innerMultipart.getBodyParts()) { partStack.add(innerPart); } } if (body instanceof Part) { partStack.add((Part) body); } } return null; } private  LocalStore(final Account account, final Context context); static LocalStore getInstance(Account account, Context context); static void removeAccount(Account account); void switchLocalStorage(final String newStorageProviderId); long getSize(); void compact(); void clear(); @Override @NonNull LocalFolder getFolder(String remoteId); @Override @NonNull List<LocalFolder> getFolders(boolean forceListAll); @Override @NonNull List<LocalFolder> getSubFolders(final String parentFolderId, boolean forceListAll); @Override void checkSettings(); void delete(); void recreate(); void resetVisibleLimits(int visibleLimit); List<PendingCommand> getPendingCommands(); void addPendingCommand(PendingCommand command); void removePendingCommand(final PendingCommand command); void removePendingCommands(); @Override boolean isMoveCapable(); @Override boolean isCopyCapable(); List<LocalMessage> searchForMessages(MessageRetrievalListener<LocalMessage> retrievalListener,
                                        LocalSearch search); List<LocalMessage> getMessagesInThread(final long rootId); AttachmentInfo getAttachmentInfo(final String attachmentId); @Nullable OpenPgpDataSource getAttachmentDataSource(final String partId); File getAttachmentFile(String attachmentId); void createFolders(final List<LocalFolder> foldersToCreate, final int visibleLimit); LockableDatabase getDatabase(); MessageFulltextCreator getMessageFulltextCreator(); void setFlag(final List<Long> messageIds, final Flag flag, final boolean newState); void setFlagForThreads(final List<Long> threadRootIds, Flag flag, final boolean newState); Map<String, List<String>> getFoldersAndUids(final List<Long> messageIds,
            final boolean threadedList); static String getColumnNameForFlag(Flag flag); }
LocalStore extends Store { static Part findPartById(Part searchRoot, long partId) { if (searchRoot instanceof LocalMessage) { LocalMessage localMessage = (LocalMessage) searchRoot; if (localMessage.getMessagePartId() == partId) { return localMessage; } } Stack<Part> partStack = new Stack<>(); partStack.add(searchRoot); while (!partStack.empty()) { Part part = partStack.pop(); if (part instanceof LocalPart) { LocalPart localBodyPart = (LocalPart) part; if (localBodyPart.getPartId() == partId) { return part; } } Body body = part.getBody(); if (body instanceof Multipart) { Multipart innerMultipart = (Multipart) body; for (BodyPart innerPart : innerMultipart.getBodyParts()) { partStack.add(innerPart); } } if (body instanceof Part) { partStack.add((Part) body); } } return null; } private  LocalStore(final Account account, final Context context); static LocalStore getInstance(Account account, Context context); static void removeAccount(Account account); void switchLocalStorage(final String newStorageProviderId); long getSize(); void compact(); void clear(); @Override @NonNull LocalFolder getFolder(String remoteId); @Override @NonNull List<LocalFolder> getFolders(boolean forceListAll); @Override @NonNull List<LocalFolder> getSubFolders(final String parentFolderId, boolean forceListAll); @Override void checkSettings(); void delete(); void recreate(); void resetVisibleLimits(int visibleLimit); List<PendingCommand> getPendingCommands(); void addPendingCommand(PendingCommand command); void removePendingCommand(final PendingCommand command); void removePendingCommands(); @Override boolean isMoveCapable(); @Override boolean isCopyCapable(); List<LocalMessage> searchForMessages(MessageRetrievalListener<LocalMessage> retrievalListener,
                                        LocalSearch search); List<LocalMessage> getMessagesInThread(final long rootId); AttachmentInfo getAttachmentInfo(final String attachmentId); @Nullable OpenPgpDataSource getAttachmentDataSource(final String partId); File getAttachmentFile(String attachmentId); void createFolders(final List<LocalFolder> foldersToCreate, final int visibleLimit); LockableDatabase getDatabase(); MessageFulltextCreator getMessageFulltextCreator(); void setFlag(final List<Long> messageIds, final Flag flag, final boolean newState); void setFlagForThreads(final List<Long> threadRootIds, Flag flag, final boolean newState); Map<String, List<String>> getFoldersAndUids(final List<Long> messageIds,
            final boolean threadedList); static String getColumnNameForFlag(Flag flag); static final int DB_VERSION; }