2
OpenChange MAPI implementation.
4
Copyright (C) Jelmer Vernooij <jelmer@openchange.org> 2008.
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.
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.
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/>.
20
#include "pymapi/pymapi.h"
24
struct mapi_session *session;
25
} PyMapiSessionObject;
27
static PyObject *py_session_create(PyTypeObject *type, PyObject *args, PyObject *kwargs)
29
enum MAPISTATUS retval;
30
char *kwnames[] = { "profname", "password", "provider" };
31
char *profname, *password;
32
uint32_t provider = 0;
33
struct mapi_session *session;
35
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ss|i", kwnames,
36
&profname, &password, &provider))
39
retval = MapiLogonProvider(&session, profname, password, provider);
41
PyErr_SetMAPISTATUS(retval);
44
return PyMapiSession_FromMapiSession(session);
47
PyObject *PyMapiSession_FromMapiSession(struct mapi_session *session)
49
PyMapiSessionObject *ret;
50
ret = PyObject_New(PyMapiSessionObject, &PyMapiSessionType);
51
ret->session = session;
52
return (PyObject *)ret;
55
static PyObject *py_session_login(PyObject *args, PyObject *kwargs)
61
static PyObject *py_open_msg_store(PyObject *self, PyObject *args)
63
PyObject *py_mapi_object;
64
PyMapiSessionObject *self_session = (PyMapiSessionObject *)self;
66
enum MAPISTATUS retval;
68
if (!PyArg_ParseTuple(args, "O", &py_mapi_object))
71
obj = PyMapiObject_GetMapiObject(py_mapi_object);
73
PyErr_SetString(PyExc_TypeError, "Expected MAPI Object");
77
retval = OpenMsgStore(self_session->session, obj);
79
PyErr_SetMAPISTATUS(retval);
86
static PyObject *py_open_user_mailbox(PyObject *self, PyObject *args)
88
PyObject *py_mapi_object;
89
PyMapiSessionObject *self_session = (PyMapiSessionObject *)self;
91
enum MAPISTATUS retval;
94
if (!PyArg_ParseTuple(args, "sO", &username, &py_mapi_object))
97
obj = PyMapiObject_GetMapiObject(py_mapi_object);
99
PyErr_SetString(PyExc_TypeError, "Expected MAPI Object");
103
retval = OpenUserMailbox(self_session->session, username, obj);
105
PyErr_SetMAPISTATUS(retval);
112
static PyObject *py_open_public_folder(PyObject *self, PyObject *args)
114
PyObject *py_mapi_object;
115
PyMapiSessionObject *self_session = (PyMapiSessionObject *)self;
117
enum MAPISTATUS retval;
119
if (!PyArg_ParseTuple(args, "O", &py_mapi_object))
122
obj = PyMapiObject_GetMapiObject(py_mapi_object);
124
PyErr_SetString(PyExc_TypeError, "Expected MAPI Object");
128
retval = OpenPublicFolder(self_session->session, obj);
130
PyErr_SetMAPISTATUS(retval);
137
static PyObject *py_unsubscribe(PyMapiSessionObject *self, PyObject *args)
139
uint32_t ulConnection;
140
enum MAPISTATUS status;
142
if (!PyArg_ParseTuple(args, "i", &ulConnection))
145
status = Unsubscribe(self->session, ulConnection);
146
PyErr_MAPISTATUS_IS_ERR_RAISE(status);
151
static PyMethodDef session_methods[] = {
152
{ "login", (PyCFunction) py_session_login, METH_VARARGS|METH_KEYWORDS },
153
{ "open_msg_store", (PyCFunction) py_open_msg_store, METH_VARARGS,
154
"S.open_msg_store(object)\n\n"
155
"This function opens the main message store. This allows access to "
156
"the normal user folders."
158
{ "open_user_mailbox", (PyCFunction) py_open_user_mailbox, METH_VARARGS,
159
"S.open_user_mailbox(username, object)\n\n"
160
"Open another users mailbox."
162
{ "open_public_folder", (PyCFunction) py_open_public_folder, METH_VARARGS,
163
"S.open_public_folder(object)\n\n"
164
"This function opens the public folder store. This allows access to "
165
"the public folders."
167
{ "unsubscribe", (PyCFunction) py_unsubscribe, METH_VARARGS,
168
"S.Unsubscribe(int) -> None"
173
static PyGetSetDef session_getsetters[] = {
174
{ "default_profile_path", NULL, NULL },
175
{ "profile_name", NULL, NULL },
176
{ "message_store", NULL, NULL },
180
PyTypeObject PyMapiSessionType = {
181
PyObject_HEAD_INIT(NULL) 0,
182
.tp_name = "Session",
183
.tp_basicsize = sizeof(PyMapiSessionObject),
184
.tp_methods = session_methods,
185
.tp_getset = session_getsetters,
186
.tp_doc = "MAPI Session",
187
.tp_new = py_session_create,
188
.tp_flags = Py_TPFLAGS_DEFAULT,