use of com.zimbra.cs.service.util.ItemId in project zm-mailbox by Zimbra.
the class AddressBookTestTest method filter.
@Test
public void filter() throws Exception {
Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
RuleManager.clearCachedRules(account);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
mbox.createContact(null, new ParsedContact(Collections.<String, Object>singletonMap(ContactConstants.A_email, "test1@zimbra.com")), Mailbox.ID_FOLDER_CONTACTS, null);
account.setMailSieveScript("if addressbook :in \"From\" { tag \"Priority\"; }");
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage("From: test1@zimbra.com".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("Priority", ArrayUtil.getFirstElement(msg.getTags()));
}
use of com.zimbra.cs.service.util.ItemId in project zm-mailbox by Zimbra.
the class AddressTest method testAddressContainingBackslash.
@Test
public void testAddressContainingBackslash() {
try {
Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
RuleManager.clearCachedRules(account);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
String filterScript = "if address :comparator \"i;ascii-casemap\" :matches \"from\" \"\\\"user\\\\1\\\"@cosmonaut.zimbra.com\" {" + " tag \"TestBackslash\";" + "}";
account.setMailSieveScript(filterScript);
InputStream is = getClass().getResourceAsStream("TestFilter-testBackslashDotInAddress.msg");
MimeMessage mm = new ZMimeMessage(JMSession.getSession(), is);
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage(mm, 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("TestBackslash", ArrayUtil.getFirstElement(msg.getTags()));
} catch (Exception e) {
fail("No exception should be thrown" + e);
}
}
use of com.zimbra.cs.service.util.ItemId in project zm-mailbox by Zimbra.
the class AddressTest method compareEmptyStringWithAsciiNumeric.
@Test
public void compareEmptyStringWithAsciiNumeric() {
try {
Account acct = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
RuleManager.clearCachedRules(acct);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
String filterScript = "if address :is :comparator \"i;ascii-numeric\" \"To\" \"\" {" + " tag \"compareEmptyStringWithAsciiNumeric\";" + "}";
acct.setMailSieveScript(filterScript);
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage("To: test1@zimbra.com".getBytes(), false), 0, acct.getName(), new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
Assert.assertEquals(1, ids.size());
Message msg = mbox.getMessageById(null, ids.get(0).getId());
Assert.assertEquals("compareEmptyStringWithAsciiNumeric", 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 AddressTest method compareHeaderNameWithLeadingSpaces.
@Test
public void compareHeaderNameWithLeadingSpaces() {
try {
Account acct = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
RuleManager.clearCachedRules(acct);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(acct);
String filterScript = "require [\"tag\"];\n" + "if address :is :comparator \"i;ascii-numeric\" \" To\" \"test1@zimbra.com\" {" + " tag \"t1\";" + "}";
acct.setMailSieveScript(filterScript);
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage("To: test1@zimbra.com".getBytes(), false), 0, acct.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);
} 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 AddressTest method testAddressContainingDot.
@Test
public void testAddressContainingDot() {
try {
Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
RuleManager.clearCachedRules(account);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
String filterScript = "if address :comparator \"i;ascii-casemap\" :matches \"to\" \"user.1@cosmonaut.zimbra.com\" {" + " tag \"TestDot\";" + "}";
account.setMailSieveScript(filterScript);
InputStream is = getClass().getResourceAsStream("TestFilter-testBackslashDotInAddress.msg");
MimeMessage mm = new ZMimeMessage(JMSession.getSession(), is);
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage(mm, 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("TestDot", ArrayUtil.getFirstElement(msg.getTags()));
} catch (Exception e) {
fail("No exception should be thrown" + e);
}
}
Aggregations