Last active
November 18, 2017 12:43
-
-
Save iomarmochtar/f804d4beed2b8a2ca18ff8ca2cbcb42d to your computer and use it in GitHub Desktop.
Example of fetching Zimbra task and task list (recursive).
This file contains hidden or 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', '[email protected]') | |
from ozpy.mailbox import Mailbox | |
import sys | |
from pprint import pprint | |
import os | |
""" | |
Example of fetching Zimbra task and task list (recursively). | |
""" | |
class MyMailbox(Mailbox): | |
def get_task(self, folder): | |
""" | |
Fetch task detail using SearchRequest | |
https://files.zimbra.com/docs/soap_api/8.7.11/api-reference/zimbraMail/Search.html | |
""" | |
body = { | |
"sortBy":"taskDueAsc", | |
"tz":{"id":"Asia/Bangkok"}, | |
"locale":{"_content":"en_US"}, | |
"offset":0, | |
"limit":100, | |
"query":"in:\"{}\"".format(folder), | |
"types":"task", | |
"needExp":1 | |
} | |
urn = "urn:zimbraMail" | |
return self.send("Search", body, urn) | |
def get_task_folders(self): | |
""" | |
Get list of task folder using GetFolderRequest | |
https://files.zimbra.com/docs/soap_api/8.7.11/api-reference/zimbraMail/GetFolder.html | |
""" | |
urn = "urn:zimbraMail" | |
body = { | |
'folder': {'path': '/'}, | |
'view': 'task' | |
} | |
return self.send("GetFolder", body, urn) | |
mbx = MyMailbox( | |
username="[email protected]", | |
password="kacangitem", | |
soapurl="https://192.168.113.75/service/soap", | |
) | |
def fetch(name, instance): | |
""" | |
Fetch task and sub-task recursively | |
""" | |
name = os.path.join(name, instance['name']) | |
# print out task folder path | |
print("{} {}".format("-"*10,name)) | |
task_req = mbx.get_task(name) | |
# iterrate all task within task folder if any | |
if task_req.has_key('task'): | |
for task in task_req['task']: | |
print('* {} - progress: {} % - location: {}'.format( | |
task['name'], | |
task['percentComplete'], | |
task['loc'] | |
)) | |
# loop if there are subfolder | |
if instance.has_key("folder"): | |
for folder in instance['folder']: | |
fetch(name, folder) | |
response = mbx.get_task_folders() | |
# get parent of task folder | |
for parent_folder in response['folder'][0]['folder']: | |
fetch("", parent_folder) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output
