use of javax.mail.util.SharedByteArrayInputStream in project zm-mailbox by Zimbra.
the class TestContentTransferEncoding method testMultipartMimeMessage.
/*
* This tests the CTE header of a forwarded message being inferred from the existing message when the message is a multipart message.
*/
@Ignore("disabled until bug 98015 is fixed")
@Test
public void testMultipartMimeMessage() throws Exception {
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
MimeMessage mimeMsg = new ZMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(getMultipartMimeString().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", "multipart test"));
mimeParts.add(MimePartInfo.createForContentTypeAndContent("text/html", "multipart test"));
mpi.setMimeParts(mimeParts);
msgToSend.setMimePart(mpi);
SendMsgRequest req = new SendMsgRequest();
req.setMsg(msgToSend);
MimeMessage parsed = sendForwardedMessage(req, msg);
ZMimeMultipart mmp = (ZMimeMultipart) parsed.getContent();
assertEquals("test1", mmp.getBodyPart(0).getHeader("Content-Transfer-Encoding")[0]);
assertEquals("test2", mmp.getBodyPart(1).getHeader("Content-Transfer-Encoding")[0]);
}
use of javax.mail.util.SharedByteArrayInputStream in project zm-mailbox by Zimbra.
the class FixedMimeMessageTest method contentTransferEncoding.
@Test
public void contentTransferEncoding() throws Exception {
String raw = "From: sender@zimbra.com\n" + "To: recipient@zimbra.com\n" + "Subject: test\n" + "Content-Type: text/plain; charset=ISO-2022-JP\n" + "\n" + "あああいいいうううえええおおお";
MimeMessage message = new FixedMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(raw.getBytes(Charsets.UTF_8)));
Assert.assertNull(message.getEncoding());
message.setHeader("X-TEST", "test");
message.saveChanges();
// Assert.assertNull(message.getEncoding());
message = new FixedMimeMessage(JMSession.getSession());
message.setHeader("X-TEST", "test");
message.setText("あああいいいうううえええおおお", "ISO-2022-JP");
message.saveChanges();
Assert.assertEquals("7bit", message.getEncoding());
message = new FixedMimeMessage(JMSession.getSession());
message.setHeader("X-TEST", "test");
message.setText("あああいいいうううえええおおお", "UTF-8");
message.saveChanges();
Assert.assertEquals("8bit", message.getEncoding());
}
use of javax.mail.util.SharedByteArrayInputStream in project zm-mailbox by Zimbra.
the class MimeTest method textCid.
@Test
public void textCid() throws Exception {
String content = baseMpMixedContent + "------------1111971890AC3BB91\r\n" + "Content-Type: text/html; charset=windows-1250\r\n" + "Content-Transfer-Encoding: quoted-printable\r\n" + //barely valid, but we shouldn't break if a bad agent sends like this
"Content-ID: <text_testemail>\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 fileAsStream.
private void fileAsStream(String extension, boolean expectText) throws MessagingException, IOException {
if (extension.charAt(0) == '.') {
extension = extension.substring(1);
}
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." + extension + "\"\r\n" + "Content-Transfer-Encoding: base64\r\n\r\n" + //obviously not a real file
"R0a1231312ad124svsdsal==";
MimeMessage mm = new Mime.FixedMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(content.getBytes()));
MimePart part = Mime.getMimePart(mm, "1");
String expectedType = expectText ? "text/plain" : "application/octet-stream";
Assert.assertEquals(expectedType, Mime.getContentType(part.getContentType()));
}
use of javax.mail.util.SharedByteArrayInputStream in project zm-mailbox by Zimbra.
the class MimeTest method multiTextBody.
@Test
public void multiTextBody() throws Exception {
StringBuilder content = new StringBuilder(baseMpMixedContent);
int count = 42;
for (int i = 0; i < count; i++) {
content.append("------------1111971890AC3BB91\r\n").append("Content-Type: text/html; charset=windows-1250\r\n").append("Content-Transfer-Encoding: quoted-printable\r\n\r\n").append("<html>Body ").append(i).append("</html>\r\n");
}
MimeMessage mm = new Mime.FixedMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(content.toString().getBytes()));
List<MPartInfo> parts = Mime.getParts(mm);
Assert.assertNotNull(parts);
Assert.assertEquals(count + 1, parts.size());
MPartInfo mpart = parts.get(0);
Assert.assertEquals("multipart/mixed", mpart.getContentType());
List<MPartInfo> children = mpart.getChildren();
Assert.assertEquals(count, children.size());
Set<MPartInfo> bodies = Mime.getBody(parts, false);
Assert.assertEquals(count, bodies.size());
for (MPartInfo body : bodies) {
Assert.assertEquals("text/html", body.getContentType());
Object mimeContent = body.getMimePart().getContent();
Assert.assertTrue(mimeContent instanceof String);
String string = (String) mimeContent;
int idx = string.indexOf("" + (body.getPartNum() - 1));
//body 0 is part 1, b1 is p2, and so on
Assert.assertTrue(idx > 0);
}
}
Aggregations