Search in sources :

Example 31 with ZMimeMessage

use of com.zimbra.common.zmime.ZMimeMessage in project zm-mailbox by Zimbra.

the class TestContentTransferEncoding method testSimpleMimeMessage.

/*
     * This tests the CTE header of a forwarded message being inferred from the existing message when the message is a simple MIME message
     */
@Ignore("disabled until bug 98015 is fixed")
@Test
public void testSimpleMimeMessage() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    MimeMessage mimeMsg = new ZMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(getSimpleMimeString().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: Simple Test");
    msgToSend.setMimePart(MimePartInfo.createForContentTypeAndContent("text/plain", "simple test"));
    SendMsgRequest req = new SendMsgRequest();
    req.setMsg(msgToSend);
    MimeMessage parsed = sendForwardedMessage(req, msg);
    assertEquals("test", parsed.getHeader("Content-Transfer-Encoding")[0]);
}
Also used : ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) Message(com.zimbra.cs.mailbox.Message) MimeMessage(javax.mail.internet.MimeMessage) ParseMimeMessage(com.zimbra.cs.service.mail.ParseMimeMessage) 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) SendMsgRequest(com.zimbra.soap.mail.message.SendMsgRequest) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) SharedByteArrayInputStream(javax.mail.util.SharedByteArrayInputStream) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 32 with ZMimeMessage

use of com.zimbra.common.zmime.ZMimeMessage 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 33 with ZMimeMessage

use of com.zimbra.common.zmime.ZMimeMessage 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 34 with ZMimeMessage

use of com.zimbra.common.zmime.ZMimeMessage 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 35 with ZMimeMessage

use of com.zimbra.common.zmime.ZMimeMessage 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

ZMimeMessage (com.zimbra.common.zmime.ZMimeMessage)53 MimeMessage (javax.mail.internet.MimeMessage)50 Test (org.junit.Test)34 SharedByteArrayInputStream (javax.mail.util.SharedByteArrayInputStream)30 InputStream (java.io.InputStream)17 Session (javax.mail.Session)14 Transport (javax.mail.Transport)14 Mailbox (com.zimbra.cs.mailbox.Mailbox)13 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)13 JMSession (com.zimbra.cs.util.JMSession)13 Message (com.zimbra.cs.mailbox.Message)12 Account (com.zimbra.cs.account.Account)10 MessagingException (javax.mail.MessagingException)10 OperationContext (com.zimbra.cs.mailbox.OperationContext)9 ItemId (com.zimbra.cs.service.util.ItemId)9 InternetAddress (javax.mail.internet.InternetAddress)9 JavaMailInternetAddress (com.zimbra.common.mime.shim.JavaMailInternetAddress)8 DeliveryContext (com.zimbra.cs.mailbox.DeliveryContext)8 Date (java.util.Date)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6