01: package org.claros.intouch.webmail.services;
02:
03: import java.io.IOException;
04: import java.io.PrintWriter;
05:
06: import javax.servlet.ServletException;
07: import javax.servlet.http.HttpServletRequest;
08: import javax.servlet.http.HttpServletResponse;
09:
10: import org.claros.commons.mail.models.ConnectionMetaHandler;
11: import org.claros.commons.mail.models.ConnectionProfile;
12: import org.claros.commons.mail.utility.Constants;
13: import org.claros.intouch.common.services.BaseService;
14: import org.claros.intouch.webmail.factory.FolderControllerFactory;
15:
16: public class GetUnreadCountService extends BaseService {
17:
18: /**
19: *
20: */
21: private static final long serialVersionUID = 2778234149147865257L;
22:
23: /**
24: * The doGet method of the servlet. <br>
25: *
26: * This method is called when a form has its tag value method equals to get.
27: *
28: * @param request the request send by the client to the server
29: * @param response the response send by the server to the client
30: * @throws ServletException if an error occurred
31: * @throws IOException if an error occurred
32: */
33: public void doGet(HttpServletRequest request,
34: HttpServletResponse response) throws ServletException,
35: IOException {
36:
37: response.setHeader("Expires", "-1");
38: response.setHeader("Pragma", "no-cache");
39: response.setHeader("Cache-control", "no-cache");
40: response.setHeader("Content-Type", "text/html; charset=utf-8");
41:
42: PrintWriter out = response.getWriter();
43: ConnectionMetaHandler handler = (ConnectionMetaHandler) request
44: .getSession().getAttribute("handler");
45: ConnectionProfile profile = getConnectionProfile(request);
46:
47: try {
48: FolderControllerFactory foldFact = new FolderControllerFactory(
49: getAuthProfile(request), profile, handler);
50: Integer count = null;
51: if (profile.getProtocol().equals(Constants.IMAP)) {
52: count = foldFact.getFolderController()
53: .countUnreadMessages(
54: Constants.FOLDER_INBOX(profile));
55: } else {
56: count = foldFact.getFolderController()
57: .countTotalMessages(
58: Constants.FOLDER_INBOX(profile));
59: }
60: int iCount = -1;
61: if (count != null) {
62: iCount = count.intValue();
63: }
64: out.print(iCount);
65: } catch (Exception e) {
66: out.print("-1");
67: }
68: }
69: }
|