use of com.zimbra.cs.filter.ZimbraMailAdapter in project zm-mailbox by Zimbra.
the class TwitterTest method executeBasic.
@Override
protected boolean executeBasic(MailAdapter mail, Arguments args, SieveContext ctx) throws SieveException {
if (mail instanceof DummyMailAdapter) {
return true;
}
if (!(mail instanceof ZimbraMailAdapter)) {
return false;
}
ZimbraMailAdapter adapter = (ZimbraMailAdapter) mail;
ParsedAddress sender = adapter.getParsedMessage().getParsedSender();
if (!Strings.isNullOrEmpty(sender.emailPart)) {
String email = sender.emailPart.toLowerCase();
if (email.equals("notify@twitter.com")) {
return true;
}
}
return false;
}
use of com.zimbra.cs.filter.ZimbraMailAdapter in project zm-mailbox by Zimbra.
the class ZimbraVariablesCtrl method executeBasic.
@Override
protected Object executeBasic(MailAdapter mail, Arguments arguments, Block block, SieveContext context) throws SieveException {
if (!(mail instanceof ZimbraMailAdapter)) {
return null;
}
ZimbraMailAdapter mailAdapter = (ZimbraMailAdapter) mail;
for (Argument arg : arguments.getArgumentList()) {
if (arg instanceof TagArgument) {
TagArgument tag = (TagArgument) arg;
String tagValue = tag.getTag();
if (RESET.equalsIgnoreCase(tagValue)) {
mailAdapter.clearValues();
} else {
throw new SyntaxException("Invalid tag: [" + tagValue + "]");
}
}
}
return null;
}
use of com.zimbra.cs.filter.ZimbraMailAdapter in project zm-mailbox by Zimbra.
the class EnvelopeTest method match.
/**
* Compares the address with operator
*
* @param operator "gt" / "ge" / "lt" / "le" / "eq" / "ne"
*/
private boolean match(MailAdapter mail, String addressPart, String comparator, String matchType, String operator, List<String> headerNames, List<String> keys, SieveContext context) throws SieveException {
if (mail instanceof DummyMailAdapter) {
return true;
}
if (!(mail instanceof ZimbraMailAdapter)) {
return false;
}
// Iterate over the address fields looking for a match
boolean isMatched = false;
List<String> headerValues = Lists.newArrayListWithExpectedSize(2);
for (final String headerName : headerNames) {
if ("to".equalsIgnoreCase(headerName)) {
// RFC 5231 4.2. ... The envelope "to" will always have only one
// entry, which is the address of the user for whom the Sieve script
// is running.
String recipient = null;
try {
recipient = ((ZimbraMailAdapter) mail).getMailbox().getAccount().getMail();
} catch (ServiceException e) {
recipient = "";
}
headerValues.add(getMatchAddressPart(addressPart, recipient));
} else if ("from".equalsIgnoreCase(headerName)) {
List<String> values = getMatchingValues(mail, headerName);
if (values != null) {
if (matchType.equalsIgnoreCase(COUNT_TAG)) {
// RFC 5231 Section 4.2 Match Type COUNT says:
// | The envelope "from" will be 0 if the MAIL FROM is empty, or 1 if MAIL
// | FROM is not empty.
// This method could be called for other match type, such as :value or :is,
// remove the empty element only if the match type is :count.
values.removeIf(s -> Strings.isNullOrEmpty(s));
}
for (String value : values) {
headerValues.add(getMatchAddressPart(addressPart, value));
}
}
} else {
throw new SyntaxException("Unexpected header name as a value for <envelope-part>: '" + headerName + "'");
}
}
if (COUNT_TAG.equals(matchType)) {
for (final String key : keys) {
isMatched = ZimbraComparatorUtils.counts(comparator, operator, headerValues, ZimbraComparatorUtils.getMatchKey(addressPart, key), context);
if (isMatched) {
break;
}
}
} else {
Iterator headerValuesIter = headerValues.iterator();
while (!isMatched && headerValuesIter.hasNext()) {
List<String> normalizedKeys = Lists.newArrayListWithExpectedSize(keys.size());
if (DOMAIN_TAG.equalsIgnoreCase(addressPart)) {
for (String key : keys) {
normalizedKeys.add(key.toLowerCase());
}
} else {
normalizedKeys = keys;
}
isMatched = match(comparator, matchType, operator, (String) headerValuesIter.next(), normalizedKeys, context);
}
}
return isMatched;
}
use of com.zimbra.cs.filter.ZimbraMailAdapter in project zm-mailbox by Zimbra.
the class Reject method executeBasic.
@Override
protected Object executeBasic(MailAdapter mail, Arguments arguments, Block block, SieveContext context) throws SieveException {
if (!(mail instanceof ZimbraMailAdapter)) {
return null;
}
ZimbraMailAdapter mailAdapter = (ZimbraMailAdapter) mail;
Account account = null;
try {
account = mailAdapter.getMailbox().getAccount();
if (account.isSieveRejectMailEnabled()) {
mailAdapter.setDiscardActionPresent();
return super.executeBasic(mail, arguments, block, context);
} else {
mail.addAction(new ActionKeep());
}
} catch (ServiceException e) {
ZimbraLog.filter.warn("Exception in executing reject action", e);
}
return null;
}
use of com.zimbra.cs.filter.ZimbraMailAdapter in project zm-mailbox by Zimbra.
the class SetVariable method executeBasic.
@Override
protected Object executeBasic(MailAdapter mail, Arguments arguments, Block block, SieveContext context) throws SieveException {
if (!(mail instanceof ZimbraMailAdapter)) {
return null;
}
ZimbraMailAdapter mailAdapter = (ZimbraMailAdapter) mail;
this.validateArguments(arguments, context);
Map<String, String> existingVars = mailAdapter.getVariables();
List<String> matchedValues = mailAdapter.getMatchedValues();
String[] operations = new String[OPERATIONS_IDX];
String key = null;
String value = null;
int index = 0;
for (Argument a : arguments.getArgumentList()) {
if (a instanceof TagArgument) {
TagArgument tag = (TagArgument) a;
String tagValue = tag.getTag();
if (isValidModifier(tagValue)) {
operations[getIndex(tagValue)] = tagValue.toLowerCase();
}
} else {
String argument = ((StringListArgument) a).getList().get(0);
if (index == 0) {
key = FilterUtil.handleQuotedAndEncodedVar(argument);
} else {
if (argument.contains("${")) {
value = FilterUtil.replaceVariables(mailAdapter, argument);
} else {
value = argument;
}
}
++index;
}
}
value = applyModifiers(value, operations);
mailAdapter.addVariable(key, value);
return null;
}
Aggregations