Search in sources :

Example 61 with SharedByteArrayInputStream

use of javax.mail.util.SharedByteArrayInputStream in project zm-mailbox by Zimbra.

the class TestParsedMessage method testMimeMutator.

/**
     * Tests message mutation.  We can't verify the entire content, since mutation
     * calls JavaMail, which mangles the headers.  We'll have to settle for confirming
     * that the subject was updated correctly.
     */
@Test
public void testMimeMutator() throws Exception {
    MimeVisitor.registerMutator(TestMimeVisitor.class);
    String subject = NAME_PREFIX + " testMimeConverter oldsubject";
    String content = TestUtil.getTestMessage(subject, RECIPIENT_NAME, SENDER_NAME, null);
    // Test ParsedMessage created from byte[]
    ParsedMessage pm = new ParsedMessage(content.getBytes(), false);
    pm = new ParsedMessage(content.getBytes(), true);
    String substring = "newsubject";
    verifyMutatedMessage(pm, substring, true);
    // Test ParsedMessage created from File
    mFile = createTempFile(content);
    pm = new ParsedMessage(mFile, null, false);
    verifyMutatedMessage(pm, substring, true);
    mFile.delete();
    mFile = createTempFile(content);
    pm = new ParsedMessage(mFile, null, true);
    verifyMutatedMessage(pm, substring, true);
    // Test ParsedMessage created from MimeMessage, attachment indexing off.
    MimeMessage mimeMsg = new ZMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(content.getBytes()));
    pm = new ParsedMessage(mimeMsg, false);
    verifyMutatedMessage(pm, substring, true);
    // Test ParsedMessage created from MimeMessage, attachment indexing on.
    mimeMsg = new ZMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(content.getBytes()));
    pm = new ParsedMessage(mimeMsg, true);
    verifyMutatedMessage(pm, substring, true);
}
Also used : ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) MimeMessage(javax.mail.internet.MimeMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) SharedByteArrayInputStream(javax.mail.util.SharedByteArrayInputStream) Test(org.junit.Test)

Aggregations

SharedByteArrayInputStream (javax.mail.util.SharedByteArrayInputStream)61 MimeMessage (javax.mail.internet.MimeMessage)53 Test (org.junit.Test)47 ZMimeMessage (com.zimbra.common.zmime.ZMimeMessage)31 Session (javax.mail.Session)15 JMSession (com.zimbra.cs.util.JMSession)14 Transport (javax.mail.Transport)14 InputStream (java.io.InputStream)9 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)7 ByteBuilder (com.zimbra.common.zmime.ZMimeUtility.ByteBuilder)6 Mailbox (com.zimbra.cs.mailbox.Mailbox)6 FixedMimeMessage (com.zimbra.cs.mime.Mime.FixedMimeMessage)6 MessagingException (javax.mail.MessagingException)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 MimeMultipart (javax.mail.internet.MimeMultipart)5 ZMimeMultipart (com.zimbra.common.zmime.ZMimeMultipart)4 DeliveryOptions (com.zimbra.cs.mailbox.DeliveryOptions)4 Message (com.zimbra.cs.mailbox.Message)4 ParseMimeMessage (com.zimbra.cs.service.mail.ParseMimeMessage)4 SendMsgRequest (com.zimbra.soap.mail.message.SendMsgRequest)4