Results 1 to 6 of 6

Thread: copy filterrules to another user

  1. #1
    dipeshmehta is offline Special Member
    Join Date
    Jun 2010
    Location
    Rajkot, India
    Posts
    160
    Rep Power
    5

    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

  2. #2
    Cine.ZxCommunity's Avatar
    Cine.ZxCommunity is offline Senior Member
    Join Date
    Jul 2011
    Posts
    55
    Rep Power
    4

    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

  3. #3
    dipeshmehta is offline Special Member
    Join Date
    Jun 2010
    Location
    Rajkot, India
    Posts
    160
    Rep Power
    5

    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'

  4. #4
    phoenix is offline Zimbra Consultant & Moderator
    Join Date
    Sep 2005
    Location
    Vannes, France
    Posts
    23,485
    Rep Power
    56

    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


    Acompli: A new adventure for Co-Founder KevinH.

  5. #5
    dipeshmehta is offline Special Member
    Join Date
    Jun 2010
    Location
    Rajkot, India
    Posts
    160
    Rep Power
    5

    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

  6. #6
    bofh is offline Elite Member
    Join Date
    May 2010
    Posts
    272
    Rep Power
    5

    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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 21
    Last Post: 02-04-2010, 10:06 AM
  2. Post instsallation problems
    By Assaf in forum Installation
    Replies: 14
    Last Post: 01-29-2007, 11:38 AM
  3. Getting problems in FC4 while instalation
    By kitty_bhoo in forum Installation
    Replies: 13
    Last Post: 09-12-2006, 10:34 PM
  4. Services stopped working
    By lilwong in forum Administrators
    Replies: 4
    Last Post: 08-15-2006, 09:19 AM
  5. Fedora Core 3, Clean Install - Not working!
    By pcjackson in forum Installation
    Replies: 17
    Last Post: 03-05-2006, 07:38 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •