Add creating IMAP folders from the app
Bump version to 0.2.0 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -136,6 +136,28 @@ class EpMailPlugin : Plugin() {
|
||||
}
|
||||
}
|
||||
|
||||
@PluginMethod
|
||||
fun listFolders(call: PluginCall) {
|
||||
try {
|
||||
val account = AndroidAccountVault.account()
|
||||
?: throw IllegalStateException("Add a mail account before listing folders.")
|
||||
call.resolve(AndroidMailService.listFolders(account).toJSObject())
|
||||
} catch (error: Exception) {
|
||||
call.resolve(JSObject().put("folders", org.json.JSONArray()).put("offline", true))
|
||||
}
|
||||
}
|
||||
|
||||
@PluginMethod
|
||||
fun createFolder(call: PluginCall) {
|
||||
try {
|
||||
val account = AndroidAccountVault.account()
|
||||
?: throw IllegalStateException("Add a mail account before creating folders.")
|
||||
call.resolve(AndroidMailService.createFolder(account, call.getString("name") ?: "").toJSObject())
|
||||
} catch (error: Exception) {
|
||||
call.reject(error.message ?: "Could not create the folder.")
|
||||
}
|
||||
}
|
||||
|
||||
@PluginMethod
|
||||
fun syncFolder(call: PluginCall) {
|
||||
try {
|
||||
@@ -145,7 +167,7 @@ class EpMailPlugin : Plugin() {
|
||||
val filters = call.getObject("filters") ?: JSObject()
|
||||
val filterFolder = filters.getString("folder")
|
||||
val selected = filterFolder?.takeIf { it in setOf("Inbox", "Sent", "Archive", "Trash", "Starred") } ?: requested
|
||||
val folder = if (selected in setOf("Inbox", "Sent", "Archive", "Trash", "Starred", "Snoozed")) selected else "Inbox"
|
||||
val folder = if (selected in setOf("Inbox", "Sent", "Archive", "Trash", "Starred", "Snoozed") || AndroidMailService.isCustomFolder(selected)) selected else "Inbox"
|
||||
val offset = (call.getInt("offset") ?: 0).coerceAtLeast(0)
|
||||
AndroidMailService.flushOutbox(account)
|
||||
call.resolve(AndroidMailService.sync(account, folder, offset, JSONObject(filters.toString())).toJSObject())
|
||||
|
||||
Reference in New Issue
Block a user