use of com.zimbra.soap.mail.type.FilterRule in project zm-mailbox by Zimbra.
the class ModifyFilterRulesTest method testBug92309_SetIncomingXMLRules_EmptyAddress.
/**
* Bug 92309: text "null" was set to To/Cc/From field
*
* When the To, Cc, or From field in the message filter rule
* composing dialogue window is left empty, ZWC automatically
* put a text "null" to the filed. This test case tests that
* the text "null" will not be set if the To/Cc/From field
* is empty.
*/
@Test
public void testBug92309_SetIncomingXMLRules_EmptyAddress() {
try {
Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
RuleManager.clearCachedRules(account);
// Construct a filter rule with 'address' test whose value is empty (null)
FilterRule rule = new FilterRule("testSetIncomingXMLRules_EmptyAddress", true);
FilterTest.AddressTest test = new FilterTest.AddressTest();
test.setHeader("to");
test.setStringComparison("is");
test.setPart("all");
test.setValue(null);
test.setIndex(0);
FilterTests tests = new FilterTests("anyof");
tests.addTest(test);
FilterAction action = new FilterAction.KeepAction();
action.setIndex(0);
rule.setFilterTests(tests);
rule.addFilterAction(action);
List<FilterRule> filterRuleList = new ArrayList<FilterRule>();
filterRuleList.add(rule);
// When the ModifyFilterRulesRequest is submitted from the Web client,
// eventually this RuleManager.setIncomingXMLRules is called to convert
// the request in JSON to the SIEVE rule text.
RuleManager.setIncomingXMLRules(account, filterRuleList);
// Verify that the saved zimbraMailSieveScript
String sieve = account.getMailSieveScript();
int result = sieve.indexOf("address :all :is :comparator \"i;ascii-casemap\" [\"to\"] \"\"");
Assert.assertNotSame(-1, result);
} catch (Exception e) {
fail("No exception should be thrown" + e);
}
}
use of com.zimbra.soap.mail.type.FilterRule in project zm-mailbox by Zimbra.
the class ModifyFilterRulesTest method SetIncomingXMLRulesForEnvelopeCountComparison.
@Test
public void SetIncomingXMLRulesForEnvelopeCountComparison() {
try {
Account account = Provisioning.getInstance().getAccount(MockProvisioning.DEFAULT_ACCOUNT_ID);
RuleManager.clearCachedRules(account);
// Construct a filter rule with 'address' test whose value is empty (null)
FilterRule rule = new FilterRule("testSetIncomingXMLRulesForEnvelope", true);
FilterTest.EnvelopeTest test = new FilterTest.EnvelopeTest();
test.setHeader("to");
test.setCountComparison("eq");
test.setPart("all");
test.setValue("1");
test.setIndex(0);
FilterTests tests = new FilterTests("anyof");
tests.addTest(test);
FilterAction action = new FilterAction.KeepAction();
action.setIndex(0);
rule.setFilterTests(tests);
rule.addFilterAction(action);
List<FilterRule> filterRuleList = new ArrayList<FilterRule>();
filterRuleList.add(rule);
// When the ModifyFilterRulesRequest is submitted from the Web client,
// eventually this RuleManager.setIncomingXMLRules is called to convert
// the request in JSON to the SIEVE rule text.
RuleManager.setIncomingXMLRules(account, filterRuleList);
// Verify that the saved zimbraMailSieveScript
String sieve = account.getMailSieveScript();
int result = sieve.indexOf("envelope :count \"eq\" :all :comparator \"i;ascii-numeric\" [\"to\"] \"1\"");
Assert.assertNotSame(-1, result);
} catch (Exception e) {
fail("No exception should be thrown" + e);
}
}
use of com.zimbra.soap.mail.type.FilterRule in project zm-mailbox by Zimbra.
the class SieveToSoap method visitRule.
@Override
protected void visitRule(Node ruleNode, VisitPhase phase, RuleProperties props) {
if (phase == VisitPhase.end) {
return;
}
if (!isNestedRule()) {
currentRule = new FilterRule(getCurrentRuleName(), props.isEnabled);
setCurrentVariables();
if (actionVariables != null && !actionVariables.isEmpty()) {
currentRule.addFilterAction(new FilterVariables(actionVariables));
}
if (actionVariables != null && !actionVariables.isEmpty()) {
currentRule.addFilterAction(new FilterVariables(actionVariables));
}
currentRule.setFilterTests(new FilterTests(props.condition.toString()));
rules.add(currentRule);
currentRuleIndex++;
// When start working on the root rule, initialise the pointer to nested rule
currentNestedRule = null;
} else {
// set new Nested Rule instance as child of current one.
NestedRule nestedRule = new NestedRule(new FilterTests(props.condition.toString()));
if (currentNestedRule != null) {
// some nested rule has been already processed
// set it as child of previous one
currentNestedRule.setChild(nestedRule);
setCurrentVariables();
if (actionVariables != null && !actionVariables.isEmpty()) {
currentNestedRule.addFilterAction(new FilterVariables(actionVariables));
}
} else {
// first nested rule
// set it as child of root rule
currentRule.setChild(nestedRule);
setCurrentVariables();
if (actionVariables != null && !actionVariables.isEmpty()) {
currentRule.addFilterAction(new FilterVariables(actionVariables));
}
}
currentNestedRule = nestedRule;
actionVariables = null;
}
}
Aggregations