-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add store and copy imap commands. improve structured concurrenc…
…y. fix socket reading when it shouldnt
- Loading branch information
1 parent
808fdb9
commit 4d1146c
Showing
34 changed files
with
338 additions
and
363 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
mailserver/imap/src/commonMain/kotlin/frames/command/CopyCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package dev.sitar.kmail.imap.frames.command | ||
|
||
import dev.sitar.kio.async.readers.AsyncReader | ||
import dev.sitar.kmail.imap.Sequence | ||
import dev.sitar.kmail.imap.readValue | ||
|
||
data class CopyCommand(val sequence: Sequence, val mailbox: String): ImapCommand { | ||
override val identifier: ImapCommand.Identifier = ImapCommand.Identifier.Copy | ||
|
||
companion object: ImapCommandSerializer<CopyCommand> { | ||
suspend fun deserialize(mode: Sequence.Mode, input: AsyncReader): CopyCommand { | ||
return CopyCommand(Sequence.deserialize(mode, input), input.readValue(isEnd = true)) | ||
} | ||
|
||
override suspend fun deserialize(input: AsyncReader): CopyCommand = | ||
deserialize(mode = Sequence.Mode.Sequence, input) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
mailserver/imap/src/commonMain/kotlin/frames/command/StoreCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package dev.sitar.kmail.imap.frames.command | ||
|
||
import dev.sitar.kio.async.readers.AsyncReader | ||
import dev.sitar.kmail.imap.Sequence | ||
import dev.sitar.kmail.imap.readList | ||
import dev.sitar.kmail.utils.io.readUtf8StringUntil | ||
import java.lang.Exception | ||
|
||
data class StoreCommand(val sequence: Sequence, val item: StoreDataItem): ImapCommand { | ||
override val identifier: ImapCommand.Identifier = ImapCommand.Identifier.Append | ||
|
||
companion object: ImapCommandSerializer<StoreCommand> { | ||
suspend fun deserialize(mode: Sequence.Mode, input: AsyncReader): StoreCommand { | ||
val sequence = Sequence.deserialize(mode, input) | ||
|
||
val rawName = input.readUtf8StringUntil { it == ' ' } | ||
val flags = input.readList() | ||
|
||
val parts = rawName.split('.') | ||
|
||
val mode: StoreMode = when (parts[0]) { | ||
"FLAGS" -> StoreMode.Set | ||
"+FLAGS" -> StoreMode.Add | ||
"-FLGS" -> StoreMode.Remove | ||
else -> throw Exception("could not parse store mode ${parts[0]}") | ||
} | ||
|
||
val silent = parts.getOrNull(1)?.lowercase()?.toBooleanStrictOrNull() ?: false | ||
|
||
return StoreCommand(sequence, StoreDataItem(mode, silent, flags)) | ||
} | ||
|
||
override suspend fun deserialize(input: AsyncReader): StoreCommand = | ||
deserialize(mode = Sequence.Mode.Sequence, input) | ||
} | ||
} | ||
|
||
enum class StoreMode { | ||
Set, | ||
Add, | ||
Remove; | ||
} | ||
|
||
data class StoreDataItem(val mode: StoreMode, var silent: Boolean, val flags: List<String>) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.