diff options
Diffstat (limited to 'src/main/kotlin/Main.kt')
-rw-r--r-- | src/main/kotlin/Main.kt | 24 |
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) } } } |