use of com.fsck.k9.mailstore.LocalStore in project k-9 by k9mail.
the class MigrationTo43 method fixOutboxFolders.
public static void fixOutboxFolders(SQLiteDatabase db, MigrationsHelper migrationsHelper) {
try {
LocalStore localStore = migrationsHelper.getLocalStore();
Account account = migrationsHelper.getAccount();
Context context = migrationsHelper.getContext();
// If folder "OUTBOX" (old, v3.800 - v3.802) exists, rename it to
// "K9MAIL_INTERNAL_OUTBOX" (new)
LocalFolder oldOutbox = new LocalFolder(localStore, "OUTBOX");
if (oldOutbox.exists()) {
ContentValues cv = new ContentValues();
cv.put("name", Account.OUTBOX);
db.update("folders", cv, "name = ?", new String[] { "OUTBOX" });
Timber.i("Renamed folder OUTBOX to %s", OUTBOX);
}
// Check if old (pre v3.800) localized outbox folder exists
String localizedOutbox = context.getString(R.string.special_mailbox_name_outbox);
LocalFolder obsoleteOutbox = new LocalFolder(localStore, localizedOutbox);
if (obsoleteOutbox.exists()) {
// Get all messages from the localized outbox ...
List<? extends Message> messages = obsoleteOutbox.getMessages(null, false);
if (messages.size() > 0) {
// ... and move them to the drafts folder (we don't want to
// surprise the user by sending potentially very old messages)
LocalFolder drafts = new LocalFolder(localStore, account.getDraftsFolderName());
obsoleteOutbox.moveMessages(messages, drafts);
}
// Now get rid of the localized outbox
obsoleteOutbox.delete();
obsoleteOutbox.delete(true);
}
} catch (Exception e) {
Timber.e(e, "Error trying to fix the outbox folders");
}
}
use of com.fsck.k9.mailstore.LocalStore in project k-9 by k9mail.
the class MessagingController method checkMailForAccount.
private void checkMailForAccount(final Context context, final Account account, final boolean ignoreLastCheckedTime, final MessagingListener listener) {
if (!account.isAvailable(context)) {
Timber.i("Skipping synchronizing unavailable account %s", account.getDescription());
return;
}
final long accountInterval = account.getAutomaticCheckIntervalMinutes() * 60 * 1000;
if (!ignoreLastCheckedTime && accountInterval <= 0) {
Timber.i("Skipping synchronizing account %s", account.getDescription());
return;
}
Timber.i("Synchronizing account %s", account.getDescription());
account.setRingNotified(false);
sendPendingMessages(account, listener);
try {
Account.FolderMode aDisplayMode = account.getFolderDisplayMode();
Account.FolderMode aSyncMode = account.getFolderSyncMode();
Store localStore = account.getLocalStore();
for (final Folder folder : localStore.getPersonalNamespaces(false)) {
folder.open(Folder.OPEN_MODE_RW);
Folder.FolderClass fDisplayClass = folder.getDisplayClass();
Folder.FolderClass fSyncClass = folder.getSyncClass();
if (modeMismatch(aDisplayMode, fDisplayClass)) {
continue;
}
if (modeMismatch(aSyncMode, fSyncClass)) {
continue;
}
synchronizeFolder(account, folder, ignoreLastCheckedTime, accountInterval, listener);
}
} catch (MessagingException e) {
Timber.e(e, "Unable to synchronize account %s", account.getName());
addErrorMessage(account, null, e);
} finally {
putBackground("clear notification flag for " + account.getDescription(), null, new Runnable() {
@Override
public void run() {
Timber.v("Clearing notification flag for %s", account.getDescription());
account.setRingNotified(false);
try {
AccountStats stats = account.getStats(context);
if (stats == null || stats.unreadMessageCount == 0) {
notificationController.clearNewMailNotifications(account);
}
} catch (MessagingException e) {
Timber.e(e, "Unable to getUnreadMessageCount for account: %s", account);
}
}
});
}
}
use of com.fsck.k9.mailstore.LocalStore in project k-9 by k9mail.
the class MessagingController method isMoveCapable.
public boolean isMoveCapable(final Account account) {
try {
Store localStore = account.getLocalStore();
Store remoteStore = account.getRemoteStore();
return localStore.isMoveCapable() && remoteStore.isMoveCapable();
} catch (MessagingException me) {
Timber.e(me, "Exception while ascertaining move capability");
return false;
}
}
use of com.fsck.k9.mailstore.LocalStore in project k-9 by k9mail.
the class MessagingController method moveOrDeleteSentMessage.
private void moveOrDeleteSentMessage(Account account, LocalStore localStore, LocalFolder localFolder, LocalMessage message) throws MessagingException {
if (!account.hasSentFolder()) {
Timber.i("Account does not have a sent mail folder; deleting sent message");
message.setFlag(Flag.DELETED, true);
} else {
LocalFolder localSentFolder = localStore.getFolder(account.getSentFolderName());
Timber.i("Moving sent message to folder '%s' (%d)", account.getSentFolderName(), localSentFolder.getId());
localFolder.moveMessages(Collections.singletonList(message), localSentFolder);
Timber.i("Moved sent message to folder '%s' (%d)", account.getSentFolderName(), localSentFolder.getId());
PendingCommand command = PendingAppend.create(localSentFolder.getName(), message.getUid());
queuePendingCommand(account, command);
processPendingCommands(account);
}
}
use of com.fsck.k9.mailstore.LocalStore 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