Search in sources :

Example 1 with MsgToSend

use of com.zimbra.soap.mail.type.MsgToSend in project zm-mailbox by Zimbra.

the class TestContentTransferEncoding method testBug98015.

/*
     * Tests that the message from bug 98015 retains the correct Content Transfer Encoding via the mechanism of
     * inferring it from the existing message referenced by the "origid" parameter.
     * This scenario also happens to test the case when a CTE header on a sub-part is inherited from the top-level.
     */
@Ignore("disabled until bug 98015 is fixed")
@Test
public void testBug98015() throws Exception {
    MimeMessage mimeMsg = new ZMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(getBug98015MimeString().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: QP bug");
    msgToSend.setMimePart(MimePartInfo.createForContentTypeAndContent("text/plain", "\n\n----- Forwarded Message -----\nSubject: QP Bug\n\n\\รถ/\nid=577281"));
    AttachmentsInfo attach = new AttachmentsInfo();
    attach.addAttachment(new MimePartAttachSpec(String.valueOf(msg.getId()), "2"));
    msgToSend.setAttachments(attach);
    SendMsgRequest req = new SendMsgRequest();
    req.setMsg(msgToSend);
    MimeMessage parsed = sendForwardedMessage(req, msg);
    ZMimeMultipart mmp = (ZMimeMultipart) parsed.getContent();
    assertEquals("8bit", mmp.getBodyPart(0).getHeader("Content-Transfer-Encoding")[0]);
    assertEquals("base64", mmp.getBodyPart(1).getHeader("Content-Transfer-Encoding")[0]);
}
Also used : AttachmentsInfo(com.zimbra.soap.mail.type.AttachmentsInfo) ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) Message(com.zimbra.cs.mailbox.Message) MimeMessage(javax.mail.internet.MimeMessage) ParseMimeMessage(com.zimbra.cs.service.mail.ParseMimeMessage) ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) MimeMessage(javax.mail.internet.MimeMessage) ParseMimeMessage(com.zimbra.cs.service.mail.ParseMimeMessage) ZMimeMultipart(com.zimbra.common.zmime.ZMimeMultipart) MsgToSend(com.zimbra.soap.mail.type.MsgToSend) SendMsgRequest(com.zimbra.soap.mail.message.SendMsgRequest) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) SharedByteArrayInputStream(javax.mail.util.SharedByteArrayInputStream) MimePartAttachSpec(com.zimbra.soap.mail.type.MimePartAttachSpec) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 2 with MsgToSend

use of com.zimbra.soap.mail.type.MsgToSend 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]);
}
Also used : ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) Message(com.zimbra.cs.mailbox.Message) MimeMessage(javax.mail.internet.MimeMessage) ParseMimeMessage(com.zimbra.cs.service.mail.ParseMimeMessage) SendMsgRequest(com.zimbra.soap.mail.message.SendMsgRequest) LinkedList(java.util.LinkedList) SharedByteArrayInputStream(javax.mail.util.SharedByteArrayInputStream) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) MimeMessage(javax.mail.internet.MimeMessage) ParseMimeMessage(com.zimbra.cs.service.mail.ParseMimeMessage) ZMimeMultipart(com.zimbra.common.zmime.ZMimeMultipart) MsgToSend(com.zimbra.soap.mail.type.MsgToSend) MimePartInfo(com.zimbra.soap.mail.type.MimePartInfo) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 3 with MsgToSend

use of com.zimbra.soap.mail.type.MsgToSend in project zm-mailbox by Zimbra.

the class SendMsgRequestTest method marshal.

@Test
public void marshal() throws Exception {
    SendMsgRequest req = new SendMsgRequest();
    MsgToSend msg = new MsgToSend();
    msg.setHeaders(ImmutableList.of(new Msg.Header("name1", "value1"), new Msg.Header("name2", "value2")));
    req.setMsg(msg);
    Element jaxbElem = JaxbUtil.jaxbToElement(req);
    logInfo("XML Element from JAXB:" + jaxbElem.toString());
    Assert.assertEquals("SendMsgRequest elem name", MailConstants.E_SEND_MSG_REQUEST, jaxbElem.getName());
    Assert.assertEquals("SendMsgRequest elem ns", MailConstants.NAMESPACE_STR, jaxbElem.getQName().getNamespaceURI());
    List<Element> hdrs = jaxbElem.getElement(MailConstants.E_MSG).listElements(MailConstants.E_HEADER);
    Assert.assertEquals("SendMsgRequest header 1 name", "name1", hdrs.get(0).getAttribute("name"));
    Assert.assertEquals("SendMsgRequest header 2 name", "name2", hdrs.get(1).getAttribute("name"));
    Assert.assertEquals("SendMsgRequest header 1 value", "value1", hdrs.get(0).getText());
    Assert.assertEquals("SendMsgRequest header 2 value", "value2", hdrs.get(1).getText());
}
Also used : Element(com.zimbra.common.soap.Element) SendMsgRequest(com.zimbra.soap.mail.message.SendMsgRequest) MsgToSend(com.zimbra.soap.mail.type.MsgToSend) Test(org.junit.Test)

Example 4 with MsgToSend

use of com.zimbra.soap.mail.type.MsgToSend in project zm-mailbox by Zimbra.

the class TestContentTransferEncoding method testSimpleMimeMessage.

/*
     * This tests the CTE header of a forwarded message being inferred from the existing message when the message is a simple MIME message
     */
@Ignore("disabled until bug 98015 is fixed")
@Test
public void testSimpleMimeMessage() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    MimeMessage mimeMsg = new ZMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(getSimpleMimeString().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: Simple Test");
    msgToSend.setMimePart(MimePartInfo.createForContentTypeAndContent("text/plain", "simple test"));
    SendMsgRequest req = new SendMsgRequest();
    req.setMsg(msgToSend);
    MimeMessage parsed = sendForwardedMessage(req, msg);
    assertEquals("test", parsed.getHeader("Content-Transfer-Encoding")[0]);
}
Also used : ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) Message(com.zimbra.cs.mailbox.Message) MimeMessage(javax.mail.internet.MimeMessage) ParseMimeMessage(com.zimbra.cs.service.mail.ParseMimeMessage) ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) MimeMessage(javax.mail.internet.MimeMessage) ParseMimeMessage(com.zimbra.cs.service.mail.ParseMimeMessage) MsgToSend(com.zimbra.soap.mail.type.MsgToSend) SendMsgRequest(com.zimbra.soap.mail.message.SendMsgRequest) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) SharedByteArrayInputStream(javax.mail.util.SharedByteArrayInputStream) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with MsgToSend

use of com.zimbra.soap.mail.type.MsgToSend 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");
    }
}
Also used : ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) Message(com.zimbra.cs.mailbox.Message) MimeMessage(javax.mail.internet.MimeMessage) ParseMimeMessage(com.zimbra.cs.service.mail.ParseMimeMessage) SendMsgRequest(com.zimbra.soap.mail.message.SendMsgRequest) LinkedList(java.util.LinkedList) SharedByteArrayInputStream(javax.mail.util.SharedByteArrayInputStream) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZMimeMessage(com.zimbra.common.zmime.ZMimeMessage) MimeMessage(javax.mail.internet.MimeMessage) ParseMimeMessage(com.zimbra.cs.service.mail.ParseMimeMessage) MsgToSend(com.zimbra.soap.mail.type.MsgToSend) MimePartInfo(com.zimbra.soap.mail.type.MimePartInfo) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) Test(org.junit.Test)

Aggregations

SendMsgRequest (com.zimbra.soap.mail.message.SendMsgRequest)6 MsgToSend (com.zimbra.soap.mail.type.MsgToSend)6 Test (org.junit.Test)5 ZMimeMessage (com.zimbra.common.zmime.ZMimeMessage)4 DeliveryOptions (com.zimbra.cs.mailbox.DeliveryOptions)4 Message (com.zimbra.cs.mailbox.Message)4 ParseMimeMessage (com.zimbra.cs.service.mail.ParseMimeMessage)4 MimeMessage (javax.mail.internet.MimeMessage)4 SharedByteArrayInputStream (javax.mail.util.SharedByteArrayInputStream)4 Mailbox (com.zimbra.cs.mailbox.Mailbox)3 MimePartInfo (com.zimbra.soap.mail.type.MimePartInfo)3 Ignore (org.junit.Ignore)3 ZMimeMultipart (com.zimbra.common.zmime.ZMimeMultipart)2 LinkedList (java.util.LinkedList)2 Element (com.zimbra.common.soap.Element)1 SoapTransport (com.zimbra.common.soap.SoapTransport)1 SendMsgResponse (com.zimbra.soap.mail.message.SendMsgResponse)1 AttachmentsInfo (com.zimbra.soap.mail.type.AttachmentsInfo)1 EmailAddrInfo (com.zimbra.soap.mail.type.EmailAddrInfo)1 MimePartAttachSpec (com.zimbra.soap.mail.type.MimePartAttachSpec)1