Search in sources :

Example 16 with DeliveryOptions

use of com.zimbra.cs.mailbox.DeliveryOptions 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 17 with DeliveryOptions

use of com.zimbra.cs.mailbox.DeliveryOptions in project zm-mailbox by Zimbra.

the class GetMsgTest method testMsgHeaderN.

@Test
public void testMsgHeaderN() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    MimeMessage message = new JavaMailMimeMessage(JMSession.getSession(), new ZSharedFileInputStream("data/unittest/email/bug_75163.txt"));
    ParsedMessage pm = new ParsedMessage(message, false);
    DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX);
    Message msg = mbox.addMessage(null, pm, dopt, null);
    Element request = new Element.XMLElement(MailConstants.GET_MSG_REQUEST);
    Element action = request.addElement(MailConstants.E_MSG);
    action.addAttribute(MailConstants.A_ID, msg.getId());
    action.addElement(MailConstants.A_HEADER).addAttribute(MailConstants.A_ATTRIBUTE_NAME, "Return-Path");
    Element response = new GetMsg().handle(request, ServiceTestUtil.getRequestContext(mbox.getAccount())).getElement(MailConstants.E_MSG);
    List<Element> headerN = response.listElements(MailConstants.A_HEADER);
    for (Element elt : headerN) {
        Assert.assertEquals(elt.getText(), "foo@example.com");
    }
}
Also used : ZSharedFileInputStream(com.zimbra.common.zmime.ZSharedFileInputStream) Mailbox(com.zimbra.cs.mailbox.Mailbox) MimeMessage(javax.mail.internet.MimeMessage) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) JavaMailMimeMessage(com.zimbra.common.mime.shim.JavaMailMimeMessage) MimeMessage(javax.mail.internet.MimeMessage) JavaMailMimeMessage(com.zimbra.common.mime.shim.JavaMailMimeMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) GetMsg(com.zimbra.cs.service.mail.GetMsg) Element(com.zimbra.common.soap.Element) JavaMailMimeMessage(com.zimbra.common.mime.shim.JavaMailMimeMessage) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) Test(org.junit.Test)

Example 18 with DeliveryOptions

use of com.zimbra.cs.mailbox.DeliveryOptions in project zm-mailbox by Zimbra.

the class GetMsgTest method testMsgMaxAttr.

@Test
public void testMsgMaxAttr() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    MimeMessage message = new JavaMailMimeMessage(JMSession.getSession(), new ZSharedFileInputStream("data/TestMailRaw/1"));
    ParsedMessage pm = new ParsedMessage(message, false);
    DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX);
    Message msg = mbox.addMessage(null, pm, dopt, null);
    Element request = new Element.XMLElement(MailConstants.GET_MSG_REQUEST);
    Element action = request.addElement(MailConstants.E_MSG);
    action.addAttribute(MailConstants.A_ID, msg.getId());
    action.addAttribute(MailConstants.A_MAX_INLINED_LENGTH, 10);
    Element response = new GetMsg().handle(request, ServiceTestUtil.getRequestContext(mbox.getAccount())).getElement(MailConstants.E_MSG);
    Assert.assertEquals(response.getElement(MailConstants.E_MIMEPART).getElement(MailConstants.E_CONTENT).getText().length(), 10);
}
Also used : ZSharedFileInputStream(com.zimbra.common.zmime.ZSharedFileInputStream) Mailbox(com.zimbra.cs.mailbox.Mailbox) MimeMessage(javax.mail.internet.MimeMessage) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) JavaMailMimeMessage(com.zimbra.common.mime.shim.JavaMailMimeMessage) MimeMessage(javax.mail.internet.MimeMessage) JavaMailMimeMessage(com.zimbra.common.mime.shim.JavaMailMimeMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) GetMsg(com.zimbra.cs.service.mail.GetMsg) Element(com.zimbra.common.soap.Element) JavaMailMimeMessage(com.zimbra.common.mime.shim.JavaMailMimeMessage) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) Test(org.junit.Test)

Example 19 with DeliveryOptions

use of com.zimbra.cs.mailbox.DeliveryOptions in project zm-mailbox by Zimbra.

the class ItemActionTest method deleteIncompleteConversation.

@Test
public void deleteIncompleteConversation() throws Exception {
    Account acct = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
    acct.setMailThreadingAlgorithm(MailThreadingAlgorithm.subject);
    // setup: add the root message
    ParsedMessage pm = MailboxTestUtil.generateMessage("test subject");
    DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX);
    int rootId = mbox.addMessage(null, pm, dopt, null).getId();
    // add additional messages
    pm = MailboxTestUtil.generateMessage("Re: test subject");
    Message draft = mbox.saveDraft(null, pm, Mailbox.ID_AUTO_INCREMENT, rootId + "", MailSender.MSGTYPE_REPLY, null, null, 0);
    Message parent = mbox.getMessageById(null, rootId);
    Assert.assertEquals(parent.getConversationId(), draft.getConversationId());
    pm = MailboxTestUtil.generateMessage("Re: test subject");
    Message draft2 = mbox.saveDraft(null, pm, Mailbox.ID_AUTO_INCREMENT);
    parent = mbox.getMessageById(null, rootId);
    Assert.assertEquals(parent.getConversationId(), draft2.getConversationId());
    MailItem.TargetConstraint tcon = new MailItem.TargetConstraint(mbox, MailItem.TargetConstraint.INCLUDE_TRASH);
    ItemId iid = new ItemId(mbox, Mailbox.ID_FOLDER_TRASH);
    // trash one message in conversation
    ItemActionHelper.MOVE(null, mbox, SoapProtocol.Soap12, Collections.singletonList(draft.getId()), MailItem.Type.MESSAGE, tcon, iid);
    draft = mbox.getMessageById(null, draft.getId());
    Assert.assertEquals(draft.getFolderId(), Mailbox.ID_FOLDER_TRASH);
    ItemActionHelper.HARD_DELETE(null, mbox, SoapProtocol.Soap12, Collections.singletonList(draft.getConversationId()), MailItem.Type.CONVERSATION, tcon);
    // the messages not in the trash should still exist and attached to the same conversation
    parent = mbox.getMessageById(null, rootId);
    Message m = mbox.getMessageById(null, draft2.getId());
    Assert.assertEquals(parent.getConversationId(), m.getConversationId());
}
Also used : Account(com.zimbra.cs.account.Account) MailItem(com.zimbra.cs.mailbox.MailItem) Mailbox(com.zimbra.cs.mailbox.Mailbox) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) ItemId(com.zimbra.cs.service.util.ItemId) Test(org.junit.Test)

Example 20 with DeliveryOptions

use of com.zimbra.cs.mailbox.DeliveryOptions in project zm-mailbox by Zimbra.

the class ItemActionTest method deleteConversation.

@Test
public void deleteConversation() throws Exception {
    Account acct = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
    acct.setMailThreadingAlgorithm(MailThreadingAlgorithm.subject);
    // setup: add the root message
    ParsedMessage pm = MailboxTestUtil.generateMessage("test subject");
    DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX);
    int rootId = mbox.addMessage(null, pm, dopt, null).getId();
    // add additional messages
    pm = MailboxTestUtil.generateMessage("Re: test subject");
    Message draft = mbox.saveDraft(null, pm, Mailbox.ID_AUTO_INCREMENT, rootId + "", MailSender.MSGTYPE_REPLY, null, null, 0);
    Message parent = mbox.getMessageById(null, rootId);
    Assert.assertEquals(parent.getConversationId(), draft.getConversationId());
    pm = MailboxTestUtil.generateMessage("Re: test subject");
    Message draft2 = mbox.saveDraft(null, pm, Mailbox.ID_AUTO_INCREMENT);
    parent = mbox.getMessageById(null, rootId);
    Assert.assertEquals(parent.getConversationId(), draft2.getConversationId());
    MailItem.TargetConstraint tcon = new MailItem.TargetConstraint(mbox, MailItem.TargetConstraint.INCLUDE_TRASH);
    ItemId iid = new ItemId(mbox, Mailbox.ID_FOLDER_TRASH);
    // trash the conversation
    ItemActionHelper.MOVE(null, mbox, SoapProtocol.Soap12, Arrays.asList(parent.getId(), draft.getId(), draft2.getId()), MailItem.Type.MESSAGE, tcon, iid);
    parent = mbox.getMessageById(null, parent.getId());
    draft = mbox.getMessageById(null, draft.getId());
    draft2 = mbox.getMessageById(null, draft2.getId());
    Assert.assertEquals(parent.getFolderId(), Mailbox.ID_FOLDER_TRASH);
    Assert.assertEquals(draft.getFolderId(), Mailbox.ID_FOLDER_TRASH);
    Assert.assertEquals(draft2.getFolderId(), Mailbox.ID_FOLDER_TRASH);
    ItemActionHelper.HARD_DELETE(null, mbox, SoapProtocol.Soap12, Collections.singletonList(parent.getConversationId()), MailItem.Type.CONVERSATION, tcon);
    Exception ex = null;
    try {
        mbox.getMessageById(null, parent.getId());
    } catch (Exception e) {
        ex = e;
        Assert.assertTrue(e instanceof NoSuchItemException);
    }
    Assert.assertNotNull(ex);
    ex = null;
    try {
        mbox.getMessageById(null, draft.getId());
    } catch (Exception e) {
        ex = e;
        Assert.assertTrue(e instanceof NoSuchItemException);
    }
    Assert.assertNotNull(ex);
    ex = null;
    try {
        mbox.getMessageById(null, draft2.getId());
    } catch (Exception e) {
        ex = e;
        Assert.assertTrue(e instanceof NoSuchItemException);
    }
    Assert.assertNotNull(ex);
    ex = null;
    try {
        mbox.getConversationById(null, draft2.getConversationId());
    } catch (Exception e) {
        ex = e;
        Assert.assertTrue(e instanceof NoSuchItemException);
    }
    Assert.assertNotNull(ex);
}
Also used : Account(com.zimbra.cs.account.Account) MailItem(com.zimbra.cs.mailbox.MailItem) Mailbox(com.zimbra.cs.mailbox.Mailbox) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) ItemId(com.zimbra.cs.service.util.ItemId) NoSuchItemException(com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException) NoSuchItemException(com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException) Test(org.junit.Test)

Aggregations

DeliveryOptions (com.zimbra.cs.mailbox.DeliveryOptions)59 Mailbox (com.zimbra.cs.mailbox.Mailbox)50 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)46 Message (com.zimbra.cs.mailbox.Message)45 Test (org.junit.Test)44 Account (com.zimbra.cs.account.Account)18 OperationContext (com.zimbra.cs.mailbox.OperationContext)14 MimeMessage (javax.mail.internet.MimeMessage)12 ItemId (com.zimbra.cs.service.util.ItemId)11 Volume (com.zimbra.cs.volume.Volume)11 ServiceException (com.zimbra.common.service.ServiceException)10 Element (com.zimbra.common.soap.Element)9 IOException (java.io.IOException)9 Folder (com.zimbra.cs.mailbox.Folder)7 BlobReference (com.zimbra.cs.store.file.BlobReference)7 DeliveryContext (com.zimbra.cs.mailbox.DeliveryContext)6 ZMimeMessage (com.zimbra.common.zmime.ZMimeMessage)5 MailItem (com.zimbra.cs.mailbox.MailItem)5 MailboxBlobInfo (com.zimbra.cs.store.MailboxBlob.MailboxBlobInfo)5 BlobConsistencyChecker (com.zimbra.cs.store.file.BlobConsistencyChecker)5