Commit 0c606c74 0c606c74e0195d00bb1410114e7b871c08c2a7f0 by Wojciech Polak

Python: Bugfixes.

* python/libmu_py/mailbox.c (api_mailbox_append_message): Bugfix.
* python/libmu_py/header.c (api_header_get_value_n): New function.
* python/mailutils/header.py (Header.get_value_n): New method.
* python/mailutils/mailbox.py (Mailbox.__str__): New method.
* python/mailutils/message.py (Message.__str__): Likewise.
1 parent 5171c0f9
......@@ -123,6 +123,21 @@ api_header_get_value (PyObject *self, PyObject *args)
}
static PyObject *
api_header_get_value_n (PyObject *self, PyObject *args)
{
int status, n;
char *name;
const char *value = NULL;
PyHeader *py_hdr;
if (!PyArg_ParseTuple (args, "O!si", &PyHeaderType, &py_hdr, &name, &n))
return NULL;
status = mu_header_sget_value_n (py_hdr->hdr, name, n, &value);
return status_object (status, PyString_FromString (value ? value : ""));
}
static PyObject *
api_header_set_value (PyObject *self, PyObject *args)
{
int status, replace = 1;
......@@ -191,6 +206,9 @@ static PyMethodDef methods[] = {
{ "get_value", (PyCFunction) api_header_get_value, METH_VARARGS,
"Retrieve header field value." },
{ "get_value_n", (PyCFunction) api_header_get_value_n, METH_VARARGS,
"Retrieve Nth header field value." },
{ "set_value", (PyCFunction) api_header_set_value, METH_VARARGS,
"Set header field value." },
......
......@@ -241,7 +241,7 @@ api_mailbox_append_message (PyObject *self, PyObject *args)
}
status = mu_mailbox_append_message (py_mbox->mbox, py_msg->msg);
return status_object (status, PyInt_FromLong (status));
return _ro (PyInt_FromLong (status));
}
static PyObject *
......
......@@ -96,6 +96,17 @@ class Header:
raise HeaderError (status)
return value
def get_value_n (self, name, n = 1, default = None):
status, value = header.get_value_n (self.hdr, name, n)
if status == MU_ERR_NOENT:
if default != None:
return default
else:
raise KeyError (name)
elif status:
raise HeaderError (status)
return value
def set_value (self, name, value, replace = True):
status = header.set_value (self.hdr, name, value, replace)
if status:
......
......@@ -184,6 +184,8 @@ class MailboxBase:
def __len__ (self):
return self.messages_count ()
def __str__ (self):
return '<Mailbox %s (%d)>' % (self.get_url (), self.messages_count ())
class Mailbox (MailboxBase):
__owner = False
......
......@@ -43,6 +43,16 @@ class Message:
message.destroy (self.msg)
del self.msg
def __str__ (self):
try:
env = self.get_envelope ()
envelope = '%s %s' % (env.get_sender ().strip (),
env.get_date ().strip ())
except MessageError:
envelope = 'UNKNOWN'
return '<Message "%s" %d %d>' % (envelope, self.get_lines (),
self.get_size ())
def __getattr__ (self, name):
if name == 'header':
return self.get_header ()
......