use of com.zimbra.cs.filter.ZimbraMailAdapter in project zm-mailbox by Zimbra.
the class FlaggedTest method executeBasic.
@Override
protected boolean executeBasic(MailAdapter mail, Arguments args, SieveContext ctx) throws SieveException {
assert (flags != null);
if (mail instanceof DummyMailAdapter) {
return true;
}
if (!(mail instanceof ZimbraMailAdapter)) {
return false;
}
ZimbraMailAdapter adapter = (ZimbraMailAdapter) mail;
// check actions already taken by a previous filter
for (Action action : adapter.getActions()) {
if (action instanceof ActionFlag) {
if (flags.contains(action)) {
return true;
}
}
}
// check the message's flags if this filter is running against the existing messages
Message msg = adapter.getMessage();
if (msg != null) {
int bitmask = msg.getFlagBitmask();
return bitmask == FilterUtil.getFlagBitmask(flags, bitmask);
}
return false;
}
use of com.zimbra.cs.filter.ZimbraMailAdapter in project zm-mailbox by Zimbra.
the class BodyTest method executeBasic.
@Override
protected boolean executeBasic(MailAdapter mail, Arguments arguments, SieveContext context) throws SieveException {
String comparison = null;
boolean caseSensitive = false;
String key = null;
@SuppressWarnings("unchecked") ListIterator<Argument> argumentsIter = arguments.getArgumentList().listIterator();
// TODO: handles ":matches" with * and ?
if (argumentsIter.hasNext()) {
Object argument = argumentsIter.next();
if (argument instanceof TagArgument) {
String tag = ((TagArgument) argument).getTag();
if (tag.equals(CONTAINS))
comparison = tag;
else
throw new SyntaxException("Found unexpected TagArgument: \"" + tag + "\"");
}
}
if (null == comparison)
throw new SyntaxException("Expecting \"" + CONTAINS + "\"");
// Second argument could be :comparator tag or else the value (string)
if (argumentsIter.hasNext()) {
Object argument = argumentsIter.next();
if (argument instanceof TagArgument) {
String tag = ((TagArgument) argument).getTag();
if (tag.equals(COMPARATOR)) {
if (argumentsIter.hasNext()) {
argument = argumentsIter.next();
if (argument instanceof StringListArgument) {
StringListArgument strList = (StringListArgument) argument;
try {
caseSensitive = Sieve.Comparator.ioctet == Sieve.Comparator.fromString(strList.getList().get(0));
} catch (ServiceException e) {
throw new SyntaxException(e.getMessage());
}
// Move to the last argument
if (argumentsIter.hasNext())
argument = argumentsIter.next();
} else {
throw new SyntaxException("Found unexpected argument after :comparator");
}
} else {
throw new SyntaxException("Unexpected end of arguments");
}
} else {
throw new SyntaxException("Found unexpected TagArgument: \"" + tag + "\"");
}
}
if (argument instanceof StringListArgument) {
StringListArgument strList = (StringListArgument) argument;
key = strList.getList().get(0);
}
}
if (null == key)
throw new SyntaxException("Expecting a string");
// There MUST NOT be any further arguments
if (argumentsIter.hasNext())
throw new SyntaxException("Found unexpected argument(s)");
return mail instanceof ZimbraMailAdapter && test(mail, caseSensitive, key);
}
use of com.zimbra.cs.filter.ZimbraMailAdapter in project zm-mailbox by Zimbra.
the class CommunityAbstractTest method checkHeaderValue.
protected boolean checkHeaderValue(MailAdapter mail, Set<String> values) {
if (mail instanceof DummyMailAdapter) {
return true;
}
if (!(mail instanceof ZimbraMailAdapter)) {
return false;
}
ZimbraMailAdapter adapter = (ZimbraMailAdapter) mail;
List<String> header = adapter.getHeader(notificationTypeHeaderName);
if (!header.isEmpty()) {
for (String id : header) {
if (values.contains(id)) {
return true;
}
}
}
return false;
}
use of com.zimbra.cs.filter.ZimbraMailAdapter in project zm-mailbox by Zimbra.
the class AddressTest method executeBasic.
/**
* <p>
* From RFC 5228, Section 5.1...
* </p>
* <code>
* Syntax: address [ADDRESS-PART] [COMPARATOR] [MATCH-TYPE]
* <header-list: string-list> <key-list: string-list>
* </code>
*
* @see org.apache.jsieve.tests.AbstractComparatorTest#executeBasic(MailAdapter,
* Arguments, SieveContext)
*/
@Override
protected boolean executeBasic(MailAdapter mail, Arguments arguments, SieveContext context) throws SieveException {
if (mail instanceof DummyMailAdapter) {
return true;
}
if (!(mail instanceof ZimbraMailAdapter)) {
return false;
}
ZimbraComparatorUtils.TestParameters params = ZimbraComparatorUtils.parseTestArguments(mail, arguments, context);
params.setKeys(HeaderTest.replaceVariables(params.getKeys(), mail));
params.setHeaderNames(HeaderTest.replaceVariables(params.getHeaderNames(), mail));
for (String headerName : params.getHeaderNames()) {
FilterUtil.headerNameHasSpace(headerName);
}
if (MatchTypeTags.MATCHES_TAG.equals(params.getMatchType())) {
ZimbraMailAdapter zma = (ZimbraMailAdapter) mail;
try {
HeaderTest.evaluateVarExp(zma, params.getHeaderNames(), HeaderTest.SourceType.HEADER, params.getKeys());
} catch (MessagingException e) {
throw new SieveException("Exception occured while evaluating variable expression.", e);
}
}
if (COUNT_TAG.equals(params.getMatchType()) || VALUE_TAG.equals(params.getMatchType()) || IS_TAG.equalsIgnoreCase(params.getMatchType())) {
return match(mail, (params.getAddressPart() == null ? ALL_TAG : params.getAddressPart()), ZimbraComparatorUtils.getComparator(params.getComparator(), params.getMatchType()), params.getMatchType(), params.getOperator(), params.getHeaderNames(), params.getKeys(), context);
} else {
return match(mail, (params.getAddressPart() == null ? ALL_TAG : params.getAddressPart()), ZimbraComparatorUtils.getComparator(params.getComparator(), params.getMatchType()), (params.getMatchType() == null ? IS_TAG : params.getMatchType()), params.getHeaderNames(), params.getKeys(), context);
}
}
Aggregations