@Test public void searchLocalMessagesSynchronous_shouldCallSearchForMessagesOnLocalStore() throws Exception { setAccountsInPreferences(Collections.singletonMap("1", account)); when(search.getAccountUuids()).thenReturn(new String[]{"allAccounts"}); controller.searchLocalMessagesSynchronous(search, listener); verify(localStore).searchForMessages(any(MessageRetrievalListener.class), eq(search)); }
@VisibleForTesting void searchLocalMessagesSynchronous(final LocalSearch search, final MessagingListener listener) { final AccountStats stats = new AccountStats(); final Set<String> uuidSet = new HashSet<>(Arrays.asList(search.getAccountUuids())); List<Account> accounts = Preferences.getPreferences(context).getAccounts(); boolean allAccounts = uuidSet.contains(SearchSpecification.ALL_ACCOUNTS); for (final Account account : accounts) { if (!allAccounts && !uuidSet.contains(account.getUuid())) { continue; } MessageRetrievalListener<LocalMessage> retrievalListener = new MessageRetrievalListener<LocalMessage>() { @Override public void messageStarted(String message, int number, int ofTotal) { } @Override public void messagesFinished(int number) { } @Override public void messageFinished(LocalMessage message, int number, int ofTotal) { if (!isMessageSuppressed(message)) { List<LocalMessage> messages = new ArrayList<>(); messages.add(message); stats.unreadMessageCount += (!message.isSet(Flag.SEEN)) ? 1 : 0; stats.flaggedMessageCount += (message.isSet(Flag.FLAGGED)) ? 1 : 0; if (listener != null) { listener.listLocalMessagesAddMessages(account, null, null, messages); } } } }; try { LocalStore localStore = account.getLocalStore(); localStore.searchForMessages(retrievalListener, search); } catch (Exception e) { Timber.e(e); } } if (listener != null) { listener.searchStats(stats); } }
MessagingController { @VisibleForTesting void searchLocalMessagesSynchronous(final LocalSearch search, final MessagingListener listener) { final AccountStats stats = new AccountStats(); final Set<String> uuidSet = new HashSet<>(Arrays.asList(search.getAccountUuids())); List<Account> accounts = Preferences.getPreferences(context).getAccounts(); boolean allAccounts = uuidSet.contains(SearchSpecification.ALL_ACCOUNTS); for (final Account account : accounts) { if (!allAccounts && !uuidSet.contains(account.getUuid())) { continue; } MessageRetrievalListener<LocalMessage> retrievalListener = new MessageRetrievalListener<LocalMessage>() { @Override public void messageStarted(String message, int number, int ofTotal) { } @Override public void messagesFinished(int number) { } @Override public void messageFinished(LocalMessage message, int number, int ofTotal) { if (!isMessageSuppressed(message)) { List<LocalMessage> messages = new ArrayList<>(); messages.add(message); stats.unreadMessageCount += (!message.isSet(Flag.SEEN)) ? 1 : 0; stats.flaggedMessageCount += (message.isSet(Flag.FLAGGED)) ? 1 : 0; if (listener != null) { listener.listLocalMessagesAddMessages(account, null, null, messages); } } } }; try { LocalStore localStore = account.getLocalStore(); localStore.searchForMessages(retrievalListener, search); } catch (Exception e) { Timber.e(e); } } if (listener != null) { listener.searchStats(stats); } } }
MessagingController { @VisibleForTesting void searchLocalMessagesSynchronous(final LocalSearch search, final MessagingListener listener) { final AccountStats stats = new AccountStats(); final Set<String> uuidSet = new HashSet<>(Arrays.asList(search.getAccountUuids())); List<Account> accounts = Preferences.getPreferences(context).getAccounts(); boolean allAccounts = uuidSet.contains(SearchSpecification.ALL_ACCOUNTS); for (final Account account : accounts) { if (!allAccounts && !uuidSet.contains(account.getUuid())) { continue; } MessageRetrievalListener<LocalMessage> retrievalListener = new MessageRetrievalListener<LocalMessage>() { @Override public void messageStarted(String message, int number, int ofTotal) { } @Override public void messagesFinished(int number) { } @Override public void messageFinished(LocalMessage message, int number, int ofTotal) { if (!isMessageSuppressed(message)) { List<LocalMessage> messages = new ArrayList<>(); messages.add(message); stats.unreadMessageCount += (!message.isSet(Flag.SEEN)) ? 1 : 0; stats.flaggedMessageCount += (message.isSet(Flag.FLAGGED)) ? 1 : 0; if (listener != null) { listener.listLocalMessagesAddMessages(account, null, null, messages); } } } }; try { LocalStore localStore = account.getLocalStore(); localStore.searchForMessages(retrievalListener, search); } catch (Exception e) { Timber.e(e); } } if (listener != null) { listener.searchStats(stats); } } @VisibleForTesting  MessagingController(Context context, NotificationController notificationController,
            Contacts contacts, TransportProvider transportProvider); }
MessagingController { @VisibleForTesting void searchLocalMessagesSynchronous(final LocalSearch search, final MessagingListener listener) { final AccountStats stats = new AccountStats(); final Set<String> uuidSet = new HashSet<>(Arrays.asList(search.getAccountUuids())); List<Account> accounts = Preferences.getPreferences(context).getAccounts(); boolean allAccounts = uuidSet.contains(SearchSpecification.ALL_ACCOUNTS); for (final Account account : accounts) { if (!allAccounts && !uuidSet.contains(account.getUuid())) { continue; } MessageRetrievalListener<LocalMessage> retrievalListener = new MessageRetrievalListener<LocalMessage>() { @Override public void messageStarted(String message, int number, int ofTotal) { } @Override public void messagesFinished(int number) { } @Override public void messageFinished(LocalMessage message, int number, int ofTotal) { if (!isMessageSuppressed(message)) { List<LocalMessage> messages = new ArrayList<>(); messages.add(message); stats.unreadMessageCount += (!message.isSet(Flag.SEEN)) ? 1 : 0; stats.flaggedMessageCount += (message.isSet(Flag.FLAGGED)) ? 1 : 0; if (listener != null) { listener.listLocalMessagesAddMessages(account, null, null, messages); } } } }; try { LocalStore localStore = account.getLocalStore(); localStore.searchForMessages(retrievalListener, search); } catch (Exception e) { Timber.e(e); } } if (listener != null) { listener.searchStats(stats); } } @VisibleForTesting  MessagingController(Context context, NotificationController notificationController,
            Contacts contacts, TransportProvider transportProvider); static synchronized MessagingController getInstance(Context context); void addListener(MessagingListener listener); void refreshListener(MessagingListener listener); void removeListener(MessagingListener listener); Set<MessagingListener> getListeners(); Set<MessagingListener> getListeners(MessagingListener listener); void listFolders(final Account account, final boolean refreshRemote, final MessagingListener listener); void listSubFolders(final Account account, final String parentFolderId, final boolean refreshRemote, final MessagingListener listener); void listFoldersSynchronous(final Account account, final boolean refreshRemote,
            final MessagingListener listener); void listSubFoldersSynchronous(final Account account, final String parentFolderId, final boolean refreshRemote,
            final MessagingListener listener); void searchLocalMessages(final LocalSearch search, final MessagingListener listener); Future<?> searchRemoteMessages(final String acctUuid, final String folderId, final String folderName, final String query,
            final Set<Flag> requiredFlags, final Set<Flag> forbiddenFlags, final MessagingListener listener); void loadSearchResults(final Account account, final String folderName, final List<Message> messages,
            final MessagingListener listener); void loadMoreMessages(Account account, String folderId, MessagingListener listener); void synchronizeMailbox(final Account account, final String folderId, final String folderName, final MessagingListener listener,
            final Folder providedRemoteFolder); void markAllMessagesRead(final Account account, final String folder); void setFlag(final Account account, final List<Long> messageIds, final Flag flag,
            final boolean newState); void setFlagForThreads(final Account account, final List<Long> threadRootIds,
            final Flag flag, final boolean newState); void setFlag(Account account, String folderId, List<? extends Message> messages, Flag flag,
            boolean newState); void setFlag(Account account, String folderName, String uid, Flag flag,
            boolean newState); void clearAllPending(final Account account); void loadMessageRemotePartial(final Account account, final String folderId,
            final String uid, final MessagingListener listener); void loadMessageRemote(final Account account, final String folderId,
            final String uid, final MessagingListener listener); LocalMessage loadMessage(Account account, String folderId, String uid); void loadAttachment(final Account account, final LocalMessage message, final Part part,
            final MessagingListener listener); void sendMessage(final Account account,
            final Message message,
            MessagingListener listener); void sendPendingMessages(MessagingListener listener); void sendPendingMessages(final Account account,
            MessagingListener listener); void getAccountStats(final Context context, final Account account,
            final MessagingListener listener); void getSearchAccountStats(final SearchAccount searchAccount,
            final MessagingListener listener); AccountStats getSearchAccountStatsSynchronous(final SearchAccount searchAccount,
            final MessagingListener listener); void getFolderUnreadMessageCount(final Account account, final String folderId,
            final MessagingListener l); boolean isMoveCapable(MessageReference messageReference); boolean isCopyCapable(MessageReference message); boolean isMoveCapable(final Account account); boolean isCopyCapable(final Account account); void moveMessages(final Account srcAccount, final String srcFolder,
            List<MessageReference> messageReferences, final String destFolder); void moveMessagesInThread(Account srcAccount, final String srcFolder,
            final List<MessageReference> messageReferences, final String destFolder); void moveMessage(final Account account, final String srcFolder, final MessageReference message,
            final String destFolder); void copyMessages(final Account srcAccount, final String srcFolder,
            final List<MessageReference> messageReferences, final String destFolder); void copyMessagesInThread(Account srcAccount, final String srcFolder,
            final List<MessageReference> messageReferences, final String destFolder); void copyMessage(final Account account, final String srcFolder, final MessageReference message,
            final String destFolder); void expunge(final Account account, final String folder); void deleteDraft(final Account account, long id); void deleteThreads(final List<MessageReference> messages); void deleteMessage(MessageReference message, final MessagingListener listener); void deleteMessages(List<MessageReference> messages, final MessagingListener listener); @SuppressLint("NewApi") // used for debugging only void debugClearMessagesLocally(final List<MessageReference> messages); void emptyTrash(final Account account, MessagingListener listener); void clearFolder(final Account account, final String folderId, final ActivityListener listener); void sendAlternate(Context context, Account account, LocalMessage message); void checkMail(final Context context, final Account account,
            final boolean ignoreLastCheckedTime,
            final boolean useManualWakeLock,
            final MessagingListener listener); void compact(final Account account, final MessagingListener ml); void clear(final Account account, final MessagingListener ml); void recreate(final Account account, final MessagingListener ml); void deleteAccount(Account account); Message saveDraft(final Account account, final Message message, long existingDraftId, boolean saveRemotely); long getId(Message message); MessagingListener getCheckMailListener(); void setCheckMailListener(MessagingListener checkMailListener); Collection<Pusher> getPushers(); boolean setupPushing(final Account account); void stopAllPushing(); void messagesArrived(final Account account, final Folder remoteFolder, final List<Message> messages,
            final boolean flagSyncOnly); void systemStatusChanged(); void cancelNotificationsForAccount(Account account); void cancelNotificationForMessage(Account account, MessageReference messageReference); void clearCertificateErrorNotifications(Account account, CheckDirection direction); void notifyUserIfCertificateProblem(Account account, Exception exception, boolean incoming); }
MessagingController { @VisibleForTesting void searchLocalMessagesSynchronous(final LocalSearch search, final MessagingListener listener) { final AccountStats stats = new AccountStats(); final Set<String> uuidSet = new HashSet<>(Arrays.asList(search.getAccountUuids())); List<Account> accounts = Preferences.getPreferences(context).getAccounts(); boolean allAccounts = uuidSet.contains(SearchSpecification.ALL_ACCOUNTS); for (final Account account : accounts) { if (!allAccounts && !uuidSet.contains(account.getUuid())) { continue; } MessageRetrievalListener<LocalMessage> retrievalListener = new MessageRetrievalListener<LocalMessage>() { @Override public void messageStarted(String message, int number, int ofTotal) { } @Override public void messagesFinished(int number) { } @Override public void messageFinished(LocalMessage message, int number, int ofTotal) { if (!isMessageSuppressed(message)) { List<LocalMessage> messages = new ArrayList<>(); messages.add(message); stats.unreadMessageCount += (!message.isSet(Flag.SEEN)) ? 1 : 0; stats.flaggedMessageCount += (message.isSet(Flag.FLAGGED)) ? 1 : 0; if (listener != null) { listener.listLocalMessagesAddMessages(account, null, null, messages); } } } }; try { LocalStore localStore = account.getLocalStore(); localStore.searchForMessages(retrievalListener, search); } catch (Exception e) { Timber.e(e); } } if (listener != null) { listener.searchStats(stats); } } @VisibleForTesting  MessagingController(Context context, NotificationController notificationController,
            Contacts contacts, TransportProvider transportProvider); static synchronized MessagingController getInstance(Context context); void addListener(MessagingListener listener); void refreshListener(MessagingListener listener); void removeListener(MessagingListener listener); Set<MessagingListener> getListeners(); Set<MessagingListener> getListeners(MessagingListener listener); void listFolders(final Account account, final boolean refreshRemote, final MessagingListener listener); void listSubFolders(final Account account, final String parentFolderId, final boolean refreshRemote, final MessagingListener listener); void listFoldersSynchronous(final Account account, final boolean refreshRemote,
            final MessagingListener listener); void listSubFoldersSynchronous(final Account account, final String parentFolderId, final boolean refreshRemote,
            final MessagingListener listener); void searchLocalMessages(final LocalSearch search, final MessagingListener listener); Future<?> searchRemoteMessages(final String acctUuid, final String folderId, final String folderName, final String query,
            final Set<Flag> requiredFlags, final Set<Flag> forbiddenFlags, final MessagingListener listener); void loadSearchResults(final Account account, final String folderName, final List<Message> messages,
            final MessagingListener listener); void loadMoreMessages(Account account, String folderId, MessagingListener listener); void synchronizeMailbox(final Account account, final String folderId, final String folderName, final MessagingListener listener,
            final Folder providedRemoteFolder); void markAllMessagesRead(final Account account, final String folder); void setFlag(final Account account, final List<Long> messageIds, final Flag flag,
            final boolean newState); void setFlagForThreads(final Account account, final List<Long> threadRootIds,
            final Flag flag, final boolean newState); void setFlag(Account account, String folderId, List<? extends Message> messages, Flag flag,
            boolean newState); void setFlag(Account account, String folderName, String uid, Flag flag,
            boolean newState); void clearAllPending(final Account account); void loadMessageRemotePartial(final Account account, final String folderId,
            final String uid, final MessagingListener listener); void loadMessageRemote(final Account account, final String folderId,
            final String uid, final MessagingListener listener); LocalMessage loadMessage(Account account, String folderId, String uid); void loadAttachment(final Account account, final LocalMessage message, final Part part,
            final MessagingListener listener); void sendMessage(final Account account,
            final Message message,
            MessagingListener listener); void sendPendingMessages(MessagingListener listener); void sendPendingMessages(final Account account,
            MessagingListener listener); void getAccountStats(final Context context, final Account account,
            final MessagingListener listener); void getSearchAccountStats(final SearchAccount searchAccount,
            final MessagingListener listener); AccountStats getSearchAccountStatsSynchronous(final SearchAccount searchAccount,
            final MessagingListener listener); void getFolderUnreadMessageCount(final Account account, final String folderId,
            final MessagingListener l); boolean isMoveCapable(MessageReference messageReference); boolean isCopyCapable(MessageReference message); boolean isMoveCapable(final Account account); boolean isCopyCapable(final Account account); void moveMessages(final Account srcAccount, final String srcFolder,
            List<MessageReference> messageReferences, final String destFolder); void moveMessagesInThread(Account srcAccount, final String srcFolder,
            final List<MessageReference> messageReferences, final String destFolder); void moveMessage(final Account account, final String srcFolder, final MessageReference message,
            final String destFolder); void copyMessages(final Account srcAccount, final String srcFolder,
            final List<MessageReference> messageReferences, final String destFolder); void copyMessagesInThread(Account srcAccount, final String srcFolder,
            final List<MessageReference> messageReferences, final String destFolder); void copyMessage(final Account account, final String srcFolder, final MessageReference message,
            final String destFolder); void expunge(final Account account, final String folder); void deleteDraft(final Account account, long id); void deleteThreads(final List<MessageReference> messages); void deleteMessage(MessageReference message, final MessagingListener listener); void deleteMessages(List<MessageReference> messages, final MessagingListener listener); @SuppressLint("NewApi") // used for debugging only void debugClearMessagesLocally(final List<MessageReference> messages); void emptyTrash(final Account account, MessagingListener listener); void clearFolder(final Account account, final String folderId, final ActivityListener listener); void sendAlternate(Context context, Account account, LocalMessage message); void checkMail(final Context context, final Account account,
            final boolean ignoreLastCheckedTime,
            final boolean useManualWakeLock,
            final MessagingListener listener); void compact(final Account account, final MessagingListener ml); void clear(final Account account, final MessagingListener ml); void recreate(final Account account, final MessagingListener ml); void deleteAccount(Account account); Message saveDraft(final Account account, final Message message, long existingDraftId, boolean saveRemotely); long getId(Message message); MessagingListener getCheckMailListener(); void setCheckMailListener(MessagingListener checkMailListener); Collection<Pusher> getPushers(); boolean setupPushing(final Account account); void stopAllPushing(); void messagesArrived(final Account account, final Folder remoteFolder, final List<Message> messages,
            final boolean flagSyncOnly); void systemStatusChanged(); void cancelNotificationsForAccount(Account account); void cancelNotificationForMessage(Account account, MessageReference messageReference); void clearCertificateErrorNotifications(Account account, CheckDirection direction); void notifyUserIfCertificateProblem(Account account, Exception exception, boolean incoming); static final long INVALID_MESSAGE_ID; }