Search in sources :

Example 86 with ItemId

use of com.zimbra.cs.service.util.ItemId in project zm-mailbox by Zimbra.

the class MailSenderTest method updateReferenceHeaders.

@Test
public void updateReferenceHeaders() throws Exception {
    MailSender sender = new MailSender();
    Provisioning prov = Provisioning.getInstance();
    Account account = prov.getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
    String from = "sender@example.com";
    String to = "recipient@example.com";
    String subject = "test subject";
    MessageBuilder builder = new MessageBuilder().withFrom(from).withToRecipient(to).withSubject(subject).withBody("test body");
    String content = builder.create();
    MimeMessage msg = new FixedMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(content.getBytes()));
    //default
    Assert.assertNull(msg.getHeader("Thread-Index"));
    Assert.assertNull(msg.getHeader("Thread-Topic"));
    sender.updateReferenceHeaders(msg, null, account);
    Assert.assertEquals(1, msg.getHeader("Thread-Index").length);
    Assert.assertEquals(1, msg.getHeader("Thread-Topic").length);
    //technically the normalized subject, but our test message already had normalized subject
    Assert.assertEquals(subject, msg.getHeader("Thread-Topic")[0]);
    //index set by sending agent (bg 96107)
    msg = new FixedMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(content.getBytes()));
    String presetIndex = "1234";
    msg.setHeader("Thread-Index", presetIndex);
    Assert.assertNull(msg.getHeader("Thread-Topic"));
    sender.updateReferenceHeaders(msg, null, account);
    Assert.assertEquals(1, msg.getHeader("Thread-Index").length);
    Assert.assertEquals(1, msg.getHeader("Thread-Topic").length);
    Assert.assertEquals(subject, msg.getHeader("Thread-Topic")[0]);
    Assert.assertEquals(presetIndex, msg.getHeader("Thread-Index")[0]);
    //topic set by sending agent (bug 96107)
    msg = new FixedMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(content.getBytes()));
    Assert.assertNull(msg.getHeader("Thread-Index"));
    String presetTopic = "mytopic";
    msg.setHeader("Thread-Topic", presetTopic);
    sender.updateReferenceHeaders(msg, null, account);
    Assert.assertEquals(1, msg.getHeader("Thread-Index").length);
    Assert.assertEquals(1, msg.getHeader("Thread-Topic").length);
    Assert.assertEquals(presetTopic, msg.getHeader("Thread-Topic")[0]);
    //both
    msg = new FixedMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(content.getBytes()));
    msg.setHeader("Thread-Topic", presetTopic);
    msg.setHeader("Thread-Index", presetIndex);
    sender.updateReferenceHeaders(msg, null, account);
    Assert.assertEquals(1, msg.getHeader("Thread-Index").length);
    Assert.assertEquals(1, msg.getHeader("Thread-Topic").length);
    Assert.assertEquals(presetTopic, msg.getHeader("Thread-Topic")[0]);
    Assert.assertEquals(presetIndex, msg.getHeader("Thread-Index")[0]);
    //subject changed from orig parent subject (bug 96954)
    String parentSubject = "parent subject";
    builder = new MessageBuilder().withFrom(from).withToRecipient(to).withSubject(parentSubject).withBody("parent body");
    String parentContent = builder.create();
    MimeMessage parentMsg = new FixedMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(parentContent.getBytes()));
    sender.updateReferenceHeaders(parentMsg, null, account);
    ParsedMessage pm = new ParsedMessage(parentMsg, false);
    Message mboxMessage = mbox.addMessage(null, pm, MailboxTest.STANDARD_DELIVERY_OPTIONS, null);
    sender = new MailSender();
    sender.setOriginalMessageId(new ItemId(mboxMessage));
    sender.setReplyType(MailSender.MSGTYPE_REPLY);
    msg = new FixedMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(content.getBytes()));
    sender.updateReferenceHeaders(msg, null, account);
    Assert.assertEquals(1, msg.getHeader("Thread-Index").length);
    Assert.assertEquals(1, msg.getHeader("Thread-Topic").length);
    Assert.assertEquals(subject, msg.getHeader("Thread-Topic")[0]);
    //keep agent specified topic and/or index even when parent specified
    msg = new FixedMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(content.getBytes()));
    msg.setHeader("Thread-Topic", presetTopic);
    sender.updateReferenceHeaders(msg, null, account);
    Assert.assertEquals(1, msg.getHeader("Thread-Index").length);
    Assert.assertEquals(1, msg.getHeader("Thread-Topic").length);
    Assert.assertEquals(presetTopic, msg.getHeader("Thread-Topic")[0]);
    msg = new FixedMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(content.getBytes()));
    msg.setHeader("Thread-Index", presetIndex);
    sender.updateReferenceHeaders(msg, null, account);
    Assert.assertEquals(1, msg.getHeader("Thread-Index").length);
    Assert.assertEquals(1, msg.getHeader("Thread-Topic").length);
    Assert.assertEquals(subject, msg.getHeader("Thread-Topic")[0]);
    Assert.assertEquals(presetIndex, msg.getHeader("Thread-Index")[0]);
    msg = new FixedMimeMessage(JMSession.getSession(), new SharedByteArrayInputStream(content.getBytes()));
    msg.setHeader("Thread-Topic", presetTopic);
    msg.setHeader("Thread-Index", presetIndex);
    sender.updateReferenceHeaders(msg, null, account);
    Assert.assertEquals(1, msg.getHeader("Thread-Index").length);
    Assert.assertEquals(1, msg.getHeader("Thread-Topic").length);
    Assert.assertEquals(presetTopic, msg.getHeader("Thread-Topic")[0]);
    Assert.assertEquals(presetIndex, msg.getHeader("Thread-Index")[0]);
}
Also used : Account(com.zimbra.cs.account.Account) MessageBuilder(com.zimbra.qa.unittest.MessageBuilder) MimeMessage(javax.mail.internet.MimeMessage) FixedMimeMessage(com.zimbra.cs.mime.Mime.FixedMimeMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) MimeMessage(javax.mail.internet.MimeMessage) FixedMimeMessage(com.zimbra.cs.mime.Mime.FixedMimeMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) FixedMimeMessage(com.zimbra.cs.mime.Mime.FixedMimeMessage) ItemId(com.zimbra.cs.service.util.ItemId) MockProvisioning(com.zimbra.cs.account.MockProvisioning) Provisioning(com.zimbra.cs.account.Provisioning) SharedByteArrayInputStream(javax.mail.util.SharedByteArrayInputStream) Test(org.junit.Test)

Example 87 with ItemId

use of com.zimbra.cs.service.util.ItemId in project zm-mailbox by Zimbra.

the class SendShareNotificationTest method shareByAdmin.

@Test
public void shareByAdmin() throws Exception {
    revoke = false;
    Account acct = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
    Account acct2 = Provisioning.getInstance().get(Key.AccountBy.name, "test2@zimbra.com");
    Account acct3 = Provisioning.getInstance().get(Key.AccountBy.name, "test3@zimbra.com");
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
    Folder f = mbox.createFolder(null, "f1", Mailbox.ID_FOLDER_BRIEFCASE, new Folder.FolderOptions().setDefaultView(MailItem.Type.DOCUMENT));
    mbox.grantAccess(null, f.getId(), acct2.getId(), ACL.GRANTEE_USER, ACL.RIGHT_ADMIN, null);
    mbox.grantAccess(null, f.getId(), acct3.getId(), ACL.GRANTEE_USER, ACL.RIGHT_ADMIN, null);
    Element request = new Element.XMLElement(MailConstants.SEND_SHARE_NOTIFICATION_REQUEST);
    request.addElement(MailConstants.E_ITEM).addAttribute(MailConstants.A_ID, new ItemId(acct.getId(), f.getId()).toString());
    request.addElement(MailConstants.E_EMAIL).addAttribute(MailConstants.A_ADDRESS, "test3@zimbra.com");
    handle(request, ServiceTestUtil.getRequestContext(acct));
}
Also used : Account(com.zimbra.cs.account.Account) Mailbox(com.zimbra.cs.mailbox.Mailbox) Element(com.zimbra.common.soap.Element) Folder(com.zimbra.cs.mailbox.Folder) ItemId(com.zimbra.cs.service.util.ItemId) Test(org.junit.Test)

Example 88 with ItemId

use of com.zimbra.cs.service.util.ItemId 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 89 with ItemId

use of com.zimbra.cs.service.util.ItemId 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)

Example 90 with ItemId

use of com.zimbra.cs.service.util.ItemId in project zm-mailbox by Zimbra.

the class ParseMimeMessage method handleAttachments.

private static void handleAttachments(Element attachElem, MimeMultipart mmp, ParseMessageContext ctxt, String contentID, String contentDisposition, boolean attachFromMessageCache) throws ServiceException, MessagingException, IOException {
    if (contentID != null) {
        contentID = '<' + contentID + '>';
    }
    String attachIds = attachElem.getAttribute(MailConstants.A_ATTACHMENT_ID, null);
    if (attachIds != null) {
        for (String uploadId : attachIds.split(FileUploadServlet.UPLOAD_DELIMITER)) {
            Upload up = FileUploadServlet.fetchUpload(ctxt.zsc.getAuthtokenAccountId(), uploadId, ctxt.zsc.getAuthToken());
            if (up == null) {
                throw MailServiceException.NO_SUCH_UPLOAD(uploadId);
            }
            attachUpload(mmp, up, contentID, ctxt, null, null, contentDisposition);
            ctxt.out.addUpload(up);
        }
    }
    for (Element elem : attachElem.listElements()) {
        String attachType = elem.getName();
        boolean optional = elem.getAttributeBool(MailConstants.A_OPTIONAL, false);
        try {
            if (attachType.equals(MailConstants.E_MIMEPART)) {
                ItemId iid = new ItemId(elem.getAttribute(MailConstants.A_MESSAGE_ID), ctxt.zsc);
                String part = elem.getAttribute(MailConstants.A_PART);
                attachPart(mmp, iid, part, contentID, ctxt, contentDisposition);
            } else if (attachType.equals(MailConstants.E_MSG)) {
                ItemId iid = new ItemId(elem.getAttribute(MailConstants.A_ID), ctxt.zsc);
                attachMessage(mmp, iid, contentID, ctxt, attachFromMessageCache);
            } else if (attachType.equals(MailConstants.E_CONTACT)) {
                ItemId iid = new ItemId(elem.getAttribute(MailConstants.A_ID), ctxt.zsc);
                attachContact(mmp, iid, contentID, ctxt);
            } else if (attachType.equals(MailConstants.E_DOC)) {
                String path = elem.getAttribute(MailConstants.A_PATH, null);
                if (path != null) {
                    attachDocument(mmp, path, contentID, ctxt);
                } else {
                    ItemId iid = new ItemId(elem.getAttribute(MailConstants.A_ID), ctxt.zsc);
                    int version = (int) elem.getAttributeLong(MailConstants.A_VERSION, 0);
                    attachDocument(mmp, iid, version, contentID, ctxt);
                }
            }
        } catch (NoSuchItemException nsie) {
            if (!optional)
                throw nsie;
            ZimbraLog.soap.info("skipping missing optional attachment: " + elem);
        }
    }
}
Also used : Element(com.zimbra.common.soap.Element) Upload(com.zimbra.cs.service.FileUploadServlet.Upload) ItemId(com.zimbra.cs.service.util.ItemId) NoSuchItemException(com.zimbra.cs.mailbox.MailServiceException.NoSuchItemException)

Aggregations

ItemId (com.zimbra.cs.service.util.ItemId)327 Mailbox (com.zimbra.cs.mailbox.Mailbox)243 OperationContext (com.zimbra.cs.mailbox.OperationContext)231 Account (com.zimbra.cs.account.Account)219 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)189 Message (com.zimbra.cs.mailbox.Message)185 DeliveryContext (com.zimbra.cs.mailbox.DeliveryContext)168 Test (org.junit.Test)161 Element (com.zimbra.common.soap.Element)81 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)80 MimeMessage (javax.mail.internet.MimeMessage)65 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)58 ServiceException (com.zimbra.common.service.ServiceException)52 LmtpEnvelope (com.zimbra.cs.lmtpserver.LmtpEnvelope)47 LmtpAddress (com.zimbra.cs.lmtpserver.LmtpAddress)45 ItemIdFormatter (com.zimbra.cs.service.util.ItemIdFormatter)44 SyntaxException (org.apache.jsieve.exception.SyntaxException)42 Folder (com.zimbra.cs.mailbox.Folder)33 ArrayList (java.util.ArrayList)30 ZMimeMessage (com.zimbra.common.zmime.ZMimeMessage)29