Skip to content

Commit 4f4e651

Browse files
committed
feat: remove gmail prefix in folder structure
1 parent fd5c5f1 commit 4f4e651

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

legacy/storage/src/main/java/com/fsck/k9/storage/messages/CreateFolderOperations.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ internal class CreateFolderOperations(private val lockableDatabase: LockableData
1111
for (folder in folders) {
1212
val folderSettings = folder.settings
1313
val values = ContentValues().apply {
14-
put("name", folder.name)
14+
put("name", folder.name.replace("\\[(Gmail|Google Mail)]/".toRegex(), ""))
1515
put("visible_limit", folderSettings.visibleLimit)
1616
put("integrate", folderSettings.integrate)
1717
put("top_group", folderSettings.inTopGroup)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.fsck.k9.storage.messages
2+
3+
import android.content.ContentValues
4+
import com.fsck.k9.mailstore.LockableDatabase
5+
6+
internal class FolderNameSanitizer(private val lockableDatabase: LockableDatabase) {
7+
fun removeGmailPrefixFromFolders() {
8+
lockableDatabase.execute(false) { db ->
9+
val cursor = db.query(
10+
"folders",
11+
arrayOf("id", "name"),
12+
"name LIKE ? OR name LIKE ?",
13+
arrayOf("%[Gmail]/%", "%[Google Mail]/%"),
14+
null,
15+
null,
16+
null,
17+
)
18+
19+
while (cursor.moveToNext()) {
20+
val id = cursor.getLong(cursor.getColumnIndexOrThrow("id"))
21+
val name = cursor.getString(cursor.getColumnIndexOrThrow("name"))
22+
val updatedName = name
23+
.replace("[Gmail]/", "")
24+
.replace("[Google Mail]/", "")
25+
26+
val values = ContentValues().apply {
27+
put("name", updatedName)
28+
}
29+
30+
db.update("folders", values, "id = ?", arrayOf(id.toString()))
31+
}
32+
33+
cursor.close()
34+
}
35+
}
36+
}

legacy/storage/src/main/java/com/fsck/k9/storage/messages/K9MessageStoreFactory.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,18 @@ class K9MessageStoreFactory(
1313
private val storageFilesProviderFactory: StorageFilesProviderFactory,
1414
private val basicPartInfoExtractor: BasicPartInfoExtractor,
1515
) : MessageStoreFactory {
16+
private lateinit var folderNameSanitizer: FolderNameSanitizer
17+
1618
override fun create(account: LegacyAccount): ListenableMessageStore {
1719
val localStore = localStoreProvider.getInstance(account)
20+
if (account.incomingServerSettings.host.contains("gmail") ||
21+
account.incomingServerSettings.host.contains("gmail")
22+
) {
23+
if (!this::folderNameSanitizer.isInitialized) {
24+
folderNameSanitizer = FolderNameSanitizer(lockableDatabase = localStore.database)
25+
}
26+
folderNameSanitizer.removeGmailPrefixFromFolders()
27+
}
1828
val storageFilesProvider = storageFilesProviderFactory.createStorageFilesProvider(account.uuid)
1929
val messageStore = K9MessageStore(
2030
localStore.database,

0 commit comments

Comments
 (0)