Search in sources :

Example 1 with ZimbraMailAdapter

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.resetValues();
            } else {
                throw new SyntaxException("Invalid tag: [" + tagValue + "]");
            }
        }
    }
    return null;
}
Also used : TagArgument(org.apache.jsieve.TagArgument) StringListArgument(org.apache.jsieve.StringListArgument) Argument(org.apache.jsieve.Argument) SyntaxException(org.apache.jsieve.exception.SyntaxException) TagArgument(org.apache.jsieve.TagArgument) ZimbraMailAdapter(com.zimbra.cs.filter.ZimbraMailAdapter)

Example 2 with ZimbraMailAdapter

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;
    Require.checkCapability(mailAdapter, CAPABILITY_VARIABLES);
    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)) {
                checkCapability(mailAdapter, 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;
}
Also used : TagArgument(org.apache.jsieve.TagArgument) Argument(org.apache.jsieve.Argument) StringListArgument(org.apache.jsieve.StringListArgument) TagArgument(org.apache.jsieve.TagArgument) ZimbraMailAdapter(com.zimbra.cs.filter.ZimbraMailAdapter)

Example 3 with ZimbraMailAdapter

use of com.zimbra.cs.filter.ZimbraMailAdapter in project zm-mailbox by Zimbra.

the class Stop 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;
    mailAdapter.setStop(true);
    return super.executeBasic(mail, arguments, block, context);
}
Also used : ZimbraMailAdapter(com.zimbra.cs.filter.ZimbraMailAdapter)

Example 4 with ZimbraMailAdapter

use of com.zimbra.cs.filter.ZimbraMailAdapter in project zm-mailbox by Zimbra.

the class SocialcastTest 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;
    ParsedMessage pm = adapter.getParsedMessage();
    ParsedAddress sender = pm.getParsedSender();
    if (!Strings.isNullOrEmpty(sender.emailPart) && sender.emailPart.endsWith("@socialcast.com")) {
        try {
            if (pm.getMimeMessage().getHeader("Reply-To", null) != null) {
                // test if Reply-To exists
                return true;
            }
        } catch (MessagingException ignore) {
        }
    }
    return false;
}
Also used : MessagingException(javax.mail.MessagingException) ParsedMessage(com.zimbra.cs.mime.ParsedMessage) DummyMailAdapter(com.zimbra.cs.filter.DummyMailAdapter) ZimbraMailAdapter(com.zimbra.cs.filter.ZimbraMailAdapter) ParsedAddress(com.zimbra.cs.mime.ParsedAddress)

Example 5 with ZimbraMailAdapter

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;
}
Also used : DummyMailAdapter(com.zimbra.cs.filter.DummyMailAdapter) ZimbraMailAdapter(com.zimbra.cs.filter.ZimbraMailAdapter) ParsedAddress(com.zimbra.cs.mime.ParsedAddress)

Aggregations

ZimbraMailAdapter (com.zimbra.cs.filter.ZimbraMailAdapter)39 DummyMailAdapter (com.zimbra.cs.filter.DummyMailAdapter)20 StringListArgument (org.apache.jsieve.StringListArgument)15 Argument (org.apache.jsieve.Argument)12 MessagingException (javax.mail.MessagingException)9 TagArgument (org.apache.jsieve.TagArgument)9 SyntaxException (org.apache.jsieve.exception.SyntaxException)9 ServiceException (com.zimbra.common.service.ServiceException)8 ArrayList (java.util.ArrayList)8 SieveException (org.apache.jsieve.exception.SieveException)7 Mailbox (com.zimbra.cs.mailbox.Mailbox)4 ParsedAddress (com.zimbra.cs.mime.ParsedAddress)4 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)4 InternetAddress (com.zimbra.common.mime.InternetAddress)3 Account (com.zimbra.cs.account.Account)3 ZimbraComparatorUtils (com.zimbra.cs.filter.ZimbraComparatorUtils)3 ZimbraSieveException (com.zimbra.cs.filter.ZimbraSieveException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 Message (com.zimbra.cs.mailbox.Message)2 IOException (java.io.IOException)2