use of com.fsck.k9.mailstore.LocalFolder in project k-9 by k9mail.
the class MigrationTo55 method createFtsSearchTable.
static void createFtsSearchTable(SQLiteDatabase db, MigrationsHelper migrationsHelper) {
db.execSQL("CREATE VIRTUAL TABLE messages_fulltext USING fts4 (fulltext)");
LocalStore localStore = migrationsHelper.getLocalStore();
MessageFulltextCreator fulltextCreator = localStore.getMessageFulltextCreator();
try {
List<LocalFolder> folders = localStore.getPersonalNamespaces(true);
ContentValues cv = new ContentValues();
FetchProfile fp = new FetchProfile();
fp.add(FetchProfile.Item.BODY);
for (LocalFolder folder : folders) {
List<String> messageUids = folder.getAllMessageUids();
for (String messageUid : messageUids) {
LocalMessage localMessage = folder.getMessage(messageUid);
folder.fetch(Collections.singletonList(localMessage), fp, null);
String fulltext = fulltextCreator.createFulltext(localMessage);
if (!TextUtils.isEmpty(fulltext)) {
Timber.d("fulltext for msg id %d is %d chars long", localMessage.getId(), fulltext.length());
cv.clear();
cv.put("docid", localMessage.getId());
cv.put("fulltext", fulltext);
db.insert("messages_fulltext", null, cv);
} else {
Timber.d("no fulltext for msg id %d :(", localMessage.getId());
}
}
}
} catch (MessagingException e) {
Timber.e(e, "error indexing fulltext - skipping rest, fts index is incomplete!");
}
}
use of com.fsck.k9.mailstore.LocalFolder in project k-9 by k9mail.
the class MigrationTo42 method from41MoveFolderPreferences.
public static void from41MoveFolderPreferences(MigrationsHelper migrationsHelper) {
try {
LocalStore localStore = migrationsHelper.getLocalStore();
Storage storage = migrationsHelper.getStorage();
long startTime = System.currentTimeMillis();
StorageEditor editor = storage.edit();
List<? extends Folder> folders = localStore.getPersonalNamespaces(true);
for (Folder folder : folders) {
if (folder instanceof LocalFolder) {
LocalFolder lFolder = (LocalFolder) folder;
lFolder.save(editor);
}
}
editor.commit();
long endTime = System.currentTimeMillis();
Timber.i("Putting folder preferences for %d folders back into Preferences took %d ms", folders.size(), endTime - startTime);
} catch (Exception e) {
Timber.e(e, "Could not replace Preferences in upgrade from DB_VERSION 41");
}
}
use of com.fsck.k9.mailstore.LocalFolder 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.LocalFolder in project k-9 by k9mail.
the class MessagingController method addErrorMessage.
private void addErrorMessage(Account account, String subject, String body) {
if (!K9.isDebug()) {
return;
}
if (!loopCatch.compareAndSet(false, true)) {
return;
}
try {
if (body == null || body.length() < 1) {
return;
}
Store localStore = account.getLocalStore();
LocalFolder localFolder = (LocalFolder) localStore.getFolder(account.getErrorFolderName());
MimeMessage message = new MimeMessage();
MimeMessageHelper.setBody(message, new TextBody(body));
message.setFlag(Flag.X_DOWNLOADED_FULL, true);
message.setSubject(subject);
long nowTime = System.currentTimeMillis();
Date nowDate = new Date(nowTime);
message.setInternalDate(nowDate);
message.addSentDate(nowDate, K9.hideTimeZone());
message.setFrom(new Address(account.getEmail(), "K9mail internal"));
localFolder.appendMessages(Collections.singletonList(message));
localFolder.clearMessagesOlderThan(nowTime - (15 * 60 * 1000));
} catch (Throwable it) {
Timber.e(it, "Could not save error message to %s", account.getErrorFolderName());
} finally {
loopCatch.set(false);
}
}
use of com.fsck.k9.mailstore.LocalFolder in project k-9 by k9mail.
the class MessagingController method downloadSaneBody.
private void downloadSaneBody(Account account, Folder remoteFolder, LocalFolder localFolder, Message message) throws MessagingException {
/*
* The provider was unable to get the structure of the message, so
* we'll download a reasonable portion of the messge and mark it as
* incomplete so the entire thing can be downloaded later if the user
* wishes to download it.
*/
FetchProfile fp = new FetchProfile();
fp.add(FetchProfile.Item.BODY_SANE);
/*
* TODO a good optimization here would be to make sure that all Stores set
* the proper size after this fetch and compare the before and after size. If
* they equal we can mark this SYNCHRONIZED instead of PARTIALLY_SYNCHRONIZED
*/
remoteFolder.fetch(Collections.singletonList(message), fp, null);
// Store the updated message locally
localFolder.appendMessages(Collections.singletonList(message));
Message localMessage = localFolder.getMessage(message.getUid());
// Certain (POP3) servers give you the whole message even when you ask for only the first x Kb
if (!message.isSet(Flag.X_DOWNLOADED_FULL)) {
/*
* Mark the message as fully downloaded if the message size is smaller than
* the account's autodownload size limit, otherwise mark as only a partial
* download. This will prevent the system from downloading the same message
* twice.
*
* If there is no limit on autodownload size, that's the same as the message
* being smaller than the max size
*/
if (account.getMaximumAutoDownloadMessageSize() == 0 || message.getSize() < account.getMaximumAutoDownloadMessageSize()) {
localMessage.setFlag(Flag.X_DOWNLOADED_FULL, true);
} else {
// Set a flag indicating that the message has been partially downloaded and
// is ready for view.
localMessage.setFlag(Flag.X_DOWNLOADED_PARTIAL, true);
}
}
}
Aggregations