⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 commandlistservmanager.java

📁 java 开发的邮件服务器平台。支持以下协议。 协议可以修改为自己的专门标识
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/*********************************************************************** * Copyright (c) 2000-2004 The Apache Software Foundation.             * * All rights reserved.                                                * * ------------------------------------------------------------------- * * Licensed under the Apache License, Version 2.0 (the "License"); you * * may not use this file except in compliance with the License. You    * * may obtain a copy of the License at:                                * *                                                                     * *     http://www.apache.org/licenses/LICENSE-2.0                      * *                                                                     * * Unless required by applicable law or agreed to in writing, software * * distributed under the License is distributed on an "AS IS" BASIS,   * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or     * * implied.  See the License for the specific language governing       * * permissions and limitations under the License.                      * ***********************************************************************/package org.apache.james.transport.mailets;import org.apache.avalon.framework.component.ComponentManager;import org.apache.avalon.framework.configuration.Configuration;import org.apache.avalon.framework.configuration.ConfigurationException;import org.apache.james.Constants;import org.apache.james.services.UsersRepository;import org.apache.james.services.UsersStore;import org.apache.james.transport.mailets.listservcommands.ErrorCommand;import org.apache.james.transport.mailets.listservcommands.IListServCommand;import org.apache.james.util.XMLResources;import org.apache.mailet.GenericMailet;import org.apache.mailet.Mail;import org.apache.mailet.MailAddress;import javax.mail.MessagingException;import java.io.File;import java.lang.reflect.Field;import java.util.*;/** * CommandListservManager is the default implementation of {@link ICommandListservManager}. * It loads all the configured {@link IListServCommand}s and delegates to them at runtime. * <br /> * * It isn't responsible for procesing messages sent to the main mailing list, but is responsible for * individual commands sent by users, such as: info, subscribe, etc... * <br /> * * Requests sent to the CommandListservManager take the form of: * <pre> * &lt;listName&gt;-&lt;commandName&gt;@domain * </pre> * * If the command isn't recognized an error will be sent using {@link #onError}. * <br /> * <br /> * * The configuration for this mailet sould be in the 'root' processor block. * <pre> * &lt;mailet match="CommandListservMatcher=announce@localhost" class="CommandListservManager"&gt; *  &lt;listName&gt;announce&lt;/listName&gt; *  &lt;displayName&gt;Announce mailing list&lt;/displayName&gt; *  &lt;listOwner&gt;owner@localhost&lt;/listOwner&gt; *  &lt;repositoryName&gt;list-announce&lt;/repositoryName&gt; *  &lt;listDomain&gt;localhost&lt;/listDomain&gt; * *  &lt;commandpackages&gt; *     &lt;commandpackage&gt;org.apache.james.transport.mailets.listservcommands&lt;/commandpackage&gt; *  &lt;/commandpackages&gt; * *  &lt;commands&gt; *     &lt;command name="subscribe" class="Subscribe"/&gt; *     &lt;command name="subscribe-confirm" class="SubscribeConfirm"/&gt; *     &lt;command name="unsubscribe" class="UnSubscribe"/&gt; *     &lt;command name="unsubscribe-confirm" class="UnSubscribeConfirm"/&gt; *     &lt;command name="error" class="ErrorCommand"/&gt; *     &lt;command name="owner" class="Owner"/&gt; *     &lt;command name="info" class="Info"/&gt; *  &lt;/commands&gt; * &lt;/mailet&gt; * </pre> * * <br /> * <br /> * Todo: refine the command matching so we can have more sophistciated commands such as: * <pre> * &lt;listName&gt;-&lt;commandName&gt;-&lt;optCommandParam&gt;@domain * </pre> * * @version CVS $Revision: 1.1.2.4 $ $Date: 2004/03/30 02:15:24 $ * @since 2.2.0 */public class CommandListservManager extends GenericMailet implements ICommandListservManager {    protected Map commandMap = new HashMap();    protected List commandPackages = new ArrayList();    protected UsersRepository usersRepository;    protected String listName;    protected String displayName;    protected String listOwner;    protected String listDomain;    protected XMLResources xmlResources;    /**     * Get the name of this list specified by the config param: 'listName'.     * <br />     * eg: <pre>&lt;listName&gt;announce&lt;/listName&gt;</pre>     *     * @param displayFormat is whether you want a display version of this or not     * @return the official display name of this list     */    public String getListName(boolean displayFormat) {        return displayFormat ? displayName : listName;    }    /**     * Gets the owner of this list specified by the config param: 'listOwner'.     * <br />     * eg: <pre>&lt;listOwner&gt;owner@localhost&lt;/listOwner&gt;</pre>     *     * @return this is an address like listOwner@localhost     */    public String getListOwner() {        return listOwner;    }    /**     * Get the domain of the list specified by the config param: 'listDomain'.     * <br />     * eg: <pre>&lt;listDomain&gt;localhost&lt;/listDomain&gt;</pre>     *     * @return a string like localhost     */    public String getListDomain() {        return listDomain;    }    /**     * Get a specific command specified by the 'commands' configuration block.     * For instance:     * <pre>     * &lt;commands&gt;     *  &lt;command name="subscribe" class="Subscribe"/&gt;     *  &lt;command name="subscribe-confirm" class="SubscribeConfirm"/&gt;     *  &lt;command name="unsubscribe" class="UnSubscribe"/&gt;     *  &lt;command name="unsubscribe-confirm" class="UnSubscribeConfirm"/&gt;     *  &lt;command name="error" class="ErrorCommand"/&gt;     *  &lt;command name="owner" class="Owner"/&gt;     *  &lt;command name="info" class="Info"/&gt;     * &lt;/commands&gt;     * </pre>     * @param name case in-sensitive     * @return a {@link IListServCommand} if found, null otherwise     */    public IListServCommand getCommand(String name) {        return (IListServCommand) commandMap.get(name.toLowerCase());    }    /**     * Get all the available commands     * @return a map of {@link IListServCommand}     * @see #getCommand     */    public Map getCommands() {        return commandMap;    }    /**     * Get the current user repository for this list serv     * @return an instance of {@link UsersRepository} that is used for the member list of the list serv     */    public UsersRepository getUsersRepository() {        return usersRepository;    }    /**     * An error occurred, send some sort of message     * @param subject the subject of the message to send     * @param mail     * @param errorMessage     */    public void onError(Mail mail, String subject, String errorMessage) throws MessagingException {        ErrorCommand errorCommand = (ErrorCommand) getCommand("error");        errorCommand.onError(mail, subject, errorMessage);    }    /**     * @return the configuration file for the xml resources     */    public String getResourcesFile() {        return getInitParameter("resources");    }    /**     * Use this to get standard properties for future calls to {@link org.apache.james.util.XMLResources}     * @return properties with the "LIST_NAME" and the "DOMAIN_NAME" properties     */    public Properties getStandardProperties() {        Properties standardProperties = new Properties();        standardProperties.put("LIST_NAME", getListName(false));        standardProperties.put("DISPLAY_NAME", getListName(true));        standardProperties.put("DOMAIN_NAME", getListDomain());        return standardProperties;    }    /**     * Initializes an array of resources     * @param names such as 'header, footer' etc...     * @return an initialized array of XMLResources     * @throws ConfigurationException     */    public XMLResources[] initXMLResources(String[] names) throws ConfigurationException {        try {            File xmlFile = new File(getResourcesFile());

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -