001: package org.claros.intouch.webmail.services;
002:
003: import java.io.IOException;
004: import java.io.PrintWriter;
005: import java.net.URLDecoder;
006:
007: import javax.servlet.ServletException;
008: import javax.servlet.http.HttpServletRequest;
009: import javax.servlet.http.HttpServletResponse;
010:
011: import org.claros.commons.auth.models.AuthProfile;
012: import org.claros.commons.mail.models.ConnectionMetaHandler;
013: import org.claros.commons.mail.models.ConnectionProfile;
014: import org.claros.commons.utility.Utility;
015: import org.claros.intouch.common.services.BaseService;
016: import org.claros.intouch.webmail.controllers.FolderController;
017: import org.claros.intouch.webmail.factory.FolderControllerFactory;
018: import org.claros.intouch.webmail.models.FolderDbObject;
019:
020: public class RenameMailFolderService extends BaseService {
021:
022: /**
023: *
024: */
025: private static final long serialVersionUID = 3143660824742631722L;
026:
027: /**
028: * The doPost method of the servlet. <br>
029: *
030: * This method is called when a form has its tag value method equals to post.
031: *
032: * @param request the request send by the client to the server
033: * @param response the response send by the server to the client
034: * @throws ServletException if an error occurred
035: * @throws IOException if an error occurred
036: */
037: public void doPost(HttpServletRequest request,
038: HttpServletResponse response) throws ServletException,
039: IOException {
040: response.setHeader("Expires", "-1");
041: response.setHeader("Pragma", "no-cache");
042: response.setHeader("Cache-control", "no-cache");
043: response.setHeader("Content-Type", "text/html; charset=utf-8");
044: PrintWriter out = response.getWriter();
045:
046: AuthProfile auth = getAuthProfile(request);
047: ConnectionMetaHandler handler = (ConnectionMetaHandler) request
048: .getSession().getAttribute("handler");
049: ConnectionProfile profile = (ConnectionProfile) request
050: .getSession().getAttribute("profile");
051:
052: /*
053: String charset = Constants.charset;
054: String oldName = new String(request.getParameter("old").getBytes(charset), "utf-8");
055: String folderName = new String(request.getParameter("newName").getBytes(charset), "utf-8");
056: */
057: String oldName = URLDecoder.decode(request.getParameter("old"),
058: "UTF-8");
059: String folderName = URLDecoder.decode(request
060: .getParameter("newName"), "UTF-8");
061:
062: try {
063: // character corrections. This is important for turkish users.
064: folderName = Utility.replaceAllOccurances(
065: folderName.trim(), ".", "_");
066: folderName = Utility.replaceAllOccurances(folderName,
067: "\u0131", "i");
068: folderName = Utility.replaceAllOccurances(folderName,
069: "\u0130", "I");
070: folderName = Utility.replaceAllOccurances(folderName,
071: "\u015E", "S");
072: folderName = Utility.replaceAllOccurances(folderName,
073: "\u015F", "s");
074: folderName = Utility.replaceAllOccurances(folderName,
075: "\u00E7", "c");
076: folderName = Utility.replaceAllOccurances(folderName,
077: "\u00C7", "C");
078: folderName = Utility.replaceAllOccurances(folderName,
079: "\u00FC", "u");
080: folderName = Utility.replaceAllOccurances(folderName,
081: "\u00DC", "U");
082: folderName = Utility.replaceAllOccurances(folderName,
083: "\u00F6", "o");
084: folderName = Utility.replaceAllOccurances(folderName,
085: "\u00D6", "O");
086: folderName = Utility.replaceAllOccurances(folderName,
087: "\u011F", "g");
088: folderName = Utility.replaceAllOccurances(folderName,
089: "\u011E", "G");
090:
091: FolderControllerFactory factory = new FolderControllerFactory(
092: auth, profile, handler);
093: FolderController foldCont = factory.getFolderController();
094: FolderDbObject itm = foldCont.getFolder(oldName);
095: foldCont.renameFolder(itm.getFolderName(), folderName);
096:
097: out.print("ok."
098: + java.net.URLEncoder.encode(folderName, "utf-8"));
099: } catch (Exception e) {
100: out.print("fail");
101: }
102: }
103:
104: }
|