use of com.zimbra.cs.account.Account in project zm-mailbox by Zimbra.
the class RuleManagerAdminFilterTest method discardOnlyAtAdminBefore.
@Test
public void discardOnlyAtAdminBefore() throws Exception {
Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
RuleManager.clearCachedRules(account);
account.unsetAdminSieveScriptBefore();
account.unsetMailSieveScript();
account.unsetAdminSieveScriptAfter();
account.setAdminSieveScriptBefore("discard;");
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage(message.getBytes(), false), 0, account.getName(), new DeliveryContext(), Mailbox.ID_FOLDER_INBOX, true);
Assert.assertEquals(0, ids.size());
}
use of com.zimbra.cs.account.Account 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 com.zimbra.cs.account.Account 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 com.zimbra.cs.account.Account in project zm-mailbox by Zimbra.
the class SocialcastTestTest method test.
@Test
public void test() throws Exception {
Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
RuleManager.clearCachedRules(account);
account.setMailSieveScript("if socialcast { tag \"socialcast\"; }");
Mailbox mbox = MailboxManager.getInstance().getMailboxByAccount(account);
// bulk from socialcast
List<ItemId> ids = RuleManager.applyRulesToIncomingMessage(new OperationContext(mbox), mbox, new ParsedMessage("From: do-not-reply@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.assertTrue(msg.getTags().length == 0);
// notification from socialcast
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());
msg = mbox.getMessageById(null, ids.get(0).getId());
Assert.assertEquals("socialcast", ArrayUtil.getFirstElement(msg.getTags()));
}
use of com.zimbra.cs.account.Account in project zm-mailbox by Zimbra.
the class ImapServerListenerPoolTest method testInstanceManagement.
@Test
public void testInstanceManagement() throws ServiceException {
String serverName1 = "example1.zimbra.com";
String serverName2 = "example2.zimbra.com";
HashMap<String, Object> attrs = new HashMap<String, Object>();
attrs.put(Provisioning.A_zimbraServiceHostname, "example1.zimbra.com");
attrs.put(Provisioning.A_zimbraAdminPort, 7071);
prov.createServer(serverName1, attrs);
attrs = new HashMap<String, Object>();
attrs.put(Provisioning.A_zimbraServiceHostname, "example2.zimbra.com");
attrs.put(Provisioning.A_zimbraAdminPort, 7071);
prov.createServer(serverName2, new HashMap<String, Object>());
attrs = new HashMap<String, Object>();
attrs.put(Provisioning.A_zimbraId, UUID.randomUUID().toString());
attrs.put(Provisioning.A_zimbraMailHost, serverName1);
Account user1 = prov.createAccount("user1@example1.zimbra.com", "test123", attrs);
attrs = new HashMap<String, Object>();
attrs.put(Provisioning.A_zimbraId, UUID.randomUUID().toString());
attrs.put(Provisioning.A_zimbraMailHost, serverName1);
Account user1_2 = prov.createAccount("user1_2@example1.zimbra.com", "test123", attrs);
attrs = new HashMap<String, Object>();
attrs.put(Provisioning.A_zimbraId, UUID.randomUUID().toString());
attrs.put(Provisioning.A_zimbraMailHost, serverName2);
Account user2 = prov.createAccount("user2@example2.zimbra.com", "test123", attrs);
attrs = new HashMap<String, Object>();
attrs.put(Provisioning.A_zimbraId, UUID.randomUUID().toString());
attrs.put(Provisioning.A_zimbraMailHost, serverName2);
Account user2_2 = prov.createAccount("user2_2@example2.zimbra.com", "test123", attrs);
ZMailbox.Options options = new ZMailbox.Options();
options.setAccount(user1.getId());
options.setAccountBy(Key.AccountBy.id);
options.setPassword("test123");
options.setAuthAuthToken(false);
options.setAuthToken("sometoken");
options.setUri("https://" + serverName1);
ZMailbox testMbox1 = new MockZMailbox(options);
options = new ZMailbox.Options();
options.setAccount(user1_2.getId());
options.setAccountBy(Key.AccountBy.id);
options.setPassword("test123");
options.setAuthAuthToken(false);
options.setAuthToken("sometoken");
options.setUri("https://" + serverName1);
ZMailbox testMbox1_2 = new MockZMailbox(options);
options = new ZMailbox.Options();
options.setAccount(user2.getId());
options.setAccountBy(Key.AccountBy.id);
options.setPassword("test123");
options.setAuthAuthToken(false);
options.setAuthToken("sometoken");
options.setUri("https://" + serverName2);
ZMailbox testMbox2 = new MockZMailbox(options);
options = new ZMailbox.Options();
options.setAccount(user2_2.getId());
options.setAccountBy(Key.AccountBy.id);
options.setPassword("test123");
options.setAuthAuthToken(false);
options.setAuthToken("sometoken");
options.setUri("https://" + serverName2);
ZMailbox testMbox2_2 = new MockZMailbox(options);
ImapServerListenerPool pool = ImapServerListenerPool.getInstance();
ImapServerListener listener1 = pool.get(testMbox1);
ImapServerListener listener2 = pool.get(testMbox2);
ImapServerListener listener1_2 = pool.get(testMbox1_2);
ImapServerListener listener2_2 = pool.get(testMbox2_2);
assertNotSame("listener 1 should be different from listener 2", listener1, listener2);
assertNotSame("listener 1_2 should be different from listener 2_2", listener1_2, listener2_2);
assertSame("listener 1 should be the same as listener 1_2", listener1, listener1_2);
assertSame("listener 2 should be the same as listener 2_2", listener2, listener2_2);
}
Aggregations