use of org.apache.jsieve.parser.generated.ParseException in project zm-mailbox by Zimbra.
the class RuleManager method getAdminRulesAsXML.
public static List<FilterRule> getAdminRulesAsXML(Entry entry, FilterType filterType, AdminFilterType afType) throws ServiceException {
Node node;
try {
node = getRulesNode(entry, filterType, afType);
} catch (ParseException | TokenMgrError e) {
throw ServiceException.PARSE_ERROR("parsing Sieve script", e);
}
String sieveScriptAttrName = getAdminScriptAttributeName(filterType, afType);
SieveToSoap sieveToSoap = new SieveToSoap(getRuleNames(entry.getAttr(sieveScriptAttrName)));
sieveToSoap.accept(node);
return sieveToSoap.toFilterRules();
}
use of org.apache.jsieve.parser.generated.ParseException 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);
}
}
}
use of org.apache.jsieve.parser.generated.ParseException 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);
}
}
}
Aggregations