1. Hector Malpica
  2. miuler-mocksmtp

Commits

Hector Malpica  committed f16cdbd

arreglando el messageReceived para que funcione bien al momento de responder comandos smtp

  • Participants
  • Parent commits fc8dee4
  • Branches default

Comments (0)

Files changed (1)

File src/main/scala/com/miuler/mocksmtp/core/MockSMTP.scala

View file
   }
 
   override def messageReceived(ctx: ChannelHandlerContext, msg: String) {
-    log.debug("mensage: \n{}", msg)
+    var outmsg = ""
+    log.debug("mensage: {}", msg)
     connectionTheadNetty.msg = msg
     connectionTheadNetty.mutex.unlock
 
-    msg match {
-      case msg:String if msg.toUpperCase matches "QUIT" =>
-        ctx.write("221 Bye\n").addListener(ChannelFutureListener.CLOSE)
+    msg.toUpperCase match {
+      case _msg:String if _msg.trim matches "HELO|EHLO" => outmsg = "501 Syntax: " + _msg + " hostname\n"
 
-      case msg:String if msg.toUpperCase.trim matches "HELO|EHLO" =>
-        ctx.write("501 Syntax: " + msg.toUpperCase + " hostname\n")
+      case _msg:String if _msg matches "(HELO|EHLO) .+" => outmsg = "250 " + InetAddress.getLocalHost.getHostName  + "\n"
 
-      case msg:String if msg.toUpperCase matches "(HELO|EHLO) .+" =>
-        ctx.write("250 " + InetAddress.getLocalHost.getHostName  + "\n")
+      case _msg:String if _msg matches "MAIL FROM:.+" => outmsg = "250 Ok\n"
 
-      case _ =>
-        ctx.write(msg + "\n")
+      case _msg:String if _msg matches "RCPT TO:.+" => outmsg = "250 Ok\n"
+
+      case _msg:String if _msg matches "DATA.*" => outmsg = "354 End data with <CR><LF>.<CR><LF>\n"
+
+      case _msg:String if _msg == "." => outmsg = "250 Ok\n"
+
+      case _msg:String if _msg == "QUIT" => {outmsg = "221 Bye\n"
+        log.debug("respuesta: {}", outmsg)
+        ctx.write(outmsg).addListener(ChannelFutureListener.CLOSE)
+        return }
+
+      case _ => log.debug("No es un comando")
     }
+
+    ctx.write(outmsg)
+    log.debug("respuesta: {}", outmsg)
   }
 
   override def exceptionCaught(ctx: ChannelHandlerContext, cause: Throwable) {