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);
}
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");
}
}
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());
}
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());
}
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());
}
Aggregations