Search in sources :

Example 11 with Account

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());
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Account(com.zimbra.cs.account.Account) Mailbox(com.zimbra.cs.mailbox.Mailbox) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) DeliveryContext(com.zimbra.cs.mailbox.DeliveryContext) ItemId(com.zimbra.cs.service.util.ItemId) Test(org.junit.Test)

Example 12 with Account

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();
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Field(java.lang.reflect.Field) Account(com.zimbra.cs.account.Account) Mailbox(com.zimbra.cs.mailbox.Mailbox) Message(com.zimbra.cs.mailbox.Message) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) AbstractActionCommand(org.apache.jsieve.commands.AbstractActionCommand) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) Method(java.lang.reflect.Method) DeliveryContext(com.zimbra.cs.mailbox.DeliveryContext) ItemId(com.zimbra.cs.service.util.ItemId) Test(org.junit.Test)

Example 13 with Account

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();
}
Also used : OperationContext(com.zimbra.cs.mailbox.OperationContext) Account(com.zimbra.cs.account.Account) Mailbox(com.zimbra.cs.mailbox.Mailbox) AbstractActionCommand(org.apache.jsieve.commands.AbstractActionCommand) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) DeliveryContext(com.zimbra.cs.mailbox.DeliveryContext) ItemId(com.zimbra.cs.service.util.ItemId) MockProvisioning(com.zimbra.cs.account.MockProvisioning) Provisioning(com.zimbra.cs.account.Provisioning) BeforeClass(org.junit.BeforeClass)

Example 14 with Account

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()));
}
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) SocialcastTest(com.zimbra.cs.filter.jsieve.SocialcastTest) Test(org.junit.Test)

Example 15 with Account

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);
}
Also used : Account(com.zimbra.cs.account.Account) ZMailbox(com.zimbra.client.ZMailbox) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

Account (com.zimbra.cs.account.Account)1444 Test (org.junit.Test)691 Mailbox (com.zimbra.cs.mailbox.Mailbox)468 OperationContext (com.zimbra.cs.mailbox.OperationContext)354 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)331 Message (com.zimbra.cs.mailbox.Message)315 DeliveryContext (com.zimbra.cs.mailbox.DeliveryContext)294 Element (com.zimbra.common.soap.Element)280 ServiceException (com.zimbra.common.service.ServiceException)261 ItemId (com.zimbra.cs.service.util.ItemId)248 Provisioning (com.zimbra.cs.account.Provisioning)234 HashMap (java.util.HashMap)179 ZimbraSoapContext (com.zimbra.soap.ZimbraSoapContext)175 Domain (com.zimbra.cs.account.Domain)149 MimeMessage (javax.mail.internet.MimeMessage)125 GuestAccount (com.zimbra.cs.account.GuestAccount)107 MailServiceException (com.zimbra.cs.mailbox.MailServiceException)100 SyntaxException (org.apache.jsieve.exception.SyntaxException)90 AccountServiceException (com.zimbra.cs.account.AccountServiceException)87 Header (javax.mail.Header)84