Extract code to decode flags column to separate function
@@ -131,6 +131,14 @@ class K9BackendFolder(
}
override fun getMessageFlags(messageServerId: String): Set<Flag> {
+ fun String?.extractFlags(): MutableSet<Flag> {
+ return if (this == null || this.isBlank()) {
+ mutableSetOf()
+ } else {
+ this.split(',').map { Flag.valueOf(it) }.toMutableSet()
+ }
+ }
+
return database.execute(false) { db ->
val cursor = db.query(
"messages",
@@ -151,8 +159,7 @@ class K9BackendFolder(
val forwarded = cursor.getInt(4) == 1
val flagsColumnValue = cursor.getString(5)
- val flags = (if (flagsColumnValue.isNullOrBlank()) mutableSetOf<Flag>()
- else flagsColumnValue.split(',').map { Flag.valueOf(it) }.toMutableSet()).apply {
+ val flags = flagsColumnValue.extractFlags().apply {
if (deleted) add(Flag.DELETED)
if (read) add(Flag.SEEN)
if (flagged) add(Flag.FLAGGED)
