mirror of
https://github.com/M66B/FairEmail.git
synced 2025-03-03 10:16:45 +00:00
Improved attachment recognition
This commit is contained in:
parent
c09c40d2f8
commit
b96fd267f6
3 changed files with 2308 additions and 7 deletions
2279
app/schemas/eu.faircode.email.DB/171.json
Normal file
2279
app/schemas/eu.faircode.email.DB/171.json
Normal file
File diff suppressed because it is too large
Load diff
|
@ -4,6 +4,7 @@ import android.content.Context;
|
|||
import android.content.SharedPreferences;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
@ -61,7 +62,7 @@ import io.requery.android.database.sqlite.SQLiteDatabase;
|
|||
// https://developer.android.com/topic/libraries/architecture/room.html
|
||||
|
||||
@Database(
|
||||
version = 170,
|
||||
version = 171,
|
||||
entities = {
|
||||
EntityIdentity.class,
|
||||
EntityAccount.class,
|
||||
|
@ -275,27 +276,39 @@ public abstract class DB extends RoomDatabase {
|
|||
public void onOpen(@NonNull SupportSQLiteDatabase db) {
|
||||
Log.i("Database version=" + db.getVersion());
|
||||
|
||||
if (BuildConfig.DEBUG) {
|
||||
db.execSQL("DROP TRIGGER IF EXISTS `attachment_insert`");
|
||||
db.execSQL("DROP TRIGGER IF EXISTS `attachment_delete`");
|
||||
}
|
||||
createTriggers(db);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void createTriggers(@NonNull SupportSQLiteDatabase db) {
|
||||
List<String> image = new ArrayList<>();
|
||||
for (String img : EntityAttachment.IMAGE_TYPES)
|
||||
image.add("'" + img + "'");
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
||||
for (String img : EntityAttachment.IMAGE_TYPES8)
|
||||
image.add("'" + img + "'");
|
||||
String images = TextUtils.join(",", image);
|
||||
|
||||
db.execSQL("CREATE TRIGGER IF NOT EXISTS attachment_insert" +
|
||||
" AFTER INSERT ON attachment" +
|
||||
" BEGIN" +
|
||||
" UPDATE message SET attachments = attachments + 1" +
|
||||
" WHERE message.id = NEW.message" +
|
||||
" AND (NEW.disposition IS NULL OR NEW.disposition <> 'inline')" +
|
||||
" AND (NEW.encryption IS NULL OR NEW.encryption = 0);" +
|
||||
" AND (NEW.encryption IS NULL" +
|
||||
" AND NOT ((NEW.disposition = 'inline' OR NEW.cid IS NOT NULL) AND NEW.type IN (" + images + ")));" +
|
||||
" END");
|
||||
db.execSQL("CREATE TRIGGER IF NOT EXISTS attachment_delete" +
|
||||
" AFTER DELETE ON attachment" +
|
||||
" BEGIN" +
|
||||
" UPDATE message SET attachments = attachments - 1" +
|
||||
" WHERE message.id = OLD.message" +
|
||||
" AND (OLD.disposition IS NULL OR OLD.disposition <> 'inline')" +
|
||||
" AND (OLD.encryption IS NULL OR OLD.encryption = 0);" +
|
||||
" AND (OLD.encryption IS NULL" +
|
||||
" AND NOT ((OLD.disposition = 'inline' OR OLD.cid IS NOT NULL) AND OLD.type IN (" + images + ")));" +
|
||||
" END");
|
||||
}
|
||||
|
||||
|
@ -1670,6 +1683,15 @@ public abstract class DB extends RoomDatabase {
|
|||
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
||||
db.execSQL("ALTER TABLE `account` ADD COLUMN `max_size` INTEGER");
|
||||
}
|
||||
})
|
||||
.addMigrations(new Migration(170, 171) {
|
||||
@Override
|
||||
public void migrate(@NonNull SupportSQLiteDatabase db) {
|
||||
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
||||
db.execSQL("DROP TRIGGER IF EXISTS `attachment_insert`");
|
||||
db.execSQL("DROP TRIGGER IF EXISTS `attachment_delete`");
|
||||
createTriggers(db);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -66,7 +66,7 @@ public class EntityAttachment {
|
|||
static final Integer SMIME_CONTENT = 8;
|
||||
|
||||
// https://developer.android.com/guide/topics/media/media-formats#image-formats
|
||||
private static final List<String> IMAGE_TYPES = Collections.unmodifiableList(Arrays.asList(
|
||||
static final List<String> IMAGE_TYPES = Collections.unmodifiableList(Arrays.asList(
|
||||
"image/bmp",
|
||||
"image/gif",
|
||||
"image/jpeg",
|
||||
|
@ -75,7 +75,7 @@ public class EntityAttachment {
|
|||
"image/webp"
|
||||
));
|
||||
|
||||
private static final List<String> IMAGE_TYPES8 = Collections.unmodifiableList(Arrays.asList(
|
||||
static final List<String> IMAGE_TYPES8 = Collections.unmodifiableList(Arrays.asList(
|
||||
"image/heic",
|
||||
"image/heif"
|
||||
));
|
||||
|
|
Loading…
Reference in a new issue