package int_2.servlets.assignments5;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import javax.mail.*;
import int_2.servlets.*;
import int_2.tools.*;
import int_2.beans.*;
/**
Please respect the copyright of this code. It is not allowed to copy this code and use at any circumstances.
@author © Fredrik Andersson
This servlet uses code from my home made toolbox that you can find in the folder 8/tools and 8/beans.
The toolbox is not ready yet, I have been working for it for a couple of years when I have time.
The goal is to get a toolbox of classes so it will be easier to map tasks to
use-case-diagram.
This servlet get emails from some server that the user decide.
*/
public class GetMail_5c extends GeneralServlet
{
public void start(HttpServletRequest request, HttpServletResponse response) throws IOException
{
String output = "";
Form form = FormManager.collectForm(request);
if(form == null || form.get("back") != null)
{
output = createPage("applications/int_2/int_2/templates/get_mail_1.html", "get_mail_1");
output = TextManager.replaceInString(output, "XXXERRORXXX", "");
}
else if(form.get("get") != null)
{
SerializableMessage[] messages = getEmail((String)form.get("user"), (String)form.get("password"), (String)form.get("host"), (String)form.get("port"));
output = createPage("applications/int_2/int_2/templates/get_mail_2.html", "get_mail_2");
output = TextManager.replaceInString(output, "XXXERRORXXX", "");
output = TextManager.replaceInString(output, "XXXMESSAGELISTXXX", createMailList(messages));
}
printString(output);
flush();
}
public String createMailList(SerializableMessage[] messages)
{
if(messages != null && messages.length > 0)
{
StringBuffer mailList = new StringBuffer();
for (int i=0; i < messages.length; i++)
{
mailList.append("