use of com.fsck.k9.mailstore.MigrationsHelper in project k-9 by k9mail.
the class MigrationTo41 method update41Metadata.
private static void update41Metadata(SQLiteDatabase db, MigrationsHelper migrationsHelper, int id, String name) {
Storage storage = migrationsHelper.getStorage();
Account account = migrationsHelper.getAccount();
String accountUuid = account.getUuid();
Folder.FolderClass displayClass = Folder.FolderClass.NO_CLASS;
Folder.FolderClass syncClass = Folder.FolderClass.INHERITED;
Folder.FolderClass pushClass = Folder.FolderClass.SECOND_CLASS;
boolean inTopGroup = false;
boolean integrate = false;
if (account.getInboxFolderName().equals(name)) {
displayClass = Folder.FolderClass.FIRST_CLASS;
syncClass = Folder.FolderClass.FIRST_CLASS;
pushClass = Folder.FolderClass.FIRST_CLASS;
inTopGroup = true;
integrate = true;
}
try {
displayClass = Folder.FolderClass.valueOf(storage.getString(accountUuid + "." + name + ".displayMode", displayClass.name()));
syncClass = Folder.FolderClass.valueOf(storage.getString(accountUuid + "." + name + ".syncMode", syncClass.name()));
pushClass = Folder.FolderClass.valueOf(storage.getString(accountUuid + "." + name + ".pushMode", pushClass.name()));
inTopGroup = storage.getBoolean(accountUuid + "." + name + ".inTopGroup", inTopGroup);
integrate = storage.getBoolean(accountUuid + "." + name + ".integrate", integrate);
} catch (Exception e) {
Timber.e(e, " Throwing away an error while trying to upgrade folder metadata");
}
if (displayClass == Folder.FolderClass.NONE) {
displayClass = Folder.FolderClass.NO_CLASS;
}
if (syncClass == Folder.FolderClass.NONE) {
syncClass = Folder.FolderClass.INHERITED;
}
if (pushClass == Folder.FolderClass.NONE) {
pushClass = Folder.FolderClass.INHERITED;
}
db.execSQL("UPDATE folders SET integrate = ?, top_group = ?, poll_class=?, push_class =?, display_class = ? WHERE id = ?", new Object[] { integrate, inTopGroup, syncClass, pushClass, displayClass, id });
}
use of com.fsck.k9.mailstore.MigrationsHelper in project k-9 by k9mail.
the class MigrationTo50 method foldersAddNotifyClassColumn.
public static void foldersAddNotifyClassColumn(SQLiteDatabase db, MigrationsHelper migrationsHelper) {
try {
db.execSQL("ALTER TABLE folders ADD notify_class TEXT default '" + Folder.FolderClass.INHERITED.name() + "'");
} catch (SQLiteException e) {
if (!e.getMessage().startsWith("duplicate column name:")) {
throw e;
}
}
ContentValues cv = new ContentValues();
cv.put("notify_class", Folder.FolderClass.FIRST_CLASS.name());
Account account = migrationsHelper.getAccount();
db.update("folders", cv, "name = ?", new String[] { account.getInboxFolderName() });
}
use of com.fsck.k9.mailstore.MigrationsHelper in project k-9 by k9mail.
the class MigrationTo51 method db51MigrateMessageFormat.
/**
* This method converts from the old message table structure to the new one.
*
* This is a complex migration, and ultimately we do not have enough
* information to recreate the mime structure of the original mails.
* What we have:
* - general mail info
* - html_content and text_content data, which is the squashed readable content of the mail
* - a table with message headers
* - attachments
*
* What we need to do:
* - migrate general mail info as-is
* - flag mails as migrated for re-download
* - for each message, recreate a mime structure from its message content and attachments:
* + insert one or both of textContent and htmlContent, depending on mimeType
* + if mimeType is text/plain, text/html or multipart/alternative and no
* attachments are present, just insert that.
* + otherwise, use multipart/mixed, adding attachments after textual content
* + revert content:// URIs in htmlContent to original cid: URIs.
*/
public static void db51MigrateMessageFormat(SQLiteDatabase db, MigrationsHelper migrationsHelper) {
renameOldMessagesTableAndCreateNew(db);
copyMessageMetadataToNewTable(db);
File attachmentDirNew, attachmentDirOld;
Account account = migrationsHelper.getAccount();
attachmentDirNew = StorageManager.getInstance(K9.app).getAttachmentDirectory(account.getUuid(), account.getLocalStorageProviderId());
attachmentDirOld = renameOldAttachmentDirAndCreateNew(account, attachmentDirNew);
Cursor msgCursor = db.query("messages_old", new String[] { "id", "flags", "html_content", "text_content", "mime_type", "attachment_count" }, null, null, null, null, null);
try {
Timber.d("migrating %d messages", msgCursor.getCount());
ContentValues cv = new ContentValues();
while (msgCursor.moveToNext()) {
long messageId = msgCursor.getLong(0);
String messageFlags = msgCursor.getString(1);
String htmlContent = msgCursor.getString(2);
String textContent = msgCursor.getString(3);
String mimeType = msgCursor.getString(4);
int attachmentCount = msgCursor.getInt(5);
try {
updateFlagsForMessage(db, messageId, messageFlags, migrationsHelper);
MimeHeader mimeHeader = loadHeaderFromHeadersTable(db, messageId);
MimeStructureState structureState = MimeStructureState.getNewRootState();
boolean messageHadSpecialFormat = false;
// we do not rely on the protocol parameter here but guess by the multipart structure
boolean isMaybePgpMimeEncrypted = attachmentCount == 2 && MimeUtil.isSameMimeType(mimeType, "multipart/encrypted");
if (isMaybePgpMimeEncrypted) {
MimeStructureState maybeStructureState = migratePgpMimeEncryptedContent(db, messageId, attachmentDirOld, attachmentDirNew, mimeHeader, structureState);
if (maybeStructureState != null) {
structureState = maybeStructureState;
messageHadSpecialFormat = true;
}
}
if (!messageHadSpecialFormat) {
boolean isSimpleStructured = attachmentCount == 0 && Utility.isAnyMimeType(mimeType, "text/plain", "text/html", "multipart/alternative");
if (isSimpleStructured) {
structureState = migrateSimpleMailContent(db, htmlContent, textContent, mimeType, mimeHeader, structureState);
} else {
mimeType = "multipart/mixed";
structureState = migrateComplexMailContent(db, attachmentDirOld, attachmentDirNew, messageId, htmlContent, textContent, mimeHeader, structureState);
}
}
cv.clear();
cv.put("mime_type", mimeType);
cv.put("message_part_id", structureState.rootPartId);
cv.put("attachment_count", attachmentCount);
db.update("messages", cv, "id = ?", new String[] { Long.toString(messageId) });
} catch (IOException e) {
Timber.e(e, "error inserting into database");
}
}
} finally {
msgCursor.close();
}
cleanUpOldAttachmentDirectory(attachmentDirOld);
dropOldMessagesTable(db);
}
use of com.fsck.k9.mailstore.MigrationsHelper in project k-9 by k9mail.
the class StoreSchemaDefinitionTest method createStoreSchemaDefinition.
private StoreSchemaDefinition createStoreSchemaDefinition() throws MessagingException {
final Account account = createAccount();
final LockableDatabase lockableDatabase = createLockableDatabase();
final LocalStore localStore = mock(LocalStore.class);
when(localStore.getDatabase()).thenReturn(lockableDatabase);
MigrationsHelper migrationsHelper = new MigrationsHelper() {
@Override
public Account getAccount() {
return account;
}
@Override
public void saveAccount() {
// Do nothing
}
};
return new StoreSchemaDefinition(migrationsHelper);
}
Aggregations