Search in sources :

Example 21 with Account

use of com.zimbra.cs.account.Account in project zm-mailbox by Zimbra.

the class ValueComparisonTest method testAddressTestValueComparisonCaseSensitivity.

/**
 * Tests rule creation through ModifyFilterRulesRequest for address test having caseSensitive attribute with
 * value comparison
 * @throws Exception
 */
@Test
public void testAddressTestValueComparisonCaseSensitivity() throws Exception {
    Account acct = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
    Element request = new Element.XMLElement(MailConstants.MODIFY_FILTER_RULES_REQUEST);
    Element rules = request.addNonUniqueElement(MailConstants.E_FILTER_RULES);
    Element rule = rules.addNonUniqueElement(MailConstants.E_FILTER_RULE);
    rule.addAttribute(MailConstants.A_ACTIVE, true);
    rule.addAttribute(MailConstants.A_NAME, "Test1");
    Element filteraction = rule.addNonUniqueElement(MailConstants.E_FILTER_ACTIONS);
    Element actionInto = filteraction.addNonUniqueElement(MailConstants.E_ACTION_FILE_INTO);
    actionInto.addAttribute(MailConstants.A_FOLDER_PATH, "Junk");
    filteraction.addNonUniqueElement(MailConstants.E_ACTION_STOP);
    Element filterTests = rule.addNonUniqueElement(MailConstants.E_FILTER_TESTS);
    filterTests.addAttribute(MailConstants.A_CONDITION, "anyof");
    Element addressTest = filterTests.addNonUniqueElement(MailConstants.E_ADDRESS_TEST);
    addressTest.addAttribute(MailConstants.A_HEADER, "from");
    addressTest.addAttribute(MailConstants.A_VALUE_COMPARISON, "eq");
    addressTest.addAttribute(MailConstants.A_CASE_SENSITIVE, "true");
    addressTest.addAttribute(MailConstants.A_VALUE, "abCD");
    try {
        new ModifyFilterRules().handle(request, ServiceTestUtil.getRequestContext(acct));
    } catch (ServiceException e) {
        fail("This test is expected not to throw exception. ");
    }
    String expectedScript = "require [\"fileinto\", \"copy\", \"reject\", \"tag\", \"flag\", \"variables\", \"log\", \"enotify\", \"envelope\", \"body\", \"ereject\", \"reject\", \"relational\", \"comparator-i;ascii-numeric\"];\n\n";
    expectedScript += "# Test1\n";
    expectedScript += "if anyof (address :value \"eq\" :all :comparator \"i;octet\" [\"from\"] \"abCD\") {\n";
    expectedScript += "    fileinto \"Junk\";\n";
    expectedScript += "    stop;\n";
    expectedScript += "}\n";
    ZimbraLog.filter.info(acct.getMailSieveScript());
    ZimbraLog.filter.info(expectedScript);
    assertEquals(expectedScript, acct.getMailSieveScript());
}
Also used : Account(com.zimbra.cs.account.Account) ModifyFilterRules(com.zimbra.cs.service.mail.ModifyFilterRules) ServiceException(com.zimbra.common.service.ServiceException) Element(com.zimbra.common.soap.Element) Test(org.junit.Test)

Example 22 with Account

use of com.zimbra.cs.account.Account in project zm-mailbox by Zimbra.

the class ValueComparisonTest method testEnvelopeTestStringComparisonCaseSensitivity.

/**
 * Tests rule creation through ModifyFilterRulesRequest for envelope test having caseSensitive attribute with
 * string comparison
 * @throws Exception
 */
@Test
public void testEnvelopeTestStringComparisonCaseSensitivity() throws Exception {
    Account acct = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
    Element request = new Element.XMLElement(MailConstants.MODIFY_FILTER_RULES_REQUEST);
    Element rules = request.addNonUniqueElement(MailConstants.E_FILTER_RULES);
    Element rule = rules.addNonUniqueElement(MailConstants.E_FILTER_RULE);
    rule.addAttribute(MailConstants.A_ACTIVE, true);
    rule.addAttribute(MailConstants.A_NAME, "Test1");
    Element filteraction = rule.addNonUniqueElement(MailConstants.E_FILTER_ACTIONS);
    Element actionInto = filteraction.addNonUniqueElement(MailConstants.E_ACTION_FILE_INTO);
    actionInto.addAttribute(MailConstants.A_FOLDER_PATH, "Junk");
    filteraction.addNonUniqueElement(MailConstants.E_ACTION_STOP);
    Element filterTests = rule.addNonUniqueElement(MailConstants.E_FILTER_TESTS);
    filterTests.addAttribute(MailConstants.A_CONDITION, "anyof");
    Element envelopeTest = filterTests.addNonUniqueElement(MailConstants.E_ENVELOPE_TEST);
    envelopeTest.addAttribute(MailConstants.A_HEADER, "from");
    envelopeTest.addAttribute(MailConstants.A_STRING_COMPARISON, "contains");
    envelopeTest.addAttribute(MailConstants.A_CASE_SENSITIVE, "true");
    envelopeTest.addAttribute(MailConstants.A_VALUE, "abCD");
    try {
        new ModifyFilterRules().handle(request, ServiceTestUtil.getRequestContext(acct));
    } catch (ServiceException e) {
        fail("This test is expected not to throw exception. ");
    }
    String expectedScript = "require [\"fileinto\", \"copy\", \"reject\", \"tag\", \"flag\", \"variables\", \"log\", \"enotify\", \"envelope\", \"body\", \"ereject\", \"reject\", \"relational\", \"comparator-i;ascii-numeric\"];\n\n";
    expectedScript += "# Test1\n";
    expectedScript += "if anyof (envelope :all :contains :comparator \"i;octet\" [\"from\"] \"abCD\") {\n";
    expectedScript += "    fileinto \"Junk\";\n";
    expectedScript += "    stop;\n";
    expectedScript += "}\n";
    ZimbraLog.filter.info(acct.getMailSieveScript());
    ZimbraLog.filter.info(expectedScript);
    assertEquals(expectedScript, acct.getMailSieveScript());
}
Also used : Account(com.zimbra.cs.account.Account) ModifyFilterRules(com.zimbra.cs.service.mail.ModifyFilterRules) ServiceException(com.zimbra.common.service.ServiceException) Element(com.zimbra.common.soap.Element) Test(org.junit.Test)

Example 23 with Account

use of com.zimbra.cs.account.Account in project zm-mailbox by Zimbra.

the class ValueComparisonTest method testHeaderTestStringComparisonCaseSensitivity.

/**
 * Tests rule creation through ModifyFilterRulesRequest for header test having caseSensitive attribute with
 * string comparison
 * @throws Exception
 */
@Test
public void testHeaderTestStringComparisonCaseSensitivity() throws Exception {
    Account acct = Provisioning.getInstance().get(Key.AccountBy.name, "test@zimbra.com");
    Element request = new Element.XMLElement(MailConstants.MODIFY_FILTER_RULES_REQUEST);
    Element rules = request.addNonUniqueElement(MailConstants.E_FILTER_RULES);
    Element rule = rules.addNonUniqueElement(MailConstants.E_FILTER_RULE);
    rule.addAttribute(MailConstants.A_ACTIVE, true);
    rule.addAttribute(MailConstants.A_NAME, "Test1");
    Element filteraction = rule.addNonUniqueElement(MailConstants.E_FILTER_ACTIONS);
    Element actionInto = filteraction.addNonUniqueElement(MailConstants.E_ACTION_FILE_INTO);
    actionInto.addAttribute(MailConstants.A_FOLDER_PATH, "Junk");
    filteraction.addNonUniqueElement(MailConstants.E_ACTION_STOP);
    Element filterTests = rule.addNonUniqueElement(MailConstants.E_FILTER_TESTS);
    filterTests.addAttribute(MailConstants.A_CONDITION, "anyof");
    Element headerTest = filterTests.addNonUniqueElement(MailConstants.E_HEADER_TEST);
    headerTest.addAttribute(MailConstants.A_HEADER, "subject");
    headerTest.addAttribute(MailConstants.A_STRING_COMPARISON, "contains");
    headerTest.addAttribute(MailConstants.A_CASE_SENSITIVE, "true");
    headerTest.addAttribute(MailConstants.A_VALUE, "Important");
    try {
        new ModifyFilterRules().handle(request, ServiceTestUtil.getRequestContext(acct));
    } catch (ServiceException e) {
        fail("This test is expected not to throw exception. ");
    }
    String expectedScript = "require [\"fileinto\", \"copy\", \"reject\", \"tag\", \"flag\", \"variables\", \"log\", \"enotify\", \"envelope\", \"body\", \"ereject\", \"reject\", \"relational\", \"comparator-i;ascii-numeric\"];\n\n";
    expectedScript += "# Test1\n";
    expectedScript += "if anyof (header :contains :comparator \"i;octet\" [\"subject\"] \"Important\") {\n";
    expectedScript += "    fileinto \"Junk\";\n";
    expectedScript += "    stop;\n";
    expectedScript += "}\n";
    ZimbraLog.filter.info(acct.getMailSieveScript());
    ZimbraLog.filter.info(expectedScript);
    assertEquals(expectedScript, acct.getMailSieveScript());
}
Also used : Account(com.zimbra.cs.account.Account) ModifyFilterRules(com.zimbra.cs.service.mail.ModifyFilterRules) ServiceException(com.zimbra.common.service.ServiceException) Element(com.zimbra.common.soap.Element) Test(org.junit.Test)

Example 24 with Account

use of com.zimbra.cs.account.Account in project zm-mailbox by Zimbra.

the class ValueComparisonTest method testGetRuleEnvelopeTestValueComparisonCaseSensitivity.

/**
 * Tests GetFilterRulesRequest for rule containing envelope test and caseSensitive attribute with
 * value comparison
 * @throws Exception
 */
@Test
public void testGetRuleEnvelopeTestValueComparisonCaseSensitivity() throws Exception {
    try {
        String filterScript = "require [\"fileinto\", \"copy\", \"reject\", \"tag\", \"flag\", \"variables\", \"log\", \"enotify\", \"envelope\", \"body\", \"ereject\", \"reject\", \"relational\", \"comparator-i;ascii-numeric\"];\n\n";
        filterScript += "if anyof (envelope :value \"eq\" :all :comparator \"i;octet\" [\"from\"] \"abCD\") {\n";
        filterScript += "    fileinto \"Junk\";\n";
        filterScript += "    stop;\n";
        filterScript += "}\n";
        ZimbraLog.filter.info(filterScript);
        Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
        RuleManager.clearCachedRules(account);
        account.setMailSieveScript(filterScript);
        Element request = new Element.XMLElement(MailConstants.GET_FILTER_RULES_REQUEST);
        Element response = new GetFilterRules().handle(request, ServiceTestUtil.getRequestContext(account));
        String expectedSoapResponse = "<GetFilterRulesResponse xmlns=\"urn:zimbraMail\"> \n" + "<filterRules> \n" + "<filterRule active=\"1\"> \n" + "<filterTests condition=\"anyof\"> \n" + "<envelopeTest valueComparison=\"eq\" caseSensitive=\"1\" part=\"all\" header=\"from\" index=\"0\" valueComparisonComparator=\"i;octet\" value=\"abCD\"/> \n" + "</filterTests> \n" + "<filterActions> \n" + " <actionFileInto folderPath=\"Junk\" index=\"0\" copy=\"0\"/> \n" + "  <actionStop index=\"1\"/> \n" + "</filterActions> \n" + "</filterRule> \n" + "</filterRules> \n" + "</GetFilterRulesResponse>";
        ZimbraLog.filter.info(response.prettyPrint());
        XMLDiffChecker.assertXMLEquals(expectedSoapResponse, response.prettyPrint());
    } catch (Exception e) {
        fail("No exception should be thrown" + e);
    }
}
Also used : Account(com.zimbra.cs.account.Account) GetFilterRules(com.zimbra.cs.service.mail.GetFilterRules) Element(com.zimbra.common.soap.Element) ServiceException(com.zimbra.common.service.ServiceException) Test(org.junit.Test)

Example 25 with Account

use of com.zimbra.cs.account.Account in project zm-mailbox by Zimbra.

the class ZimletUserPropertiesTest method save.

@Test
public void save() throws Exception {
    Provisioning prov = Provisioning.getInstance();
    Account account = prov.getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
    ZimletUserProperties prop = ZimletUserProperties.getProperties(account);
    prop.setProperty("phone", "123123", "aaaaaaaaaaaa");
    prop.setProperty("phone", "number", "bar");
    prop.saveProperties(account);
    String[] values = account.getZimletUserProperties();
    Arrays.sort(values);
    Assert.assertArrayEquals(new String[] { "phone:123123:aaaaaaaaaaaa", "phone:number:bar" }, values);
}
Also used : Account(com.zimbra.cs.account.Account) MockProvisioning(com.zimbra.cs.account.MockProvisioning) Provisioning(com.zimbra.cs.account.Provisioning) 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