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