2018-08-02 13:33:06 +00:00
|
|
|
package eu.faircode.email;
|
|
|
|
|
|
|
|
import android.content.Context;
|
2018-12-23 18:20:08 +00:00
|
|
|
import android.content.SharedPreferences;
|
2018-08-24 09:20:14 +00:00
|
|
|
import android.database.Cursor;
|
2018-08-06 16:22:01 +00:00
|
|
|
import android.text.TextUtils;
|
2018-08-02 13:33:06 +00:00
|
|
|
|
2019-05-31 06:57:23 +00:00
|
|
|
import androidx.annotation.NonNull;
|
2019-04-17 18:21:44 +00:00
|
|
|
import androidx.preference.PreferenceManager;
|
|
|
|
import androidx.room.Database;
|
2019-05-31 06:57:23 +00:00
|
|
|
import androidx.room.InvalidationTracker;
|
2019-04-17 18:21:44 +00:00
|
|
|
import androidx.room.Room;
|
|
|
|
import androidx.room.RoomDatabase;
|
|
|
|
import androidx.room.TypeConverter;
|
|
|
|
import androidx.room.TypeConverters;
|
|
|
|
import androidx.room.migration.Migration;
|
|
|
|
import androidx.sqlite.db.SupportSQLiteDatabase;
|
|
|
|
|
2018-08-07 16:25:57 +00:00
|
|
|
import org.json.JSONArray;
|
|
|
|
import org.json.JSONException;
|
|
|
|
import org.json.JSONObject;
|
|
|
|
|
2019-03-14 09:12:19 +00:00
|
|
|
import java.io.File;
|
2018-08-07 16:25:57 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2019-05-31 06:57:23 +00:00
|
|
|
import java.util.Set;
|
2019-01-04 14:48:55 +00:00
|
|
|
import java.util.concurrent.ExecutorService;
|
|
|
|
import java.util.concurrent.Executors;
|
2018-08-07 16:25:57 +00:00
|
|
|
|
|
|
|
import javax.mail.Address;
|
|
|
|
import javax.mail.internet.InternetAddress;
|
|
|
|
|
2018-11-09 07:38:07 +00:00
|
|
|
import io.requery.android.database.sqlite.RequerySQLiteOpenHelperFactory;
|
2018-08-08 06:55:47 +00:00
|
|
|
|
2018-08-02 13:33:06 +00:00
|
|
|
/*
|
2018-08-14 05:53:24 +00:00
|
|
|
This file is part of FairEmail.
|
2018-08-02 13:33:06 +00:00
|
|
|
|
2018-08-14 05:53:24 +00:00
|
|
|
FairEmail is free software: you can redistribute it and/or modify
|
2018-08-02 13:33:06 +00:00
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
2018-10-29 10:46:49 +00:00
|
|
|
FairEmail is distributed in the hope that it will be useful,
|
2018-08-02 13:33:06 +00:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2018-10-29 10:46:49 +00:00
|
|
|
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
|
2018-08-02 13:33:06 +00:00
|
|
|
|
2018-12-31 08:04:33 +00:00
|
|
|
Copyright 2018-2019 by Marcel Bokhorst (M66B)
|
2018-08-02 13:33:06 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
// https://developer.android.com/topic/libraries/architecture/room.html
|
|
|
|
|
|
|
|
@Database(
|
2019-05-25 14:01:51 +00:00
|
|
|
version = 85,
|
2018-08-02 13:33:06 +00:00
|
|
|
entities = {
|
|
|
|
EntityIdentity.class,
|
|
|
|
EntityAccount.class,
|
|
|
|
EntityFolder.class,
|
|
|
|
EntityMessage.class,
|
2018-08-03 12:07:51 +00:00
|
|
|
EntityAttachment.class,
|
2018-08-27 07:06:03 +00:00
|
|
|
EntityOperation.class,
|
2019-02-13 09:24:06 +00:00
|
|
|
EntityContact.class,
|
2018-08-27 07:06:03 +00:00
|
|
|
EntityAnswer.class,
|
2019-01-17 13:29:35 +00:00
|
|
|
EntityRule.class,
|
2019-05-22 05:51:50 +00:00
|
|
|
EntityLog.class
|
2018-08-08 10:22:12 +00:00
|
|
|
}
|
2018-08-02 13:33:06 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
@TypeConverters({DB.Converters.class})
|
|
|
|
public abstract class DB extends RoomDatabase {
|
|
|
|
public abstract DaoAccount account();
|
|
|
|
|
2019-05-31 06:57:23 +00:00
|
|
|
public abstract DaoIdentity identity();
|
|
|
|
|
2018-08-02 13:33:06 +00:00
|
|
|
public abstract DaoFolder folder();
|
|
|
|
|
|
|
|
public abstract DaoMessage message();
|
|
|
|
|
2018-08-03 12:07:51 +00:00
|
|
|
public abstract DaoAttachment attachment();
|
|
|
|
|
2018-08-02 13:33:06 +00:00
|
|
|
public abstract DaoOperation operation();
|
|
|
|
|
2019-02-13 09:24:06 +00:00
|
|
|
public abstract DaoContact contact();
|
|
|
|
|
2018-08-27 07:06:03 +00:00
|
|
|
public abstract DaoAnswer answer();
|
|
|
|
|
2019-01-17 13:29:35 +00:00
|
|
|
public abstract DaoRule rule();
|
|
|
|
|
2018-09-03 19:11:16 +00:00
|
|
|
public abstract DaoLog log();
|
|
|
|
|
2018-08-02 13:33:06 +00:00
|
|
|
private static DB sInstance;
|
2019-05-30 11:21:45 +00:00
|
|
|
private static ExecutorService executor = Executors.newCachedThreadPool(Helper.backgroundThreadFactory);
|
2018-08-02 13:33:06 +00:00
|
|
|
|
2018-11-13 09:05:33 +00:00
|
|
|
private static final String DB_NAME = "fairemail";
|
2018-08-02 13:33:06 +00:00
|
|
|
|
2019-04-16 18:19:50 +00:00
|
|
|
public static synchronized DB getInstance(Context ctx) {
|
2018-08-24 12:31:51 +00:00
|
|
|
if (sInstance == null) {
|
2019-04-16 18:19:50 +00:00
|
|
|
Context context = ctx.getApplicationContext();
|
2019-01-06 16:31:53 +00:00
|
|
|
sInstance = migrate(context, getBuilder(context));
|
2019-05-31 06:57:23 +00:00
|
|
|
|
|
|
|
sInstance.getInvalidationTracker().addObserver(new InvalidationTracker.Observer(
|
|
|
|
EntityAccount.TABLE_NAME,
|
|
|
|
EntityIdentity.TABLE_NAME,
|
|
|
|
EntityFolder.TABLE_NAME,
|
|
|
|
EntityMessage.TABLE_NAME,
|
|
|
|
EntityAttachment.TABLE_NAME,
|
|
|
|
EntityOperation.TABLE_NAME,
|
|
|
|
EntityContact.TABLE_NAME,
|
|
|
|
EntityAnswer.TABLE_NAME,
|
|
|
|
EntityRule.TABLE_NAME,
|
|
|
|
EntityLog.TABLE_NAME) {
|
|
|
|
@Override
|
|
|
|
public void onInvalidated(@NonNull Set<String> tables) {
|
|
|
|
Log.i("ROOM invalidated=" + TextUtils.join(",", tables));
|
|
|
|
}
|
|
|
|
});
|
2018-08-24 12:31:51 +00:00
|
|
|
}
|
|
|
|
|
2018-08-02 13:33:06 +00:00
|
|
|
return sInstance;
|
|
|
|
}
|
|
|
|
|
2019-01-06 16:31:53 +00:00
|
|
|
private static RoomDatabase.Builder getBuilder(Context context) {
|
|
|
|
return Room
|
2019-04-16 18:19:50 +00:00
|
|
|
.databaseBuilder(context, DB.class, DB_NAME)
|
2019-01-06 16:31:53 +00:00
|
|
|
.openHelperFactory(new RequerySQLiteOpenHelperFactory())
|
|
|
|
.setQueryExecutor(executor)
|
|
|
|
.setJournalMode(JournalMode.WRITE_AHEAD_LOGGING);
|
|
|
|
}
|
|
|
|
|
2018-12-23 18:20:08 +00:00
|
|
|
private static DB migrate(final Context context, RoomDatabase.Builder<DB> builder) {
|
2018-11-13 09:05:33 +00:00
|
|
|
// https://www.sqlite.org/lang_altertable.html
|
2018-08-02 13:33:06 +00:00
|
|
|
return builder
|
2018-08-08 10:22:12 +00:00
|
|
|
.addCallback(new Callback() {
|
|
|
|
@Override
|
|
|
|
public void onOpen(SupportSQLiteDatabase db) {
|
2018-12-24 12:27:45 +00:00
|
|
|
Log.i("Database version=" + db.getVersion());
|
2018-08-08 10:22:12 +00:00
|
|
|
super.onOpen(db);
|
|
|
|
}
|
|
|
|
})
|
2018-08-23 09:48:27 +00:00
|
|
|
.addMigrations(new Migration(1, 2) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
2018-12-24 12:27:45 +00:00
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
2018-11-14 09:49:59 +00:00
|
|
|
db.execSQL("ALTER TABLE `folder` RENAME COLUMN `after` TO `sync_days`");
|
|
|
|
db.execSQL("ALTER TABLE `folder` ADD COLUMN `keep_days` INTEGER NOT NULL DEFAULT 30");
|
|
|
|
db.execSQL("UPDATE `folder` SET keep_days = sync_days");
|
2018-11-12 13:45:02 +00:00
|
|
|
}
|
|
|
|
})
|
2018-11-14 13:51:50 +00:00
|
|
|
.addMigrations(new Migration(2, 3) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
2018-12-24 12:27:45 +00:00
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
2018-11-14 13:51:50 +00:00
|
|
|
db.execSQL("ALTER TABLE `identity` ADD COLUMN `signature` TEXT");
|
|
|
|
db.execSQL("UPDATE `identity` SET signature =" +
|
|
|
|
" (SELECT account.signature FROM account WHERE account.id = identity.account)");
|
|
|
|
}
|
|
|
|
})
|
2018-11-16 12:48:45 +00:00
|
|
|
.addMigrations(new Migration(3, 4) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
2018-12-24 12:27:45 +00:00
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
2018-11-16 12:48:45 +00:00
|
|
|
db.execSQL("ALTER TABLE `message` ADD COLUMN `forwarding` INTEGER" +
|
|
|
|
" REFERENCES `message`(`id`) ON UPDATE NO ACTION ON DELETE SET NULL");
|
2018-12-06 10:59:57 +00:00
|
|
|
db.execSQL("CREATE INDEX `index_message_forwarding` ON `message` (`forwarding`)");
|
2018-11-16 12:48:45 +00:00
|
|
|
}
|
|
|
|
})
|
2018-11-19 13:14:02 +00:00
|
|
|
.addMigrations(new Migration(4, 5) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
2018-12-24 12:27:45 +00:00
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
2018-11-19 13:14:02 +00:00
|
|
|
db.execSQL("ALTER TABLE `account` ADD COLUMN `last_connected` INTEGER");
|
|
|
|
db.execSQL("ALTER TABLE `message` ADD COLUMN `last_attempt` INTEGER");
|
|
|
|
}
|
|
|
|
})
|
2018-11-24 08:26:34 +00:00
|
|
|
.addMigrations(new Migration(5, 6) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
2018-12-24 12:27:45 +00:00
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
2018-11-24 08:26:34 +00:00
|
|
|
db.execSQL("ALTER TABLE `account` ADD COLUMN `notify` INTEGER NOT NULL DEFAULT 0");
|
|
|
|
}
|
|
|
|
})
|
2018-11-24 18:14:28 +00:00
|
|
|
.addMigrations(new Migration(6, 7) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
2018-12-24 12:27:45 +00:00
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
2018-11-24 18:14:28 +00:00
|
|
|
db.execSQL("ALTER TABLE `message` ADD COLUMN `answered` INTEGER NOT NULL DEFAULT 0");
|
|
|
|
db.execSQL("ALTER TABLE `message` ADD COLUMN `ui_answered` INTEGER NOT NULL DEFAULT 0");
|
|
|
|
}
|
|
|
|
})
|
2018-11-25 12:34:08 +00:00
|
|
|
.addMigrations(new Migration(7, 8) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
2018-12-24 12:27:45 +00:00
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
2018-11-25 12:34:08 +00:00
|
|
|
db.execSQL("ALTER TABLE `message` ADD COLUMN `keywords` TEXT");
|
|
|
|
}
|
|
|
|
})
|
2018-11-26 08:12:44 +00:00
|
|
|
.addMigrations(new Migration(8, 9) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
2018-12-24 12:27:45 +00:00
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
2018-11-26 08:12:44 +00:00
|
|
|
db.execSQL("ALTER TABLE `folder` ADD COLUMN `keywords` TEXT");
|
|
|
|
}
|
|
|
|
})
|
2018-11-26 15:57:00 +00:00
|
|
|
.addMigrations(new Migration(9, 10) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
2018-12-24 12:27:45 +00:00
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
2018-11-26 15:57:00 +00:00
|
|
|
db.execSQL("ALTER TABLE `message` ADD COLUMN `ui_browsed` INTEGER NOT NULL DEFAULT 0");
|
2018-12-06 10:59:57 +00:00
|
|
|
db.execSQL("CREATE INDEX `index_message_ui_browsed` ON `message` (`ui_browsed`)");
|
2018-11-26 15:57:00 +00:00
|
|
|
}
|
|
|
|
})
|
2018-12-01 14:13:57 +00:00
|
|
|
.addMigrations(new Migration(10, 11) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
2018-12-24 12:27:45 +00:00
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
2018-12-01 14:13:57 +00:00
|
|
|
db.execSQL("ALTER TABLE `operation` ADD COLUMN `error` TEXT");
|
|
|
|
}
|
|
|
|
})
|
2018-12-02 13:19:54 +00:00
|
|
|
.addMigrations(new Migration(11, 12) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
2018-12-24 12:27:45 +00:00
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
2018-12-02 13:19:54 +00:00
|
|
|
db.execSQL("DROP INDEX `index_operation_folder`");
|
|
|
|
db.execSQL("DROP INDEX `index_operation_message`");
|
|
|
|
db.execSQL("DROP TABLE `operation`");
|
|
|
|
db.execSQL("CREATE TABLE `operation`" +
|
|
|
|
" (`id` INTEGER PRIMARY KEY AUTOINCREMENT" +
|
|
|
|
", `folder` INTEGER NOT NULL" +
|
|
|
|
", `message` INTEGER" +
|
|
|
|
", `name` TEXT NOT NULL" +
|
|
|
|
", `args` TEXT NOT NULL" +
|
|
|
|
", `created` INTEGER NOT NULL" +
|
|
|
|
", `error` TEXT" +
|
|
|
|
", FOREIGN KEY(`folder`) REFERENCES `folder`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE" +
|
|
|
|
", FOREIGN KEY(`message`) REFERENCES `message`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE)");
|
|
|
|
db.execSQL("CREATE INDEX `index_operation_folder` ON `operation` (`folder`)");
|
|
|
|
db.execSQL("CREATE INDEX `index_operation_message` ON `operation` (`message`)");
|
|
|
|
}
|
|
|
|
})
|
2018-12-03 08:33:43 +00:00
|
|
|
.addMigrations(new Migration(12, 13) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
2018-12-24 12:27:45 +00:00
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
2019-03-05 13:38:05 +00:00
|
|
|
db.execSQL("CREATE INDEX `index_message_ui_flagged` ON `message` (`ui_flagged`)");
|
2018-12-03 08:33:43 +00:00
|
|
|
}
|
|
|
|
})
|
2018-12-03 09:39:44 +00:00
|
|
|
.addMigrations(new Migration(13, 14) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
2018-12-24 12:27:45 +00:00
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
2018-12-03 09:39:44 +00:00
|
|
|
db.execSQL("ALTER TABLE `folder` ADD COLUMN `level` INTEGER NOT NULL DEFAULT 0");
|
|
|
|
}
|
|
|
|
})
|
2018-12-03 12:41:36 +00:00
|
|
|
.addMigrations(new Migration(14, 15) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
2018-12-24 12:27:45 +00:00
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
2018-12-03 12:41:36 +00:00
|
|
|
db.execSQL("ALTER TABLE `folder` ADD COLUMN `sync_state` TEXT");
|
|
|
|
}
|
|
|
|
})
|
2018-12-05 09:25:35 +00:00
|
|
|
.addMigrations(new Migration(15, 16) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
2018-12-24 12:27:45 +00:00
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
2018-12-05 09:25:35 +00:00
|
|
|
db.execSQL("ALTER TABLE `folder` ADD COLUMN `poll` INTEGER NOT NULL DEFAULT 0");
|
|
|
|
}
|
|
|
|
})
|
2018-12-06 10:59:57 +00:00
|
|
|
.addMigrations(new Migration(16, 17) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
2018-12-24 12:27:45 +00:00
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
2018-12-06 10:59:57 +00:00
|
|
|
db.execSQL("DELETE FROM `message` WHERE ui_found");
|
|
|
|
db.execSQL("DROP INDEX `index_message_folder_uid_ui_found`");
|
|
|
|
db.execSQL("DROP INDEX `index_message_msgid_folder_ui_found`");
|
|
|
|
db.execSQL("CREATE UNIQUE INDEX `index_message_folder_uid` ON `message` (`folder`, `uid`)");
|
|
|
|
db.execSQL("CREATE UNIQUE INDEX `index_message_msgid_folder` ON `message` (`msgid`, `folder`)");
|
|
|
|
}
|
|
|
|
})
|
2018-12-06 12:43:00 +00:00
|
|
|
.addMigrations(new Migration(17, 18) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
2018-12-24 12:27:45 +00:00
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
2018-12-06 12:43:00 +00:00
|
|
|
db.execSQL("ALTER TABLE `account` ADD COLUMN `tbd` INTEGER");
|
|
|
|
db.execSQL("ALTER TABLE `identity` ADD COLUMN `tbd` INTEGER");
|
|
|
|
db.execSQL("ALTER TABLE `folder` ADD COLUMN `tbd` INTEGER");
|
|
|
|
}
|
|
|
|
})
|
2018-12-07 15:48:52 +00:00
|
|
|
.addMigrations(new Migration(18, 19) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
2018-12-24 12:27:45 +00:00
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
2018-12-07 15:48:52 +00:00
|
|
|
db.execSQL("ALTER TABLE `identity` ADD COLUMN `delivery_receipt` INTEGER NOT NULL DEFAULT 0");
|
|
|
|
db.execSQL("ALTER TABLE `identity` ADD COLUMN `read_receipt` INTEGER NOT NULL DEFAULT 0");
|
|
|
|
}
|
|
|
|
})
|
2018-12-09 08:38:23 +00:00
|
|
|
.addMigrations(new Migration(19, 20) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
2018-12-24 12:27:45 +00:00
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
2018-12-09 08:38:23 +00:00
|
|
|
db.execSQL("ALTER TABLE `folder` ADD COLUMN `notify` INTEGER NOT NULL DEFAULT 0");
|
|
|
|
db.execSQL("UPDATE `folder` SET notify = unified");
|
|
|
|
}
|
|
|
|
})
|
2018-12-10 15:45:52 +00:00
|
|
|
.addMigrations(new Migration(20, 21) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
2018-12-24 12:27:45 +00:00
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
2018-12-10 15:45:52 +00:00
|
|
|
db.execSQL("ALTER TABLE `identity` ADD COLUMN `display` TEXT");
|
|
|
|
db.execSQL("ALTER TABLE `identity` ADD COLUMN `bcc` TEXT");
|
|
|
|
}
|
|
|
|
})
|
2018-12-11 11:18:26 +00:00
|
|
|
.addMigrations(new Migration(21, 22) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
2018-12-24 12:27:45 +00:00
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
2018-12-11 11:18:26 +00:00
|
|
|
db.execSQL("ALTER TABLE `folder` ADD COLUMN `initialize` INTEGER NOT NULL DEFAULT 1");
|
|
|
|
db.execSQL("UPDATE `folder` SET sync_days = 1");
|
|
|
|
}
|
|
|
|
})
|
2018-12-14 11:31:25 +00:00
|
|
|
.addMigrations(new Migration(22, 23) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
2018-12-24 12:27:45 +00:00
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
2018-12-14 11:31:25 +00:00
|
|
|
db.execSQL("ALTER TABLE `folder` ADD COLUMN `download` INTEGER NOT NULL DEFAULT 1");
|
|
|
|
}
|
|
|
|
})
|
2018-12-22 11:40:47 +00:00
|
|
|
.addMigrations(new Migration(23, 24) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
2018-12-24 12:27:45 +00:00
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
2018-12-22 11:40:47 +00:00
|
|
|
db.execSQL("ALTER TABLE `folder` ADD COLUMN `tbc` INTEGER");
|
|
|
|
}
|
|
|
|
})
|
2018-12-22 17:39:16 +00:00
|
|
|
.addMigrations(new Migration(24, 25) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
2018-12-24 12:27:45 +00:00
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
2018-12-22 17:39:16 +00:00
|
|
|
db.execSQL("ALTER TABLE `account` ADD COLUMN `prefix` TEXT");
|
|
|
|
}
|
|
|
|
})
|
2018-12-23 18:20:08 +00:00
|
|
|
.addMigrations(new Migration(25, 26) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
2018-12-24 12:27:45 +00:00
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
2018-12-23 18:20:08 +00:00
|
|
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
|
|
int browse = (prefs.getBoolean("browse", true) ? 1 : 0);
|
|
|
|
db.execSQL("ALTER TABLE `account` ADD COLUMN `browse` INTEGER NOT NULL DEFAULT " + browse);
|
|
|
|
}
|
|
|
|
})
|
2018-12-27 11:32:20 +00:00
|
|
|
.addMigrations(new Migration(26, 27) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("ALTER TABLE `message` ADD COLUMN `sender` TEXT");
|
2019-03-05 13:38:05 +00:00
|
|
|
db.execSQL("CREATE INDEX `index_message_sender` ON `message` (`sender`)");
|
2018-12-28 08:04:56 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
.addMigrations(new Migration(27, 28) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
2018-12-27 11:32:20 +00:00
|
|
|
|
2019-02-22 15:59:23 +00:00
|
|
|
try (Cursor cursor = db.query("SELECT `id`, `from` FROM message")) {
|
2018-12-28 08:04:56 +00:00
|
|
|
while (cursor.moveToNext())
|
|
|
|
try {
|
|
|
|
long id = cursor.getLong(0);
|
|
|
|
String json = cursor.getString(1);
|
|
|
|
Address[] from = Converters.decodeAddresses(json);
|
|
|
|
String sender = MessageHelper.getSortKey(from);
|
2018-12-27 11:32:20 +00:00
|
|
|
db.execSQL(
|
|
|
|
"UPDATE message SET sender = ? WHERE id = ?",
|
|
|
|
new Object[]{sender, id});
|
2018-12-28 08:04:56 +00:00
|
|
|
} catch (Throwable ex) {
|
|
|
|
Log.e(ex);
|
|
|
|
}
|
2018-12-27 11:32:20 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2019-01-01 18:49:21 +00:00
|
|
|
.addMigrations(new Migration(28, 29) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("ALTER TABLE `folder` ADD COLUMN `last_sync` INTEGER");
|
|
|
|
}
|
|
|
|
})
|
2019-01-05 14:09:47 +00:00
|
|
|
.addMigrations(new Migration(29, 30) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("ALTER TABLE `attachment` ADD COLUMN `encryption` INTEGER");
|
|
|
|
db.execSQL("UPDATE attachment SET encryption = " + EntityAttachment.PGP_MESSAGE + " where name = 'encrypted.asc'");
|
|
|
|
}
|
|
|
|
})
|
2019-01-06 11:00:08 +00:00
|
|
|
.addMigrations(new Migration(30, 31) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("ALTER TABLE `attachment` ADD COLUMN `disposition` TEXT");
|
|
|
|
}
|
|
|
|
})
|
2019-01-07 15:05:24 +00:00
|
|
|
.addMigrations(new Migration(31, 32) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("ALTER TABLE `message` ADD COLUMN `ui_snoozed` INTEGER");
|
2019-03-05 13:38:05 +00:00
|
|
|
db.execSQL("CREATE INDEX `index_message_ui_snoozed` ON `message` (`ui_snoozed`)");
|
2019-01-07 15:05:24 +00:00
|
|
|
}
|
|
|
|
})
|
2019-01-10 18:24:20 +00:00
|
|
|
.addMigrations(new Migration(32, 33) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("ALTER TABLE `account` ADD COLUMN `realm` TEXT");
|
|
|
|
db.execSQL("ALTER TABLE `identity` ADD COLUMN `realm` TEXT");
|
|
|
|
}
|
|
|
|
})
|
2019-01-16 17:37:45 +00:00
|
|
|
.addMigrations(new Migration(33, 34) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("ALTER TABLE `message` ADD COLUMN `raw` INTEGER");
|
|
|
|
}
|
|
|
|
})
|
2019-01-16 18:27:03 +00:00
|
|
|
.addMigrations(new Migration(34, 35) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("ALTER TABLE `attachment` ADD COLUMN `error` TEXT");
|
|
|
|
}
|
|
|
|
})
|
2019-01-17 10:49:18 +00:00
|
|
|
.addMigrations(new Migration(35, 36) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("ALTER TABLE `message` ADD COLUMN `warning` TEXT");
|
|
|
|
}
|
|
|
|
})
|
2019-01-17 13:29:35 +00:00
|
|
|
.addMigrations(new Migration(36, 37) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("CREATE TABLE `rule`" +
|
|
|
|
" (`id` INTEGER PRIMARY KEY AUTOINCREMENT," +
|
|
|
|
" `folder` INTEGER NOT NULL," +
|
|
|
|
" `name` TEXT NOT NULL," +
|
|
|
|
" `order` INTEGER NOT NULL," +
|
2019-01-17 21:25:22 +00:00
|
|
|
" `enabled` INTEGER NOT NULL," +
|
2019-01-17 13:29:35 +00:00
|
|
|
" `condition` TEXT NOT NULL," +
|
|
|
|
" `action` TEXT NOT NULL," +
|
|
|
|
" FOREIGN KEY(`folder`) REFERENCES `folder`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE)");
|
2019-03-05 13:38:05 +00:00
|
|
|
db.execSQL("CREATE INDEX `index_rule_folder` ON `rule` (`folder`)");
|
|
|
|
db.execSQL("CREATE INDEX `index_rule_order` ON `rule` (`order`)");
|
2019-01-17 13:29:35 +00:00
|
|
|
}
|
|
|
|
})
|
2019-01-18 10:58:55 +00:00
|
|
|
.addMigrations(new Migration(37, 38) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("ALTER TABLE `rule` ADD COLUMN `stop` INTEGER NOT NULL DEFAULT 0");
|
|
|
|
}
|
|
|
|
})
|
2019-01-20 15:22:21 +00:00
|
|
|
.addMigrations(new Migration(38, 39) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("ALTER TABLE `account` ADD COLUMN `swipe_left` INTEGER");
|
|
|
|
db.execSQL("ALTER TABLE `account` ADD COLUMN `swipe_right` INTEGER");
|
|
|
|
}
|
|
|
|
})
|
2019-01-25 18:13:00 +00:00
|
|
|
.addMigrations(new Migration(39, 40) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("ALTER TABLE `identity` ADD COLUMN `last_connected` INTEGER");
|
|
|
|
}
|
|
|
|
})
|
2019-01-29 20:15:24 +00:00
|
|
|
.addMigrations(new Migration(40, 41) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("ALTER TABLE `message` ADD COLUMN `flags` TEXT");
|
|
|
|
}
|
|
|
|
})
|
2019-02-09 12:54:58 +00:00
|
|
|
.addMigrations(new Migration(41, 42) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("ALTER TABLE `identity` ADD COLUMN `plain_only` INTEGER NOT NULL DEFAULT 0");
|
|
|
|
}
|
|
|
|
})
|
2019-02-09 21:03:53 +00:00
|
|
|
.addMigrations(new Migration(42, 43) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("ALTER TABLE `account` ADD COLUMN `pop` INTEGER NOT NULL DEFAULT 0");
|
|
|
|
}
|
|
|
|
})
|
2019-02-13 09:24:06 +00:00
|
|
|
.addMigrations(new Migration(43, 44) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("CREATE TABLE IF NOT EXISTS `contact`" +
|
|
|
|
" (`id` INTEGER PRIMARY KEY AUTOINCREMENT" +
|
|
|
|
", `type` INTEGER NOT NULL" +
|
|
|
|
", `email` TEXT NOT NULL" +
|
|
|
|
", `name` TEXT)");
|
|
|
|
db.execSQL("CREATE UNIQUE INDEX `index_contact_email_type` ON `contact` (`email`, `type`)");
|
2019-03-05 13:38:05 +00:00
|
|
|
db.execSQL("CREATE INDEX `index_contact_name_type` ON `contact` (`name`, `type`)");
|
2019-02-13 09:24:06 +00:00
|
|
|
}
|
|
|
|
})
|
2019-02-17 18:29:00 +00:00
|
|
|
.addMigrations(new Migration(44, 45) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("ALTER TABLE `account` ADD COLUMN `ondemand` INTEGER NOT NULL DEFAULT 0");
|
|
|
|
}
|
|
|
|
})
|
2019-02-18 16:54:33 +00:00
|
|
|
.addMigrations(new Migration(45, 46) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("ALTER TABLE `identity` ADD COLUMN `encrypt` INTEGER NOT NULL DEFAULT 0");
|
|
|
|
}
|
|
|
|
})
|
2019-02-21 19:13:11 +00:00
|
|
|
.addMigrations(new Migration(46, 47) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("ALTER TABLE `identity` ADD COLUMN `use_ip` INTEGER NOT NULL DEFAULT 0");
|
|
|
|
}
|
|
|
|
})
|
2019-02-28 16:05:55 +00:00
|
|
|
.addMigrations(new Migration(47, 48) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("UPDATE `identity` SET use_ip = 1");
|
|
|
|
}
|
|
|
|
})
|
2019-03-03 12:59:58 +00:00
|
|
|
.addMigrations(new Migration(48, 49) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
2019-03-05 13:38:05 +00:00
|
|
|
db.execSQL("CREATE INDEX `index_operation_name` ON `operation` (`name`)");
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.addMigrations(new Migration(49, 50) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("DROP INDEX `index_message_replying`");
|
|
|
|
db.execSQL("DROP INDEX `index_message_forwarding`");
|
|
|
|
db.execSQL("CREATE INDEX `index_message_subject` ON `message` (`subject`)");
|
2019-03-03 12:59:58 +00:00
|
|
|
}
|
|
|
|
})
|
2019-03-07 08:45:10 +00:00
|
|
|
.addMigrations(new Migration(50, 51) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
2019-04-25 16:47:52 +00:00
|
|
|
db.execSQL("DELETE FROM operation WHERE name = 'wait'");
|
2019-03-07 08:45:10 +00:00
|
|
|
}
|
|
|
|
})
|
2019-03-09 08:20:46 +00:00
|
|
|
.addMigrations(new Migration(51, 52) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("ALTER TABLE `folder` ADD COLUMN `total` INTEGER");
|
|
|
|
}
|
|
|
|
})
|
2019-03-12 15:54:25 +00:00
|
|
|
.addMigrations(new Migration(52, 53) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("ALTER TABLE `operation` ADD COLUMN `account` INTEGER");
|
|
|
|
}
|
|
|
|
})
|
2019-03-14 09:12:19 +00:00
|
|
|
.addMigrations(new Migration(53, 54) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
File folder = new File(context.getFilesDir(), "attachments");
|
|
|
|
File[] attachments = folder.listFiles();
|
|
|
|
if (attachments != null)
|
|
|
|
for (File source : attachments) {
|
|
|
|
long id = Long.parseLong(source.getName().split("\\.")[0]);
|
|
|
|
Cursor cursor = null;
|
|
|
|
try {
|
|
|
|
cursor = db.query("SELECT name FROM attachment WHERE id = ?", new Object[]{id});
|
|
|
|
if (cursor != null && cursor.moveToNext()) {
|
|
|
|
String name = cursor.getString(0);
|
|
|
|
if (!TextUtils.isEmpty(name)) {
|
|
|
|
File target = new File(folder, id + "." + Helper.sanitizeFilename(name));
|
|
|
|
if (source.renameTo(target))
|
|
|
|
Log.i("Renamed attachment=" + target.getName());
|
|
|
|
else {
|
|
|
|
Log.i("Unavailable attachment=" + source.getName());
|
|
|
|
db.execSQL("UPDATE attachment SET available = 0 WHERE id = ?", new Object[]{id});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Throwable ex) {
|
|
|
|
if (cursor != null)
|
|
|
|
cursor.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
2019-03-14 17:46:45 +00:00
|
|
|
.addMigrations(new Migration(54, 55) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("ALTER TABLE `contact` ADD COLUMN `avatar` TEXT");
|
|
|
|
db.execSQL("ALTER TABLE `contact` ADD COLUMN `times_contacted` INTEGER NOT NULL DEFAULT 1");
|
|
|
|
db.execSQL("ALTER TABLE `contact` ADD COLUMN `last_contacted` INTEGER");
|
|
|
|
}
|
|
|
|
})
|
2019-03-15 08:36:23 +00:00
|
|
|
.addMigrations(new Migration(55, 56) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("ALTER TABLE `contact` ADD COLUMN `favorite` INTEGER NOT NULL DEFAULT 0");
|
|
|
|
}
|
|
|
|
})
|
2019-03-15 08:50:31 +00:00
|
|
|
.addMigrations(new Migration(56, 57) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("CREATE INDEX `index_contact_times_contacted` ON `contact` (`times_contacted`)");
|
|
|
|
db.execSQL("CREATE INDEX `index_contact_last_contacted` ON `contact` (`last_contacted`)");
|
|
|
|
db.execSQL("CREATE INDEX `index_contact_favorite` ON `contact` (`favorite`)");
|
|
|
|
}
|
|
|
|
})
|
2019-03-17 08:26:17 +00:00
|
|
|
.addMigrations(new Migration(57, 58) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("DROP TABLE `contact`");
|
|
|
|
db.execSQL("CREATE TABLE IF NOT EXISTS `contact`" +
|
|
|
|
" (`id` INTEGER PRIMARY KEY AUTOINCREMENT" +
|
|
|
|
", `account` INTEGER NOT NULL" +
|
|
|
|
", `type` INTEGER NOT NULL" +
|
|
|
|
", `email` TEXT NOT NULL" +
|
|
|
|
", `name` TEXT, `avatar` TEXT" +
|
|
|
|
", `times_contacted` INTEGER NOT NULL" +
|
|
|
|
", `first_contacted` INTEGER NOT NULL" +
|
|
|
|
", `last_contacted` INTEGER NOT NULL" +
|
|
|
|
", `state` INTEGER NOT NULL" +
|
|
|
|
", FOREIGN KEY(`account`) REFERENCES `account`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE )");
|
|
|
|
db.execSQL("CREATE UNIQUE INDEX `index_contact_account_type_email` ON `contact` (`account`, `type`, `email`)");
|
|
|
|
db.execSQL("CREATE INDEX `index_contact_email` ON `contact` (`email`)");
|
|
|
|
db.execSQL("CREATE INDEX `index_contact_name` ON `contact` (`name`)");
|
|
|
|
db.execSQL("CREATE INDEX `index_contact_times_contacted` ON `contact` (`times_contacted`)");
|
|
|
|
db.execSQL("CREATE INDEX `index_contact_last_contacted` ON `contact` (`last_contacted`)");
|
|
|
|
db.execSQL("CREATE INDEX `index_contact_state` ON `contact` (`state`)");
|
|
|
|
}
|
|
|
|
})
|
2019-03-17 09:49:50 +00:00
|
|
|
.addMigrations(new Migration(58, 59) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("CREATE INDEX `index_contact_avatar` ON `contact` (`avatar`)");
|
|
|
|
}
|
|
|
|
})
|
2019-03-17 19:32:57 +00:00
|
|
|
.addMigrations(new Migration(59, 60) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("ALTER TABLE `folder` ADD COLUMN `parent` INTEGER");
|
|
|
|
}
|
|
|
|
})
|
2019-03-18 08:33:40 +00:00
|
|
|
.addMigrations(new Migration(60, 61) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("ALTER TABLE `folder` ADD COLUMN `collapsed` INTEGER NOT NULL DEFAULT 0");
|
|
|
|
}
|
|
|
|
})
|
2019-03-27 08:19:11 +00:00
|
|
|
.addMigrations(new Migration(61, 62) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("ALTER TABLE `account` ADD COLUMN `warning` TEXT");
|
|
|
|
}
|
|
|
|
})
|
2019-03-31 14:36:41 +00:00
|
|
|
.addMigrations(new Migration(62, 63) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("DROP INDEX index_message_msgid_folder");
|
2019-03-31 17:09:46 +00:00
|
|
|
db.execSQL("CREATE INDEX `index_message_msgid` ON `message` (`msgid`)");
|
2019-03-31 14:36:41 +00:00
|
|
|
}
|
|
|
|
})
|
2019-04-12 14:15:42 +00:00
|
|
|
.addMigrations(new Migration(63, 64) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("ALTER TABLE `message` ADD COLUMN `dkim` INTEGER");
|
|
|
|
db.execSQL("ALTER TABLE `message` ADD COLUMN `spf` INTEGER");
|
|
|
|
db.execSQL("ALTER TABLE `message` ADD COLUMN `dmarc` INTEGER");
|
|
|
|
}
|
|
|
|
})
|
2019-04-17 15:27:57 +00:00
|
|
|
.addMigrations(new Migration(64, 65) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("ALTER TABLE `identity` ADD COLUMN `sender_extra` INTEGER NOT NULL DEFAULT 0");
|
|
|
|
}
|
|
|
|
})
|
2019-04-17 18:21:44 +00:00
|
|
|
.addMigrations(new Migration(65, 66) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("ALTER TABLE `message` ADD COLUMN `receipt_request` INTEGER");
|
|
|
|
}
|
|
|
|
})
|
2019-04-18 07:12:30 +00:00
|
|
|
.addMigrations(new Migration(66, 67) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("ALTER TABLE `message` ADD COLUMN `revision` INTEGER");
|
|
|
|
}
|
|
|
|
})
|
2019-04-18 09:29:15 +00:00
|
|
|
.addMigrations(new Migration(67, 68) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("ALTER TABLE `message` ADD COLUMN `revisions` INTEGER");
|
|
|
|
db.execSQL("UPDATE message SET revisions = revision");
|
|
|
|
}
|
|
|
|
})
|
2019-04-18 17:13:38 +00:00
|
|
|
.addMigrations(new Migration(68, 69) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("ALTER TABLE `message` ADD COLUMN `receipt_to` TEXT");
|
|
|
|
}
|
|
|
|
})
|
2019-04-19 11:33:41 +00:00
|
|
|
.addMigrations(new Migration(69, 70) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("UPDATE message SET uid = NULL WHERE uid < 0");
|
|
|
|
}
|
|
|
|
})
|
2019-04-20 08:35:30 +00:00
|
|
|
.addMigrations(new Migration(70, 71) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("ALTER TABLE `answer` ADD COLUMN `hide` INTEGER NOT NULL DEFAULT 0");
|
|
|
|
}
|
|
|
|
})
|
2019-04-23 09:47:56 +00:00
|
|
|
.addMigrations(new Migration(71, 72) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("ALTER TABLE `message` ADD COLUMN `list_post` TEXT");
|
|
|
|
}
|
|
|
|
})
|
2019-04-25 06:18:01 +00:00
|
|
|
.addMigrations(new Migration(72, 73) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("ALTER TABLE `account` ADD COLUMN `order` INTEGER");
|
|
|
|
}
|
|
|
|
})
|
2019-04-25 15:23:56 +00:00
|
|
|
.addMigrations(new Migration(73, 74) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("ALTER TABLE `folder` ADD COLUMN `subscribed` INTEGER");
|
|
|
|
}
|
|
|
|
})
|
2019-04-29 08:14:55 +00:00
|
|
|
.addMigrations(new Migration(74, 75) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("ALTER TABLE `folder` ADD COLUMN `navigation` INTEGER NOT NULL DEFAULT 0");
|
|
|
|
}
|
|
|
|
})
|
2019-04-29 11:09:11 +00:00
|
|
|
.addMigrations(new Migration(75, 76) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("ALTER TABLE `folder` ADD COLUMN `order` INTEGER");
|
|
|
|
}
|
|
|
|
})
|
2019-04-30 07:06:32 +00:00
|
|
|
.addMigrations(new Migration(76, 77) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("ALTER TABLE `folder` ADD COLUMN `read_only` INTEGER NOT NULL DEFAULT 0");
|
|
|
|
}
|
|
|
|
})
|
2019-05-01 09:26:32 +00:00
|
|
|
.addMigrations(new Migration(77, 78) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("ALTER TABLE `folder` ADD COLUMN `auto_delete` INTEGER NOT NULL DEFAULT 0");
|
|
|
|
}
|
|
|
|
})
|
2019-05-04 18:52:21 +00:00
|
|
|
.addMigrations(new Migration(78, 79) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("ALTER TABLE `message` ADD COLUMN `plain_only` INTEGER");
|
|
|
|
}
|
|
|
|
})
|
2019-05-08 08:32:37 +00:00
|
|
|
.addMigrations(new Migration(79, 80) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("DROP INDEX index_attachment_message_cid");
|
|
|
|
db.execSQL("CREATE INDEX `index_attachment_message_cid` ON `attachment` (`message`, `cid`)");
|
|
|
|
}
|
|
|
|
})
|
2019-05-11 19:04:27 +00:00
|
|
|
.addMigrations(new Migration(80, 81) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("ALTER TABLE `operation` ADD COLUMN `state` TEXT");
|
|
|
|
}
|
|
|
|
})
|
2019-05-11 19:30:09 +00:00
|
|
|
.addMigrations(new Migration(81, 82) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("CREATE INDEX `index_operation_account` ON `operation` (`account`)");
|
|
|
|
db.execSQL("CREATE INDEX `index_operation_state` ON `operation` (`state`)");
|
|
|
|
}
|
|
|
|
})
|
2019-05-15 09:10:47 +00:00
|
|
|
.addMigrations(new Migration(82, 83) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("ALTER TABLE `message` ADD COLUMN `color` INTEGER");
|
|
|
|
}
|
|
|
|
})
|
2019-05-25 14:01:51 +00:00
|
|
|
.addMigrations(new Migration(83, 84) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("UPDATE attachment SET disposition = lower(disposition) WHERE NOT disposition IS NULL");
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.addMigrations(new Migration(84, 85) {
|
|
|
|
@Override
|
|
|
|
public void migrate(SupportSQLiteDatabase db) {
|
|
|
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
|
|
|
db.execSQL("UPDATE attachment SET size = NULL WHERE size = 0");
|
|
|
|
}
|
|
|
|
})
|
2018-08-02 13:33:06 +00:00
|
|
|
.build();
|
|
|
|
}
|
|
|
|
|
2019-05-30 10:57:57 +00:00
|
|
|
@Override
|
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
public void beginTransaction() {
|
|
|
|
super.beginTransaction();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
public void setTransactionSuccessful() {
|
|
|
|
super.setTransactionSuccessful();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
public void endTransaction() {
|
|
|
|
super.endTransaction();
|
|
|
|
}
|
|
|
|
|
2018-08-02 13:33:06 +00:00
|
|
|
public static class Converters {
|
|
|
|
@TypeConverter
|
2018-11-25 12:34:08 +00:00
|
|
|
public static String[] toStringArray(String value) {
|
|
|
|
if (value == null)
|
|
|
|
return new String[0];
|
|
|
|
else
|
2018-11-25 17:29:11 +00:00
|
|
|
return TextUtils.split(value, " ");
|
2018-08-02 13:33:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@TypeConverter
|
2018-11-25 12:34:08 +00:00
|
|
|
public static String fromStringArray(String[] value) {
|
|
|
|
if (value == null || value.length == 0)
|
|
|
|
return null;
|
|
|
|
else
|
|
|
|
return TextUtils.join(" ", value);
|
2018-08-02 13:33:06 +00:00
|
|
|
}
|
2018-08-07 16:25:57 +00:00
|
|
|
|
|
|
|
@TypeConverter
|
|
|
|
public static String encodeAddresses(Address[] addresses) {
|
|
|
|
if (addresses == null)
|
|
|
|
return null;
|
|
|
|
JSONArray jaddresses = new JSONArray();
|
2018-12-09 14:49:43 +00:00
|
|
|
for (Address address : addresses)
|
|
|
|
try {
|
|
|
|
if (address instanceof InternetAddress) {
|
|
|
|
String a = ((InternetAddress) address).getAddress();
|
|
|
|
String p = ((InternetAddress) address).getPersonal();
|
|
|
|
JSONObject jaddress = new JSONObject();
|
|
|
|
if (a != null)
|
|
|
|
jaddress.put("address", a);
|
|
|
|
if (p != null)
|
|
|
|
jaddress.put("personal", p);
|
|
|
|
jaddresses.put(jaddress);
|
|
|
|
} else {
|
|
|
|
JSONObject jaddress = new JSONObject();
|
|
|
|
jaddress.put("address", address.toString());
|
|
|
|
jaddresses.put(jaddress);
|
2018-08-07 16:25:57 +00:00
|
|
|
}
|
2018-12-09 14:49:43 +00:00
|
|
|
} catch (JSONException ex) {
|
2018-12-24 12:27:45 +00:00
|
|
|
Log.e(ex);
|
2018-12-09 14:49:43 +00:00
|
|
|
}
|
2018-08-07 16:25:57 +00:00
|
|
|
return jaddresses.toString();
|
|
|
|
}
|
|
|
|
|
|
|
|
@TypeConverter
|
|
|
|
public static Address[] decodeAddresses(String json) {
|
|
|
|
if (json == null)
|
|
|
|
return null;
|
|
|
|
List<Address> result = new ArrayList<>();
|
|
|
|
try {
|
|
|
|
JSONArray jaddresses = new JSONArray(json);
|
|
|
|
for (int i = 0; i < jaddresses.length(); i++) {
|
|
|
|
JSONObject jaddress = (JSONObject) jaddresses.get(i);
|
|
|
|
if (jaddress.has("personal"))
|
|
|
|
result.add(new InternetAddress(
|
|
|
|
jaddress.getString("address"),
|
|
|
|
jaddress.getString("personal")));
|
|
|
|
else
|
|
|
|
result.add(new InternetAddress(
|
|
|
|
jaddress.getString("address")));
|
|
|
|
}
|
|
|
|
} catch (Throwable ex) {
|
2018-08-29 05:31:00 +00:00
|
|
|
// Compose can store invalid addresses
|
2018-12-24 12:27:45 +00:00
|
|
|
Log.w(ex);
|
2018-08-07 16:25:57 +00:00
|
|
|
}
|
|
|
|
return result.toArray(new Address[0]);
|
|
|
|
}
|
2018-08-02 13:33:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|