package com.parkerriver;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;

public class NewEmailServlet extends HttpServlet{
   protected void doGet(HttpServletRequest httpServletRequest, 
         HttpServletResponse httpServletResponse) throws 
         ServletException, IOException {
      doPost(httpServletRequest,httpServletResponse);
   }

   protected void doPost(HttpServletRequest httpServletRequest,
         HttpServletResponse httpServletResponse) throws 
         ServletException, IOException {
      String fromAddr = httpServletRequest.getParameter("fromAddr");
      String toAddr = httpServletRequest.getParameter("toAddr");
      String eMsg = httpServletRequest.getParameter("emessage");
      String subj = httpServletRequest.getParameter("subj");
      boolean outcome = false;
      if(check(fromAddr) && check(toAddr) && check(eMsg)){
         EmailBean bean = new  EmailBean();
         bean.setFrom(fromAddr);
         bean.setTo(toAddr);
         bean.setSubject(subj);
         bean.setContent(eMsg);
         outcome = bean.sendMessage();
      }
      AjaxUtil.sendXML(httpServletResponse,"<outcome>"+
         outcome+"</outcome>");

   }
   private boolean check(String content) {
      if(content != null && content.length() > 0) {return true;}
      return false;
   }
}
