Search in sources :

Example 6 with DeliveryOptions

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

the class ConversationTestTest method started.

@Test
public void started() throws Exception {
    Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
    RuleManager.clearCachedRules(account);
    account.setMailSieveScript("if conversation :where \"started\" { tag \"started\"; }");
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
    mbox.addMessage(new OperationContext(mbox), new ParsedMessage("From: test1@zimbra.com\nSubject: test".getBytes(), false), MailboxTest.STANDARD_DELIVERY_OPTIONS, new DeliveryContext());
    DeliveryOptions dopt = new DeliveryOptions();
    dopt.setFolderId(Mailbox.ID_FOLDER_SENT);
    dopt.setFlags(Flag.BITMASK_FROM_ME);
    mbox.addMessage(new OperationContext(mbox), new ParsedMessage("From: test@zimbra.com\nSubject: Re: test".getBytes(), false), dopt, new DeliveryContext());
    List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage("From: test1@zimbra.com\nSubject: Re: test".getBytes(), false), 0, account.getName(), new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
    Assert.assertEquals(1, ids.size());
    Message msg = mbox.getMessageById(null, ids.get(0).getId());
    Assert.assertEquals(0, msg.getTags().length);
    dopt = new DeliveryOptions();
    dopt.setFolderId(Mailbox.ID_FOLDER_SENT);
    dopt.setFlags(Flag.BITMASK_FROM_ME);
    mbox.addMessage(new OperationContext(mbox), new ParsedMessage("From: test@zimbra.com\nSubject: test1".getBytes(), false), dopt, new DeliveryContext());
    ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage("From: test1@zimbra.com\nSubject: Re: test1".getBytes(), false), 0, account.getName(), new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
    Assert.assertEquals(1, ids.size());
    msg = mbox.getMessageById(null, ids.get(0).getId());
    Assert.assertEquals("started", ArrayUtil.getFirstElement(msg.getTags()));
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Account(com.zimbra.cs.account.Account) Mailbox(com.zimbra.cs.mailbox.Mailbox) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) DeliveryContext(com.zimbra.cs.mailbox.DeliveryContext) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) ItemId(com.zimbra.cs.service.util.ItemId) Test(org.junit.Test) MailboxTest(com.zimbra.cs.mailbox.MailboxTest)

Example 7 with DeliveryOptions

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

the class ConversationTestTest method participated.

@Test
public void participated() throws Exception {
    Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
    RuleManager.clearCachedRules(account);
    account.setMailSieveScript("if conversation :where \"participated\" { tag \"participated\"; }");
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
    mbox.addMessage(new OperationContext(mbox), new ParsedMessage("From: test1@zimbra.com\nSubject: test".getBytes(), false), MailboxTest.STANDARD_DELIVERY_OPTIONS, new DeliveryContext());
    List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage("From: test1@zimbra.com\nSubject: Re: test".getBytes(), false), 0, account.getName(), new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
    Assert.assertEquals(1, ids.size());
    Message msg = mbox.getMessageById(null, ids.get(0).getId());
    Assert.assertEquals(0, msg.getTags().length);
    DeliveryOptions dopt = new DeliveryOptions();
    dopt.setFolderId(Mailbox.ID_FOLDER_SENT);
    dopt.setFlags(Flag.BITMASK_FROM_ME);
    mbox.addMessage(new OperationContext(mbox), new ParsedMessage("From: test@zimbra.com\nSubject: Re: test".getBytes(), false), dopt, new DeliveryContext());
    ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage("From: test1@zimbra.com\nSubject: Re: test".getBytes(), false), 0, account.getName(), new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
    Assert.assertEquals(1, ids.size());
    msg = mbox.getMessageById(null, ids.get(0).getId());
    Assert.assertEquals("participated", ArrayUtil.getFirstElement(msg.getTags()));
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Account(com.zimbra.cs.account.Account) Mailbox(com.zimbra.cs.mailbox.Mailbox) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) DeliveryContext(com.zimbra.cs.mailbox.DeliveryContext) ItemId(com.zimbra.cs.service.util.ItemId) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) Test(org.junit.Test) MailboxTest(com.zimbra.cs.mailbox.MailboxTest)

Example 8 with DeliveryOptions

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

the class ExistingMessageHandlerTest method existing.

@Test
public void existing() throws Exception {
    Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
    RuleManager.clearCachedRules(account);
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
    OperationContext octx = new OperationContext(mbox);
    Message msg = mbox.addMessage(octx, new ParsedMessage("From: sender@zimbra.com\nTo: test@zimbra.com\nSubject: test".getBytes(), false), new DeliveryOptions().setFolderId(Mailbox.ID_FOLDER_INBOX).setFlags(Flag.BITMASK_PRIORITY), new DeliveryContext());
    Folder f = mbox.createFolder(null, "test", new Folder.FolderOptions().setDefaultView(MailItem.Type.MESSAGE));
    ExistingMessageHandler handler = new ExistingMessageHandler(octx, mbox, msg.getId(), (int) msg.getSize());
    ItemId newMsgItemId = handler.fileInto("test", new ArrayList<ActionFlag>(), new String[0]);
    Message newMsg = mbox.getMessageById(octx, newMsgItemId.getId());
    Assert.assertEquals(msg.getFolderId(), Integer.parseInt(newMsg.getUnderlyingData().getPrevFolders().split(":")[1]));
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Account(com.zimbra.cs.account.Account) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) Folder(com.zimbra.cs.mailbox.Folder) ItemId(com.zimbra.cs.service.util.ItemId) ActionFlag(com.zimbra.cs.filter.jsieve.ActionFlag) Mailbox(com.zimbra.cs.mailbox.Mailbox) DeliveryContext(com.zimbra.cs.mailbox.DeliveryContext) DeliveryOptions(com.zimbra.cs.mailbox.DeliveryOptions) Test(org.junit.Test)

Example 9 with DeliveryOptions

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

the class ZimbraQueryTest method suggest.

@Test
public void suggest() 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: all hands meeting".getBytes(), false), dopt, null);
    MailboxTestUtil.index(mbox);
    SearchParams params = new SearchParams();
    params.setQueryString("all hands me");
    params.setSortBy(SortBy.NONE);
    params.setTypes(EnumSet.of(MailItem.Type.MESSAGE));
    params.setQuick(true);
    ZimbraQuery query = new ZimbraQuery(new OperationContext(mbox), SoapProtocol.Soap12, mbox, params);
    ZimbraQueryResults result = query.execute();
    Assert.assertEquals(msg.getId(), result.getNext().getItemId());
    Closeables.closeQuietly(result);
}
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 10 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)

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