Search in sources :

Example 1 with DeliveryOptions

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

the class AppendMessage method store.

private int store(Mailbox mbox, Folder folder) throws ImapSessionClosedException, ServiceException, IOException {
    boolean idxAttach = mbox.attachmentsIndexingEnabled();
    Long receivedDate = date != null ? date.getTime() : null;
    ParsedMessage pm = new ParsedMessage(content, receivedDate, idxAttach);
    try {
        if (!pm.getSender().isEmpty()) {
            InternetAddress ia = new JavaMailInternetAddress(pm.getSender());
            if (AccountUtil.addressMatchesAccountOrSendAs(mbox.getAccount(), ia.getAddress())) {
                flags |= Flag.BITMASK_FROM_ME;
            }
        }
    } catch (Exception e) {
    }
    DeliveryOptions dopt = new DeliveryOptions().setFolderId(folder).setNoICal(true).setFlags(flags).setTags(tags);
    Message msg = mbox.addMessage(handler.getContext(), pm, dopt, null);
    if (msg != null && sflags != 0 && handler.getState() == ImapHandler.State.SELECTED) {
        ImapFolder selectedFolder = handler.getSelectedFolder();
        //   (note that this leaves session flags unset on remote appended messages)
        if (selectedFolder != null) {
            ImapMessage i4msg = selectedFolder.getById(msg.getId());
            if (i4msg != null) {
                i4msg.setSessionFlags(sflags, selectedFolder);
            }
        }
    }
    return msg == null ? -1 : msg.getId();
}
Also used : InternetAddress(javax.mail.internet.InternetAddress) JavaMailInternetAddress(com.zimbra.common.mime.shim.JavaMailInternetAddress) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) JavaMailInternetAddress(com.zimbra.common.mime.shim.JavaMailInternetAddress) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) MessagingException(javax.mail.MessagingException) ServiceException(com.zimbra.common.service.ServiceException) ParseException(java.text.ParseException) IOException(java.io.IOException)

Example 2 with DeliveryOptions

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

the class LuceneQueryOperationTest method subjectQuery.

@Test
public void subjectQuery() 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("Subject: one two three".getBytes(), false), dopt, null);
    MailboxTestUtil.index(mbox);
    // phrase query
    SearchParams params = new SearchParams();
    params.setQueryString("subject:\"one two three\"");
    params.setTypes(EnumSet.of(MailItem.Type.MESSAGE));
    params.setSortBy(SortBy.NONE);
    ZimbraQuery query = new ZimbraQuery(new OperationContext(mbox), SoapProtocol.Soap12, mbox, params);
    ZimbraQueryResults results = query.execute();
    Assert.assertTrue(results.hasNext());
    Assert.assertEquals(msg.getId(), results.getNext().getItemId());
    results.close();
    // verify subject is not repeated during index
    params = new SearchParams();
    params.setQueryString("subject:\"three one\"");
    params.setTypes(EnumSet.of(MailItem.Type.MESSAGE));
    params.setSortBy(SortBy.NONE);
    query = new ZimbraQuery(new OperationContext(mbox), SoapProtocol.Soap12, mbox, params);
    results = query.execute();
    Assert.assertFalse(results.hasNext());
    results.close();
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) 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) Test(org.junit.Test)

Example 3 with DeliveryOptions

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

the class LuceneQueryOperationTest method notClause.

@Test
public void notClause() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    DeliveryOptions dopt = new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX);
    mbox.addMessage(null, new ParsedMessage("From: test1@zimbra.com".getBytes(), false), dopt, null);
    Message msg2 = mbox.addMessage(null, new ParsedMessage("From: test2@zimbra.com".getBytes(), false), dopt, null);
    Message msg3 = mbox.addMessage(null, new ParsedMessage("From: test3@zimbra.com".getBytes(), false), dopt, null);
    MailboxTestUtil.index(mbox);
    SearchParams params = new SearchParams();
    params.setQueryString("-from:test1@zimbra.com");
    params.setTypes(EnumSet.of(MailItem.Type.MESSAGE));
    params.setSortBy(SortBy.NONE);
    ZimbraQuery query = new ZimbraQuery(new OperationContext(mbox), SoapProtocol.Soap12, mbox, params);
    ZimbraQueryResults results = query.execute();
    List<Integer> expecteds = Lists.newArrayList();
    List<Integer> matches = Lists.newArrayList();
    Assert.assertTrue(results.hasNext());
    matches.add(results.getNext().getItemId());
    Assert.assertTrue(results.hasNext());
    matches.add(results.getNext().getItemId());
    Assert.assertFalse(results.hasNext());
    expecteds.add(msg2.getId());
    expecteds.add(msg3.getId());
    Collections.sort(matches);
    Collections.sort(expecteds);
    Assert.assertEquals("Match Item ID", expecteds.get(0), matches.get(0));
    Assert.assertEquals("Match Item ID", expecteds.get(1), matches.get(1));
    results.close();
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) 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) Test(org.junit.Test)

Example 4 with DeliveryOptions

use of com.zimbra.cs.mailbox.DeliveryOptions 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 5 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("test NoSuchItemException (parent/id)", ex instanceof NoSuchItemException);
    ex = null;
    try {
        mbox.getMessageById(null, draft.getId());
    } catch (Exception e) {
        ex = e;
    }
    Assert.assertTrue("test NoSuchItemException (draft/id)", ex instanceof NoSuchItemException);
    ex = null;
    try {
        mbox.getMessageById(null, draft2.getId());
    } catch (Exception e) {
        ex = e;
    }
    Assert.assertTrue("test NoSuchItemException (draft2/id)", ex instanceof NoSuchItemException);
    ex = null;
    try {
        mbox.getConversationById(null, draft2.getConversationId());
    } catch (Exception e) {
        ex = e;
    }
    Assert.assertTrue("test NoSuchItemException (draft2/conversation)", ex instanceof NoSuchItemException);
}
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)73 Mailbox (com.zimbra.cs.mailbox.Mailbox)63 Test (org.junit.Test)57 Message (com.zimbra.cs.mailbox.Message)53 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)51 Account (com.zimbra.cs.account.Account)28 OperationContext (com.zimbra.cs.mailbox.OperationContext)14 ItemId (com.zimbra.cs.service.util.ItemId)13 ServiceException (com.zimbra.common.service.ServiceException)12 Element (com.zimbra.common.soap.Element)12 MimeMessage (javax.mail.internet.MimeMessage)12 Volume (com.zimbra.cs.volume.Volume)11 SearchRequest (com.zimbra.soap.mail.message.SearchRequest)11 SearchHit (com.zimbra.soap.type.SearchHit)10 IOException (java.io.IOException)10 Folder (com.zimbra.cs.mailbox.Folder)9 SearchResponse (com.zimbra.soap.mail.message.SearchResponse)8 BlobReference (com.zimbra.cs.store.file.BlobReference)7 DeliveryContext (com.zimbra.cs.mailbox.DeliveryContext)6 MailItem (com.zimbra.cs.mailbox.MailItem)6