2
OpenChange MAPI implementation.
4
Python interface to mapistore management
6
Copyright (C) Julien Kerihuel 2011.
8
This program is free software; you can redistribute it and/or modify
9
it under the terms of the GNU General Public License as published by
10
the Free Software Foundation; either version 3 of the License, or
11
(at your option) any later version.
13
This program is distributed in the hope that it will be useful,
14
but WITHOUT ANY WARRANTY; without even the implied warranty of
15
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
GNU General Public License for more details.
18
You should have received a copy of the GNU General Public License
19
along with this program. If not, see <http://www.gnu.org/licenses/>.
23
#include "pyopenchange/mapistore/pymapistore.h"
25
void initmapistore_mgmt(void);
27
static void py_MAPIStoreMGMT_dealloc(PyObject *_self)
29
PyMAPIStoreMGMTObject *self = (PyMAPIStoreMGMTObject *)_self;
31
printf("deallocate MGMT object\n");
32
mapistore_mgmt_release(self->mgmt_ctx);
34
Py_DECREF(self->parent);
38
static PyObject *py_MAPIStoreMGMT_registered_backend(PyMAPIStoreMGMTObject *self, PyObject *args)
43
if (!PyArg_ParseTuple(args, "s", &bname)) {
47
ret = mapistore_mgmt_registered_backend(self->mgmt_ctx, bname);
48
return PyBool_FromLong(ret == MAPISTORE_SUCCESS ? true : false);
52
static PyObject *py_MAPIStoreMGMT_registered_users(PyMAPIStoreMGMTObject *self, PyObject *args)
58
struct mapistore_mgmt_users_list *ulist;
61
if (!PyArg_ParseTuple(args, "ss", &backend, &vuser)) {
66
PyDict_SetItemString(dict, "backend", PyString_FromString(backend));
67
PyDict_SetItemString(dict, "user", PyString_FromString(vuser));
69
ulist = mapistore_mgmt_registered_users(self->mgmt_ctx, backend, vuser);
70
userlist = PyList_New(0);
72
if (ulist && ulist->count != 0) {
73
PyDict_SetItem(dict, PyString_FromString("count"), PyLong_FromLong(ulist->count));
74
for (i = 0; i < ulist->count; i++) {
75
PyList_Append(userlist, PyString_FromString(ulist->user[i]));
78
PyDict_SetItem(dict, PyString_FromString("count"), PyLong_FromLong(0));
80
PyDict_SetItem(dict, PyString_FromString("usernames"), userlist);
86
return (PyObject *)dict;
89
static PyObject *py_MAPIStoreMGMT_registered_message(PyMAPIStoreMGMTObject *self, PyObject *args)
99
if (!PyArg_ParseTuple(args, "ssszzs", &backend, &sysuser, &vuser, &folder, &rootURI, &message)) {
103
ret = mapistore_mgmt_registered_message(self->mgmt_ctx, backend, sysuser, vuser, folder, rootURI, message);
105
return PyBool_FromLong(ret);
108
static PyObject *py_MAPIStoreMGMT_register_message(PyMAPIStoreMGMTObject *self, PyObject *args)
113
const char *messageID;
114
char *registered_uri;
119
if (!PyArg_ParseTuple(args, "ssss", &backend, &user, &uri, &messageID)) {
123
retlist = PyList_New(0);
125
/* Gets a new message ID */
126
ret = openchangedb_get_new_folderID(self->parent->ocdb_ctx, &mid);
127
if (ret) return (PyObject *)retlist;
129
/* Register the message within specified user indexing database */
130
ret = mapistore_mgmt_register_message(self->mgmt_ctx, backend, user, mid, uri, messageID, ®istered_uri);
131
if (ret) return (PyObject *)retlist;
133
PyList_Append(retlist, PyLong_FromLongLong(mid));
134
PyList_Append(retlist, PyString_FromString(registered_uri));
136
talloc_free(registered_uri);
137
return (PyObject *) retlist;
140
static PyObject *py_MAPIStoreMGMT_existing_users(PyMAPIStoreMGMTObject *self, PyObject *args)
155
if (!PyArg_ParseTuple(args, "sss", &backend, &vuser, &folder)) {
160
userlist = PyList_New(0);
161
PyDict_SetItemString(dict, "backend", PyString_FromString(backend));
162
PyDict_SetItemString(dict, "user", PyString_FromString(vuser));
163
PyDict_SetItemString(dict, "count", PyLong_FromLong(0));
164
PyDict_SetItem(dict, PyString_FromString("infos"), userlist);
166
ret = mapistore_mgmt_generate_uri(self->mgmt_ctx, backend, vuser, folder, NULL, NULL, &uri);
167
if (ret != MAPISTORE_SUCCESS) return (PyObject *)dict;
168
printf("uri: %s\n", uri);
170
ret = openchangedb_get_users_from_partial_uri(self->mgmt_ctx, self->parent->ocdb_ctx, uri,
171
&count, &MAPIStoreURI, &users);
172
if (ret != MAPISTORE_SUCCESS) return (PyObject *)dict;
174
PyDict_SetItemString(dict, "count", PyLong_FromLong(count));
175
for (i = 0; i != count; i++) {
177
PyDict_SetItemString(item, "username", PyString_FromString(users[i]));
178
PyDict_SetItemString(item, "mapistoreURI", PyString_FromString(MAPIStoreURI[i]));
179
PyList_Append(userlist, item);
181
PyDict_SetItem(dict, PyString_FromString("infos"), userlist);
183
return (PyObject *)dict;
186
static PyObject *py_MAPIStoreMGMT_registered_subscription(PyMAPIStoreMGMTObject *self, PyObject *args)
189
const char *username;
192
uint16_t NotificationFlags;
194
if (!PyArg_ParseTuple(args, "sshh", &username, &uri, &type, &NotificationFlags)) {
199
case MAPISTORE_FOLDER:
200
ret = mapistore_mgmt_registered_folder_subscription(self->mgmt_ctx, username, uri,
202
return PyBool_FromLong((ret == MAPISTORE_SUCCESS) ? true : false);
204
case MAPISTORE_MESSAGE:
205
DEBUG(0, ("[%s:%d]: Unsupported subscription type\n", __FUNCTION__, __LINE__));
206
return PyBool_FromLong(false);
210
return PyBool_FromLong(false);
213
static PyObject *py_MAPIStoreMGMT_send_newmail(PyMAPIStoreMGMTObject *self, PyObject *args)
216
const char *username;
217
const char *storeuser;
218
const char *FolderURI;
219
const char *MessageURI;
224
if (!PyArg_ParseTuple(args, "ssss", &username, &storeuser, &FolderURI, &MessageURI)) {
228
/* Turn MessageURI into MessageID from indexing database */
229
ret = mapistore_indexing_record_get_fmid(self->mgmt_ctx->mstore_ctx, storeuser, MessageURI,
230
false, &MessageID, &softdeleted);
231
if (ret != MAPISTORE_SUCCESS || softdeleted == true) {
232
return PyBool_FromLong(false);
235
/* Turn FolderURI into FolderID from openchangedb or indexing database */
236
ret = openchangedb_get_fid(self->parent->ocdb_ctx, FolderURI, &FolderID);
237
if (ret != MAPI_E_SUCCESS) {
238
ret = mapistore_indexing_record_get_fmid(self->mgmt_ctx->mstore_ctx, username, FolderURI, false,
239
&FolderID, &softdeleted);
240
if (ret != MAPISTORE_SUCCESS || softdeleted == true) {
241
return PyBool_FromLong(false);
245
/* Send notification on user queue */
246
ret = mapistore_mgmt_send_newmail_notification(self->mgmt_ctx, username, FolderID,
247
MessageID, MessageURI);
249
return PyBool_FromLong((ret == MAPISTORE_SUCCESS) ? true : false);
252
static PyObject *obj_get_verbose(PyMAPIStoreMGMTObject *self, void *closure)
254
return PyBool_FromLong(self->mgmt_ctx->verbose);
257
static int obj_set_verbose(PyMAPIStoreMGMTObject *self, PyObject *verbose, void *closure)
259
if (!PyBool_Check(verbose))
261
if (mapistore_mgmt_set_verbosity(self->mgmt_ctx, PyLong_AsLong(verbose)) != MAPISTORE_SUCCESS) return -1;
265
static PyMethodDef mapistore_mgmt_methods[] = {
266
{ "registered_backend", (PyCFunction)py_MAPIStoreMGMT_registered_backend, METH_VARARGS },
267
{ "registered_users", (PyCFunction)py_MAPIStoreMGMT_registered_users, METH_VARARGS },
268
{ "registered_message", (PyCFunction)py_MAPIStoreMGMT_registered_message, METH_VARARGS },
269
{ "register_message", (PyCFunction)py_MAPIStoreMGMT_register_message, METH_VARARGS },
270
{ "registered_subscription", (PyCFunction)py_MAPIStoreMGMT_registered_subscription, METH_VARARGS },
271
{ "existing_users", (PyCFunction)py_MAPIStoreMGMT_existing_users, METH_VARARGS },
272
{ "send_newmail", (PyCFunction)py_MAPIStoreMGMT_send_newmail, METH_VARARGS },
276
static PyGetSetDef mapistore_mgmt_getsetters[] = {
277
{ (char *)"verbose", (getter)obj_get_verbose, (setter)obj_set_verbose,
278
"Enable/Disable verbosity for management object" },
282
PyTypeObject PyMAPIStoreMGMT = {
283
PyObject_HEAD_INIT(NULL) 0,
284
.tp_name = "mapistore_mgmt",
285
.tp_basicsize = sizeof (PyMAPIStoreMGMTObject),
286
.tp_methods = mapistore_mgmt_methods,
287
.tp_getset = mapistore_mgmt_getsetters,
288
.tp_doc = "mapistore management object",
289
.tp_dealloc = (destructor)py_MAPIStoreMGMT_dealloc,
290
.tp_flags = Py_TPFLAGS_DEFAULT,