About filter rules

Discuss your pilot or production implementation with other Zimbra admins or our engineers.
User avatar
DanielEugenin
Posts: 16
Joined: Thu Sep 19, 2013 9:51 am
Location: Chile
ZCS/ZD Version: 9.0.0_GA_3924.RHEL7_64_202003310103
Contact:

Re: About filter rules

Post by DanielEugenin »

Max Zamaraev wrote:
DanielEugenin wrote:Hi rojoblandino,.

I have an example without using xml file, just execute:

Code: Select all

zmsoap  -z -m user@domain.com ApplyFilterRulesRequest/filterRules/filterRule @name="Services" ../../query="in:/Inbox"
Where:
@name="Services" is the name of your filter created.
query => execute filter on /Inbox folder
Daniel, thanks for the brilliant idea!
Don't you know if there is the way to apply ALL active rules that user has? Rules in my case can be added or removed by user without notifications.

TIA

Something like this:

1) Get all active rules by user:

Code: Select all

zmsoap -z -m user@domain.com GetFilterRulesRequest/filterRules | grep "filterRule name" | grep "active=\"1\"" | cut -d"=" -f2 | sed 's/ active//g'
2) Use this information into script:

Code: Select all

zmsoap -z -m user@domain.com GetFilterRulesRequest/filterRules | grep "filterRule name" | grep "active=\"1\"" | cut -d"=" -f2 | sed 's/ active//g'` > /tmp/rules.tmp
while read rule; do 
    zmsoap  -z -m user@domain.com ApplyFilterRulesRequest/filterRules/filterRule @name="$rule" ../../query="in:/Inbox"
 done < /tmp/rules.tmp
Max Zamaraev
Posts: 2
Joined: Wed Jan 12, 2022 4:38 pm

Re: About filter rules

Post by Max Zamaraev »

DanielEugenin wrote:
Something like this:

1) Get all active rules by user:

Code: Select all

zmsoap -z -m user@domain.com GetFilterRulesRequest/filterRules | grep "filterRule name" | grep "active=\"1\"" | cut -d"=" -f2 | sed 's/ active//g'
2) Use this information into script:

Code: Select all

zmsoap -z -m user@domain.com GetFilterRulesRequest/filterRules | grep "filterRule name" | grep "active=\"1\"" | cut -d"=" -f2 | sed 's/ active//g'` > /tmp/rules.tmp
while read rule; do 
    zmsoap  -z -m user@domain.com ApplyFilterRulesRequest/filterRules/filterRule @name="$rule" ../../query="in:/Inbox"
 done < /tmp/rules.tmp
You are the best! Thank you very much, will try this way.
Caifo
Posts: 3
Joined: Wed Nov 14, 2018 7:02 am

Re: About filter rules

Post by Caifo »

Is there a way to apply a filter to the whole account? Command zmsoap ApplyFilterRulesRequest doesn’t like folder names with spaces, and the users of this server have bunch of those.

Thanks

—Álvaro
heiko.robert
Posts: 5
Joined: Wed Aug 31, 2022 2:54 pm

Re: About filter rules

Post by heiko.robert »

doing the same using xmlstarlet (apt install xmlstarlet) to parse the xml output in a more reliable way:

Code: Select all

ACTIVE_FILTERS=$(zmsoap -z -m $ADDR GetFilterRulesRequest/filterRules | xmlstarlet sel -t  -v "_:GetFilterRulesResponse/_:filterRules/_:filterRule[@active=1]/@name")
for f in $ACTIVE_FILTERS;do
    zmsoap  -z -m $ADDR ApplyFilterRulesRequest/filterRules/filterRule @name="$f" ../../query="in:/Inbox"
done
Post Reply