Commit 181e0c84 181e0c84c1f0bd3d18bc39a9ac6df3c5dcedf3b5 by Wojciech Polak

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.
1 parent 8ea94114
......@@ -49,6 +49,7 @@ class MailboxBase
void append_message (const Message& msg);
void expunge ();
void sync ();
List& get_uidls ();
void lock ();
void unlock ();
mu_off_t get_size ();
......
......@@ -124,6 +124,18 @@ MailboxBase :: sync ()
throw Exception ("MailboxBase::sync", status);
}
List&
MailboxBase :: get_uidls ()
{
mu_list_t c_list;
int status = mu_mailbox_get_uidls (mbox, &c_list);
if (status)
throw Exception ("MailboxBase::get_uidls", status);
return *new List (c_list);
}
void
MailboxBase :: lock ()
{
......
......@@ -264,6 +264,38 @@ api_mailbox_sync (PyObject *self, PyObject *args)
return _ro (PyInt_FromLong (status));
}
static int
uidls_extractor (void *data, PyObject **dst)
{
struct mu_uidl *uidl = (struct mu_uidl *)data;
*dst = PyTuple_New (2);
PyTuple_SetItem (*dst, 0, PyInt_FromLong (uidl->msgno));
PyTuple_SetItem (*dst, 1, PyString_FromString (uidl->uidl));
return 0;
}
static PyObject *
api_mailbox_get_uidls (PyObject *self, PyObject *args)
{
int status;
PyMailbox *py_mbox;
PyObject *py_list;
mu_list_t c_list = NULL;
if (!PyArg_ParseTuple (args, "O!", &PyMailboxType, &py_mbox))
return NULL;
status = mu_mailbox_get_uidls (py_mbox->mbox, &c_list);
if (c_list)
py_list = mu_py_mulist_to_pylist (c_list, uidls_extractor);
else
py_list = PyTuple_New (0);
return status_object (status, py_list);
}
static PyObject *
api_mailbox_lock (PyObject *self, PyObject *args)
{
......@@ -397,6 +429,9 @@ static PyMethodDef methods[] = {
{ "sync", (PyCFunction) api_mailbox_sync, METH_VARARGS,
"" },
{ "get_uidls", (PyCFunction) api_mailbox_get_uidls, METH_VARARGS,
"" },
{ "lock", (PyCFunction) api_mailbox_lock, METH_VARARGS,
"" },
......
......@@ -103,6 +103,13 @@ class MailboxBase:
if status:
raise MailboxError (status)
def get_uidls (self):
"""Get UIDL list."""
status, uidls = mailbox.get_uidls (self.mbox)
if status:
raise MailboxError (status)
return uidls
def lock (self):
"""Lock the mailbox."""
status = mailbox.lock (self.mbox)
......