Added folder subtype flagged

This commit is contained in:
M66B 2023-01-18 20:54:42 +01:00
parent 41e9935c88
commit cbebeb29d2
6 changed files with 2877 additions and 4 deletions

File diff suppressed because it is too large Load Diff

View File

@ -377,7 +377,8 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
tvType.setText(EntityFolder.localizeType(context, folder.type) +
(folder.inherited_type == null || !(BuildConfig.DEBUG || EntityFolder.SENT.equals(folder.inherited_type))
? ""
: "/" + EntityFolder.localizeType(context, folder.inherited_type)));
: "/" + EntityFolder.localizeType(context, folder.inherited_type)) +
(EntityFolder.FLAGGED.equals(folder.subtype) ? "*" : ""));
tvTotal.setText(folder.total == null ? null : NF.format(folder.total));

View File

@ -750,7 +750,8 @@ class Core {
if (MessageHelper.isRemoved(ex)) {
if (message != null &&
!EntityOperation.SEEN.equals(op.name) &&
!EntityOperation.FLAG.equals(op.name))
(!EntityOperation.FLAG.equals(op.name) ||
EntityFolder.FLAGGED.equals(folder.subtype)))
db.message().deleteMessage(message.id);
}
@ -2742,6 +2743,7 @@ class Core {
String[] attrs = ((IMAPFolder) ifolder.second).getAttributes();
String type = EntityFolder.getType(attrs, fullName, false);
String subtype = EntityFolder.getSubtype(attrs, fullName);
boolean subscribed = subscription.contains(fullName);
boolean selectable = true;
@ -2758,7 +2760,7 @@ class Core {
if (EntityFolder.INBOX.equals(type))
selectable = true;
Log.i(account.name + ":" + fullName + " type=" + type +
Log.i(account.name + ":" + fullName + " type=" + type + ":" + subtype +
" subscribed=" + subscribed +
" selectable=" + selectable +
" inferiors=" + inferiors +
@ -2791,6 +2793,7 @@ class Core {
folder.separator = separator;
folder.name = fullName;
folder.type = type;
folder.subtype = type;
folder.subscribed = subscribed;
folder.selectable = selectable;
folder.inferiors = inferiors;
@ -2829,6 +2832,7 @@ class Core {
if (db.folder().getFolderByType(folder.account, EntityFolder.INBOX) == null)
db.folder().setFolderType(folder.id, type);
}
db.folder().setFolderSubtype(folder.id, subtype);
}
db.setTransactionSuccessful();

View File

@ -68,7 +68,7 @@ import javax.mail.internet.InternetAddress;
// https://developer.android.com/topic/libraries/architecture/room.html
@Database(
version = 261,
version = 262,
entities = {
EntityIdentity.class,
EntityAccount.class,
@ -2649,6 +2649,12 @@ public abstract class DB extends RoomDatabase {
public void migrate(@NonNull SupportSQLiteDatabase db) {
logMigration(startVersion, endVersion);
}
}).addMigrations(new Migration(261, 262) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase db) {
logMigration(startVersion, endVersion);
db.execSQL("ALTER TABLE `folder` ADD COLUMN `subtype` TEXT");
}
}).addMigrations(new Migration(998, 999) {
@Override
public void migrate(@NonNull SupportSQLiteDatabase db) {

View File

@ -304,6 +304,9 @@ public interface DaoFolder {
@Query("UPDATE folder SET inherited_type = :type WHERE id = :id AND NOT (inherited_type IS :type)")
int setFolderInheritedType(long id, String type);
@Query("UPDATE folder SET subtype = :subtype WHERE id = :id AND NOT (subtype IS :subtype)")
int setFolderSubtype(long id, String subtype);
@Query("UPDATE folder SET `order` = :order WHERE id = :id AND NOT (`order` IS :order)")
int setFolderOrder(long id, Integer order);

View File

@ -78,6 +78,7 @@ public class EntityFolder extends EntityOrder implements Serializable {
@NonNull
public String type;
public String inherited_type;
public String subtype;
@NonNull
public Integer level = 0; // obsolete
@NonNull
@ -157,6 +158,8 @@ public class EntityFolder extends EntityOrder implements Serializable {
static final String SYSTEM = "System";
static final String USER = "User";
static final String FLAGGED = "flagged";
// https://tools.ietf.org/html/rfc6154
// https://www.iana.org/assignments/imap-mailbox-name-attributes/imap-mailbox-name-attributes.xhtml
private static final List<String> SYSTEM_FOLDER_ATTR = Collections.unmodifiableList(Arrays.asList(
@ -507,6 +510,13 @@ public class EntityFolder extends EntityOrder implements Serializable {
return USER;
}
static String getSubtype(String[] attrs, String fullname) {
for (String attr : attrs)
if ("\\Flagged".equals(attr)) // Gmail
return FLAGGED;
return null;
}
private static class TypeScore {
@NonNull
private String type;