mimemessagetest.java

来自「java mail,java mailjava mailjava mailjav」· Java 代码 · 共 97 行

JAVA
97
字号
/**************************************************************** * Licensed to the Apache Software Foundation (ASF) under one   * * or more contributor license agreements.  See the NOTICE file * * distributed with this work for additional information        * * regarding copyright ownership.  The ASF licenses this file   * * to you 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.core;import org.apache.avalon.framework.container.ContainerUtil;import org.apache.mailet.RFC2822Headers;import javax.mail.BodyPart;import javax.mail.Session;import javax.mail.internet.InternetHeaders;import javax.mail.internet.MimeBodyPart;import javax.mail.internet.MimeMessage;import javax.mail.internet.MimeMultipart;import java.io.ByteArrayInputStream;import java.io.ByteArrayOutputStream;import java.util.Arrays;import java.util.Enumeration;import java.util.Properties;import junit.framework.TestCase;/** * Test the subject folding issue. */public class MimeMessageTest extends TestCase {    protected MimeMessage getSimpleMessage() throws Exception {        MimeMessage mmCreated = new MimeMessage(Session.getDefaultInstance(new Properties()));        mmCreated.setSubject("test");        mmCreated.setText("test body");        mmCreated.saveChanges();        return mmCreated;    }        protected String getSimpleMessageCleanedSource() throws Exception {        return "Subject: test\r\n"            +"MIME-Version: 1.0\r\n"            +"Content-Type: text/plain; charset=us-ascii\r\n"            +"Content-Transfer-Encoding: 7bit\r\n"            +"\r\n"            +"test body";    }        protected MimeMessage getMessageWithBadReturnPath() throws Exception {        MimeMessage mmCreated = new MimeMessage(Session.getDefaultInstance(new Properties()));        mmCreated.setSubject("test");        mmCreated.setHeader(RFC2822Headers.RETURN_PATH, "<mybadreturn@example.com>");        mmCreated.setText("test body");        mmCreated.saveChanges();        return mmCreated;    }        protected String getMessageWithBadReturnPathSource() throws Exception {        return "Subject: test\r\n"            +"Return-Path: <mybadreturn@example.com>\r\n"            +"MIME-Version: 1.0\r\n"            +"Content-Type: text/plain; charset=us-ascii\r\n"            +"Content-Transfer-Encoding: 7bit\r\n"            +"\r\n"            +"test body";    }        protected String getSimpleMessageCleanedSourceHeaderExpected() throws Exception {        return "X-Test: foo\r\n"+getSimpleMessageCleanedSource();    }        /*     * Class under test for String getSubject()     */    public void testSimpleMessage() throws Exception {        assertEquals(getSimpleMessageCleanedSource(), getCleanedMessageSource(getSimpleMessage()));    }            protected MimeMessage getMultipartMessage() throws Exception {        MimeMessage mmCreated = new MimeMessage(Session.getDefaultInstance(new Properties()));        mmCreated.setSubject("test");        MimeMultipart mm = new MimeMultipart("alternative");        mm.addBodyPart(new MimeBodyPart(new InternetHeaders(new ByteArrayInputStream("X-header: test1\r\nContent-Type: text/plain; charset=Cp1252\r\n".getBytes())),"first part 蜞

⌨️ 快捷键说明

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