diff options
author | Wojciech Polak <polak@gnu.org> | 2009-08-21 21:05:45 +0200 |
---|---|---|
committer | Wojciech Polak <polak@gnu.org> | 2009-08-21 21:06:50 +0200 |
commit | 0c606c74e0195d00bb1410114e7b871c08c2a7f0 (patch) | |
tree | adfa2a2b068077fefb7535229b7372c7dedfc69c | |
parent | 5171c0f91ea69eacd76068661db628f46f267c9e (diff) | |
download | mailutils-0c606c74e0195d00bb1410114e7b871c08c2a7f0.tar.gz mailutils-0c606c74e0195d00bb1410114e7b871c08c2a7f0.tar.bz2 |
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.
-rw-r--r-- | python/libmu_py/header.c | 18 | ||||
-rw-r--r-- | python/libmu_py/mailbox.c | 2 | ||||
-rw-r--r-- | python/mailutils/header.py | 11 | ||||
-rw-r--r-- | python/mailutils/mailbox.py | 2 | ||||
-rw-r--r-- | python/mailutils/message.py | 10 |
5 files changed, 42 insertions, 1 deletions
diff --git a/python/libmu_py/header.c b/python/libmu_py/header.c index bd4721a36..878448d2b 100644 --- a/python/libmu_py/header.c +++ b/python/libmu_py/header.c @@ -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." }, diff --git a/python/libmu_py/mailbox.c b/python/libmu_py/mailbox.c index dde938379..b5fc60790 100644 --- a/python/libmu_py/mailbox.c +++ b/python/libmu_py/mailbox.c @@ -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 * diff --git a/python/mailutils/header.py b/python/mailutils/header.py index 86ba9043a..8e06c9a6f 100644 --- a/python/mailutils/header.py +++ b/python/mailutils/header.py @@ -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: diff --git a/python/mailutils/mailbox.py b/python/mailutils/mailbox.py index b10c804e1..af4905a61 100644 --- a/python/mailutils/mailbox.py +++ b/python/mailutils/mailbox.py @@ -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 diff --git a/python/mailutils/message.py b/python/mailutils/message.py index 19ca0e87e..2e8fd7bad 100644 --- a/python/mailutils/message.py +++ b/python/mailutils/message.py @@ -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 () |