001: package org.claros.intouch.webmail.services;
002:
003: import java.io.IOException;
004: import java.io.PrintWriter;
005: import java.net.URLDecoder;
006: import java.util.StringTokenizer;
007:
008: import javax.servlet.ServletException;
009: import javax.servlet.http.HttpServletRequest;
010: import javax.servlet.http.HttpServletResponse;
011:
012: import org.apache.commons.logging.Log;
013: import org.apache.commons.logging.LogFactory;
014: import org.claros.commons.auth.models.AuthProfile;
015: import org.claros.commons.mail.models.ConnectionMetaHandler;
016: import org.claros.commons.mail.models.ConnectionProfile;
017: import org.claros.intouch.common.services.BaseService;
018: import org.claros.intouch.webmail.controllers.MailController;
019: import org.claros.intouch.webmail.factory.MailControllerFactory;
020:
021: public class MoveMailsService extends BaseService {
022:
023: /**
024: *
025: */
026: private static final long serialVersionUID = -1791821901766371404L;
027: private static Log log = LogFactory.getLog(DeleteMailService.class);
028:
029: /**
030: * The doGet method of the servlet. <br>
031: *
032: * This method is called when a form has its tag value method equals to get.
033: *
034: * @param request the request send by the client to the server
035: * @param response the response send by the server to the client
036: * @throws ServletException if an error occurred
037: * @throws IOException if an error occurred
038: */
039: public void doGet(HttpServletRequest request,
040: HttpServletResponse response) throws ServletException,
041: IOException {
042: doPost(request, response);
043: }
044:
045: /**
046: * The doPost method of the servlet. <br>
047: *
048: * This method is called when a form has its tag value method equals to post.
049: *
050: * @param request the request send by the client to the server
051: * @param response the response send by the server to the client
052: * @throws ServletException if an error occurred
053: * @throws IOException if an error occurred
054: */
055: public void doPost(HttpServletRequest request,
056: HttpServletResponse response) throws ServletException,
057: IOException {
058:
059: response.setHeader("Expires", "-1");
060: response.setHeader("Pragma", "no-cache");
061: response.setHeader("Cache-control", "no-cache");
062: response.setHeader("Content-Type", "text/html; charset=utf-8");
063:
064: PrintWriter out = response.getWriter();
065:
066: String ids = request.getParameter("ids");
067: String srcFolder = URLDecoder.decode(request
068: .getParameter("source"), "UTF-8");
069: String targetFolder = URLDecoder.decode(request
070: .getParameter("target"), "UTF-8");
071:
072: if (ids != null && srcFolder != null && targetFolder != null) {
073: try {
074: AuthProfile auth = getAuthProfile(request);
075: ConnectionMetaHandler handler = (ConnectionMetaHandler) request
076: .getSession().getAttribute("handler");
077: ConnectionProfile profile = (ConnectionProfile) request
078: .getSession().getAttribute("profile");
079:
080: MailControllerFactory factory = new MailControllerFactory(
081: auth, profile, handler, srcFolder);
082: MailController mailCont = factory.getMailController();
083:
084: // determine the ids of the messages to be deleted or moved to the trash folder
085: StringTokenizer token = new StringTokenizer(ids
086: .substring(1), "_");
087: int size = token.countTokens();
088:
089: int msgs[] = new int[size];
090: int counter = 0;
091: while (token.hasMoreTokens()) {
092: msgs[counter] = Integer.parseInt(token.nextToken());
093: counter++;
094: }
095:
096: // action time
097: mailCont.moveEmails(msgs, targetFolder);
098: } catch (Exception e) {
099: log.info("error moving mail", e);
100: out.print("fail");
101: }
102: }
103: out.print("ok");
104:
105: }
106:
107: }
|