~ubuntu-branches/debian/sid/openchange/sid

« back to all changes in this revision

Viewing changes to pymapi/object.c

  • Committer: Package Import Robot
  • Author(s): Jelmer Vernooij
  • Date: 2012-04-12 20:07:57 UTC
  • mfrom: (11 sid)
  • mto: This revision was merged to the branch mainline in revision 12.
  • Revision ID: package-import@ubuntu.com-20120412200757-k933d9trljmxj1l4
Tags: 1:1.0-4
* openchangeserver: Add dependency on openchangeproxy.
* Rebuild against newer version of Samba 4.
* Use dpkg-buildflags.
* Migrate to Git, update Vcs-Git header.
* Switch to debhelper 9.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
   OpenChange MAPI implementation.
3
 
 
4
 
   Copyright (C) Jelmer Vernooij <jelmer@openchange.org> 2008.
5
 
 
6
 
   This program is free software; you can redistribute it and/or modify
7
 
   it under the terms of the GNU General Public License as published by
8
 
   the Free Software Foundation; either version 3 of the License, or
9
 
   (at your option) any later version.
10
 
   
11
 
   This program is distributed in the hope that it will be useful,
12
 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 
   GNU General Public License for more details.
15
 
   
16
 
   You should have received a copy of the GNU General Public License
17
 
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 
 */
19
 
 
20
 
#include "pymapi/pymapi.h"
21
 
 
22
 
static PyObject *PyMapiObject_FromMapiObject(mapi_object_t *obj)
23
 
{
24
 
        return NULL; /* FIXME */
25
 
}       
26
 
 
27
 
static PyObject *object_create(PyTypeObject *type, PyObject *args, PyObject *kwargs)
28
 
{
29
 
        /* FIXME */
30
 
        return (PyObject *)PyObject_New(PyMapiObjectObject, type);
31
 
}
32
 
 
33
 
static void object_dealloc(PyObject *_self)
34
 
{
35
 
        PyMapiObjectObject *self = (PyMapiObjectObject *)_self;
36
 
        mapi_object_release(self->object);
37
 
        PyObject_Del(_self);
38
 
}
39
 
 
40
 
mapi_object_t *PyMapiObject_GetMapiObject(PyObject *obj)
41
 
{
42
 
        PyMapiObjectObject *self = (PyMapiObjectObject *)obj;
43
 
        if (!PyMapiObject_Check(obj))
44
 
                return NULL;
45
 
 
46
 
        return self->object;
47
 
}
48
 
 
49
 
static PyObject *py_folder_get_items_count(PyMapiObjectObject *self)
50
 
{
51
 
        enum MAPISTATUS status;
52
 
        uint32_t unread, total;
53
 
 
54
 
        status = GetFolderItemsCount(self->object, &unread, &total);
55
 
        PyErr_MAPISTATUS_IS_ERR_RAISE(status);
56
 
 
57
 
        return Py_BuildValue("(ii)", unread, total);
58
 
}
59
 
 
60
 
static PyObject *py_folder_remove_user_permissions(PyMapiObjectObject *self, PyObject *args)
61
 
{
62
 
        char *username;
63
 
        enum MAPISTATUS status;
64
 
        if (!PyArg_ParseTuple(args, "s", &username))
65
 
                return NULL;
66
 
 
67
 
        status = RemoveUserPermission(self->object, username);
68
 
        PyErr_MAPISTATUS_IS_ERR_RAISE(status);
69
 
 
70
 
        return Py_None;
71
 
}
72
 
 
73
 
static PyObject *py_folder_create(PyMapiObjectObject *self, PyObject *args)
74
 
{
75
 
        int foldertype;
76
 
        char *name, *comment;
77
 
        uint32_t flags;
78
 
        enum MAPISTATUS status;
79
 
        mapi_object_t child;
80
 
 
81
 
        if (!PyArg_ParseTuple(args, "issI", &foldertype, &name, &comment, &flags))
82
 
                return NULL;
83
 
 
84
 
        status = CreateFolder(self->object, foldertype, name, comment, flags, &child);
85
 
        PyErr_MAPISTATUS_IS_ERR_RAISE(status);
86
 
 
87
 
        return PyMapiObject_FromMapiObject(&child);
88
 
}
89
 
 
90
 
static PyObject *py_folder_delete(PyMapiObjectObject *self, PyObject *args)
91
 
{
92
 
        mapi_id_t folderid; 
93
 
        int flags;
94
 
        enum MAPISTATUS status;
95
 
        bool partial;
96
 
        if (!PyArg_ParseTuple(args, "ii", &folderid, &flags))
97
 
                return NULL;
98
 
 
99
 
        status = DeleteFolder(self->object, folderid, flags, &partial);
100
 
        PyErr_MAPISTATUS_IS_ERR_RAISE(status);
101
 
 
102
 
        return PyBool_FromLong(partial);
103
 
}
104
 
 
105
 
static PyObject *py_folder_empty(PyMapiObjectObject *self)
106
 
{
107
 
        enum MAPISTATUS status = EmptyFolder(self->object);
108
 
        PyErr_MAPISTATUS_IS_ERR_RAISE(status);
109
 
        return Py_None;
110
 
}
111
 
 
112
 
static PyObject *py_folder_create_message(PyMapiObjectObject *self)
113
 
{
114
 
        mapi_object_t msg;
115
 
        enum MAPISTATUS status = CreateMessage(self->object, &msg);
116
 
        PyErr_MAPISTATUS_IS_ERR_RAISE(status);
117
 
        return PyMapiObject_FromMapiObject(&msg);
118
 
}
119
 
 
120
 
static PyObject *py_folder_delete_messages(PyMapiObjectObject *self, PyObject *args)
121
 
{
122
 
        PyObject *py_ids;
123
 
        uint32_t cn_messages;
124
 
        mapi_id_t *ids;
125
 
        enum MAPISTATUS status;
126
 
        int i;
127
 
 
128
 
        if (!PyArg_ParseTuple(args, "O", &py_ids))
129
 
                return NULL;
130
 
 
131
 
        if (!PySequence_Check(py_ids)) {
132
 
                PyErr_SetString(PyExc_TypeError, "ids should be a list of ids");
133
 
                return NULL;
134
 
        }
135
 
 
136
 
        cn_messages = PySequence_Size(py_ids);
137
 
        ids = talloc_array(NULL, mapi_id_t, cn_messages);
138
 
        if (ids == NULL) {
139
 
                PyErr_NoMemory();
140
 
                return NULL;
141
 
        }
142
 
 
143
 
        for (i = 0; i < cn_messages; i++) {
144
 
                PyObject *item;
145
 
                item = PySequence_GetItem(py_ids, i);
146
 
                ids[i] = PyInt_AsLong(item);
147
 
        }
148
 
 
149
 
        status = DeleteMessage(self->object, ids, cn_messages);
150
 
        talloc_free(ids);
151
 
        PyErr_MAPISTATUS_IS_ERR_RAISE(status);
152
 
 
153
 
        return Py_None;
154
 
}
155
 
 
156
 
static PyObject *py_folder_set_read_flags(PyMapiObjectObject *self, PyObject *args)
157
 
{
158
 
        int flags;
159
 
        PyObject *py_ids;
160
 
        enum MAPISTATUS status;
161
 
        uint16_t cn_ids;
162
 
    uint64_t *ids;
163
 
        int i;
164
 
        if (!PyArg_ParseTuple(args, "iO", &flags, &py_ids))
165
 
                return NULL;
166
 
 
167
 
        if (!PySequence_Check(py_ids)) {
168
 
                PyErr_SetString(PyExc_TypeError, "ids should be a list of ids");
169
 
                return NULL;
170
 
        }
171
 
 
172
 
        cn_ids = PySequence_Size(py_ids);
173
 
        ids = talloc_array(NULL, uint64_t, cn_ids);
174
 
        if (ids == NULL) {
175
 
                PyErr_NoMemory();
176
 
                return NULL;
177
 
        }
178
 
 
179
 
        for (i = 0; i < cn_ids; i++) {
180
 
                PyObject *item;
181
 
                item = PySequence_GetItem(py_ids, i);
182
 
                ids[i] = PyInt_AsLong(item);
183
 
        }
184
 
 
185
 
        status = SetReadFlags(self->object, flags, cn_ids, ids);
186
 
        talloc_free(ids);
187
 
        PyErr_MAPISTATUS_IS_ERR_RAISE(status);
188
 
 
189
 
        return Py_None;
190
 
}
191
 
 
192
 
static PyObject *py_folder_get_message_status(PyMapiObjectObject *self, PyObject *args)
193
 
{
194
 
        mapi_id_t msgid;
195
 
        uint32_t lstatus;
196
 
        enum MAPISTATUS status;
197
 
        if (!PyArg_ParseTuple(args, "i", &msgid))
198
 
                return NULL;
199
 
        
200
 
        status = GetMessageStatus(self->object, msgid, &lstatus);
201
 
        PyErr_MAPISTATUS_IS_ERR_RAISE(status);
202
 
 
203
 
        return PyInt_FromLong(lstatus);
204
 
}
205
 
 
206
 
static PyObject *py_message_get_best_body(PyMapiObjectObject *self)
207
 
{
208
 
        enum MAPISTATUS status;
209
 
        uint8_t format;
210
 
        
211
 
        status = GetBestBody(self->object, &format);
212
 
        PyErr_MAPISTATUS_IS_ERR_RAISE(status);
213
 
 
214
 
        return PyInt_FromLong(status);
215
 
}
216
 
 
217
 
static PyObject *py_get_default_folder(PyMapiObjectObject *self, PyObject *args)
218
 
{
219
 
        enum MAPISTATUS status;
220
 
        uint32_t type;
221
 
        uint64_t folder;
222
 
 
223
 
        if (!PyArg_ParseTuple(args, "i", &type))
224
 
                return NULL;
225
 
 
226
 
        status = GetDefaultFolder(self->object, &folder, type);
227
 
        PyErr_MAPISTATUS_IS_ERR_RAISE(status);
228
 
 
229
 
        return PyLong_FromLong(folder);
230
 
}
231
 
 
232
 
static PyObject *py_get_default_public_folder(PyMapiObjectObject *self, PyObject *args)
233
 
{
234
 
        enum MAPISTATUS status;
235
 
        uint32_t type;
236
 
        uint64_t folder;
237
 
 
238
 
        if (!PyArg_ParseTuple(args, "i", &type))
239
 
                return NULL;
240
 
 
241
 
        status = GetDefaultPublicFolder(self->object, &folder, type);
242
 
        PyErr_MAPISTATUS_IS_ERR_RAISE(status);
243
 
 
244
 
        return PyLong_FromLong(folder);
245
 
}
246
 
 
247
 
static PyObject *py_folder_add_user_permission(PyMapiObjectObject *self, PyObject *args)
248
 
{
249
 
        char *name;
250
 
        int rights;
251
 
        enum MAPISTATUS status;
252
 
        if (!PyArg_ParseTuple(args, "si", &name, &rights))
253
 
                return NULL;
254
 
 
255
 
        status = AddUserPermission(self->object, name, rights);
256
 
        PyErr_MAPISTATUS_IS_ERR_RAISE(status);
257
 
 
258
 
        return Py_None;
259
 
}
260
 
 
261
 
static PyObject *py_folder_modify_user_permission(PyMapiObjectObject *self, PyObject *args)
262
 
{
263
 
        char *name;
264
 
        int rights;
265
 
        enum MAPISTATUS status;
266
 
        if (!PyArg_ParseTuple(args, "si", &name, &rights))
267
 
                return NULL;
268
 
 
269
 
        status = ModifyUserPermission(self->object, name, rights);
270
 
        PyErr_MAPISTATUS_IS_ERR_RAISE(status);
271
 
 
272
 
        return Py_None;
273
 
}
274
 
 
275
 
static PyMethodDef object_methods[] = {
276
 
        { "get_folder_items_count", (PyCFunction)py_folder_get_items_count, METH_NOARGS, 
277
 
                "S.get_folder_items_count() -> (unread, total)" },
278
 
        { "remove_user_permission", (PyCFunction)py_folder_remove_user_permissions, METH_VARARGS,
279
 
                "S.remove_user_permissions(user) -> None" },
280
 
        { "add_user_permission", (PyCFunction)py_folder_add_user_permission, METH_VARARGS,
281
 
                "S.add_user_permission(user, perm) -> None" },
282
 
        { "modify_user_permission", (PyCFunction)py_folder_modify_user_permission, METH_VARARGS,
283
 
                "S.modify_user_permission(user, perm) -> None" },
284
 
        { "create_folder", (PyCFunction)py_folder_create, METH_VARARGS,
285
 
                "S.create_folder(type, name, comment, flags) -> None" },
286
 
        { "empty_folder", (PyCFunction)py_folder_empty, METH_NOARGS, 
287
 
                "S.empty_folder() -> None" },
288
 
        { "delete_folder", (PyCFunction)py_folder_delete, METH_VARARGS,
289
 
                "S.delete_folder(folderid, flags) -> None" },
290
 
        { "create_message", (PyCFunction)py_folder_create_message, METH_NOARGS,
291
 
                "S.create_message() -> message" },
292
 
        { "delete_messages", (PyCFunction)py_folder_delete_messages, METH_VARARGS,
293
 
                "S.delete_messages([ids]) -> None" },
294
 
        { "get_message_status", (PyCFunction)py_folder_get_message_status, METH_VARARGS,
295
 
                "S.get_message_status(id) -> status" },
296
 
        { "set_read_flags", (PyCFunction)py_folder_set_read_flags, METH_VARARGS,
297
 
                "S.set_read_flags(flags, [ids]) -> None" },
298
 
        { "get_best_body", (PyCFunction)py_message_get_best_body, METH_NOARGS,
299
 
                "S.get_best_body() -> format" },
300
 
        { "get_default_folder", (PyCFunction)py_get_default_folder, METH_VARARGS,
301
 
                "S.get_default_folder(type) -> id" },
302
 
        { "get_default_public_folder", (PyCFunction)py_get_default_public_folder, METH_VARARGS,
303
 
                "S.get_default_public_folder(type) -> id" },
304
 
        { NULL },
305
 
};
306
 
 
307
 
static PyObject *object_get_session(PyObject *_self, void *closure)
308
 
{
309
 
        PyMapiObjectObject *self = (PyMapiObjectObject *)_self;
310
 
        struct mapi_session *session;
311
 
 
312
 
        session = mapi_object_get_session(self->object);
313
 
 
314
 
        return PyMapiSession_FromMapiSession(session);
315
 
}
316
 
 
317
 
static PyObject *object_get_id(PyObject *_self, void *closure)
318
 
{
319
 
        PyMapiObjectObject *self = (PyMapiObjectObject *)_self;
320
 
        mapi_id_t id;
321
 
 
322
 
        id = mapi_object_get_id(self->object);
323
 
 
324
 
        return PyLong_FromLong(id);
325
 
}
326
 
 
327
 
static PyGetSetDef object_getsetters[] = {
328
 
        { "session", object_get_session, NULL, "The MAPI session" },
329
 
        { "id", object_get_id, NULL, "MAPI ID" },
330
 
        { NULL }
331
 
};
332
 
 
333
 
PyTypeObject PyMapiObjectType = {
334
 
        PyObject_HEAD_INIT(NULL) 0,
335
 
        .tp_name = "Object",
336
 
        .tp_basicsize = sizeof(PyMapiObjectObject),
337
 
        .tp_methods = object_methods,
338
 
        .tp_getset = object_getsetters,
339
 
        .tp_doc = "MAPI Object",
340
 
        .tp_new = object_create,
341
 
        .tp_dealloc = object_dealloc,
342
 
        .tp_flags = Py_TPFLAGS_DEFAULT,
343
 
};
344