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

📄 servertime.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.Address;import javax.mail.internet.InternetAddress;import javax.mail.internet.MimeMessage;import java.util.HashSet;import java.util.Set;/** * Returns the current time for the mail server.  Sample configuration: * <mailet match="RecipientIs=time@cadenza.lokitech.com" class="ServerTime"> * </mailet> * */public class ServerTime extends GenericMailet {    /**     * Sends a message back to the sender indicating what time the server thinks it is.     *     * @param mail the mail being processed     *     * @throws MessagingException if an error is encountered while formulating the reply message     */    public void service(Mail mail) throws javax.mail.MessagingException {        MimeMessage response = (MimeMessage)mail.getMessage().reply(false);        response.setSubject("The time is now...");        StringBuffer textBuffer =            new StringBuffer(128)                    .append("This mail server thinks it's ")                    .append((new java.util.Date()).toString())                    .append(".");        response.setText(textBuffer.toString());        // Someone manually checking the server time by hand may send        // an formatted message, lacking From and To headers.  If the        // response fields are null, try setting them from the SMTP        // MAIL FROM/RCPT TO commands used to send the inquiry.        if (response.getFrom() == null) {            response.setFrom(((MailAddress)mail.getRecipients().iterator().next()).toInternetAddress());        }        if (response.getAllRecipients() == null) {            response.setRecipients(MimeMessage.RecipientType.TO, mail.getSender().toString());        }        response.saveChanges();        getMailetContext().sendMail(response);    }    /**     * Return a string describing this mailet.     *     * @return a string describing this mailet     */    public String getMailetInfo() {        return "ServerTime Mailet";    }}

⌨️ 快捷键说明

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