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.content.SharedPreferences;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.Build;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
@ -61,7 +62,7 @@ import io.requery.android.database.sqlite.SQLiteDatabase;
|
||||||
// https://developer.android.com/topic/libraries/architecture/room.html
|
// https://developer.android.com/topic/libraries/architecture/room.html
|
||||||
|
|
||||||
@Database(
|
@Database(
|
||||||
version = 170,
|
version = 171,
|
||||||
entities = {
|
entities = {
|
||||||
EntityIdentity.class,
|
EntityIdentity.class,
|
||||||
EntityAccount.class,
|
EntityAccount.class,
|
||||||
|
@ -275,27 +276,39 @@ public abstract class DB extends RoomDatabase {
|
||||||
public void onOpen(@NonNull SupportSQLiteDatabase db) {
|
public void onOpen(@NonNull SupportSQLiteDatabase db) {
|
||||||
Log.i("Database version=" + db.getVersion());
|
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);
|
createTriggers(db);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void createTriggers(@NonNull SupportSQLiteDatabase 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" +
|
db.execSQL("CREATE TRIGGER IF NOT EXISTS attachment_insert" +
|
||||||
" AFTER INSERT ON attachment" +
|
" AFTER INSERT ON attachment" +
|
||||||
" BEGIN" +
|
" BEGIN" +
|
||||||
" UPDATE message SET attachments = attachments + 1" +
|
" UPDATE message SET attachments = attachments + 1" +
|
||||||
" WHERE message.id = NEW.message" +
|
" WHERE message.id = NEW.message" +
|
||||||
" AND (NEW.disposition IS NULL OR NEW.disposition <> 'inline')" +
|
" AND (NEW.encryption IS NULL" +
|
||||||
" AND (NEW.encryption IS NULL OR NEW.encryption = 0);" +
|
" AND NOT ((NEW.disposition = 'inline' OR NEW.cid IS NOT NULL) AND NEW.type IN (" + images + ")));" +
|
||||||
" END");
|
" END");
|
||||||
db.execSQL("CREATE TRIGGER IF NOT EXISTS attachment_delete" +
|
db.execSQL("CREATE TRIGGER IF NOT EXISTS attachment_delete" +
|
||||||
" AFTER DELETE ON attachment" +
|
" AFTER DELETE ON attachment" +
|
||||||
" BEGIN" +
|
" BEGIN" +
|
||||||
" UPDATE message SET attachments = attachments - 1" +
|
" UPDATE message SET attachments = attachments - 1" +
|
||||||
" WHERE message.id = OLD.message" +
|
" WHERE message.id = OLD.message" +
|
||||||
" AND (OLD.disposition IS NULL OR OLD.disposition <> 'inline')" +
|
" AND (OLD.encryption IS NULL" +
|
||||||
" AND (OLD.encryption IS NULL OR OLD.encryption = 0);" +
|
" AND NOT ((OLD.disposition = 'inline' OR OLD.cid IS NOT NULL) AND OLD.type IN (" + images + ")));" +
|
||||||
" END");
|
" END");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1670,6 +1683,15 @@ public abstract class DB extends RoomDatabase {
|
||||||
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
Log.i("DB migration from version " + startVersion + " to " + endVersion);
|
||||||
db.execSQL("ALTER TABLE `account` ADD COLUMN `max_size` INTEGER");
|
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;
|
static final Integer SMIME_CONTENT = 8;
|
||||||
|
|
||||||
// https://developer.android.com/guide/topics/media/media-formats#image-formats
|
// 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/bmp",
|
||||||
"image/gif",
|
"image/gif",
|
||||||
"image/jpeg",
|
"image/jpeg",
|
||||||
|
@ -75,7 +75,7 @@ public class EntityAttachment {
|
||||||
"image/webp"
|
"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/heic",
|
||||||
"image/heif"
|
"image/heif"
|
||||||
));
|
));
|
||||||
|
|
Loading…
Reference in a new issue