Created
September 27, 2016 04:52
-
-
Save iomarmochtar/05105984c8f44d0ef57e407b19b3dc04 to your computer and use it in GitHub Desktop.
Demo script menggunakan zmpython pada kopdar python-ID Jogja 240916
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
__author__ = ('Imam Omar Mochtar', ('iomarmochtar@gmail.com', 'omar@jabetto.com')) | |
from com.zimbra.common.soap import AccountConstants, AdminConstants | |
from com.zimbra.cs.account import Provisioning | |
from com.zimbra.cs.account.soap import SoapProvisioning | |
from com.zimbra.client import ZMailbox | |
from com.zimbra.common.account.Key import AccountBy | |
KBYTES = 1024 | |
MBYTES = 1024*1024 | |
GBYTES = 1024*1024*1024 | |
def formatter(size): | |
size = float(size) | |
if size > GBYTES: | |
return "%.2f GB"%(size/GBYTES) | |
elif size > MBYTES: | |
return "%.2f MB"%(size/MBYTES) | |
elif size > KBYTES: | |
return "%.2f KB"%(size/KBYTES) | |
else: | |
return "%d B"%(size) | |
path = AccountConstants.USER_SERVICE_URI | |
sslport = Provisioning.getInstance().getLocalServer().getIntAttr(Provisioning.A_zimbraMailSSLPort, 0) | |
# provme | |
prov = Provisioning.getInstance() | |
domain = prov.getDomain( prov.getAccount('admin') ) | |
# mendapatkan admin auth token | |
sp = SoapProvisioning() | |
sp.soapSetURI("https://localhost:7071" + AdminConstants.ADMIN_SERVICE_URI) | |
sp.soapZimbraAdminAuthenticate() | |
token = sp.getAuthToken() | |
soapurl = "https://localhost:%s%s"%(sslport, path) | |
options = ZMailbox.Options(token, soapurl) | |
options.setTargetAccountBy(AccountBy.name) | |
for user in prov.getAllAccounts(None): | |
mail = user.getMail() | |
options.setTargetAccount(mail) | |
mbx = ZMailbox.getMailbox(options) | |
info = mbx.getAccountInfo(True) | |
rsize = info.getMailboxQuotaUsed() | |
size = formatter( rsize ) | |
print "[JYT] Mailbox size of %s = %s"%(mail,size) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment