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);
}
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;
}
Aggregations