001: package org.claros.intouch.webmail.services;
002:
003: import java.io.IOException;
004: import java.io.PrintWriter;
005:
006: import javax.mail.Address;
007: import javax.servlet.ServletException;
008: import javax.servlet.http.HttpServletRequest;
009: import javax.servlet.http.HttpServletResponse;
010:
011: import org.claros.commons.mail.models.Email;
012: import org.claros.commons.utility.Utility;
013: import org.claros.intouch.common.services.BaseService;
014:
015: public class GetHeaderInfoService extends BaseService {
016:
017: /**
018: *
019: */
020: private static final long serialVersionUID = 808344999094917540L;
021:
022: /**
023: * The doGet method of the servlet. <br>
024: *
025: * This method is called when a form has its tag value method equals to get.
026: *
027: * @param request the request send by the client to the server
028: * @param response the response send by the server to the client
029: * @throws ServletException if an error occurred
030: * @throws IOException if an error occurred
031: */
032: public void doGet(HttpServletRequest request,
033: HttpServletResponse response) throws ServletException,
034: IOException {
035: response.setHeader("Expires", "-1");
036: response.setHeader("Pragma", "no-cache");
037: response.setHeader("Cache-control", "no-cache");
038: response.setHeader("Content-Type", "text/xml; charset=utf-8");
039: PrintWriter out = response.getWriter();
040:
041: Email email = (Email) request.getSession()
042: .getAttribute("email");
043:
044: out.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
045: out.write("<data>");
046: out.write("<from>"
047: + Utility.htmlSpecialChars(email.getBaseHeader()
048: .getFromShown()) + "</from>");
049: out.write("<subject>"
050: + Utility.htmlSpecialChars(email.getBaseHeader()
051: .getSubject()) + "</subject>");
052: out.write("<date>" + email.getBaseHeader().getDateShown()
053: + "</date>");
054:
055: Address replyTo[] = email.getBaseHeader().getReplyTo();
056: if (replyTo != null && replyTo.length > 0) {
057: try {
058: out
059: .write("<replyTo>"
060: + Utility
061: .htmlSpecialChars(org.claros.commons.mail.utility.Utility
062: .addressArrToString(replyTo))
063: + "</replyTo>");
064: } catch (Exception e) {
065: out.write("<replyTo> </replyTo>");
066: }
067: } else {
068: out.write("<replyTo> </replyTo>");
069: }
070:
071: String to = email.getBaseHeader().getFromShown();
072: if (email.getBaseHeader().getCc() != null
073: && !email.getBaseHeader().getCc().equals("")) {
074: to += ", " + email.getBaseHeader().getCcShown();
075: }
076: if (email.getBaseHeader().getToShown() != null
077: && !email.getBaseHeader().getToShown().equals("")) {
078: to += ", " + email.getBaseHeader().getToShown();
079: }
080: out.write("<recipients>" + Utility.htmlSpecialChars(to)
081: + "</recipients>");
082:
083: out.write("</data>");
084: }
085:
086: /**
087: * The doPost method of the servlet. <br>
088: *
089: * This method is called when a form has its tag value method equals to post.
090: *
091: * @param request the request send by the client to the server
092: * @param response the response send by the server to the client
093: * @throws ServletException if an error occurred
094: * @throws IOException if an error occurred
095: */
096: public void doPost(HttpServletRequest request,
097: HttpServletResponse response) throws ServletException,
098: IOException {
099:
100: doGet(request, response);
101: }
102: }
|