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

Unverified Commit c65b5b75 authored by Rafael Tonholo's avatar Rafael Tonholo
Browse files

feat: add remote folder creation logic

parent f70b0fda
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -4,5 +4,7 @@ plugins {
}

dependencies {
    implementation(projects.core.account)
    implementation(projects.core.outcome)
    api(projects.mail.common)
}
+8 −0
Original line number Diff line number Diff line
package net.thunderbird.backend.api

import com.fsck.k9.backend.api.Backend
import net.thunderbird.core.account.BaseAccount

interface BackendFactory<TAccount : BaseAccount> {
    fun createBackend(account: TAccount): Backend
}
+8 −0
Original line number Diff line number Diff line
package net.thunderbird.backend.api

import com.fsck.k9.backend.api.BackendStorage
import net.thunderbird.core.account.BaseAccount

interface BackendStorageFactory<in TAccount : BaseAccount> {
    fun createBackendStorage(account: TAccount): BackendStorage
}
+65 −0
Original line number Diff line number Diff line
package net.thunderbird.backend.api.folder

import com.fsck.k9.mail.folders.FolderServerId
import net.thunderbird.core.account.BaseAccount
import net.thunderbird.core.outcome.Outcome

interface RemoteFolderCreator {
    /**
     * Creates a folder on the remote server. If the folder already exists and [mustCreate] is `false`,
     * the operation will succeed returning [RemoteFolderCreationOutcome.Success.AlreadyExists].
     *
     * @param folderServerId The folder server ID.
     * @param mustCreate If `true`, the folder must be created returning
     * [RemoteFolderCreationOutcome.Error.FailedToCreateRemoteFolder]. If `false`, the folder will be created
     * only if it doesn't exist.
     * @return The result of the operation.
     * @see RemoteFolderCreationOutcome.Success
     * @see RemoteFolderCreationOutcome.Error
     */
    suspend fun create(
        folderServerId: FolderServerId,
        mustCreate: Boolean,
    ): Outcome<RemoteFolderCreationOutcome.Success, RemoteFolderCreationOutcome.Error>

    interface Factory {
        fun create(account: BaseAccount): RemoteFolderCreator
    }
}

sealed interface RemoteFolderCreationOutcome {
    sealed interface Success : RemoteFolderCreationOutcome {
        /**
         * Used to flag that the folder was created successfully.
         */
        data object Created : Success

        /**
         * Used to flag that the folder creation was skipped because the folder already exists and
         * the creation is NOT mandatory.
         */
        data object AlreadyExists : Success
    }

    sealed interface Error : RemoteFolderCreationOutcome {
        /**
         * Used to flag that the folder creation has failed because the folder already exists and
         * the creation is mandatory.
         */
        data object AlreadyExists : Error

        /**
         * Used to flag that the folder creation failed on the remote server.
         * @param reason The reason why the folder creation failed.
         */
        data class FailedToCreateRemoteFolder(
            val reason: String,
        ) : Error

        /**
         * Used to flag that the Create Folder operation is not supported by the server.
         * E.g. POP3 servers don't support creating archive folders.
         */
        data object NotSupportedOperation : Error
    }
}
+2 −0
Original line number Diff line number Diff line
@@ -5,6 +5,8 @@ plugins {

dependencies {
    api(projects.backend.api)
    api(projects.core.outcome)
    api(projects.core.account)
    api(projects.mail.protocols.imap)
    api(projects.mail.protocols.smtp)

Loading