Search in sources :

Example 6 with MessagePart

use of com.zimbra.client.ZMailbox.ZOutgoingMessage.MessagePart in project zm-mailbox by Zimbra.

the class TestSendAndReceive method testInlineAttachment.

/**
     * Test inline attachment. See bug #88933
     */
@Test
public void testInlineAttachment() throws Exception {
    TestUtil.createAccount(USER_NAME);
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    //create inline image attachment
    String imgName = "synacore.jpg";
    String content = "<content><img src=\"cid:" + imgName + "\"></content>";
    List<AttachedMessagePart> inlineAttachments = new ArrayList<AttachedMessagePart>();
    String attachId = mbox.uploadAttachment(imgName, new byte[1024], MimeConstants.CT_IMAGE_JPEG, 5000);
    AttachedMessagePart inlineImg = new AttachedMessagePart(attachId, imgName);
    inlineAttachments.add(inlineImg);
    MessagePart html = new MessagePart(MimeConstants.CT_TEXT_HTML, content, inlineAttachments);
    //create outgoing message
    String subject = NAME_PREFIX + " testInlineAttachment " + MimeConstants.CT_TEXT_PLAIN + " 1";
    ZOutgoingMessage outgoingMsg = new ZOutgoingMessage();
    List<ZEmailAddress> addresses = new ArrayList<ZEmailAddress>();
    addresses.add(new ZEmailAddress(TestUtil.addDomainIfNecessary(USER_NAME), null, null, ZEmailAddress.EMAIL_TYPE_TO));
    outgoingMsg.setAddresses(addresses);
    outgoingMsg.setSubject(subject);
    MessagePart related = new MessagePart(MimeConstants.CT_MULTIPART_RELATED, html);
    outgoingMsg.setMessagePart(related);
    mbox.sendMessage(outgoingMsg, null, false);
    //verify that received message has the attachment
    ZMessage incoming = TestUtil.waitForMessage(mbox, "in:inbox subject:\"" + subject + "\"");
    Assert.assertTrue("this message should have an attachment", incoming.hasAttachment());
    Assert.assertNotNull("this message should have mime parts", incoming.getMimeStructure());
    Assert.assertNotNull("this message should have two subparts", incoming.getMimeStructure().getChildren());
    List<ZMimePart> parts = incoming.getMimeStructure().getChildren();
    Assert.assertEquals("this message should have 2 subparts", 2, parts.size());
    Assert.assertTrue("one of the parts should have a content id", parts.get(0).getContentId() != null || parts.get(1).getContentId() != null);
    Assert.assertTrue("one of the parts should be " + imgName, imgName.equalsIgnoreCase(parts.get(0).getFileName()) || imgName.equalsIgnoreCase(parts.get(1).getFileName()));
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZOutgoingMessage(com.zimbra.client.ZMailbox.ZOutgoingMessage) ZMailbox(com.zimbra.client.ZMailbox) AttachedMessagePart(com.zimbra.client.ZMailbox.ZOutgoingMessage.AttachedMessagePart) ZEmailAddress(com.zimbra.client.ZEmailAddress) MessagePart(com.zimbra.client.ZMailbox.ZOutgoingMessage.MessagePart) AttachedMessagePart(com.zimbra.client.ZMailbox.ZOutgoingMessage.AttachedMessagePart) ArrayList(java.util.ArrayList) ZMimePart(com.zimbra.client.ZMessage.ZMimePart) Test(org.junit.Test)

Example 7 with MessagePart

use of com.zimbra.client.ZMailbox.ZOutgoingMessage.MessagePart in project zm-mailbox by Zimbra.

the class TestLmtp method testAttachedMessage.

/**
     * Sends a message with another message attached and confirms that the subject
     * of the attached message is indexed.
     * @see MessageRFC822Handler
     */
@Test
public void testAttachedMessage() throws Exception {
    String outerSubject = NAME_PREFIX + " testAttachedMessage outer";
    String innerSubject = NAME_PREFIX + " testAttachedMessage inner";
    ZMailbox mbox = TestUtil.getZMailbox(USER_NAME);
    // Assemble outer message
    ZOutgoingMessage msg = new ZOutgoingMessage();
    List<ZEmailAddress> addresses = new ArrayList<ZEmailAddress>();
    addresses.add(new ZEmailAddress(TestUtil.getAddress(USER_NAME), null, null, ZEmailAddress.EMAIL_TYPE_TO));
    msg.setAddresses(addresses);
    msg.setSubject(outerSubject);
    // Assemble body and inner message
    String attachedMessageString = TestUtil.getTestMessage(innerSubject, USER_NAME, USER_NAME, null);
    MessagePart attachedMessage = new MessagePart("message/rfc822", attachedMessageString);
    MessagePart body = new MessagePart("text/plain", "This is the outer message");
    msg.setMessagePart(new MessagePart("multipart/mixed", body, attachedMessage));
    // Send and wait for it to arrive
    mbox.sendMessage(msg, null, false);
    TestUtil.waitForMessage(mbox, "in:inbox " + outerSubject);
    // Test search for message subject
    List<ZMessage> msgs = TestUtil.search(mbox, "in:inbox " + innerSubject);
    Assert.assertEquals(1, msgs.size());
    msgs = TestUtil.search(mbox, "in:sent " + innerSubject);
    Assert.assertEquals(1, msgs.size());
    // Test search for message body
    msgs = TestUtil.search(mbox, "in:inbox " + NAME_PREFIX + " waves");
    Assert.assertEquals(1, msgs.size());
    msgs = TestUtil.search(mbox, "in:sent " + NAME_PREFIX + " waves");
    Assert.assertEquals(1, msgs.size());
}
Also used : ZMessage(com.zimbra.client.ZMessage) ZOutgoingMessage(com.zimbra.client.ZMailbox.ZOutgoingMessage) ZMailbox(com.zimbra.client.ZMailbox) ZEmailAddress(com.zimbra.client.ZEmailAddress) MessagePart(com.zimbra.client.ZMailbox.ZOutgoingMessage.MessagePart) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 8 with MessagePart

use of com.zimbra.client.ZMailbox.ZOutgoingMessage.MessagePart in project zm-mailbox by Zimbra.

the class TestUtil method getOutgoingMessage.

public static ZOutgoingMessage getOutgoingMessage(String recipient, String subject, String body, String attachmentUploadId) throws ServiceException {
    ZOutgoingMessage msg = new ZOutgoingMessage();
    List<ZEmailAddress> addresses = new ArrayList<ZEmailAddress>();
    addresses.add(new ZEmailAddress(addDomainIfNecessary(recipient), null, null, ZEmailAddress.EMAIL_TYPE_TO));
    msg.setAddresses(addresses);
    msg.setSubject(subject);
    msg.setMessagePart(new MessagePart("text/plain", body));
    msg.setAttachmentUploadId(attachmentUploadId);
    return msg;
}
Also used : ZOutgoingMessage(com.zimbra.client.ZMailbox.ZOutgoingMessage) ZEmailAddress(com.zimbra.client.ZEmailAddress) AttachedMessagePart(com.zimbra.client.ZMailbox.ZOutgoingMessage.AttachedMessagePart) MessagePart(com.zimbra.client.ZMailbox.ZOutgoingMessage.MessagePart) ArrayList(java.util.ArrayList)

Aggregations

ZEmailAddress (com.zimbra.client.ZEmailAddress)8 ZOutgoingMessage (com.zimbra.client.ZMailbox.ZOutgoingMessage)8 MessagePart (com.zimbra.client.ZMailbox.ZOutgoingMessage.MessagePart)8 ZMessage (com.zimbra.client.ZMessage)7 ArrayList (java.util.ArrayList)7 Test (org.junit.Test)6 ZMailbox (com.zimbra.client.ZMailbox)4 AttachedMessagePart (com.zimbra.client.ZMailbox.ZOutgoingMessage.AttachedMessagePart)3 ZMimePart (com.zimbra.client.ZMessage.ZMimePart)2 BufferedReader (java.io.BufferedReader)1 StringReader (java.io.StringReader)1