Search in sources :

Example 81 with Message

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

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

the class SearchActionTest method testSearchActionRead.

@Test
public void testSearchActionRead() throws Exception {
    Account acct = Provisioning.getInstance().getAccountByName("testRead@zimbra.com");
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
    // Add two messages to inbox, one with search match and other with no match
    DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX).setFlags(Flag.BITMASK_UNREAD | Flag.BITMASK_MUTED);
    Message message1 = mbox.addMessage(null, MailboxTestUtil.generateMessage("test subject"), dopt, null);
    Message message2 = mbox.addMessage(null, MailboxTestUtil.generateMessage("unmatched subject"), dopt, null);
    TypedIdList ids = mbox.getItemIds(null, 2);
    Assert.assertEquals(2, ids.size());
    Assert.assertEquals(true, message1.isUnread());
    Assert.assertEquals(true, message2.isUnread());
    SearchRequest sRequest = new SearchRequest();
    sRequest.setSearchTypes("conversation");
    // search with query 'test'
    sRequest.setQuery("test");
    BulkAction bAction = new BulkAction();
    // search action - mark search result with 'read'
    bAction.setOp(BulkAction.Operation.read);
    Map<String, Object> context = ServiceTestUtil.getRequestContext(acct);
    ZimbraSoapContext zsc = (ZimbraSoapContext) context.get(SoapEngine.ZIMBRA_CONTEXT);
    Element searchResponse = new Search().handle(zsc.jaxbToElement(sRequest), ServiceTestUtil.getRequestContext(acct));
    com.zimbra.soap.mail.message.SearchResponse sResponse = zsc.elementToJaxb(searchResponse);
    List<SearchHit> searchHits = sResponse.getSearchHits();
    ConvActionRequest req = SearchAction.getConvActionRequest(searchHits, "read");
    ConvAction convAction = new ConvAction();
    PowerMockito.stub(PowerMockito.method(SoapHttpTransport.class, "invokeWithoutSession")).toReturn(convAction.handle(zsc.jaxbToElement(req), ServiceTestUtil.getRequestContext(acct)));
    SearchAction.performAction(bAction, sRequest, searchHits, mbox, null);
    // check search result message is marked read
    Assert.assertEquals(false, message1.isUnread());
    Assert.assertEquals(true, message2.isUnread());
}
Also used : Account(com.zimbra.cs.account.Account) SearchRequest(com.zimbra.soap.mail.message.SearchRequest) Message(com.zimbra.cs.mailbox.Message) SearchHit(com.zimbra.soap.type.SearchHit) ConvActionRequest(com.zimbra.soap.mail.message.ConvActionRequest) Element(com.zimbra.common.soap.Element) BulkAction(com.zimbra.soap.mail.type.BulkAction) TypedIdList(com.zimbra.cs.mailbox.util.TypedIdList) Mailbox(com.zimbra.cs.mailbox.Mailbox) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 83 with Message

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

the class ParseMimeMessageTest method staleReference.

@Test
public void staleReference() throws Exception {
    Account acct = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
    // first, create the original draft
    OperationContext octxt = new OperationContext(acct);
    Document doc = mbox.createDocument(octxt, Mailbox.ID_FOLDER_BRIEFCASE, "testdoc", MimeConstants.CT_TEXT_PLAIN, null, null, randomContent("test1", 8192));
    Document doc2 = mbox.createDocument(octxt, Mailbox.ID_FOLDER_BRIEFCASE, "testdoc2", MimeConstants.CT_TEXT_PLAIN, null, null, randomContent("test2", 8192));
    Element el = new Element.JSONElement(MailConstants.E_MSG), attach;
    el.addAttribute(MailConstants.E_SUBJECT, "has attachment");
    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.");
    attach = el.addElement(MailConstants.E_ATTACH);
    attach.addElement(MailConstants.E_DOC).addAttribute(MailConstants.A_ID, doc.getId());
    attach.addElement(MailConstants.E_DOC).addAttribute(MailConstants.A_ID, doc2.getId());
    ZimbraSoapContext zsc = getMockSoapContext();
    MimeMessage mm = ParseMimeMessage.parseMimeMsgSoap(zsc, octxt, null, el, null, new ParseMimeMessage.MimeMessageData());
    Message draft = mbox.saveDraft(octxt, new ParsedMessage(mm, false), -1);
    // then, create a new draft that references one of the original draft's attachments
    attach.detach();
    (attach = el.addElement(MailConstants.E_ATTACH)).addElement(MailConstants.E_MIMEPART).addAttribute(MailConstants.A_MESSAGE_ID, draft.getId()).addAttribute(MailConstants.A_PART, "3");
    mm = ParseMimeMessage.parseMimeMsgSoap(zsc, octxt, null, el, null, new ParseMimeMessage.MimeMessageData());
    // delete the draft itself and then try to save the new draft
    mbox.delete(octxt, draft.getId(), MailItem.Type.MESSAGE);
    Message draft2 = mbox.saveDraft(octxt, new ParsedMessage(mm, false), -1);
    // check that the attachment's content is present and correct
    MimeMultipart multi = (MimeMultipart) (draft2.getMimeMessage().getContent());
    Assert.assertEquals("2 parts in draft", 2, multi.getCount());
    Assert.assertEquals("attached part content", "test2", firstLine((MimeBodyPart) multi.getBodyPart(1)));
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Account(com.zimbra.cs.account.Account) Message(com.zimbra.cs.mailbox.Message) MimeMessage(javax.mail.internet.MimeMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) Element(com.zimbra.common.soap.Element) Document(com.zimbra.cs.mailbox.Document) Mailbox(com.zimbra.cs.mailbox.Mailbox) MimeMessage(javax.mail.internet.MimeMessage) MimeMultipart(javax.mail.internet.MimeMultipart) ZimbraSoapContext(com.zimbra.soap.ZimbraSoapContext) MimeBodyPart(javax.mail.internet.MimeBodyPart) Test(org.junit.Test)

Example 84 with Message

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

the class AbstractBlobConsistencyCheckTest method wrongSize.

@Test
public void wrongSize() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX);
    Message msg = mbox.addMessage(null, new ParsedMessage("From: test1-1@sub1.zimbra.com".getBytes(), false), dopt, null);
    MailboxBlob blob = msg.getBlob();
    String text = "some garbage";
    appendText(blob, text);
    BlobConsistencyChecker checker = getChecker();
    Results results = checker.check(getVolumeIds(), mbox.getId(), true, false);
    Assert.assertEquals(0, results.missingBlobs.size());
    Assert.assertEquals(0, results.unexpectedBlobs.size());
    Assert.assertEquals(0, results.usedBlobs.size());
    Assert.assertEquals(1, results.incorrectSize.size());
    BlobInfo info = results.incorrectSize.values().iterator().next();
    Assert.assertEquals(blob.size + text.length(), (long) info.fileDataSize);
    Assert.assertEquals(0, results.incorrectModContent.size());
}
Also used : Mailbox(com.zimbra.cs.mailbox.Mailbox) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) Results(com.zimbra.cs.store.file.BlobConsistencyChecker.Results) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) BlobConsistencyChecker(com.zimbra.cs.store.file.BlobConsistencyChecker) BlobInfo(com.zimbra.cs.store.file.BlobConsistencyChecker.BlobInfo) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) Test(org.junit.Test)

Example 85 with Message

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

the class UrlNamespace method getCalendarItemForMessage.

private static DavResource getCalendarItemForMessage(DavContext ctxt, Message msg) throws ServiceException {
    Mailbox mbox = msg.getMailbox();
    if (msg.isInvite() && msg.hasCalendarItemInfos()) {
        Message.CalendarItemInfo calItemInfo = msg.getCalendarItemInfo(0);
        try {
            Invite invite = calItemInfo.getInvite();
            if (invite == null && calItemInfo.calItemCreated()) {
                // Pre-6.0 data
                CalendarItem item = mbox.getCalendarItemById(ctxt.getOperationContext(), calItemInfo.getCalendarItemId());
                invite = calItemInfo.getInvite();
                int compNum = calItemInfo.getComponentNo();
                invite = item.getInvite(msg.getId(), compNum);
            }
            if (invite != null) {
                String path = CalendarObject.CalendarPath.generate(ctxt, msg.getPath(), invite.getUid(), mbox.getId(), msg.getId(), msg.getId());
                return new CalendarObject.ScheduleMessage(ctxt, path, ctxt.getUser(), invite, msg);
            }
        } catch (MailServiceException.NoSuchItemException e) {
        // the appt must have been cancelled or deleted.
        // bug 26315
        }
    }
    return null;
}
Also used : CalendarItem(com.zimbra.cs.mailbox.CalendarItem) Mailbox(com.zimbra.cs.mailbox.Mailbox) Message(com.zimbra.cs.mailbox.Message) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) Invite(com.zimbra.cs.mailbox.calendar.Invite) Mountpoint(com.zimbra.cs.mailbox.Mountpoint)

Aggregations

Message (com.zimbra.cs.mailbox.Message)442 Mailbox (com.zimbra.cs.mailbox.Mailbox)375 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)358 Test (org.junit.Test)335 Account (com.zimbra.cs.account.Account)315 OperationContext (com.zimbra.cs.mailbox.OperationContext)302 DeliveryContext (com.zimbra.cs.mailbox.DeliveryContext)281 ItemId (com.zimbra.cs.service.util.ItemId)211 MimeMessage (javax.mail.internet.MimeMessage)123 SyntaxException (org.apache.jsieve.exception.SyntaxException)87 Header (javax.mail.Header)83 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)63 DeliveryOptions (com.zimbra.cs.mailbox.DeliveryOptions)53 LmtpEnvelope (com.zimbra.cs.lmtpserver.LmtpEnvelope)46 LmtpAddress (com.zimbra.cs.lmtpserver.LmtpAddress)43 ServiceException (com.zimbra.common.service.ServiceException)41 Element (com.zimbra.common.soap.Element)41 ZMimeMessage (com.zimbra.common.zmime.ZMimeMessage)36 Folder (com.zimbra.cs.mailbox.Folder)32 ZMailbox (com.zimbra.client.ZMailbox)26