Search in sources :

Example 16 with DummyMailAdapter

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

the class FacebookTest 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.endsWith("@facebookmail.com") && email.startsWith("notification+")) {
            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 17 with DummyMailAdapter

use of com.zimbra.cs.filter.DummyMailAdapter 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 18 with DummyMailAdapter

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

Example 19 with DummyMailAdapter

use of com.zimbra.cs.filter.DummyMailAdapter 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]
     *         &lt;header-list: string-list&gt; &lt;key-list: string-list&gt;
     * </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);
    }
}
Also used : SieveException(org.apache.jsieve.exception.SieveException) MessagingException(javax.mail.MessagingException) DummyMailAdapter(com.zimbra.cs.filter.DummyMailAdapter) ZimbraComparatorUtils(com.zimbra.cs.filter.ZimbraComparatorUtils) ZimbraMailAdapter(com.zimbra.cs.filter.ZimbraMailAdapter)

Aggregations

DummyMailAdapter (com.zimbra.cs.filter.DummyMailAdapter)19 ZimbraMailAdapter (com.zimbra.cs.filter.ZimbraMailAdapter)19 ServiceException (com.zimbra.common.service.ServiceException)6 MessagingException (javax.mail.MessagingException)5 Mailbox (com.zimbra.cs.mailbox.Mailbox)4 ParsedAddress (com.zimbra.cs.mime.ParsedAddress)4 ArrayList (java.util.ArrayList)4 Argument (org.apache.jsieve.Argument)4 StringListArgument (org.apache.jsieve.StringListArgument)4 TagArgument (org.apache.jsieve.TagArgument)4 SyntaxException (org.apache.jsieve.exception.SyntaxException)4 InternetAddress (com.zimbra.common.mime.InternetAddress)3 ZimbraComparatorUtils (com.zimbra.cs.filter.ZimbraComparatorUtils)3 ZimbraSieveException (com.zimbra.cs.filter.ZimbraSieveException)3 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)3 SieveException (org.apache.jsieve.exception.SieveException)3 Message (com.zimbra.cs.mailbox.Message)2 ParseException (java.text.ParseException)2 Calendar (java.util.Calendar)2 Date (java.util.Date)2