use of javax.mail.util.SharedByteArrayInputStream in project zm-mailbox by Zimbra.
the class MimeTest method imgNoCid.
@Test
public void imgNoCid() 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 no img</html>\r\n" + "------------1111971890AC3BB91\r\n" + "Content-Type: image/jpeg;\r\n" + "name=\"img.jpg\"\r\n" + "Content-Transfer-Encoding: base64\r\n\r\n" + //no CID here, so sender means for us to show it as body
"R0a1231312ad124svsdsal==";
//obviously not a real image
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(2, bodies.size());
Set<String> types = Sets.newHashSet("text/html", "image/jpeg");
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 SmtpTransportTest method dataException.
@Test(timeout = 3000)
public void dataException() 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").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))) {
@Override
public void writeTo(OutputStream os, String[] ignoreList) throws MessagingException {
// exception while encoding
throw new MessagingException();
}
};
try {
transport.sendMessage(msg, msg.getAllRecipients());
Assert.fail();
} catch (SendFailedException expected) {
} 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:<rcpt@zimbra.com>\r\n", server.replay());
Assert.assertEquals("DATA\r\n", server.replay());
Assert.assertNull(server.replay());
}
use of javax.mail.util.SharedByteArrayInputStream in project zm-mailbox by Zimbra.
the class SmtpTransportTest method rcptToError.
@Test(timeout = 3000)
public void rcptToError() throws Exception {
server = MockTcpServer.scenario().sendLine("220 test ready").recvLine().sendLine("250 OK").recvLine().sendLine("250 OK").recvLine().sendLine("550 error").recvLine().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\nTo: rcpt@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());
Assert.fail();
} catch (SendFailedException e) {
Assert.assertEquals(0, e.getValidSentAddresses().length);
Assert.assertEquals(0, e.getValidUnsentAddresses().length);
Assert.assertEquals(1, 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:<rcpt@zimbra.com>\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 FixedMimeMessageTest method messageId.
@Test
public void messageId() throws Exception {
String raw = "From: sender@zimbra.com\n" + "To: recipient@zimbra.com\n" + "Subject: test\n" + "\n" + "Hello World.";
MimeMessage message = new FixedMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(raw.getBytes()));
Assert.assertNull(message.getMessageID());
message.setHeader("X-TEST", "test");
message.saveChanges();
Assert.assertNotNull(message.getMessageID());
raw = "From: sender@zimbra.com\n" + "To: recipient@zimbra.com\n" + "Subject: test\n" + "Message-ID: <12345@zimbra.com>" + "\n" + "Hello World.";
message = new FixedMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(raw.getBytes()));
Assert.assertEquals("<12345@zimbra.com>", message.getMessageID());
message.setHeader("X-TEST", "test");
message.saveChanges();
Assert.assertEquals("<12345@zimbra.com>", message.getMessageID());
}
use of javax.mail.util.SharedByteArrayInputStream in project zm-mailbox by Zimbra.
the class MimeTest method pdfAsStream.
@Test
public void pdfAsStream() throws Exception {
String content = "From: user1@example.com\r\n" + "To: user2@example.com\r\n" + "Subject: test\r\n" + "Content-Type: application/octet-stream;name=\"test.pdf\"\r\n" + "Content-Transfer-Encoding: base64\r\n\r\n" + //obviously not a real pdf
"R0a1231312ad124svsdsal==";
MimeMessage mm = new Mime.FixedMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(content.getBytes()));
MimePart part = Mime.getMimePart(mm, "1");
Assert.assertEquals("application/octet-stream", Mime.getContentType(part.getContentType()));
}
Aggregations