2
# -*- coding: utf-8 -*-
8
import openchange.mapistoredb as mapistoredb
9
import openchange.mapistore as mapistore
10
from openchange import mapi
13
username = "jkerihuel"
16
provisioning_root_dir = "/tmp/test_mapistore"
17
os.mkdir(provisioning_root_dir)
19
def newTitle(title, separator):
21
ftitle = "[Step %d]. %s" % (title_nb, title)
24
print separator * len(ftitle)
33
def TreeLeafStatus(name, retval, errstr):
34
tree = " " * (indent * 8)
36
print tree + "[+] %s: %s (%s)" % (string.ljust(name, 60 - indent * 8), "[KO]", errstr)
39
print tree + "[+] %s: %s" % (string.ljust(name, 60 - indent * 8), "[OK]")
50
newTitle("Initializing mapistore database", '=')
51
MAPIStoreDB = mapistoredb.mapistoredb()
52
MAPIStoreDB.initialize(provisioning_root_dir)
54
newTitle("Provisioning mapistore database", '=')
55
retval = MAPIStoreDB.provision(netbiosname = "server",
56
firstorg = "OpenChange Project",
57
firstou = "OpenChange Development Unit")
59
print "\t* Provisioning: SUCCESS"
61
print "\t* Provisioning: FAILURE (ret = %d)" % MAPIStoreDB.errstr(retval)
63
newTitle("Create mapistore named properties database", '=')
64
retval = MAPIStoreDB.provision_named_properties()
66
print "\t* Provisioning: SUCCESS"
67
(retval,npid) = MAPIStoreDB.namedprops_get_default_id(mapistoredb.MAPISTORE_NAMEDPROPS_EXTERNAL)
68
print "\t\t* Last External Index: 0x%.4x" % (npid)
69
(retval,npid) = MAPIStoreDB.namedprops_get_default_id(mapistoredb.MAPISTORE_NAMEDPROPS_INTERNAL)
70
print "\t\t* Last Internal Index: 0x%.4x" % (npid)
72
print "\t* Provisioning: FAILURE (ret = %s)" % MAPIStoreDB.errstr(retval)
74
newTitle("Provision named properties namespace for backends", "=")
75
retval = MAPIStoreDB.namedprops_provision_backends()
77
newTitle("Provision named properties namespace for user", "=")
78
retval = MAPIStoreDB.namedprops_provision_user(username)
79
"\t* Return status: %s" % MAPIStoreDB.errstr(retval)
81
newTitle("Create a new mailbox", '=')
82
mailbox_root = MAPIStoreDB.get_mapistore_uri(folder=mapistoredb.MDB_ROOT_FOLDER,
84
namespace="mstoredb://")
85
retval = MAPIStoreDB.new_mailbox(username, mailbox_root)
86
print "\t* Mailbox Root: %s" % mailbox_root
88
newTitle("Get and Set a new allocation range to the mailbox", '=')
89
(retval, rstart,rend) = MAPIStoreDB.get_new_allocation_range(username,
92
print "\t* Allocation range received:"
93
print "\t\t* [start]: 0x%.16x" % rstart
94
print "\t\t* [end]: 0x%.16x\n\n" % rend
95
retval = MAPIStoreDB.set_mailbox_allocation_range(username,
98
print "\t * Allocation range successfully set to mailbox"
100
print "\t * Error while setting allocation range to the mailbox"
102
newTitle("Uninitializing mapistore database context", '=')
103
MAPIStoreDB.release()
105
newTitle("Initializing mapistore context", '=')
106
mapistore.set_mapping_path(os.path.join(provisioning_root_dir, "mapistore"))
107
MAPIStore = mapistore.mapistore()
109
newTitle("Adding a context over Mailbox Root Folder", '=')
110
(context_id, mailbox_fid) = MAPIStore.add_context(username, mailbox_root)
111
print "\t* context_id = %s" % context_id
112
print "\t* mailbox FID = 0x%.16x" % mailbox_fid
114
newTitle("Create the mailbox hierarchy", '=')
116
TreeRoot("Mailbox Root Folder")
118
# MDB_DEFERRED_ACTIONS
119
retval = MAPIStore.root_mkdir(context_id=context_id,
120
parent_index=mapistore.MDB_ROOT_FOLDER,
121
index=mapistore.MDB_DEFERRED_ACTIONS,
123
TreeLeafStatus("Deferred Actions", retval, MAPIStore.errstr(retval))
126
retval = MAPIStore.root_mkdir(context_id=context_id,
127
parent_index=mapistore.MDB_ROOT_FOLDER,
128
index=mapistore.MDB_SPOOLER_QUEUE,
130
TreeLeafStatus("Spooler Queue", retval, MAPIStore.errstr(retval))
133
retval = MAPIStore.root_mkdir(context_id=context_id,
134
parent_index=mapistore.MDB_ROOT_FOLDER,
135
index=mapistore.MDB_IPM_SUBTREE,
137
TreeLeafStatus("IPM Subtree", retval, MAPIStore.errstr(retval))
139
# MDB_IPM_SUBTREE > MDB_INBOX
141
retval = MAPIStore.root_mkdir(context_id=context_id,
142
parent_index=mapistore.MDB_IPM_SUBTREE,
143
index=mapistore.MDB_INBOX,
145
TreeLeafStatus("Inbox", retval, MAPIStore.errstr(retval))
147
# MDB_IPM_SUBTREE > MDB_OUTBOX
148
retval = MAPIStore.root_mkdir(context_id=context_id,
149
parent_index=mapistore.MDB_IPM_SUBTREE,
150
index=mapistore.MDB_OUTBOX,
152
TreeLeafStatus("Outbox", retval, MAPIStore.errstr(retval))
154
# MDB_IPM_SUBTREE > MDB_SENT_ITEMS
155
retval = MAPIStore.root_mkdir(context_id=context_id,
156
parent_index=mapistore.MDB_IPM_SUBTREE,
157
index=mapistore.MDB_SENT_ITEMS,
159
TreeLeafStatus("Sent Items", retval, MAPIStore.errstr(retval))
161
# MDB_IPM_SUBTREE > MDB_DELETED_ITEMS
162
retval = MAPIStore.root_mkdir(context_id=context_id,
163
parent_index=mapistore.MDB_IPM_SUBTREE,
164
index=mapistore.MDB_DELETED_ITEMS,
166
TreeLeafStatus("Deleted Items", retval, MAPIStore.errstr(retval))
168
#### SPECIAL FOLDERS #####
170
# MDB_IPM_SUBTREE > MDB_CALENDAR
171
retval = MAPIStore.root_mkdir(context_id=context_id,
172
parent_index=mapistore.MDB_IPM_SUBTREE,
173
index=mapistore.MDB_CALENDAR,
175
TreeLeafStatus("Calendar", retval, MAPIStore.errstr(retval))
177
# MDB_IPM_SUBTREE > MDB_CONTACTS
178
retval = MAPIStore.root_mkdir(context_id=context_id,
179
parent_index=mapistore.MDB_IPM_SUBTREE,
180
index=mapistore.MDB_CONTACTS,
182
TreeLeafStatus("Contacts", retval, MAPIStore.errstr(retval))
184
# MDB_IPM_SUBTREE > MDB_JOURNAL
185
retval = MAPIStore.root_mkdir(context_id=context_id,
186
parent_index=mapistore.MDB_IPM_SUBTREE,
187
index=mapistore.MDB_JOURNAL,
189
TreeLeafStatus("Journal", retval, MAPIStore.errstr(retval))
191
# MDB_IPM_SUBTREE > MDB_NOTES
192
retval = MAPIStore.root_mkdir(context_id=context_id,
193
parent_index=mapistore.MDB_IPM_SUBTREE,
194
index=mapistore.MDB_NOTES,
196
TreeLeafStatus("Notes", retval, MAPIStore.errstr(retval))
198
# MDB_IPM_SUBTREE > MDB_TASKS
199
retval = MAPIStore.root_mkdir(context_id=context_id,
200
parent_index=mapistore.MDB_IPM_SUBTREE,
201
index=mapistore.MDB_TASKS,
203
TreeLeafStatus("Tasks", retval, MAPIStore.errstr(retval))
205
# MDB_IPM_SUBTREE > MDB_DRAFTS
206
retval = MAPIStore.root_mkdir(context_id=context_id,
207
parent_index=mapistore.MDB_IPM_SUBTREE,
208
index=mapistore.MDB_DRAFTS,
210
TreeLeafStatus("Drafts", retval, MAPIStore.errstr(retval))
213
retval = MAPIStore.root_mkdir(context_id=context_id,
214
parent_index=mapistore.MDB_IPM_SUBTREE,
215
index=mapistore.MDB_SYNC_ISSUES,
217
TreeLeafStatus("Sync Issues", retval, MAPIStore.errstr(retval))
221
# MDB_SYNC_ISSUES > MDB_CONFLICTS
222
ipm_subtree = MAPIStore.get_folder_identifier(context_id=context_id,
223
index=mapistore.MDB_IPM_SUBTREE,
225
sync_fid = MAPIStore.get_folder_identifier(context_id=context_id,
226
index=mapistore.MDB_SYNC_ISSUES,
228
print "IPM Subtree FID: 0x%.16x" % ipm_subtree
229
print "Synchronization Issue FID: 0x%.16x" % sync_fid
230
MAPIStore.opendir(context_id=context_id, parent_fid=ipm_subtree, fid=sync_fid)
231
conflicts_fid = MAPIStore.mkdir(context_id, sync_fid, "Conflicts", None, mapistore.FOLDER_GENERIC)
232
print "Conflicts FID: 0x%.16x" % conflicts_fid
237
retval = MAPIStore.root_mkdir(context_id=context_id,
238
parent_index=mapistore.MDB_ROOT_FOLDER,
239
index=mapistore.MDB_COMMON_VIEWS,
241
TreeLeafStatus("Common Views", retval, MAPIStore.errstr(retval))
244
retval = MAPIStore.root_mkdir(context_id=context_id,
245
parent_index=mapistore.MDB_ROOT_FOLDER,
246
index=mapistore.MDB_SCHEDULE,
248
TreeLeafStatus("Schedule", retval, MAPIStore.errstr(retval))
251
retval = MAPIStore.root_mkdir(context_id=context_id,
252
parent_index=mapistore.MDB_ROOT_FOLDER,
253
index=mapistore.MDB_SEARCH,
255
TreeLeafStatus("Search", retval, MAPIStore.errstr(retval))
258
retval = MAPIStore.root_mkdir(context_id=context_id,
259
parent_index=mapistore.MDB_ROOT_FOLDER,
260
index=mapistore.MDB_VIEWS,
262
TreeLeafStatus("Views", retval, MAPIStore.errstr(retval))
265
retval = MAPIStore.root_mkdir(context_id=context_id,
266
parent_index=mapistore.MDB_ROOT_FOLDER,
267
index=mapistore.MDB_SHORTCUTS,
269
TreeLeafStatus("Shortcuts", retval, MAPIStore.errstr(retval))
272
retval = MAPIStore.root_mkdir(context_id=context_id,
273
parent_index=mapistore.MDB_ROOT_FOLDER,
274
index=mapistore.MDB_REMINDERS,
276
TreeLeafStatus("Reminders", retval, MAPIStore.errstr(retval))
279
newTitle("Setting mailbox folders to fsocpf", '=')
280
inbox_uri = MAPIStore.get_mapistore_uri(mapistore.MDB_INBOX, username, "fsocpf://")
281
retval = MAPIStore.set_mapistore_uri(context_id, mapistore.MDB_INBOX, inbox_uri)
283
print "\t* Inbox [fsocpf]: [OK] - " + inbox_uri
285
print "\t* Inbox [fsocpf]: [KO] (%s)" % MAPIStore.errstr(retval)
288
newTitle("Creating mailbox folder", "=")
289
(inbox_context_id, inbox_fid) = MAPIStore.add_context(username, inbox_uri)
291
print "\t* Inbox FID: 0x%x" % inbox_fid