01: package org.claros.intouch.webmail.services;
02:
03: import java.io.IOException;
04: import java.io.PrintWriter;
05:
06: import javax.mail.Address;
07: import javax.mail.internet.InternetAddress;
08: import javax.servlet.ServletException;
09: import javax.servlet.http.HttpServletRequest;
10: import javax.servlet.http.HttpServletResponse;
11:
12: import org.claros.commons.auth.models.AuthProfile;
13: import org.claros.commons.mail.models.Email;
14: import org.claros.intouch.common.services.BaseService;
15: import org.claros.intouch.contacts.controllers.ContactsController;
16:
17: public class SaveSenderService extends BaseService {
18:
19: /**
20: *
21: */
22: private static final long serialVersionUID = 384282706587364201L;
23:
24: /**
25: * The doGet method of the servlet. <br>
26: *
27: * This method is called when a form has its tag value method equals to get.
28: *
29: * @param request the request send by the client to the server
30: * @param response the response send by the server to the client
31: * @throws ServletException if an error occurred
32: * @throws IOException if an error occurred
33: */
34: public void doGet(HttpServletRequest request,
35: HttpServletResponse response) throws ServletException,
36: IOException {
37:
38: response.setHeader("Expires", "-1");
39: response.setHeader("Pragma", "no-cache");
40: response.setHeader("Cache-control", "no-cache");
41: response.setHeader("Content-Type", "text/html; charset=utf-8");
42:
43: PrintWriter out = response.getWriter();
44:
45: Email email = (Email) request.getSession()
46: .getAttribute("email");
47:
48: try {
49: Address adrs[] = email.getBaseHeader().getFrom();
50:
51: if (adrs != null && adrs[0] != null
52: && adrs[0] instanceof InternetAddress) {
53: InternetAddress adr = (InternetAddress) adrs[0];
54: AuthProfile auth = getAuthProfile(request);
55: ContactsController.saveSenderFromAddr(auth, adr);
56:
57: out.print("ok");
58: }
59: } catch (Exception e) {
60: out.print("fail");
61: }
62: }
63:
64: }
|