001/*
002 * (C) Copyright 2006-2008 Nuxeo SAS (http://nuxeo.com/) and contributors.
003 *
004 * All rights reserved. This program and the accompanying materials
005 * are made available under the terms of the GNU Lesser General Public License
006 * (LGPL) version 2.1 which accompanies this distribution, and is available at
007 * http://www.gnu.org/licenses/lgpl.html
008 *
009 * This library is distributed in the hope that it will be useful,
010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012 * Lesser General Public License for more details.
013 *
014 * Contributors:
015 *     Alexandre Russel
016 *
017 * $Id$
018 */
019
020package org.nuxeo.ecm.platform.mail.service;
021
022import java.util.Map;
023
024import javax.mail.Address;
025import javax.mail.MessagingException;
026import javax.mail.Session;
027import javax.mail.Store;
028import javax.mail.Transport;
029
030import org.nuxeo.ecm.platform.mail.action.MailBoxActions;
031import org.nuxeo.ecm.platform.mail.action.MessageActionPipe;
032import org.nuxeo.ecm.platform.mail.fetcher.PropertiesFetcher;
033
034/**
035 * @author Alexandre Russel
036 */
037public interface MailService {
038
039    /**
040     * Returns an actions pipe configured with this factory.
041     * <p>
042     * The actions will start from this folder. The context is be passed to the sessionFactory to be able to find the
043     * session. Use the default session if context is not used.
044     */
045    MailBoxActions getMailBoxActions(String factoryName, String folderName) throws MessagingException;
046
047    MailBoxActions getMailBoxActions(String factoryName, String folderName, Map<String, Object> context)
048            throws MessagingException;
049
050    /**
051     * Gets the pipe of actions for given name
052     */
053    MessageActionPipe getPipe(String name);
054
055    /**
056     * Sends a mail using the setting of this factory to this recipients.
057     * <p>
058     * The context is passed to the sessionFactory to be able to find the session. Use the default session if context is
059     * not used. This template is used, replacing variables with the ones from this variables.
060     */
061    void sendMail(String text, String subject, String factory, Address[] recipients);
062
063    void sendMail(String text, String subject, String factory, Address[] recipients, Map<String, Object> context);
064
065    /**
066     * Returns a connected store for this factory. The store needs to be closed after use.
067     *
068     * @param name The name of the factory that provides the properties.
069     * @return the store.
070     */
071    Store getConnectedStore(String name) throws MessagingException;
072
073    Store getConnectedStore(String name, Map<String, Object> context) throws MessagingException;
074
075    /**
076     * Returns a connected transport for this factory. The transport needs to be closed after use.
077     *
078     * @param name the name of the factory that provides the properties.
079     * @return the transport.
080     */
081    Transport getConnectedTransport(String name) throws MessagingException;
082
083    Transport getConnectedTransport(String name, Map<String, Object> context) throws MessagingException;
084
085    /**
086     * Returns a session for this factory, using the context to find the session or the default if no context is
087     * provided.
088     */
089    Session getSession(String name);
090
091    Session getSession(String name, Map<String, Object> context);
092
093    PropertiesFetcher getFetcher(String name);
094
095}