Search in sources :

Example 36 with ZimbraMailAdapter

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;
}
Also used : Action(org.apache.jsieve.mail.Action) Message(com.zimbra.cs.mailbox.Message) DummyMailAdapter(com.zimbra.cs.filter.DummyMailAdapter) ZimbraMailAdapter(com.zimbra.cs.filter.ZimbraMailAdapter)

Example 37 with ZimbraMailAdapter

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

the class LinkedInTest 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) && ADDRESSES.contains(sender.emailPart.toLowerCase())) {
        return true;
    }
    return false;
}
Also used : DummyMailAdapter(com.zimbra.cs.filter.DummyMailAdapter) ZimbraMailAdapter(com.zimbra.cs.filter.ZimbraMailAdapter) ParsedAddress(com.zimbra.cs.mime.ParsedAddress)

Example 38 with ZimbraMailAdapter

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

the class HeaderTest method match.

protected boolean match(MailAdapter mail, String comparator, String matchType, List<String> headerNames, List<String> keys, SieveContext context) throws SieveException {
    if (mail instanceof DummyMailAdapter) {
        return true;
    }
    if (!(mail instanceof ZimbraMailAdapter)) {
        return false;
    }
    ZimbraMailAdapter zma = (ZimbraMailAdapter) mail;
    if (matchType.equals(MatchTypeTags.MATCHES_TAG)) {
        try {
            evaluateVarExp(zma, headerNames, SourceType.HEADER, keys);
        } catch (MessagingException e) {
            throw new SieveException("Exception occured while evaluating variable expression.", e);
        }
    }
    // Iterate over the header names looking for a match
    boolean isMatched = false;
    Iterator<String> headerNamesIter = headerNames.iterator();
    while (!isMatched && headerNamesIter.hasNext()) {
        List<String> values = zma.getMatchingHeader(headerNamesIter.next());
        if (MatchTypeTags.CONTAINS_TAG.equals(matchType) && values != null && values.isEmpty()) {
            isMatched = false;
        } else {
            isMatched = match(comparator, matchType, values, keys, context);
        }
    }
    return isMatched;
}
Also used : SieveException(org.apache.jsieve.exception.SieveException) MessagingException(javax.mail.MessagingException) DummyMailAdapter(com.zimbra.cs.filter.DummyMailAdapter) ZimbraMailAdapter(com.zimbra.cs.filter.ZimbraMailAdapter)

Example 39 with ZimbraMailAdapter

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

the class HeaderTest method replaceVariables.

/**
 * @param keys
 * @param mail
 * @return
 * @throws SyntaxException
 */
public static List<String> replaceVariables(List<String> keys, MailAdapter mail) throws SyntaxException {
    List<String> replacedVariables = new ArrayList<String>();
    if (!(mail instanceof ZimbraMailAdapter)) {
        return replacedVariables;
    }
    ZimbraMailAdapter zma = (ZimbraMailAdapter) mail;
    for (String key : keys) {
        String temp = FilterUtil.replaceVariables(zma, key);
        replacedVariables.add(temp);
    }
    return replacedVariables;
}
Also used : ArrayList(java.util.ArrayList) ZimbraMailAdapter(com.zimbra.cs.filter.ZimbraMailAdapter)

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