diff options
author | nea <romangraef@gmail.com> | 2021-09-29 17:12:27 +0200 |
---|---|---|
committer | nea <romangraef@gmail.com> | 2021-09-29 17:12:27 +0200 |
commit | 24b3430c42614bc2f9076a8a04d79720c05bb67b (patch) | |
tree | d2802431d5c76daadcca8bd1d6f1abf3ec84e271 /src/main/kotlin/SMTPProtocol.kt | |
parent | ee3a29a2f94b6c7e35726e4c8e89c15c7dfc77b7 (diff) | |
download | javamailserver-24b3430c42614bc2f9076a8a04d79720c05bb67b.tar.gz javamailserver-24b3430c42614bc2f9076a8a04d79720c05bb67b.tar.bz2 javamailserver-24b3430c42614bc2f9076a8a04d79720c05bb67b.zip |
transaction resets
Diffstat (limited to 'src/main/kotlin/SMTPProtocol.kt')
-rw-r--r-- | src/main/kotlin/SMTPProtocol.kt | 52 |
1 files changed, 37 insertions, 15 deletions
diff --git a/src/main/kotlin/SMTPProtocol.kt b/src/main/kotlin/SMTPProtocol.kt index 2294c88..6f01bb2 100644 --- a/src/main/kotlin/SMTPProtocol.kt +++ b/src/main/kotlin/SMTPProtocol.kt @@ -162,35 +162,54 @@ class SMTPReceiveProtocol(val localHost: String, val inetAddress: InetAddress) : Commands(line, this).block() } + data class Mail(val sender: String, val recipient: List<String>, val text: String) + + class MailTransaction( + var isHelod: Boolean = false, + var isEhlod: Boolean = false, + var recipients: MutableList<String> = mutableListOf(), + var sender: String? = null, + ) { + fun reset() { + recipients = mutableListOf() + sender = null + } + } + override suspend fun IO.execute() { send("220 $localHost\r\n") - var isHelod = false - var receipient: String? = null - var sender: String? = null - var text: String? = null + val messages = mutableListOf<Mail>() + val trans = MailTransaction() while (isOpen()) { commands(readLine()) { println(line) - command("HELO", "EHLO") { + command("EHLO") { + send("250 hello advanced $it\r\n") + trans.isHelod = true + trans.isEhlod = true + } + command("HELO") { send("250 Hello $it, how are you on this fine day?\r\n") - isHelod = true + trans.isHelod = true } command("MAIL FROM:") { send("250 Sender ok\r\n") - sender = it + trans.sender = it } command("RCPT TO:") { send("250 Receipient ok\r\n") - receipient = it + trans.recipients.add(it) } command("DATA") { send("354 Enter mail, end with \".\" on a line by itself\r\n") - text = "" + var text = "" while (true) { val tmp = readLine() if (tmp == ".") break - text += tmp + "\r\n" + text += tmp + "\n" } + messages.add(Mail(trans.sender!!, trans.recipients.toList(), text)) + trans.reset() send("250 Message accepted for delivery\r\n") } command("QUIT") { @@ -198,13 +217,16 @@ class SMTPReceiveProtocol(val localHost: String, val inetAddress: InetAddress) : close() } otherwise { - send("XXX ERROR UNKNOWN CODE $it\r\n") + send("500 ERROR UNKNOWN CODE $it\r\n") } } } - println("IsHelod: $isHelod") - println("From: $sender") - println("To: $receipient") - println("\n$text") + println("Got ${messages.size} messages") + messages.forEach { + println("Message:") + println("MAIL FROM: ${it.sender}") + println("RCPTS TO: ${it.recipient}") + println("CONTENT: ${it.text}") + } } } |