001/* 002 * (C) Copyright 2006-2009 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Nuxeo - initial API and implementation 018 * 019 * $Id$ 020 */ 021 022package org.nuxeo.ecm.platform.mail.web.actions; 023 024import static org.nuxeo.ecm.platform.mail.utils.MailCoreConstants.MAIL_FOLDER_TYPE; 025import static org.nuxeo.ecm.platform.mail.web.utils.MailWebConstants.CURRENT_PAGE; 026 027import java.io.Serializable; 028 029import javax.mail.MessagingException; 030 031import org.apache.commons.logging.Log; 032import org.apache.commons.logging.LogFactory; 033import org.jboss.seam.ScopeType; 034import org.jboss.seam.annotations.In; 035import org.jboss.seam.annotations.Name; 036import org.jboss.seam.annotations.Scope; 037import org.jboss.seam.core.Events; 038import org.jboss.seam.faces.FacesMessages; 039import org.jboss.seam.international.StatusMessage; 040import org.nuxeo.ecm.core.api.CoreSession; 041import org.nuxeo.ecm.core.api.DocumentModel; 042import org.nuxeo.ecm.platform.mail.utils.MailCoreHelper; 043import org.nuxeo.ecm.platform.ui.web.api.NavigationContext; 044import org.nuxeo.ecm.webapp.helpers.ResourcesAccessor; 045 046/** 047 * Handles mail actions. 048 * 049 * @author Catalin Baican 050 */ 051@Name("mailActions") 052@Scope(ScopeType.CONVERSATION) 053public class MailActionsBean implements Serializable { 054 055 private static final long serialVersionUID = 1L; 056 057 private static final Log log = LogFactory.getLog(MailActionsBean.class); 058 059 @In(create = true, required = false) 060 protected transient NavigationContext navigationContext; 061 062 @In(create = true, required = false) 063 protected transient CoreSession documentManager; 064 065 @In(create = true, required = false) 066 protected transient FacesMessages facesMessages; 067 068 @In(create = true) 069 protected transient ResourcesAccessor resourcesAccessor; 070 071 public String checkCurrentInbox() { 072 DocumentModel mailFolder = navigationContext.getCurrentDocument(); 073 074 try { 075 MailCoreHelper.checkMail(mailFolder, documentManager); 076 } catch (MessagingException e) { 077 log.debug(e, e); 078 facesMessages.add(StatusMessage.Severity.ERROR, 079 resourcesAccessor.getMessages().get("feedback.check.mail.error") + e.getMessage()); 080 081 return CURRENT_PAGE; 082 } 083 084 facesMessages.add(StatusMessage.Severity.INFO, 085 resourcesAccessor.getMessages().get("feedback.check.mail.success")); 086 Events.instance().raiseEvent("documentChildrenChanged"); 087 088 return CURRENT_PAGE; 089 } 090 091 public boolean isMailFolder() { 092 DocumentModel currentDocument = navigationContext.getCurrentDocument(); 093 return MAIL_FOLDER_TYPE.equals(currentDocument.getType()); 094 } 095 096}