01: package org.claros.intouch.webmail.services;
02:
03: import java.io.IOException;
04: import java.io.PrintWriter;
05: import java.util.List;
06: import java.util.StringTokenizer;
07:
08: import javax.servlet.ServletException;
09: import javax.servlet.http.HttpServletRequest;
10: import javax.servlet.http.HttpServletResponse;
11:
12: import org.claros.commons.mail.models.Email;
13: import org.claros.intouch.common.services.BaseService;
14:
15: public class GetAllHeadersService extends BaseService {
16:
17: /**
18: *
19: */
20: private static final long serialVersionUID = -5531591567232821418L;
21:
22: /**
23: * The doGet method of the servlet. <br>
24: *
25: * This method is called when a form has its tag value method equals to get.
26: *
27: * @param request the request send by the client to the server
28: * @param response the response send by the server to the client
29: * @throws ServletException if an error occurred
30: * @throws IOException if an error occurred
31: */
32: public void doGet(HttpServletRequest request,
33: HttpServletResponse response) throws ServletException,
34: IOException {
35: response.setHeader("Expires", "-1");
36: response.setHeader("Pragma", "no-cache");
37: response.setHeader("Cache-control", "no-cache");
38: response.setHeader("Content-Type", "text/html; charset=utf-8");
39: PrintWriter out = response.getWriter();
40:
41: Email email = (Email) request.getSession()
42: .getAttribute("email");
43:
44: if (email != null) {
45: List headers = email.getHeaders();
46: if (headers != null) {
47: // name + (char)6 + value
48: String tmp = null;
49: String name = null;
50: String value = null;
51: for (int i = 0; i < headers.size(); i++) {
52: try {
53: tmp = (String) headers.get(i);
54: StringTokenizer tk = new StringTokenizer(tmp,
55: "" + (char) 6);
56: name = tk.nextToken();
57: value = tk.nextToken();
58:
59: out.print(name + ": "
60: + ((value == null) ? "" : value)
61: + "<br/>");
62: } catch (Exception e) {
63: e.printStackTrace();
64: }
65: }
66: }
67: }
68: }
69:
70: }
|