Search in sources :

Example 41 with SharedByteArrayInputStream

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

the class SmtpTransportTest method authLogin.

@Test(timeout = 3000)
public void authLogin() throws Exception {
    server = MockTcpServer.scenario().sendLine("220 test ready").recvLine().sendLine("250-smtp.zimbra.com").sendLine("250 AUTH LOGIN").recvLine().sendLine("334 OK").recvLine().sendLine("334").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 LOGIN\r\n", server.replay());
    Assert.assertEquals(base64("zimbra") + "\r\n", server.replay());
    Assert.assertEquals(base64("secret") + "\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 42 with SharedByteArrayInputStream

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

the class SmtpTransportTest method bracketsInMailAndRcpt.

@Test(timeout = 3000)
public void bracketsInMailAndRcpt() throws Exception {
    server = MockTcpServer.scenario().sendLine("220 test ready").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();
    session.getProperties().setProperty("mail.smtp.from", "<>");
    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, new Address[] { new InternetAddress("<rcpt@zimbra.com>") });
    transport.close();
    server.shutdown(1000);
    Assert.assertEquals("EHLO localhost\r\n", server.replay());
    Assert.assertEquals("MAIL FROM:<>\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 : InternetAddress(javax.mail.internet.InternetAddress) 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 43 with SharedByteArrayInputStream

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

the class SmtpTransportTest method nullMailFrom.

@Test(timeout = 3000)
public void nullMailFrom() throws Exception {
    server = MockTcpServer.scenario().sendLine("220 test ready").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();
    session.getProperties().setProperty("mail.smtp.from", "from@zimbra.com");
    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";
    SMTPMessage msg = new SMTPMessage(session, new SharedByteArrayInputStream(raw.getBytes(Charsets.ISO_8859_1)));
    // this should override the previously set mail.smtp.from
    msg.setEnvelopeFrom("<>");
    transport.sendMessage(msg, msg.getAllRecipients());
    transport.close();
    server.shutdown(1000);
    Assert.assertEquals("EHLO localhost\r\n", server.replay());
    Assert.assertEquals("MAIL FROM:<>\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 : SMTPMessage(com.sun.mail.smtp.SMTPMessage) Transport(javax.mail.Transport) JMSession(com.zimbra.cs.util.JMSession) Session(javax.mail.Session) SharedByteArrayInputStream(javax.mail.util.SharedByteArrayInputStream) Test(org.junit.Test)

Example 44 with SharedByteArrayInputStream

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

the class SmtpTransportTest method mailFromError.

@Test(timeout = 3000)
public void mailFromError() throws Exception {
    server = MockTcpServer.scenario().sendLine("220 test ready").recvLine().sendLine("250 OK").recvLine().sendLine("451 error").recvLine().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\n" + "Subject: test\n\ntest";
    MimeMessage msg = new ZMimeMessage(session, new SharedByteArrayInputStream(raw.getBytes(Charsets.ISO_8859_1)));
    try {
        transport.sendMessage(msg, msg.getAllRecipients());
        Assert.fail();
    } catch (SendFailedException e) {
        Assert.assertEquals(0, e.getValidSentAddresses().length);
        Assert.assertEquals(0, e.getValidUnsentAddresses().length);
        Assert.assertEquals(0, 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("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 45 with SharedByteArrayInputStream

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

the class SmtpTransportTest method endOfData.

@Test(timeout = 3000)
public void endOfData() throws Exception {
    server = MockTcpServer.scenario().sendLine("220 test ready").recvLine().sendLine("250 OK").recvLine().sendLine("250 OK").recvLine().sendLine("250 OK").recvLine().sendLine("354 OK").recvUntil("\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\n" + ".\n" + "..\n" + ".\n";
    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("From: sender@zimbra.com\r\nTo: rcpt@zimbra.com\r\nSubject: test\r\n\r\n" + "..\r\n" + "...\r\n" + "..\r\n" + ".\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