use of javax.mail.internet.MimeMultipart in project zm-mailbox by Zimbra.
the class ZMimeParserTest method parse.
@Test
public void parse() throws Exception {
ByteBuilder bb = new ByteBuilder(CharsetUtil.UTF_8);
bb.append("Content-Type: text/plain\r\n");
bb.append("From: <foo@example.com\r\n");
bb.append("Subject: sample\r\n");
bb.append("Content-Type: multipart/alternative; boundary=").append(BOUNDARY1).append("\r\n");
bb.append("\r\n");
bb.append("--").append(BOUNDARY1).append("\r\n");
bb.append("Content-Type: text/plain\r\n");
bb.append("\r\n");
bb.append("foo! bar! loud noises\r\n\r\n");
bb.append("--").append(BOUNDARY1).append("--\r\n");
try {
MimeMessage mm = ZMimeParser.parse(getSession(), new SharedByteArrayInputStream(bb.toByteArray()));
Assert.assertFalse("content isn't multipart", mm.getContent() instanceof MimeMultipart);
Assert.assertEquals("text/plain", "text/plain", new ZContentType(mm.getContentType()).getBaseType());
} catch (ClassCastException e) {
Assert.fail("mishandled double Content-Type headers");
}
}
use of javax.mail.internet.MimeMultipart in project zm-mailbox by Zimbra.
the class ExtShareInfoTest method testGenNotifyBody.
@Test
public void testGenNotifyBody() {
Locale locale = new Locale("en", "US");
String notes = "none";
ShareInfoData sid = new ShareInfoData();
sid.setGranteeDisplayName("Demo User Three");
sid.setGranteeId(testAcct.getId());
sid.setGranteeName(testAcct.getName());
sid.setGranteeType(ACL.GRANTEE_GUEST);
sid.setPath("/Inbox/Test");
sid.setFolderDefaultView(MailItem.Type.MESSAGE);
sid.setItemUuid("9badf685-3420-458b-9ce5-826b0bec638f");
sid.setItemId(257);
sid.setOwnerAcctId(ownerAcct.getId());
sid.setOwnerAcctEmail(ownerAcct.getName());
sid.setOwnerAcctDisplayName("Demo User Two");
try {
sid.setRights(ACL.stringToRights("rwidxap"));
MimeMultipart mmp = ShareInfo.NotificationSender.genNotifBody(sid, notes, locale, null, null);
Assert.assertNotNull(mmp);
String body = (String) mmp.getBodyPart(0).getDataHandler().getContent();
int index = body.indexOf("http");
int endIndex = body.indexOf(".", index);
String authUrl = body.substring(index, endIndex);
index = authUrl.indexOf("p=");
String authToken = authUrl.substring(index + 2);
try {
ZimbraAuthToken.getAuthToken(authToken);
fail("Authtoken should fail");
} catch (AuthTokenException e) {
assertTrue(e.getMessage().contains("hmac failure"));
}
// Commenting for now, need to figure out why it fails on hudson
// try {
// ExternalUserProvServlet.validatePrelimToken(authToken);
// } catch (Exception e) {
// fail("Should not throw Exception" + e.getMessage());
// }
} catch (ServiceException | MessagingException | IOException e) {
fail("Exception should not be thrown: " + e.getMessage());
}
}
use of javax.mail.internet.MimeMultipart in project zm-mailbox by Zimbra.
the class ShareInfoTest method testGenNotifyBody.
@Test
public void testGenNotifyBody() {
Locale locale = new Locale("en", "US");
String notes = "none";
ShareInfoData sid = new ShareInfoData();
sid.setGranteeDisplayName("Demo User Three");
sid.setGranteeId("46031e4c-deb4-4724-b5bb-8f854d0c518a");
sid.setGranteeName("Demo User Three");
sid.setGranteeType(ACL.GRANTEE_USER);
sid.setPath("/Calendar/Cal1");
sid.setFolderDefaultView(MailItem.Type.APPOINTMENT);
sid.setItemUuid("9badf685-3420-458b-9ce5-826b0bec638f");
sid.setItemId(257);
sid.setOwnerAcctId("bbf152ca-e7cd-477e-9f72-70fef715c5f9");
sid.setOwnerAcctEmail("test@zimbra.com");
sid.setOwnerAcctDisplayName("Demo User Two");
try {
sid.setRights(ACL.stringToRights("rwidxap"));
MimeMultipart mmp = ShareInfo.NotificationSender.genNotifBody(sid, notes, locale, null, null);
Assert.assertNotNull(mmp);
String body = (String) mmp.getBodyPart(0).getDataHandler().getContent();
assertTrue(body.indexOf("Role: Admin") != -1);
} catch (ServiceException | MessagingException | IOException e) {
fail("Exception should not be thrown: " + e.getMessage());
}
}
use of javax.mail.internet.MimeMultipart in project zm-mailbox by Zimbra.
the class MailboxTestUtil method generateMessageWithAttachment.
public static ParsedMessage generateMessageWithAttachment(String subject) throws Exception {
MimeMessage mm = new Mime.FixedMimeMessage(JMSession.getSession());
mm.setHeader("From", "Vera Oliphant <oli@example.com>");
mm.setHeader("To", "Jimmy Dean <jdean@example.com>");
mm.setHeader("Subject", subject);
mm.setText("Good as gold");
MimeMultipart multi = new ZMimeMultipart("mixed");
ContentDisposition cdisp = new ContentDisposition(Part.ATTACHMENT);
cdisp.setParameter("filename", "fun.txt");
ZMimeBodyPart bp = new ZMimeBodyPart();
// it gets called before setting Content-Type and CTE headers.
try {
bp.setDataHandler(new DataHandler(new ByteArrayDataSource("Feeling attached.", "text/plain")));
} catch (IOException e) {
throw new MessagingException("could not generate mime part content", e);
}
bp.addHeader("Content-Disposition", cdisp.toString());
bp.addHeader("Content-Type", "text/plain");
bp.addHeader("Content-Transfer-Encoding", MimeConstants.ET_8BIT);
multi.addBodyPart(bp);
mm.setContent(multi);
mm.saveChanges();
return new ParsedMessage(mm, false);
}
use of javax.mail.internet.MimeMultipart in project zm-mailbox by Zimbra.
the class ParseMimeMessageTest method attachZimbraDocument.
@Test
public void attachZimbraDocument() throws Exception {
Account acct = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
OperationContext octxt = new OperationContext(acct);
Document doc = mbox.createDocument(octxt, Mailbox.ID_FOLDER_BRIEFCASE, "testdoc", MimeConstants.CT_APPLICATION_ZIMBRA_DOC, "author", "description", new ByteArrayInputStream("test123".getBytes()));
Element el = new Element.JSONElement(MailConstants.E_MSG);
el.addAttribute(MailConstants.E_SUBJECT, "attach message");
el.addElement(MailConstants.E_EMAIL).addAttribute(MailConstants.A_ADDRESS_TYPE, EmailType.TO.toString()).addAttribute(MailConstants.A_ADDRESS, "rcpt@zimbra.com");
el.addElement(MailConstants.E_MIMEPART).addAttribute(MailConstants.A_CONTENT_TYPE, "text/plain").addAttribute(MailConstants.E_CONTENT, "This is the content.");
el.addElement(MailConstants.E_ATTACH).addElement(MailConstants.E_DOC).addAttribute(MailConstants.A_ID, doc.getId());
ZimbraSoapContext zsc = getMockSoapContext();
MimeMessage mm = ParseMimeMessage.parseMimeMsgSoap(zsc, octxt, null, el, null, new ParseMimeMessage.MimeMessageData());
MimeMultipart mmp = (MimeMultipart) mm.getContent();
MimeBodyPart part = (MimeBodyPart) mmp.getBodyPart(1);
Assert.assertEquals(MimeConstants.CT_TEXT_HTML, new ContentType(part.getContentType()).getContentType());
}
Aggregations