Sorry about that...
If you're not familiar with Zimbra, it's a collection of Open Source software, all integrated together into a single Email & Collaboration package. It includes Apache, Jetty, Java, Postfix, Amavis, ClamAV, MySQL, Lucene, OpenLDAP, and more...
While most day to day management is done through a graphical admin console, there are many tasks that are better and easier to do using the CLI fron Linux. While I can use the admin console to list all the shared folders, calendars, and contact lists for a user, the problem is that I need to perform this for roughly 1500 mailboxes. I'm having some problems getting the output formatted properly. First off, a quick note on the commands being used from the command line & their output:
For instance, to get a list of all the folders in a mailbox (including calendars and contact lists), the command is "zmmailbox ... gaf" "Get All Folders"
Code:
$ zmmailbox -z -m pop3.test@domain.name gaf
Id View Unread Msg Count Path
---------- ---- ---------- ---------- ----------
1 unkn 0 0 /
16 docu 0 0 /Briefcase
10 appo 0 0 /Calendar
14 mess 0 0 /Chats
7 cont 0 1 /Contacts
6 mess 0 0 /Drafts
13 cont 0 3 /Emailed Contacts
2 mess 8 8 /Inbox
386 mess 7 9 /Inbox/Shared With Mark
4 mess 0 0 /Junk
5 mess 0 7 /Sent
15 task 0 0 /Tasks
340 appo 0 7 /Test1
3 unkn 0 5 /Trash
366 mess 2 2 /Imap Test's Folder 1 (imap.test@domain.name:280)
367 mess 2 2 /Imap Test's Folder 2 (imap.test@domain.name:281)
84bc3505-5 mess 7 9 /Imap Test's Folder 2/Folder 2a
365 cont 0 83 /Imap Test's Gmail Contacts (imap.test@domain.name:3227)
364 appo 0 1460 /Imap Test's Imported Calendar (imap.test@domain.name:283)
399 appo 0 1 /mhlevy's Calendar Shared With Pop3 (mhlevy@domain.name:158627)
The folders, such as "/Imap Test's Folder 1 (imap.test@domain.name:280) indicate this is another user's folder (imap.test) that was shared with this user (pop3.test).
Once we have the list of folders, then each folder can be checked to see if share rights have been granted, for example, the folder "/Inbox/Shared With Mark" was shared, and the folder share grants can be displayed with the GFG (Get Folder Grants) option:
Code:
$ zmmailbox -z -m pop3.test@domain.name gfg "/Inbox/Shared With Mark"
Permissions Type Display
----------- -------- -------
rwidxa account mhlevy@domain.name
But I'm having trouble just getting an accurate list of folders. I've tried to come up with a script (for testing, just using this single test user, though eventually I'll loop through all the users in the email system), and quite frankly, the embedded spaces are vexxing me!
I considered trying to replace the embedded spaces with '_' (underscores), that I could later substitute back to a space using sed, but then I learned that many users use the underscore in their folder names.
Code:
#!/bin/bash
# getFolderGrants
echo Getting Folder Share Grants...
for FOLDER in `zmmailbox -z -m pop3.test@domain.name gaf | awk -v nr=5 '{ for (x=nr; x<=NF; x++) {printf $x " "; }; print " " }' | egrep -v ':|Count|----------'`
do
echo The folder is $FOLDER
done
$ ./getFolderGrants
Getting Folder Share Grants...
The folder is /
The folder is /Briefcase
The folder is /Calendar
The folder is /Chats
The folder is /Contacts
The folder is /Drafts
The folder is /Emailed
The folder is Contacts
The folder is /Inbox
The folder is /Inbox/Shared
The folder is With
The folder is Mark
The folder is /Junk
The folder is /Sent
The folder is /Tasks
The folder is /Test1
The folder is /Trash
The folder is /Imap
The folder is Test's
The folder is Folder
The folder is 2/Folder
The folder is 2a
** For instance, what I'm getting is:
Code:
The folder is /Inbox/Shared
The folder is With
The folder is Mark
** But what I'm trying to get is:
Code:
The folder is /Inbox/Shared With Mark
I thought of embedding the zmmailbox command in double quotes, but that didn't really help either, printing out everything on a single line...
The problem seems to be that awk is seeing the embedded spaces as cause to begin a new line, and no matter what I try, I seem to be getting the same thing; For instance:
Code:
#!/bin/bash
echo Getting Folder Share Grants...
for FOLDER in `zmmailbox -z -m pop3.test@domain.name gaf | egrep -v ':|Count|----------' | awk '{ for (i=5; i<=NF; i++) printf("%s "),$i; print""}'`
do
echo The folder is $FOLDER
done
$ ./getFolderGrants
Getting Folder Share Grants...
The folder is /
The folder is /Briefcase
The folder is /Calendar
The folder is /Chats
The folder is /Contacts
The folder is /Drafts
The folder is /Emailed
The folder is Contacts
The folder is /Inbox
The folder is /Inbox/Shared
The folder is With
The folder is Mark
The folder is /Junk
The folder is /Sent
The folder is /Tasks
The folder is /Test1
The folder is /Trash
The folder is /Imap
The folder is Test's
The folder is Folder
The folder is 2/Folder
The folder is 2a
$
Any help would be VERY much appreciated!
Thanks!
Mark