001: package org.claros.mini.actions;
002:
003: import java.util.Collections;
004: import java.util.List;
005: import java.util.Locale;
006:
007: import javax.servlet.http.HttpServletRequest;
008: import javax.servlet.http.HttpServletResponse;
009:
010: import org.apache.commons.logging.Log;
011: import org.apache.commons.logging.LogFactory;
012: import org.apache.struts.action.ActionForm;
013: import org.apache.struts.action.ActionForward;
014: import org.apache.struts.action.ActionMapping;
015:
016: import org.claros.commons.mail.comparator.EmailHeaderComparator;
017: import org.claros.commons.mail.models.ConnectionMetaHandler;
018: import org.claros.commons.mail.models.ConnectionProfile;
019: import org.claros.commons.models.AuthProfile;
020: import org.claros.mini.common.BaseLoggedAction;
021: import org.claros.mini.controllers.FolderController;
022: import org.claros.mini.controllers.InboxController;
023: import org.claros.mini.factory.FolderControllerFactory;
024: import org.claros.mini.factory.InboxControllerFactory;
025: import org.claros.mini.models.FolderDbItem;
026: import org.claros.mini.utility.Constants;
027:
028: /**
029: * @version 1.0
030: * @author Umut Gökbayrak
031: */
032: public class MailboxAction extends BaseLoggedAction {
033: private static Log log = LogFactory.getLog(MailboxAction.class);
034: private static Locale loc = new Locale("en", "US");
035:
036: public ActionForward myExecute(ActionMapping mapping,
037: ActionForm form, HttpServletRequest request,
038: HttpServletResponse response) throws Exception {
039: AuthProfile auth = getAuthProfile(request);
040:
041: String sFolder = (String) getVariable(request, "fid");
042: List headers = null;
043:
044: ConnectionMetaHandler handler = null;
045: ConnectionProfile profile = getConnectionProfile(request);
046:
047: FolderControllerFactory foldFact = null;
048: FolderController folderCont = null;
049: String currFolder = org.claros.commons.mail.utility.Constants.FOLDER_INBOX;
050: if (sFolder == null || sFolder.equals("")) {
051: // if sFolder == currFOlder(which is INBOX at the moment) it is imap
052: // and it is fetching the inbox. So do the mail filtering.
053: try {
054: InboxControllerFactory inFact = new InboxControllerFactory(
055: auth, profile, handler);
056: InboxController inCont = inFact.getInboxController();
057: handler = inCont.checkEmail();
058: request.getSession().setAttribute("handler", handler);
059: foldFact = new FolderControllerFactory(auth, profile,
060: handler);
061: folderCont = foldFact.getFolderController();
062: } catch (Exception e) {
063: log
064: .debug(
065: "error while checking new mail in mailboxaction",
066: e);
067: }
068:
069: if (profile.getProtocol().equals(
070: org.claros.commons.mail.utility.Constants.POP3)) {
071: currFolder = folderCont.getInboxFolder().getId()
072: .toString();
073: } else {
074: currFolder = folderCont.getInboxFolder()
075: .getFolderName();
076: }
077: } else {
078: currFolder = sFolder;
079: handler = getConnectionHandler(request);
080: foldFact = new FolderControllerFactory(auth, profile,
081: handler);
082: folderCont = foldFact.getFolderController();
083: }
084:
085: headers = folderCont.getHeadersByFolder(currFolder);
086: request.getSession().setAttribute("fid", currFolder);
087:
088: if (headers != null) {
089: Collections.sort(headers, new EmailHeaderComparator(false));
090: request.setAttribute("totalMessages", Integer
091: .toString(headers.size()));
092: } else {
093: request.setAttribute("totalMessages", Integer.toString(0));
094: }
095: request.setAttribute("headers", headers);
096:
097: // get current folder name
098: FolderDbItem fItem = folderCont.getFolder(currFolder);
099: request.setAttribute("folderName", fItem.getFolderName()
100: .toUpperCase(loc));
101: if (fItem.getType().equals(Constants.FOLDER_TYPE_SENT)) {
102: request.setAttribute("isSentItems", new Boolean(true));
103: }
104:
105: return mapping.findForward("success");
106: }
107: }
|