Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 91ae94d4 authored by cketti's avatar cketti
Browse files

Add FolderType support to (Local)Folder

parent fbf4f448
Loading
Loading
Loading
Loading
+33 −0
Original line number Diff line number Diff line
@file:JvmName("FolderTypeConverter")
package com.fsck.k9.mailstore

import com.fsck.k9.mail.Folder.FolderType


@JvmName("fromDatabaseFolderType")
fun String.toFolderType(): FolderType {
    return when (this) {
        "regular" -> FolderType.REGULAR
        "inbox" -> FolderType.INBOX
        "outbox" -> FolderType.OUTBOX
        "drafts" -> FolderType.DRAFTS
        "sent" -> FolderType.SENT
        "trash" -> FolderType.TRASH
        "spam" -> FolderType.SPAM
        "archive" -> FolderType.ARCHIVE
        else -> throw AssertionError("Unknown folder type: $this")
    }
}

fun FolderType.toDatabaseFolderType(): String {
    return when (this) {
        FolderType.REGULAR -> "regular"
        FolderType.INBOX -> "inbox"
        FolderType.OUTBOX -> "outbox"
        FolderType.DRAFTS -> "drafts"
        FolderType.SENT -> "sent"
        FolderType.TRASH -> "trash"
        FolderType.SPAM -> "spam"
        FolderType.ARCHIVE -> "archive"
    }
}
+18 −0
Original line number Diff line number Diff line
@@ -109,9 +109,14 @@ public class LocalFolder extends Folder<LocalMessage> {
    }

    public LocalFolder(LocalStore localStore, String serverId, String name) {
        this(localStore, serverId, name, FolderType.REGULAR);
    }

    public LocalFolder(LocalStore localStore, String serverId, String name, FolderType type) {
        this.localStore = localStore;
        this.serverId = serverId;
        this.name = name;
        super.setType(type);
        attachmentInfoExtractor = localStore.getAttachmentInfoExtractor();

        if (getAccount().getInboxFolder().equals(getServerId())) {
@@ -218,6 +223,9 @@ public class LocalFolder extends Folder<LocalMessage> {
        moreMessages = MoreMessages.fromDatabaseName(moreMessagesValue);
        name = cursor.getString(LocalStore.FOLDER_NAME_INDEX);
        localOnly = cursor.getInt(LocalStore.LOCAL_ONLY_INDEX) == 1;
        String typeString = cursor.getString(LocalStore.TYPE_INDEX);
        FolderType folderType = FolderTypeConverter.fromDatabaseFolderType(typeString);
        super.setType(folderType);
    }

    @Override
@@ -255,6 +263,16 @@ public class LocalFolder extends Folder<LocalMessage> {
        updateFolderColumn("name", name);
    }

    @Override
    public void setType(FolderType type) {
        super.setType(type);
        try {
            updateFolderColumn("type", FolderTypeConverter.toDatabaseFolderType(type));
        } catch (MessagingException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public boolean exists() throws MessagingException {
        return this.localStore.getDatabase().execute(false, new DbCallback<Boolean>() {
+6 −3
Original line number Diff line number Diff line
@@ -132,7 +132,7 @@ public class LocalStore {
    static final String GET_FOLDER_COLS =
        "folders.id, name, visible_limit, last_updated, status, push_state, last_pushed, " +
        "integrate, top_group, poll_class, push_class, display_class, notify_class, more_messages, server_id, " +
        "local_only";
        "local_only, type";

    static final int FOLDER_ID_INDEX = 0;
    static final int FOLDER_NAME_INDEX = 1;
@@ -150,6 +150,7 @@ public class LocalStore {
    static final int MORE_MESSAGES_INDEX = 13;
    static final int FOLDER_SERVER_ID_INDEX = 14;
    static final int LOCAL_ONLY_INDEX = 15;
    static final int TYPE_INDEX = 16;

    static final String[] UID_CHECK_PROJECTION = { "uid" };

@@ -911,6 +912,7 @@ public class LocalStore {
                    String serverId = folder.getServerId();
                    String name = folder.getName();
                    boolean localOnly = folder.isLocalOnly();
                    String databaseFolderType = FolderTypeConverter.toDatabaseFolderType(folder.getType());

                    if (K9.DEVELOPER_MODE) {
                        Cursor cursor = db.query("folders", new String[] { "id", "server_id" },
@@ -953,7 +955,7 @@ public class LocalStore {
                    }
                    folder.refresh(serverId, prefHolder);   // Recover settings from Preferences

                    db.execSQL("INSERT INTO folders (name, visible_limit, top_group, display_class, poll_class, notify_class, push_class, integrate, server_id, local_only) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", new Object[] {
                    db.execSQL("INSERT INTO folders (name, visible_limit, top_group, display_class, poll_class, notify_class, push_class, integrate, server_id, local_only, type) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", new Object[] {
                                   name,
                                   visibleLimit,
                                   prefHolder.inTopGroup ? 1 : 0,
@@ -963,7 +965,8 @@ public class LocalStore {
                                   prefHolder.pushClass.name(),
                                   prefHolder.integrate ? 1 : 0,
                                   serverId,
                                   localOnly ? 1 : 0
                                   localOnly ? 1 : 0,
                                   databaseFolderType
                               });

                }
+20 −0
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ public abstract class Folder<T extends Message> {
    private String status = null;
    private long lastChecked = 0;
    private long lastPush = 0;
    private FolderType type = FolderType.REGULAR;

    public static final int OPEN_MODE_RW=0;
    public static final int OPEN_MODE_RO=1;
@@ -22,6 +23,17 @@ public abstract class Folder<T extends Message> {
        NONE, NO_CLASS, INHERITED, FIRST_CLASS, SECOND_CLASS
    }

    public enum FolderType {
        REGULAR,
        INBOX,
        OUTBOX,
        DRAFTS,
        SENT,
        TRASH,
        SPAM,
        ARCHIVE
    }

    /**
     * Forces an open of the MailProvider. If the provider is already open this
     * function returns without doing anything.
@@ -201,4 +213,12 @@ public abstract class Folder<T extends Message> {
        throws MessagingException {
        throw new MessagingException("K-9 does not support searches on this folder type");
    }

    public FolderType getType() {
        return type;
    }

    public void setType(FolderType type) {
        this.type = type;
    }
}