-
Notifications
You must be signed in to change notification settings - Fork 0
/
getShare.py
35 lines (32 loc) · 1013 Bytes
/
getShare.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import sys
import codecs
from ZmSharing import ZmSharing
reload(sys)
sys.setdefaultencoding('utf-8')
url = os.getenv('ldap_url')
userdn = os.getenv('zimbra_ldap_userdn')
password = os.getenv('zimbra_ldap_password')
searchAccount = ZmSharing(url, userdn, password)
filename = sys.argv[1]
f = open(filename, 'r')
index = [1,2,5,7,8]
dictShare = {}
with f:
lines = [line.rstrip("\n") for line in f]
for account in lines:
getAccountShare = searchAccount.zmLdapSearch(account)
try:
zimbraShare = getAccountShare['zimbraSharedItem']
except KeyError:
pass
else:
for share in zimbraShare:
myshare = share.split(";")
for getindex in index:
(key, value) = myshare[getindex].split(':')
dictShare[key] = value
with codecs.open('sharing.sh', 'a', encoding='utf-8') as sharing:
sharing.write('zmmailbox -z -m %s mfg "%s" account %s %s\n'%(account, dictShare['folderPath'], dictShare['granteeName'], dictShare['rights']))