Granting permissions on zimbra mail folders

Warning, this a rather old article I am moving over from an old blog, it might be deprecated. — Originally posted on August, 26 2015

Let’s assume we want to share all mail folders from user to the user
First we need all folders from the user

zmmailbox -z -m getAllFolders > all_folders.txt

and you will get something like this:

Id  View      Unread   Msg Count  Path
---------- ---- ---------- ---------- ----------
1 unkn 0 0 /
16 docu 0 1 /Briefcase
10 appo 0 506 /Calendar
14 mess 0 0 /Chats
7 cont 0 58 /Contacts
6 mess 0 3 /Drafts
13 cont 0 1121 /Emailed Contacts
2 mess 0 11 /Inbox
40985 mess 0 1 /Inbox/Foo
28856 mess 0 5 /Inbox/Bar

From the resulting file you need to remove everything that's not a sub folder of inbox and also make it look like this:

mfg "/Inbox" account rwidxa
mfg "/Inbox/Foo" account rwidxa
mfg "/Inbox/Foo Bar" account rwidxa
mfg "/Inbox/Foo Bar/Example" account rwidxa

mfg is the zmmailbox shortcut for modifyFolderGrant

I also recommend adding quotes around the folder names as it won't work otherwise if you have folders with spaces.
You could use some bash super powers (awk,cut...) to get the data in the desired output format, but I just used sublimetext, never really got friendly with awk.

Now the last step is to run zmmailbox and have it read the data from the file we just created, this can be done by using the -f parameter.

zmmailbox -z -m -f all_folders.txt

You will probably get some "ERROR: mail.GRANT_EXISTS (grantee already exists ...)" errors for folders which did get the grant but we can ignore this.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.