summaryrefslogtreecommitdiff
path: root/src/main/kotlin/Main.kt
diff options
context:
space:
mode:
authornea <romangraef@gmail.com>2022-09-13 00:25:28 +0200
committernea <romangraef@gmail.com>2022-09-13 00:25:28 +0200
commitb7793a83b1f39ff94bfbaeef8ac4c387839a94de (patch)
tree2d89200e800de8230cf91aa4741d9958edd76d0a /src/main/kotlin/Main.kt
parent24b3430c42614bc2f9076a8a04d79720c05bb67b (diff)
downloadjavamailserver-b7793a83b1f39ff94bfbaeef8ac4c387839a94de.tar.gz
javamailserver-b7793a83b1f39ff94bfbaeef8ac4c387839a94de.tar.bz2
javamailserver-b7793a83b1f39ff94bfbaeef8ac4c387839a94de.zip
Diffstat (limited to 'src/main/kotlin/Main.kt')
-rw-r--r--src/main/kotlin/Main.kt24
1 files changed, 7 insertions, 17 deletions
diff --git a/src/main/kotlin/Main.kt b/src/main/kotlin/Main.kt
index 577c3fb..7f19f90 100644
--- a/src/main/kotlin/Main.kt
+++ b/src/main/kotlin/Main.kt
@@ -1,31 +1,21 @@
-import kotlinx.coroutines.CoroutineScope
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.Job
import kotlinx.coroutines.runBlocking
-import java.net.ServerSocket
+import kotlin.system.exitProcess
object Main {
@JvmStatic
fun main(args: Array<String>) {
if (args.size != 1) {
- System.err.println("Use ./javamailteste run/install")
+ System.err.println("Use ./javamailteste run")
+ exitProcess(1)
}
when (args[0]) {
- "run" -> runServer(2500)
+ "run" -> runServer(args.getOrElse(1) { "2500" }.toInt())
}
}
- fun runServer(port: Int) = runBlocking(Dispatchers.Default) {
- val ss = ServerSocket(port)
- val jobs = mutableListOf<Job>()
- println("Starting SMTP socket on port $port")
- while (true) {
- val scope = CoroutineScope(Dispatchers.Default)
- val socket = with(Dispatchers.IO) { ss.accept() }
- val prot = SMTPReceiveProtocol("nea89.moe", socket.inetAddress)
- jobs.add(prot.executeAsync(scope, Protocol.IO.FromSocket(socket)))
- println("jobs: $jobs")
- }
+ fun runServer(port: Int) {
+ val mailServer = MailServer("nea89.moe")
+ runBlocking { mailServer.createServer(port) }
}
}