Search in sources :

Example 1 with PushReceiver

use of com.fsck.k9.mail.PushReceiver in project k-9 by k9mail.

the class ImapPusherTest method setUp.

@Before
public void setUp() throws Exception {
    imapStore = mock(ImapStore.class);
    PushReceiver pushReceiver = mock(PushReceiver.class);
    imapPusher = new TestImapPusher(imapStore, pushReceiver);
}
Also used : PushReceiver(com.fsck.k9.mail.PushReceiver) Before(org.junit.Before)

Example 2 with PushReceiver

use of com.fsck.k9.mail.PushReceiver in project k-9 by k9mail.

the class MessagingController method setupPushing.

public boolean setupPushing(final Account account) {
    try {
        Pusher previousPusher = pushers.remove(account);
        if (previousPusher != null) {
            previousPusher.stop();
        }
        Account.FolderMode aDisplayMode = account.getFolderDisplayMode();
        Account.FolderMode aPushMode = account.getFolderPushMode();
        List<String> names = new ArrayList<>();
        Store localStore = account.getLocalStore();
        for (final Folder folder : localStore.getPersonalNamespaces(false)) {
            if (folder.getName().equals(account.getErrorFolderName()) || folder.getName().equals(account.getOutboxFolderName())) {
                continue;
            }
            folder.open(Folder.OPEN_MODE_RW);
            Folder.FolderClass fDisplayClass = folder.getDisplayClass();
            Folder.FolderClass fPushClass = folder.getPushClass();
            if (modeMismatch(aDisplayMode, fDisplayClass)) {
                continue;
            }
            if (modeMismatch(aPushMode, fPushClass)) {
                continue;
            }
            Timber.i("Starting pusher for %s:%s", account.getDescription(), folder.getName());
            names.add(folder.getName());
        }
        if (!names.isEmpty()) {
            PushReceiver receiver = new MessagingControllerPushReceiver(context, account, this);
            int maxPushFolders = account.getMaxPushFolders();
            if (names.size() > maxPushFolders) {
                Timber.i("Count of folders to push for account %s is %d, greater than limit of %d, truncating", account.getDescription(), names.size(), maxPushFolders);
                names = names.subList(0, maxPushFolders);
            }
            try {
                Store store = account.getRemoteStore();
                if (!store.isPushCapable()) {
                    Timber.i("Account %s is not push capable, skipping", account.getDescription());
                    return false;
                }
                Pusher pusher = store.getPusher(receiver);
                if (pusher != null) {
                    Pusher oldPusher = pushers.putIfAbsent(account, pusher);
                    if (oldPusher == null) {
                        pusher.start(names);
                    }
                }
            } catch (Exception e) {
                Timber.e(e, "Could not get remote store");
                return false;
            }
            return true;
        } else {
            Timber.i("No folders are configured for pushing in account %s", account.getDescription());
            return false;
        }
    } catch (Exception e) {
        Timber.e(e, "Got exception while setting up pushing");
    }
    return false;
}
Also used : SearchAccount(com.fsck.k9.search.SearchAccount) Account(com.fsck.k9.Account) ArrayList(java.util.ArrayList) LocalStore(com.fsck.k9.mailstore.LocalStore) Store(com.fsck.k9.mail.Store) Pop3Store(com.fsck.k9.mail.store.pop3.Pop3Store) Folder(com.fsck.k9.mail.Folder) LocalFolder(com.fsck.k9.mailstore.LocalFolder) Pusher(com.fsck.k9.mail.Pusher) SuppressLint(android.annotation.SuppressLint) CertificateValidationException(com.fsck.k9.mail.CertificateValidationException) UnavailableStorageException(com.fsck.k9.mailstore.UnavailableStorageException) IOException(java.io.IOException) MessagingException(com.fsck.k9.mail.MessagingException) AuthenticationFailedException(com.fsck.k9.mail.AuthenticationFailedException) PushReceiver(com.fsck.k9.mail.PushReceiver)

Aggregations

PushReceiver (com.fsck.k9.mail.PushReceiver)2 SuppressLint (android.annotation.SuppressLint)1 Account (com.fsck.k9.Account)1 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)1 CertificateValidationException (com.fsck.k9.mail.CertificateValidationException)1 Folder (com.fsck.k9.mail.Folder)1 MessagingException (com.fsck.k9.mail.MessagingException)1 Pusher (com.fsck.k9.mail.Pusher)1 Store (com.fsck.k9.mail.Store)1 Pop3Store (com.fsck.k9.mail.store.pop3.Pop3Store)1 LocalFolder (com.fsck.k9.mailstore.LocalFolder)1 LocalStore (com.fsck.k9.mailstore.LocalStore)1 UnavailableStorageException (com.fsck.k9.mailstore.UnavailableStorageException)1 SearchAccount (com.fsck.k9.search.SearchAccount)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1