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

📄 localdelivery.java

📁 java 开发的邮件服务器平台。支持以下协议。 协议可以修改为自己的专门标识
💻 JAVA
字号:
/*********************************************************************** * 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.mailet.GenericMailet;import org.apache.mailet.Mail;import org.apache.mailet.MailAddress;import javax.mail.MessagingException;import javax.mail.internet.MimeMessage;import java.util.Collection;import java.util.Iterator;import java.util.Vector;/** * Receives a Mail from JamesSpoolManager and takes care of delivery * of the message to local inboxes. * */public class LocalDelivery extends GenericMailet {    /**     * Delivers a mail to a local mailbox.     *     * @param mail the mail being processed     *     * @throws MessagingException if an error occurs while storing the mail     */    public void service(Mail mail) throws MessagingException {        Collection recipients = mail.getRecipients();        Collection errors = new Vector();        MimeMessage message = mail.getMessage();        for (Iterator i = recipients.iterator(); i.hasNext(); ) {            MailAddress recipient = (MailAddress) i.next();            try {                // Add qmail's de facto standard Delivered-To header                MimeMessage localMessage = new MimeMessage(message) {                    protected void updateHeaders() throws MessagingException {                        if (getMessageID() == null) super.updateHeaders();                        else {                            modified = false;                        }                    }                };                localMessage.addHeader("Delivered-To", recipient.toString());                localMessage.saveChanges();                getMailetContext().storeMail(mail.getSender(), recipient, localMessage);            } catch (Exception ex) {                getMailetContext().log("Error while storing mail.", ex);                errors.add(recipient);            }        }        if (!errors.isEmpty()) {            // If there were errors, we redirect the email to the ERROR processor.            // In order for this server to meet the requirements of the SMTP specification,            // mails on the ERROR processor must be returned to the sender.  Note that this            // email doesn't include any details regarding the details of the failure(s).            // In the future we may wish to address this.            getMailetContext().sendMail(mail.getSender(),                                        errors, message, Mail.ERROR);        }        //We always consume this message        mail.setState(Mail.GHOST);    }    /**     * Return a string describing this mailet.     *     * @return a string describing this mailet     */    public String getMailetInfo() {        return "Local Delivery Mailet";    }}

⌨️ 快捷键说明

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