Zimbra offers Open Source email server software and shared calendar for Linux and the Mac
Go Back   Zimbra :: Forums > Zimbra Collaboration Suite > Administrators

Welcome to the Zimbra :: Forums!
Welcome, if you would like to post a comment please register. We also encourage you to explore all things Zimbra with our team and members of the community.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-19-2011, 11:16 PM
Special Member
 
Posts: 149
Default copy filterrules to another user

Hello,

I need to copy filter rules of one user to another user, there are nearly 100 rules! I understand this can be achieved with 'zimbraMailSieveScript' but could not find how to export and to import into another. Can anybody please tell me syntax for the same?

Thanks in advance.

Dipesh
Reply With Quote
  #2 (permalink)  
Old 07-20-2011, 01:54 AM
Senior Member
 
Posts: 50
Default

A couple of shell commands are enough


Code:
zmmailbox -z -m source_mailbox@domain.org > filters.txt
sed -i 's/^/afrl /' filters.txt
zmmailbox -z -m destination_mailbox@domain.org < filters.txt
First line extracts all the filter rules from the source mailbox to a file
Second line adds 'afrl ' (Add Filter RuLe) at the beginning of each line in the file
Third line executes zmmailbox for each line of the files, adding the filters on the destination account.

Remember that the filters must be 'logically' valid on the new account (e.g. if a filter moves mail to a folder, such folder must exist)

Be sure to check out the syntax in the file after the 'sed', run it on a test mailbox if you can
__________________
Cine - Community Manager - ZeXtras
www.zextras.com
Reply With Quote
  #3 (permalink)  
Old 07-20-2011, 04:25 AM
Special Member
 
Posts: 149
Default

Thanks for your guidance.

Quote:
Originally Posted by Cine.ZxCommunity View Post
Code:
zmmailbox -z -m source_mailbox@domain.org > filters.txt
First line extracts all the filter rules from the source mailbox to a file
Sorry but this didn't work. Executing command as zimbra user throws permission error
Code:
zimbra@mail:~$ zmmailbox -z -m user1@domain.com > filters.txt
-su: filters.txt: Permission denied
and running as root it gives 'command not found'
Reply With Quote
  #4 (permalink)  
Old 07-20-2011, 04:47 AM
Zimbra Consultant & Moderator
 
Posts: 20,314
Default

Quote:
Originally Posted by dipeshmehta View Post
Sorry but this didn't work.
Of course it works.

Quote:
Originally Posted by dipeshmehta View Post
Executing command as zimbra user throws permission error
Code:
zimbra@mail:~$ zmmailbox -z -m user1@domain.com > filters.txt
-su: filters.txt: Permission denied
I guess you wrote the output file to a directory which the zimbra user actually has write permission?

Quote:
Originally Posted by dipeshmehta View Post
....and running as root it gives 'command not found'
That's hardly surprising as the vast majority of the zm* commands are run by the zimbra user.
__________________
Regards


Bill
Reply With Quote
  #5 (permalink)  
Old 07-20-2011, 09:34 PM
Special Member
 
Posts: 149
Thumbs up

Quote:
Originally Posted by phoenix View Post
I guess you wrote the output file to a directory which the zimbra user actually has write permission?
Your guess was right, sometimes silly mistakes made. I just 'su - zimbra' and entered the command with in mind that zimbra user do not need permissions for /opt/zimbra.

Quote:
Originally Posted by Cine.ZxCommunity View Post
Code:
zmmailbox -z -m source_mailbox@domain.org > filters.txt
Well, I needed to modify it little:
Code:
zmmailbox -z -m source_mailbox@domain.org gfrl > filters.txt
Rest two commands worked well, and finally all filters were copied as needed.

Thanks a lot, this saved my lot time.

Dipesh
Reply With Quote
  #6 (permalink)  
Old 12-21-2011, 12:10 AM
Advanced Member
 
Posts: 214
Default Script

Hello guys

Because i need that sometimes i thought hey why not make a little script
i know i know its a sbolute overkill but hey its just quick and dirty and prevent hopefully most errors

have fun

Code:
#!/bin/bash
#adjust this 2 values - zimbra need write perm in tmp path
#logs getting saved in your log directory as zmcopyfilter_last.log and zmcopyfilter.log

zpath="/opt/zimbra" #zimbra dir without trailing /
tmp="/tmp" #temp dir to write for zimbra user without trailing /
##############################donttouchfromhere########################################

fnstart(){
clear;
echo "Simple copy Filter Script"
echo -e "\n\n\n\n\n"
read -p "Source Username: " vus
read -p "Destination Username: " vud
fnask;
}

fnask(){
   clear;
   echo -e "\n\n\n\n\n"
   echo "Copy Filter from: " $vus
   echo "To User:          " $vud
   echo "(P)roceed or (A)bort or (R)estart"
   read -s -n 1 qpa
       case $qpa in
           p|P)fngo;;
           a|A)fnbye;;
           r|R)fnrestart;;
           *)fnask;;
   esac
}
fnrestart() {
   vus=""
   vud=""
   fnstart;
}
fnbye(){
   clear
   echo -e "\n\n\n\n\n"
   echo "Aborted no Harm done - Have a Nice Day"
   exit;
}
fngo(){
rm -f $tmp/tmpfiltercopy.txt
zmmailbox -z -m $vus gfrl > $tmp/tmpfiltercopy.txt
sed -i 's/^/afrl /' $tmp/tmpfiltercopy.txt
zmmailbox -z -m $vud < $tmp/tmpfiltercopy.txt >$zpath/log/zmcopyfilter_last.log
cat $zpath/log/zmcopyfilter_last.log >> $zpath/log/zmcopyfilter.log
clear
   echo -e "\n\n\n\n\n"
   echo "Work done hopefully nothing dead - Have a Nice Day"
   exit;
}
fnstart
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads

Why Join?

Registering let's you ask questions, makes it easier to search, displays any files attached to posts, and notifies you about replies.

blog.zimbra.com




 

SEO by vBSEO ©2011, Crawlability, Inc.