Search in sources :

Example 21 with Node

use of org.apache.jsieve.parser.generated.Node in project zm-mailbox by Zimbra.

the class RuleManager method folderRenamed.

private static void folderRenamed(Account account, String originalPath, String newPath, String sieveScriptAttrName, String rulesCacheKey) throws ServiceException {
    String script = getRules(account, sieveScriptAttrName);
    if (script != null) {
        Node node;
        try {
            node = parse(script);
        } catch (ParseException e) {
            ZimbraLog.filter.warn("Unable to update filter rules with new folder path '%s'.", e);
            return;
        }
        FolderRenamer renamer = new FolderRenamer(originalPath, newPath);
        renamer.accept(node);
        if (renamer.renamed()) {
            // Kind of a hacky way to convert a Node tree to a script.  We
            // convert to XML first, and then to a String.  Unfortunately
            // jSieve 0.2 doesn't have an API that generates a script from
            // a Node tree.
            List<String> ruleNames = getRuleNames(script);
            SieveToSoap sieveToSoap = new SieveToSoap(ruleNames);
            sieveToSoap.accept(node);
            SoapToSieve soapToSieve = new SoapToSieve(sieveToSoap.toFilterRules());
            String newScript = soapToSieve.getSieveScript();
            setRules(account, newScript, sieveScriptAttrName, rulesCacheKey);
            ZimbraLog.filter.info("Updated %s due to folder move or rename from %s to %s.", sieveScriptAttrName, originalPath, newPath);
            ZimbraLog.filter.debug("Old rules:\n%s, new rules:\n%s", script, newScript);
        }
    }
}
Also used : Node(org.apache.jsieve.parser.generated.Node) ParseException(org.apache.jsieve.parser.generated.ParseException)

Example 22 with Node

use of org.apache.jsieve.parser.generated.Node in project zm-mailbox by Zimbra.

the class RuleManager method folderDeleted.

private static void folderDeleted(Account account, String originalPath, String sieveScriptAttrName, String rulesCacheKey) throws ServiceException {
    String script = getRules(account, sieveScriptAttrName);
    if (script != null) {
        Node node;
        try {
            node = parse(script);
        } catch (ParseException e) {
            ZimbraLog.filter.warn("Unable to update filter rules after folder '%s' was deleted.", originalPath, e);
            return;
        }
        FolderDeleted deleted = new FolderDeleted(originalPath);
        deleted.accept(node);
        if (deleted.modified()) {
            // Kind of a hacky way to convert a Node tree to a script.  We
            // convert to XML first, and then to a String.  Unfortunately
            // jSieve 0.2 doesn't have an API that generates a script from
            // a Node tree.
            List<String> ruleNames = getRuleNames(script);
            SieveToSoap sieveToSoap = new SieveToSoap(ruleNames);
            sieveToSoap.accept(node);
            SoapToSieve soapToSieve = new SoapToSieve(sieveToSoap.toFilterRules());
            String newScript = soapToSieve.getSieveScript();
            setRules(account, newScript, sieveScriptAttrName, rulesCacheKey);
            ZimbraLog.filter.info("Updated %s filter rules after folder %s was deleted.", sieveScriptAttrName, originalPath);
            ZimbraLog.filter.debug("Old rules:\n%s, new rules:\n%s", script, newScript);
        }
    }
}
Also used : Node(org.apache.jsieve.parser.generated.Node) ParseException(org.apache.jsieve.parser.generated.ParseException)

Aggregations

Node (org.apache.jsieve.parser.generated.Node)22 ParseException (org.apache.jsieve.parser.generated.ParseException)10 SieveNode (org.apache.jsieve.parser.SieveNode)9 TokenMgrError (org.apache.jsieve.parser.generated.TokenMgrError)6 Mountpoint (com.zimbra.cs.mailbox.Mountpoint)5 ArrayList (java.util.ArrayList)5 Account (com.zimbra.cs.account.Account)4 ServiceException (com.zimbra.common.service.ServiceException)3 Element (com.zimbra.common.soap.Element)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 SieveException (org.apache.jsieve.exception.SieveException)3 ASTcommand (org.apache.jsieve.parser.generated.ASTcommand)3 DeliveryServiceException (com.zimbra.common.service.DeliveryServiceException)2 ErejectException (com.zimbra.cs.filter.jsieve.ErejectException)2 Message (com.zimbra.cs.mailbox.Message)2 ParsedMessage (com.zimbra.cs.mime.ParsedMessage)2 ItemId (com.zimbra.cs.service.util.ItemId)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 List (java.util.List)2