Add mailbox.get_uidls() to Python/C++.
* libmu_cpp/mailbox.cc (get_uidls): New method. * python/libmu_py/mailbox.c (api_mailbox_get_uidls): New function. * python/mailutils/mailbox.py (get_uidls): New method.
Showing
4 changed files
with
55 additions
and
0 deletions
... | @@ -49,6 +49,7 @@ class MailboxBase | ... | @@ -49,6 +49,7 @@ class MailboxBase |
49 | void append_message (const Message& msg); | 49 | void append_message (const Message& msg); |
50 | void expunge (); | 50 | void expunge (); |
51 | void sync (); | 51 | void sync (); |
52 | List& get_uidls (); | ||
52 | void lock (); | 53 | void lock (); |
53 | void unlock (); | 54 | void unlock (); |
54 | mu_off_t get_size (); | 55 | mu_off_t get_size (); | ... | ... |
... | @@ -124,6 +124,18 @@ MailboxBase :: sync () | ... | @@ -124,6 +124,18 @@ MailboxBase :: sync () |
124 | throw Exception ("MailboxBase::sync", status); | 124 | throw Exception ("MailboxBase::sync", status); |
125 | } | 125 | } |
126 | 126 | ||
127 | List& | ||
128 | MailboxBase :: get_uidls () | ||
129 | { | ||
130 | mu_list_t c_list; | ||
131 | |||
132 | int status = mu_mailbox_get_uidls (mbox, &c_list); | ||
133 | if (status) | ||
134 | throw Exception ("MailboxBase::get_uidls", status); | ||
135 | |||
136 | return *new List (c_list); | ||
137 | } | ||
138 | |||
127 | void | 139 | void |
128 | MailboxBase :: lock () | 140 | MailboxBase :: lock () |
129 | { | 141 | { | ... | ... |
... | @@ -264,6 +264,38 @@ api_mailbox_sync (PyObject *self, PyObject *args) | ... | @@ -264,6 +264,38 @@ api_mailbox_sync (PyObject *self, PyObject *args) |
264 | return _ro (PyInt_FromLong (status)); | 264 | return _ro (PyInt_FromLong (status)); |
265 | } | 265 | } |
266 | 266 | ||
267 | static int | ||
268 | uidls_extractor (void *data, PyObject **dst) | ||
269 | { | ||
270 | struct mu_uidl *uidl = (struct mu_uidl *)data; | ||
271 | |||
272 | *dst = PyTuple_New (2); | ||
273 | PyTuple_SetItem (*dst, 0, PyInt_FromLong (uidl->msgno)); | ||
274 | PyTuple_SetItem (*dst, 1, PyString_FromString (uidl->uidl)); | ||
275 | return 0; | ||
276 | } | ||
277 | |||
278 | static PyObject * | ||
279 | api_mailbox_get_uidls (PyObject *self, PyObject *args) | ||
280 | { | ||
281 | int status; | ||
282 | PyMailbox *py_mbox; | ||
283 | PyObject *py_list; | ||
284 | mu_list_t c_list = NULL; | ||
285 | |||
286 | if (!PyArg_ParseTuple (args, "O!", &PyMailboxType, &py_mbox)) | ||
287 | return NULL; | ||
288 | |||
289 | status = mu_mailbox_get_uidls (py_mbox->mbox, &c_list); | ||
290 | |||
291 | if (c_list) | ||
292 | py_list = mu_py_mulist_to_pylist (c_list, uidls_extractor); | ||
293 | else | ||
294 | py_list = PyTuple_New (0); | ||
295 | |||
296 | return status_object (status, py_list); | ||
297 | } | ||
298 | |||
267 | static PyObject * | 299 | static PyObject * |
268 | api_mailbox_lock (PyObject *self, PyObject *args) | 300 | api_mailbox_lock (PyObject *self, PyObject *args) |
269 | { | 301 | { |
... | @@ -397,6 +429,9 @@ static PyMethodDef methods[] = { | ... | @@ -397,6 +429,9 @@ static PyMethodDef methods[] = { |
397 | { "sync", (PyCFunction) api_mailbox_sync, METH_VARARGS, | 429 | { "sync", (PyCFunction) api_mailbox_sync, METH_VARARGS, |
398 | "" }, | 430 | "" }, |
399 | 431 | ||
432 | { "get_uidls", (PyCFunction) api_mailbox_get_uidls, METH_VARARGS, | ||
433 | "" }, | ||
434 | |||
400 | { "lock", (PyCFunction) api_mailbox_lock, METH_VARARGS, | 435 | { "lock", (PyCFunction) api_mailbox_lock, METH_VARARGS, |
401 | "" }, | 436 | "" }, |
402 | 437 | ... | ... |
... | @@ -103,6 +103,13 @@ class MailboxBase: | ... | @@ -103,6 +103,13 @@ class MailboxBase: |
103 | if status: | 103 | if status: |
104 | raise MailboxError (status) | 104 | raise MailboxError (status) |
105 | 105 | ||
106 | def get_uidls (self): | ||
107 | """Get UIDL list.""" | ||
108 | status, uidls = mailbox.get_uidls (self.mbox) | ||
109 | if status: | ||
110 | raise MailboxError (status) | ||
111 | return uidls | ||
112 | |||
106 | def lock (self): | 113 | def lock (self): |
107 | """Lock the mailbox.""" | 114 | """Lock the mailbox.""" |
108 | status = mailbox.lock (self.mbox) | 115 | status = mailbox.lock (self.mbox) | ... | ... |
-
Please register or sign in to post a comment