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

📄 commandlistservprocessor.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.james.Constants;import org.apache.james.services.UsersRepository;import org.apache.james.services.UsersStore;import org.apache.james.util.RFC2822Headers;import org.apache.james.util.XMLResources;import org.apache.mailet.GenericMailet;import org.apache.mailet.Mail;import org.apache.mailet.MailAddress;import org.apache.mailet.MailetException;import javax.mail.MessagingException;import javax.mail.internet.MimeMessage;import javax.mail.internet.MimeMultipart;import javax.mail.internet.ParseException;import java.io.IOException;import java.util.*;/** * CommandListservProcessor processes messages intended for the list serv mailing list. * For command handling, see {@link CommandListservManager} <br /> * * This class is based on the existing list serv processor shipped with James. * <br /> * <br /> * * To configure the CommandListservProcessor place this configuratin in the root processor: * <pre> * &lt;mailet match="RecipientIs=announce@localhost" class="CommandListservProcessor"&gt; *  &lt;membersonly&gt;false&lt;/membersonly&gt; *  &lt;attachmentsallowed&gt;true&lt;/attachmentsallowed&gt; *  &lt;replytolist&gt;true&lt;/replytolist&gt; *  &lt;repositoryName&gt;list-announce&lt;/repositoryName&gt; *  &lt;subjectprefix&gt;Announce&lt;/subjectprefix&gt; *  &lt;autobracket&gt;true&lt;/autobracket&gt; *  &lt;listOwner&gt;owner@localhost&lt;/listOwner&gt; *  &lt;listName&gt;announce&lt;/listName&gt; * &lt;/mailet&gt; * * </pre> * * @version CVS $Revision: 1.1.2.6 $ $Date: 2004/04/16 20:59:14 $ * @since 2.2.0 */public class CommandListservProcessor extends GenericMailet {    /**     * Whether only members can post to the list specified by the config param: 'membersonly'.     * <br />     * eg: <pre>&lt;membersonly&gt;false&lt;/membersonly&gt;</pre>     *     * Defaults to false     */    protected boolean membersOnly;    /**     * Whether attachments can be sent to the list specified by the config param: 'attachmentsallowed'.     * <br />     * eg: <pre>&lt;attachmentsallowed&gt;true&lt;/attachmentsallowed&gt;</pre>     *     * Defaults to true     */    protected boolean attachmentsAllowed;    /**     * Whether the reply-to header should be set to the list address     * specified by the config param: 'replytolist'.     * <br />     * eg: <pre>&lt;replytolist&gt;true&lt;/replytolist&gt;</pre>     *     * Defaults to true     */    protected boolean replyToList;    /**     * A String to prepend to the subject of the message when it is sent to the list     * specified by the config param: 'subjectPrefix'.     * <br />     * eg: <pre>&lt;subjectPrefix&gt;MyList&lt;/subjectPrefix&gt;</pre>     *     * For example: MyList     */    protected String subjectPrefix;    /**     * Whether the subject prefix should be bracketed with '[' and ']'     * specified by the config param: 'autoBracket'.     * <br />     * eg: <pre>&lt;autoBracket&gt;true&lt;/autoBracket&gt;</pre>     *     * Defaults to true     */    protected boolean autoBracket;    /**     * The repository containing the users on this list     * specified by the config param: 'repositoryName'.     * <br />     * eg: <pre>&lt;repositoryName&gt;list-announce&lt;/repositoryName&gt;</pre>     */    protected UsersRepository usersRepository;    /**     * The list owner     * specified by the config param: 'listOwner'.     * <br />     * eg: <pre>&lt;listOwner&gt;owner@localhost&lt;/listOwner&gt;</pre>     */    protected MailAddress listOwner;    /**     * Name of the mailing list     * specified by the config param: 'listName'.     * <br />     * eg: <pre>&lt;listName&gt;announce&lt;/listName&gt;</pre>     *     */    protected String listName;    /**     * The list serv manager     */    protected ICommandListservManager commandListservManager;    /**     * Mailet that will add the footer to the message     */    protected CommandListservFooter commandListservFooter;    /**     * @see XMLResources     */    protected XMLResources xmlResources;    /**     * Initialize the mailet     */    public void init() throws MessagingException {        membersOnly = getBoolean("membersonly", false);        attachmentsAllowed = getBoolean("attachmentsallowed", true);        replyToList = getBoolean("replytolist", true);        subjectPrefix = getString("subjectprefix", null);        listName = getString("listName", null);        autoBracket = getBoolean("autobracket", true);        try {            listOwner = new MailAddress(getString("listOwner", null));            //initialize resources            initializeResources();            //init user repos            initUsersRepository();        } catch (Exception e) {            throw new MessagingException(e.getMessage(), e);        }    }    /**     * A message was sent to the list serv.  Broadcast if appropriate...     * @param mail     * @throws MessagingException     */    public void service(Mail mail) throws MessagingException {        try {            Collection members = new ArrayList();            members.addAll(getMembers());            MailAddress listservAddr = (MailAddress) mail.getRecipients().iterator().next();            //Check for members only flag....            if (!checkMembers(members, mail)) {                return;            }            //Check for no attachments            if (!checkAnnouncements(mail)) {                return;            }            //check been there            if (!checkBeenThere(listservAddr, mail)) {                return;            }            //addfooter            addFooter(mail);            //prepare the new message            MimeMessage message = prepareListMessage(mail, listservAddr);            //Set the subject if set            setSubject(message);            //Send the message to the list members            //We set the list owner as the sender for now so bounces go to him/her            getMailetContext().sendMail(listOwner, members, message);        } catch (IOException ioe) {            throw new MailetException("Error creating listserv message", ioe);        } finally {            //Kill the old message            mail.setState(Mail.GHOST);        }    }    /**     * Add the footer using {@link CommandListservFooter}     * @param mail     * @throws MessagingException     */    protected void addFooter(Mail mail) throws MessagingException {        getCommandListservFooter().service(mail);    }    protected void setSubject(MimeMessage message) throws MessagingException {        String prefix = subjectPrefix;        if (prefix != null) {            if (autoBracket) {                StringBuffer prefixBuffer =                        new StringBuffer(64)                        .append("[")                        .append(prefix)                        .append("]");                prefix = prefixBuffer.toString();            }            String subj = message.getSubject();            if (subj == null) {                subj = "";            }            subj = normalizeSubject(subj, prefix);            AbstractRedirect.changeSubject(message, subj);        }    }    /**     * Create a new message with some set headers     * @param mail     * @param listservAddr

⌨️ 快捷键说明

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