use of com.fsck.k9.mailstore.MigrationsHelper 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.MigrationsHelper 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.MigrationsHelper 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.MigrationsHelper in project k-9 by k9mail.
the class MigrationTo46 method addMessagesFlagColumns.
public static void addMessagesFlagColumns(SQLiteDatabase db, MigrationsHelper migrationsHelper) {
db.execSQL("ALTER TABLE messages ADD read INTEGER default 0");
db.execSQL("ALTER TABLE messages ADD flagged INTEGER default 0");
db.execSQL("ALTER TABLE messages ADD answered INTEGER default 0");
db.execSQL("ALTER TABLE messages ADD forwarded INTEGER default 0");
String[] projection = { "id", "flags" };
ContentValues cv = new ContentValues();
List<Flag> extraFlags = new ArrayList<>();
Cursor cursor = db.query("messages", projection, null, null, null, null, null);
try {
while (cursor.moveToNext()) {
long id = cursor.getLong(0);
String flagList = cursor.getString(1);
boolean read = false;
boolean flagged = false;
boolean answered = false;
boolean forwarded = false;
if (flagList != null && flagList.length() > 0) {
String[] flags = flagList.split(",");
for (String flagStr : flags) {
try {
Flag flag = Flag.valueOf(flagStr);
switch(flag) {
case ANSWERED:
{
answered = true;
break;
}
case DELETED:
{
// Don't store this in column 'flags'
break;
}
case FLAGGED:
{
flagged = true;
break;
}
case FORWARDED:
{
forwarded = true;
break;
}
case SEEN:
{
read = true;
break;
}
case DRAFT:
case RECENT:
case X_DESTROYED:
case X_DOWNLOADED_FULL:
case X_DOWNLOADED_PARTIAL:
case X_REMOTE_COPY_STARTED:
case X_SEND_FAILED:
case X_SEND_IN_PROGRESS:
{
extraFlags.add(flag);
break;
}
}
} catch (Exception e) {
// Ignore bad flags
}
}
}
cv.put("flags", migrationsHelper.serializeFlags(extraFlags));
cv.put("read", read);
cv.put("flagged", flagged);
cv.put("answered", answered);
cv.put("forwarded", forwarded);
db.update("messages", cv, "id = ?", new String[] { Long.toString(id) });
cv.clear();
extraFlags.clear();
}
} finally {
cursor.close();
}
db.execSQL("CREATE INDEX IF NOT EXISTS msg_read ON messages (read)");
db.execSQL("CREATE INDEX IF NOT EXISTS msg_flagged ON messages (flagged)");
}
use of com.fsck.k9.mailstore.MigrationsHelper in project k-9 by k9mail.
the class MigrationTo51 method updateFlagsForMessage.
private static void updateFlagsForMessage(SQLiteDatabase db, long messageId, String messageFlags, MigrationsHelper migrationsHelper) {
List<Flag> extraFlags = new ArrayList<>();
if (messageFlags != null && messageFlags.length() > 0) {
String[] flags = messageFlags.split(",");
for (String flagStr : flags) {
try {
Flag flag = Flag.valueOf(flagStr);
extraFlags.add(flag);
} catch (Exception e) {
// Ignore bad flags
}
}
}
extraFlags.add(Flag.X_MIGRATED_FROM_V50);
String flagsString = migrationsHelper.serializeFlags(extraFlags);
db.execSQL("UPDATE messages SET flags = ? WHERE id = ?", new Object[] { flagsString, messageId });
}
Aggregations