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");
}
}
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");
}
}
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");
}
}
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());
}
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());
}
Aggregations