use of org.apache.jsieve.commands.AbstractActionCommand in project zm-mailbox by Zimbra.
the class RuleManagerWithCustomActionFilterTest method init.
@BeforeClass
public static void init() throws Exception {
// keep original sieve factory
original_sf = RuleManager.getSieveFactory();
ExtensionTestUtil.init();
MailboxTestUtil.initServer();
Provisioning prov = Provisioning.getInstance();
prov.createAccount("test@zimbra.com", "secret", new HashMap<String, Object>());
// make sure the behavior before registering custom actions
Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
AbstractActionCommand ext = (AbstractActionCommand) ExtensionUtil.getExtension("discard");
Assert.assertNull(ext);
RuleManager.clearCachedRules(account);
account.setMailSieveScript("if socialcast { discard; }");
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage("From: do-not-reply@socialcast.com\nReply-To: share@socialcast.com\nSubject: test".getBytes(), false), 0, account.getName(), new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
Assert.assertEquals(0, ids.size());
// register custom action extensions
ExtensionTestUtil.registerExtension("com.zimbra.extensions.DummyCustomDiscard");
ExtensionTestUtil.registerExtension("com.zimbra.extensions.DummyCustomTag");
ExtensionUtil.initAll();
}
use of org.apache.jsieve.commands.AbstractActionCommand in project zm-mailbox by Zimbra.
the class RuleManagerWithCustomActionFilterTest method customDicardAndCustomTag.
@Test
public void customDicardAndCustomTag() throws Exception {
// register custom action extensions
//ExtensionTestUtil.registerExtension("com.zimbra.extensions.DummyCustomDiscard");
//ExtensionTestUtil.registerExtension("com.zimbra.extensions.DummyCustomTag");
//ExtensionUtil.initAll();
JsieveConfigMapHandler.registerCommand("discard", "com.zimbra.extensions.DummyCustomDiscard");
JsieveConfigMapHandler.registerCommand("tag", "com.zimbra.extensions.DummyCustomTag");
// recreate sieve factory
Method method = RuleManager.class.getDeclaredMethod("createSieveFactory");
method.setAccessible(true);
Field field = RuleManager.class.getDeclaredField("SIEVE_FACTORY");
field.setAccessible(true);
field.set(RuleManager.class, method.invoke(RuleManager.class));
// make sure the registrations
AbstractActionCommand discard_ext = (AbstractActionCommand) ExtensionUtil.getExtension("discard");
Assert.assertNotNull(discard_ext);
AbstractActionCommand tag_ext = (AbstractActionCommand) ExtensionUtil.getExtension("tag");
Assert.assertNotNull(tag_ext);
Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
RuleManager.clearCachedRules(account);
account.setMailSieveScript("if header :contains [\"Subject\"] [\"Zimbra\"] { tag \"socialcast\"; discard; }");
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage("From: do-not-reply@socialcast.com\nReply-To: share@socialcast.com\nSubject: Zimbra".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.assertArrayEquals(new String[] { "zimbra", "priority" }, msg.getTags());
// inactivate custom tag action extension for just in case this test would be executed
// before tagAndCustomDiscard test above
//ZimbraExtension tag_ext2 = ExtensionUtil.getExtension("tag");
//tag_ext2.destroy();
}
use of org.apache.jsieve.commands.AbstractActionCommand in project zm-mailbox by Zimbra.
the class RuleManagerWithCustomActionFilterTest method tagAndCustomDiscard.
@Test
public void tagAndCustomDiscard() throws Exception {
// register custom action extension
//ExtensionTestUtil.registerExtension("com.zimbra.extensions.DummyCustomDiscard");
//ExtensionUtil.initAll();
JsieveConfigMapHandler.registerCommand("discard", "com.zimbra.extensions.DummyCustomDiscard");
JsieveConfigMapHandler.registerCommand("tag", "com.zimbra.cs.filter.jsieve.Tag");
// recreate sieve factory
Method method = RuleManager.class.getDeclaredMethod("createSieveFactory");
method.setAccessible(true);
Field field = RuleManager.class.getDeclaredField("SIEVE_FACTORY");
field.setAccessible(true);
field.set(RuleManager.class, method.invoke(RuleManager.class));
// make sure the registrations
AbstractActionCommand ext = (AbstractActionCommand) ExtensionUtil.getExtension("discard");
Assert.assertNotNull(ext);
Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
RuleManager.clearCachedRules(account);
account.setMailSieveScript("if socialcast { tag \"socialcast\"; discard; }");
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage("From: do-not-reply@socialcast.com\nReply-To: share@socialcast.com\nSubject: 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("Inbox", mbox.getFolderById(null, msg.getFolderId()).getName());
Assert.assertArrayEquals(new String[] { "socialcast", "priority" }, msg.getTags());
}
Aggregations