Search in sources :

Example 81 with ItemId

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

the class SetVariableTest method testOutofRangeVarIndexWithLeadingZeroes.

@Test
public void testOutofRangeVarIndexWithLeadingZeroes() {
    try {
        Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
        RuleManager.clearCachedRules(account);
        Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
        filterScript = "if header :matches :comparator \"i;ascii-casemap\" \"Subject\" \"*C*a*c*ple*oo *ge*yo 123 *56*89 sie*e*t\" { " + "tag \"${0010}\";}";
        account.setMailSieveScript(filterScript);
        String raw = "From: sender@zimbra.com\n" + "To: test1@zimbra.com\n" + "Subject: test C-51 abc sample foo bar hoge piyo 123 456 789 sieve test";
        List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage(raw.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());
        String tag = msg.getTags()[0];
        // ${0010} is not valid variable index. So, no tag will be set because of a Sieve syntax Exception
        fail("Should not reach here");
    } catch (ArrayIndexOutOfBoundsException e) {
        assertTrue(true);
    } catch (Exception e) {
        e.printStackTrace();
        fail("No exception should be thrown");
    }
}
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) SyntaxException(org.apache.jsieve.exception.SyntaxException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) Test(org.junit.Test)

Example 82 with ItemId

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

the class SetVariableTest method testStringInterpretation.

@Test
public void testStringInterpretation() {
    try {
        Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
        RuleManager.clearCachedRules(account);
        Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
        filterScript = "require [\"variables\"];\n" + "set \"a\" \"juMBlEd lETteRS\";\n" + "if header :matches \"Subject\" \"*\" {\n" + "  tag \"${d}\";\n" + "}\n";
        account.setMailSieveScript(filterScript);
        String raw = "From: sender@zimbra.com\n" + "To: test1@zimbra.com\n" + "Subject: Test\n" + "\n" + "Hello World.";
        try {
            List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage(raw.getBytes(), false), 0, account.getName(), new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
            Message msg = mbox.getMessageById(null, ids.get(0).getId());
        } catch (MailServiceException e) {
            String t = e.getArgumentValue("name");
            assertTrue(e.getCode().equals("mail.INVALID_NAME"));
            assertEquals("", t);
        }
        RuleManager.clearCachedRules(account);
        filterScript = "require [\"variables\"];\n" + "set \"a\" \"juMBlEd lETteRS\";\n" + "if header :matches \"Subject\" \"*\" {\n" + "  tag \"${}\";\n" + "}";
        account.setMailSieveScript(filterScript);
        try {
            List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage(raw.getBytes(), false), 0, account.getName(), new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
        } catch (MailServiceException e) {
            String t = e.getArgumentValue("name");
            assertTrue(e.getCode().equals("mail.INVALID_NAME"));
            assertEquals("${}", t);
        }
        RuleManager.clearCachedRules(account);
        filterScript = "require [\"variables\"];\n" + "set \"ave\" \"juMBlEd lETteRS\";\n" + "if header :matches \"Subject\" \"*\" {\n" + "  tag \"${ave!}\";\n" + "}\n";
        account.setMailSieveScript(filterScript);
        try {
            List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage(raw.getBytes(), false), 0, account.getName(), new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
        } catch (MailServiceException e) {
            String t = e.getArgumentValue("name");
            assertTrue(e.getCode().equals("mail.INVALID_NAME"));
            assertEquals("${ave!}", t);
        }
    } catch (Exception e) {
        fail("No exception should be thrown");
    }
}
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) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) DeliveryContext(com.zimbra.cs.mailbox.DeliveryContext) ItemId(com.zimbra.cs.service.util.ItemId) SyntaxException(org.apache.jsieve.exception.SyntaxException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) Test(org.junit.Test)

Example 83 with ItemId

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

the class SetVariableTest method testSetMatchVarAndUseInHeader.

@Test
public void testSetMatchVarAndUseInHeader() {
    try {
        Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
        RuleManager.clearCachedRules(account);
        Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
        filterScript = "require [\"variables\"];\n" + "if header :matches [\"To\", \"Cc\"] [\"coyote@**.com\",\"wile@**.com\"]{\n" + "  log \"Match 1 ${1}\";\n" + "  tag \"${2}\";\n" + "}\n";
        account.setMailSieveScript(filterScript);
        String raw = "From: sender@zimbra.com\n" + "To: coyote@ACME.Example.COM\n" + "Subject: hello version 1.0 is out\n" + "\n" + "Hello World.";
        List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage(raw.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("ACME.Example", ArrayUtil.getFirstElement(msg.getTags()));
    } catch (Exception e) {
        fail("No exception should be thrown");
    }
}
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) SyntaxException(org.apache.jsieve.exception.SyntaxException) MailServiceException(com.zimbra.cs.mailbox.MailServiceException) Test(org.junit.Test)

Example 84 with ItemId

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

the class MsgQueryResultsTest method merge.

@Test
public void merge() throws Exception {
    MockQueryResults top = new MockQueryResults(EnumSet.of(MailItem.Type.MESSAGE), SortBy.NONE);
    top.add(new MessageHit(top, null, 1000, null, null, 0));
    top.add(new MessagePartHit(top, null, 1000, null, null, 0));
    top.add(new MessagePartHit(top, null, 1000, null, null, 0));
    top.add(new MessageHit(top, null, 1001, null, null, 0));
    top.add(new MessageHit(top, null, 1001, null, null, 0));
    top.add(new MessagePartHit(top, null, 1001, null, null, 0));
    top.add(new MessagePartHit(top, null, 1001, null, null, 0));
    top.add(new MessageHit(top, null, 1002, null, null, 0));
    top.add(new MessageHit(top, null, 1003, null, null, 0));
    ProxiedHit phit = new ProxiedHit(top, null, 0);
    phit.setParsedItemId(new ItemId("A", 1000));
    top.add(phit);
    phit = new ProxiedHit(top, null, 0);
    phit.setParsedItemId(new ItemId("B", 1000));
    top.add(phit);
    MsgQueryResults result = new MsgQueryResults(top, null, SortBy.NONE, SearchParams.Fetch.NORMAL);
    ZimbraHit hit = result.getNext();
    Assert.assertEquals(hit.getClass(), MessageHit.class);
    Assert.assertEquals(hit.getItemId(), 1000);
    hit = result.getNext();
    Assert.assertEquals(hit.getClass(), MessageHit.class);
    Assert.assertEquals(hit.getItemId(), 1001);
    hit = result.getNext();
    Assert.assertEquals(hit.getClass(), MessageHit.class);
    Assert.assertEquals(hit.getItemId(), 1002);
    hit = result.getNext();
    Assert.assertEquals(hit.getClass(), MessageHit.class);
    Assert.assertEquals(hit.getItemId(), 1003);
    hit = result.getNext();
    Assert.assertEquals(hit.getClass(), ProxiedHit.class);
    Assert.assertEquals(hit.getItemId(), 1000);
    hit = result.getNext();
    Assert.assertEquals(hit.getClass(), ProxiedHit.class);
    Assert.assertEquals(hit.getItemId(), 1000);
    Assert.assertFalse(result.hasNext());
}
Also used : ItemId(com.zimbra.cs.service.util.ItemId) Test(org.junit.Test)

Example 85 with ItemId

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

the class InQueryTest method inAnyFolder.

@Test
public void inAnyFolder() throws Exception {
    Mailbox mbox = MailboxManager.getInstance().getMailboxByAccountId(MockProvisioning.DEFAULT_ACCOUNT_ID);
    Query query = InQuery.create(mbox, new ItemId(MockProvisioning.DEFAULT_ACCOUNT_ID, 1), null, true);
    Assert.assertEquals("Q(UNDER:ANY_FOLDER)", query.toString());
    query = InQuery.create(mbox, new ItemId(MockProvisioning.DEFAULT_ACCOUNT_ID, 1), null, false);
    Assert.assertEquals("Q(IN:USER_ROOT)", query.toString());
    query = InQuery.create(mbox, new ItemId("1-1-1", 1), null, true);
    Assert.assertEquals("Q(UNDER:1-1-1:1)", query.toString());
    query = InQuery.create(mbox, new ItemId("1-1-1", 1), null, false);
    Assert.assertEquals("Q(IN:1-1-1:1)", query.toString());
}
Also used : Mailbox(com.zimbra.cs.mailbox.Mailbox) ItemId(com.zimbra.cs.service.util.ItemId) Test(org.junit.Test)

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