use of javax.mail.util.SharedByteArrayInputStream in project zm-mailbox by Zimbra.
the class SmtpTransportTest method send.
@Test(timeout = 3000)
public void send() 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();
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());
}
use of javax.mail.util.SharedByteArrayInputStream in project zm-mailbox by Zimbra.
the class SmtpTransportTest method mailSmtpFrom.
@Test(timeout = 3000)
public void mailSmtpFrom() 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";
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:<from@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());
}
use of javax.mail.util.SharedByteArrayInputStream in project zm-mailbox by Zimbra.
the class MimeTest method imgCid.
@Test
public void imgCid() throws Exception {
String content = baseMpMixedContent + "------------1111971890AC3BB91\r\n" + "Content-Type: text/html; charset=windows-1250\r\n" + "Content-Transfer-Encoding: quoted-printable\r\n\r\n" + "<html>Email with img<img src=\"cid:12345_testemail\"/></html>\r\n" + "------------1111971890AC3BB91\r\n" + "Content-Type: image/jpeg;\r\n" + "name=\"img.jpg\"\r\n" + "Content-Transfer-Encoding: base64\r\n" + "Content-ID: <12345_testemail>\r\n\r\n" + //obviously not a real image
"R0a1231312ad124svsdsal==";
MimeMessage mm = new Mime.FixedMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(content.getBytes()));
List<MPartInfo> parts = Mime.getParts(mm);
Assert.assertNotNull(parts);
Assert.assertEquals(3, parts.size());
MPartInfo mpart = parts.get(0);
Assert.assertEquals("multipart/mixed", mpart.getContentType());
List<MPartInfo> children = mpart.getChildren();
Assert.assertEquals(2, children.size());
Set<MPartInfo> bodies = Mime.getBody(parts, false);
Assert.assertEquals(1, bodies.size());
MPartInfo body = bodies.iterator().next();
Assert.assertEquals("text/html", body.getContentType());
}
use of javax.mail.util.SharedByteArrayInputStream in project zm-mailbox by Zimbra.
the class MimeTest method multipartReportRfc822Headers.
@Test
public void multipartReportRfc822Headers() throws Exception {
String content = baseNdrContent + boundary + "\r\n" + "Content-Description: Notification\r\n" + "Content-Type: text/plain;charset=us-ascii\r\n\r\n" + "<mta@example.com>: host mta.example.com[255.255.255.0] said: 554 delivery error: This user doesn't have an example.com account (in reply to end of DATA command)\r\n\r\n" + boundary + "\r\n" + "Content-Description: Delivery report\r\n" + "Content-Type: message/delivery-status\r\n\r\n" + "X-Postfix-Queue-ID: 12345\r\n" + "X-Postfix-Sender: rfc822; test123@example.com\r\n" + "Arrival-Date: Wed, 8 Aug 2012 00:05:30 +0900 (JST)\r\n\r\n" + boundary + "\r\n" + "Content-Description: Undelivered Message Headers\r\n" + "Content-Type: text/rfc822-headers\r\n" + "Content-Transfer-Encoding: 7bit\r\n\r\n" + "From: admin@example\r\n" + "To: test15@example.com\r\n" + "Message-ID: <123456@client.example.com>\r\n" + "Subject: test msg";
MimeMessage mm = new Mime.FixedMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(content.getBytes()));
List<MPartInfo> parts = Mime.getParts(mm);
Assert.assertNotNull(parts);
Assert.assertEquals(4, parts.size());
MPartInfo mpart = parts.get(0);
Assert.assertEquals("multipart/report", mpart.getContentType());
List<MPartInfo> children = mpart.getChildren();
Assert.assertEquals(3, children.size());
Set<String> types = Sets.newHashSet("text/plain", "message/delivery-status", "text/rfc822-headers");
for (MPartInfo child : children) {
Assert.assertTrue("Expected: " + child.getContentType(), types.remove(child.getContentType()));
}
Set<MPartInfo> bodies = Mime.getBody(parts, false);
Assert.assertEquals(2, bodies.size());
types = Sets.newHashSet("text/plain", "text/rfc822-headers");
for (MPartInfo body : bodies) {
Assert.assertTrue("Expected: " + body.getContentType(), types.remove(body.getContentType()));
}
}
use of javax.mail.util.SharedByteArrayInputStream in project zm-mailbox by Zimbra.
the class MimeTest method strayBoundaryInEpilogue.
@Test
public void strayBoundaryInEpilogue() throws Exception {
String content = baseMpMixedContent + "\r\n";
StringBuilder sb = new StringBuilder(content);
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");
String plainText = RandomStringUtils.randomAlphabetic(10);
sb.append(plainText).append("\r\n");
sb.append("------------1111971890AC3BB91--").append("\r\n");
//this is the point of this test; if MIME has a stray boundary it used to cause NPE
sb.append("\r\n").append("--bogusBoundary").append("\r\n").append("\r\n");
MimeMessage mm = new Mime.FixedMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(sb.toString().getBytes()));
List<MPartInfo> parts = Mime.getParts(mm);
Assert.assertEquals(2, parts.size());
MPartInfo body = Mime.getTextBody(parts, false);
Assert.assertNotNull(body);
Assert.assertTrue(TestUtil.bytesEqual(plainText.getBytes(), body.getMimePart().getInputStream()));
}
Aggregations