Search in sources :

Example 36 with SharedByteArrayInputStream

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

the class MimeTest method bigMime.

@Test
@Ignore("expensive test")
public void bigMime() throws Exception {
    String content = baseMpMixedContent + "\r\n";
    StringBuilder sb = new StringBuilder(content);
    long total = 0;
    int count = 10;
    int partCount = 100;
    int textcount = 1000000;
    int lineSize = 200;
    for (int i = 0; i < partCount; i++) {
        sb.append("------------1111971890AC3BB91\r\n").append("Content-Type: text/plain; charset=windows-1250\r\n").append("Content-Transfer-Encoding: quoted-printable\r\n\r\n");
        for (int j = 0; j < textcount; j += lineSize) {
            String text = RandomStringUtils.randomAlphabetic(lineSize);
            sb.append(text).append("\r\n");
        }
        sb.append("\r\n");
    }
    for (int i = 0; i < count; i++) {
        long start = System.currentTimeMillis();
        MimeMessage mm = new Mime.FixedMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(sb.toString().getBytes()));
        List<MPartInfo> parts = Mime.getParts(mm);
        long end = System.currentTimeMillis();
        total += (end - start);
        ZimbraLog.test.info("took %dms", end - start);
        Assert.assertNotNull(parts);
        Assert.assertEquals(partCount + 1, parts.size());
        MPartInfo body = Mime.getTextBody(parts, false);
        Assert.assertNotNull(body);
    }
    ZimbraLog.test.info("Avg %dms", total / count);
}
Also used : MimeMessage(javax.mail.internet.MimeMessage) SharedByteArrayInputStream(javax.mail.util.SharedByteArrayInputStream) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 37 with SharedByteArrayInputStream

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

the class TestContentTransferEncoding method testNestedMultipartMessage.

/*
     * Tests bug 103193, which is a regression introduced by bugfix for 98015.
     * The problem seems to be that the MIME structure of the forwarded message doesn't match the structure
     * of the original, which is assumed by the bugfix. Specifically, it lacks the top-level multipart/mixed parent.
     */
@Test
public void testNestedMultipartMessage() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    MimeMessage mimeMsg = new ZMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(getNestedMimeString().getBytes()));
    ParsedMessage pm = new ParsedMessage(mimeMsg, true);
    DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX);
    Message msg = mbox.addMessage(null, pm, dopt, null);
    MsgToSend msgToSend = new MsgToSend();
    msgToSend.setOrigId(String.valueOf(msg.getId()));
    msgToSend.setReplyType("w");
    msgToSend.setSubject("Fwd: Multipart Test");
    MimePartInfo mpi = new MimePartInfo();
    mpi.setContentType("multipart/alternative");
    List<MimePartInfo> mimeParts = new LinkedList<MimePartInfo>();
    mimeParts.add(MimePartInfo.createForContentTypeAndContent("text/plain", "text content"));
    mimeParts.add(MimePartInfo.createForContentTypeAndContent("text/html", "html content"));
    mpi.setMimeParts(mimeParts);
    msgToSend.setMimePart(mpi);
    SendMsgRequest req = new SendMsgRequest();
    req.setMsg(msgToSend);
    try {
        MimeMessage parsed = sendForwardedMessage(req, msg);
    } catch (ArrayIndexOutOfBoundsException e) {
        fail("could not build MIME message");
    }
}
Also used : ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) Message(com.zimbra.cs.mailbox.Message) MimeMessage(javax.mail.internet.MimeMessage) ParseMimeMessage(com.zimbra.cs.service.mail.ParseMimeMessage) SendMsgRequest(com.zimbra.soap.mail.message.SendMsgRequest) LinkedList(java.util.LinkedList) SharedByteArrayInputStream(javax.mail.util.SharedByteArrayInputStream) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) MimeMessage(javax.mail.internet.MimeMessage) ParseMimeMessage(com.zimbra.cs.service.mail.ParseMimeMessage) MsgToSend(com.zimbra.soap.mail.type.MsgToSend) MimePartInfo(com.zimbra.soap.mail.type.MimePartInfo) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) Test(org.junit.Test)

Example 38 with SharedByteArrayInputStream

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

the class SmtpTransportTest method multilineGreeting.

@Test(timeout = 3000)
public void multilineGreeting() throws Exception {
    server = MockTcpServer.scenario().sendLine("220-first line").sendLine("220 second line").recvLine().sendLine("250 OK").recvLine().sendLine("250 OK").recvLine().sendLine("250 OK").recvLine().sendLine("354 OK").swallowUntil("\r\n.\r\n").sendLine("250 OK").recvLine().sendLine("221 bye").build().start(PORT);
    Session session = JMSession.getSession();
    Transport transport = session.getTransport("smtp");
    transport.connect("localhost", PORT, null, null);
    String raw = "From: sender@zimbra.com\nTo: rcpt@zimbra.com\nSubject: test\n\ntest";
    MimeMessage msg = new ZMimeMessage(session, new SharedByteArrayInputStream(raw.getBytes(Charsets.ISO_8859_1)));
    transport.sendMessage(msg, msg.getAllRecipients());
    transport.close();
    server.shutdown(1000);
    Assert.assertEquals("EHLO localhost\r\n", server.replay());
    Assert.assertEquals("MAIL FROM:<sender@zimbra.com>\r\n", server.replay());
    Assert.assertEquals("RCPT TO:<rcpt@zimbra.com>\r\n", server.replay());
    Assert.assertEquals("DATA\r\n", server.replay());
    Assert.assertEquals("QUIT\r\n", server.replay());
    Assert.assertNull(server.replay());
}
Also used : ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) MimeMessage(javax.mail.internet.MimeMessage) Transport(javax.mail.Transport) JMSession(com.zimbra.cs.util.JMSession) Session(javax.mail.Session) SharedByteArrayInputStream(javax.mail.util.SharedByteArrayInputStream) Test(org.junit.Test)

Example 39 with SharedByteArrayInputStream

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

the class SmtpTransportTest method sendPartially.

@Test(timeout = 3000)
public void sendPartially() throws Exception {
    server = MockTcpServer.scenario().sendLine("220 test ready").recvLine().sendLine("250 OK").recvLine().sendLine("250 OK").recvLine().sendLine("250 OK").recvLine().sendLine("550 not found").recvLine().sendLine("550 not found").recvLine().sendLine("354 OK").swallowUntil("\r\n.\r\n").sendLine("250 OK").recvLine().sendLine("221 bye").build().start(PORT);
    Session session = JMSession.getSession();
    session.getProperties().setProperty("mail.smtp.sendpartial", "true");
    Transport transport = session.getTransport("smtp");
    transport.connect("localhost", PORT, null, null);
    String raw = "From: sender@zimbra.com\n" + "To: rcpt1@zimbra.com, rcpt2@zimbra.com, rcpt3@zimbra.com\nSubject: test\n\ntest";
    MimeMessage msg = new ZMimeMessage(session, new SharedByteArrayInputStream(raw.getBytes(Charsets.ISO_8859_1)));
    try {
        transport.sendMessage(msg, msg.getAllRecipients());
    } catch (SendFailedException e) {
        Assert.assertEquals(1, e.getValidSentAddresses().length);
        Assert.assertEquals(0, e.getValidUnsentAddresses().length);
        Assert.assertEquals(2, e.getInvalidAddresses().length);
    } finally {
        transport.close();
    }
    server.shutdown(1000);
    Assert.assertEquals("EHLO localhost\r\n", server.replay());
    Assert.assertEquals("MAIL FROM:<sender@zimbra.com>\r\n", server.replay());
    Assert.assertEquals("RCPT TO:<rcpt1@zimbra.com>\r\n", server.replay());
    Assert.assertEquals("RCPT TO:<rcpt2@zimbra.com>\r\n", server.replay());
    Assert.assertEquals("RCPT TO:<rcpt3@zimbra.com>\r\n", server.replay());
    Assert.assertEquals("DATA\r\n", server.replay());
    Assert.assertEquals("QUIT\r\n", server.replay());
    Assert.assertNull(server.replay());
}
Also used : SendFailedException(javax.mail.SendFailedException) ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) MimeMessage(javax.mail.internet.MimeMessage) Transport(javax.mail.Transport) JMSession(com.zimbra.cs.util.JMSession) Session(javax.mail.Session) SharedByteArrayInputStream(javax.mail.util.SharedByteArrayInputStream) Test(org.junit.Test)

Example 40 with SharedByteArrayInputStream

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

the class SmtpTransportTest method authPlain.

@Test(timeout = 3000)
public void authPlain() throws Exception {
    server = MockTcpServer.scenario().sendLine("220 test ready").recvLine().sendLine("250-smtp.zimbra.com").sendLine("250 AUTH PLAIN").recvLine().sendLine("235 Authentication successful").recvLine().sendLine("250 OK").recvLine().sendLine("250 OK").recvLine().sendLine("354 OK").swallowUntil("\r\n.\r\n").sendLine("250 OK").recvLine().sendLine("221 bye").build().start(PORT);
    Session session = JMSession.getSession();
    Transport transport = session.getTransport("smtp");
    transport.connect("localhost", PORT, "zimbra", "secret");
    String raw = "From: sender@zimbra.com\nTo: rcpt@zimbra.com\nSubject: test\n\ntest";
    MimeMessage msg = new ZMimeMessage(session, new SharedByteArrayInputStream(raw.getBytes(Charsets.ISO_8859_1)));
    transport.sendMessage(msg, msg.getAllRecipients());
    transport.close();
    server.shutdown(1000);
    Assert.assertEquals("EHLO localhost\r\n", server.replay());
    Assert.assertEquals("AUTH PLAIN " + base64("\0zimbra\0secret") + "\r\n", server.replay());
    Assert.assertEquals("MAIL FROM:<sender@zimbra.com>\r\n", server.replay());
    Assert.assertEquals("RCPT TO:<rcpt@zimbra.com>\r\n", server.replay());
    Assert.assertEquals("DATA\r\n", server.replay());
    Assert.assertEquals("QUIT\r\n", server.replay());
    Assert.assertNull(server.replay());
}
Also used : ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) MimeMessage(javax.mail.internet.MimeMessage) Transport(javax.mail.Transport) JMSession(com.zimbra.cs.util.JMSession) Session(javax.mail.Session) 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