2 OpenChange MAPI implementation.
4 Python interface to mapistore folder
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"
24 #include "gen_ndr/exchange.h"
26 static void py_MAPIStoreFolder_dealloc(PyObject *_self)
28 PyMAPIStoreFolderObject *self = (PyMAPIStoreFolderObject *)_self;
30 Py_DECREF(self->context);
34 static PyObject *py_MAPIStoreFolder_create_folder(PyMAPIStoreFolderObject *self, PyObject *args, PyObject *kwargs)
37 /* PyMAPIStoreFolderObject *folder; */
38 char *kwnames[] = { "name", "description", "foldertype", "flags" };
40 const char *desc = NULL;
41 uint16_t foldertype = FOLDER_GENERIC;
42 uint16_t flags = NONE;
45 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|shh", kwnames, &name, &desc, &foldertype, &flags)) {
49 /* Step 1. Check if the folder already exists */
50 ret = mapistore_folder_get_child_fid_by_name(self->context->mstore_ctx,
51 self->context->context_id,
52 self->context->folder_object,
54 if (ret == MAPISTORE_SUCCESS) {
55 if (flags != OPEN_IF_EXISTS) {
56 PyErr_MAPIStore_IS_ERR_RAISE(MAPISTORE_ERR_EXIST);
61 /* TODO: Complete the implementation */
66 static PyObject *py_MAPIStoreFolder_get_fid(PyMAPIStoreFolderObject *self, void *closure)
68 return PyLong_FromLongLong(self->fid);
71 static PyObject *py_MAPIStoreFolder_get_folder_count(PyMAPIStoreFolderObject *self, void *closure)
76 retval = mapistore_folder_get_folder_count(self->context->mstore_ctx, self->context->context_id,
77 (self->folder_object ? self->folder_object :
78 self->context->folder_object), &RowCount);
79 if (retval != MAPISTORE_SUCCESS) {
80 return PyInt_FromLong(-1);
83 return PyInt_FromLong(RowCount);
87 static PyObject *py_MAPIStoreFolder_get_message_count(PyMAPIStoreFolderObject *self, void *closure)
92 retval = mapistore_folder_get_message_count(self->context->mstore_ctx, self->context->context_id,
93 (self->folder_object ? self->folder_object :
94 self->context->folder_object),
95 MAPISTORE_MESSAGE_TABLE, &RowCount);
96 if (retval != MAPISTORE_SUCCESS) {
97 return PyInt_FromLong(-1);
100 return PyInt_FromLong(RowCount);
104 static PyObject *py_MAPIStoreFolder_get_fai_message_count(PyMAPIStoreFolderObject *self, void *closure)
109 retval = mapistore_folder_get_message_count(self->context->mstore_ctx, self->context->context_id,
110 (self->folder_object ? self->folder_object :
111 self->context->folder_object),
112 MAPISTORE_FAI_TABLE, &RowCount);
113 if (retval != MAPISTORE_SUCCESS) {
114 return PyInt_FromLong(-1);
117 return PyInt_FromLong(RowCount);
120 static PyMethodDef mapistore_folder_methods[] = {
121 { "create_folder", (PyCFunction)py_MAPIStoreFolder_create_folder, METH_VARARGS|METH_KEYWORDS },
125 static PyGetSetDef mapistore_folder_getsetters[] = {
126 { (char *)"fid", (getter)py_MAPIStoreFolder_get_fid, NULL, NULL },
127 { (char *)"folder_count", (getter)py_MAPIStoreFolder_get_folder_count, NULL, NULL },
128 { (char *)"message_count", (getter)py_MAPIStoreFolder_get_message_count, NULL, NULL },
129 { (char *)"fai_message_count", (getter)py_MAPIStoreFolder_get_fai_message_count, NULL, NULL },
133 PyTypeObject PyMAPIStoreFolder = {
134 PyObject_HEAD_INIT(NULL) 0,
135 .tp_name = "mapistore folder",
136 .tp_basicsize = sizeof (PyMAPIStoreFolderObject),
137 .tp_methods = mapistore_folder_methods,
138 .tp_getset = mapistore_folder_getsetters,
139 .tp_doc = "mapistore folder object",
140 .tp_dealloc = (destructor)py_MAPIStoreFolder_dealloc,
141 .tp_flags = Py_TPFLAGS_DEFAULT,