Commit b390f377 b390f3773720cf07d88a192740c0082504faa7f8 by Wojciech Polak

Add more is/set/unset attribute methods (Python).

* python/libmu_py/attribute.c: Add userflag functions.
* python/mailutils/attribute.py: Add more is/set/unset methods.
* python/mailutils/mailbox.py (open): Bugfix.
1 parent 36a121b9
......@@ -181,6 +181,45 @@ api_attribute_unset_flags (PyObject *self, PyObject *args)
}
static PyObject *
api_attribute_is_userflag (PyObject *self, PyObject *args)
{
int state, flag;
PyAttribute *py_attr;
if (!PyArg_ParseTuple (args, "O!i", &PyAttributeType, &py_attr, &flag))
return NULL;
state = mu_attribute_is_userflag (py_attr->attr, flag);
return _ro (PyBool_FromLong (state));
}
static PyObject *
api_attribute_set_userflag (PyObject *self, PyObject *args)
{
int status, flag;
PyAttribute *py_attr;
if (!PyArg_ParseTuple (args, "O!i", &PyAttributeType, &py_attr, &flag))
return NULL;
status = mu_attribute_set_userflag (py_attr->attr, flag);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_attribute_unset_userflag (PyObject *self, PyObject *args)
{
int status, flag;
PyAttribute *py_attr;
if (!PyArg_ParseTuple (args, "O!i", &PyAttributeType, &py_attr, &flag))
return NULL;
status = mu_attribute_unset_userflag (py_attr->attr, flag);
return _ro (PyInt_FromLong (status));
}
static PyObject *
api_attribute_to_string (PyObject *self, PyObject *args)
{
char buf[MU_STATUS_BUF_SIZE];
......@@ -221,6 +260,15 @@ static PyMethodDef methods[] = {
{ "unset_flags", (PyCFunction) api_attribute_unset_flags, METH_VARARGS,
"" },
{ "is_userflag", (PyCFunction) api_attribute_is_userflag, METH_VARARGS,
"" },
{ "set_userflag", (PyCFunction) api_attribute_set_userflag, METH_VARARGS,
"" },
{ "unset_userflag", (PyCFunction) api_attribute_unset_userflag,
METH_VARARGS, "" },
{ "to_string", (PyCFunction) api_attribute_to_string, METH_VARARGS,
"" },
......
......@@ -81,3 +81,79 @@ class Attribute:
if flags & flag:
return True
return False
def set_userflag (self, flag):
status = attribute.set_userflag (self.attr, flag)
if status:
raise Error (status)
def unset_userflag (self, flag):
status = attribute.unset_userflag (self.attr, flag)
if status:
raise Error (status)
def is_userflag (self, flag):
return attribute.is_userflag (self.attr, flag)
def is_answered (self):
return self.is_flag (MU_ATTRIBUTE_ANSWERED)
def is_flagged (self):
return self.is_flag (MU_ATTRIBUTE_FLAGGED)
def is_deleted (self):
return self.is_flag (MU_ATTRIBUTE_DELETED)
def is_draft (self):
return self.is_flag (MU_ATTRIBUTE_DRAFT)
def is_seen (self):
return self.is_flag (MU_ATTRIBUTE_SEEN)
def is_read (self):
return self.is_flag (MU_ATTRIBUTE_READ)
def set_answered (self):
self.set_flags (MU_ATTRIBUTE_ANSWERED)
def set_flagged (self):
self.set_flags (MU_ATTRIBUTE_FLAGGED)
def set_deleted (self):
self.set_flags (MU_ATTRIBUTE_DELETED)
def set_draft (self):
self.set_flags (MU_ATTRIBUTE_DRAFT)
def set_seen (self):
self.set_flags (MU_ATTRIBUTE_SEEN)
def set_read (self):
self.set_flags (MU_ATTRIBUTE_READ)
def set_recent (self):
self.unset_flags (MU_ATTRIBUTE_READ | MU_ATTRIBUTE_SEEN)
def unset_answered (self):
self.unset_flags (MU_ATTRIBUTE_ANSWERED)
def unset_flagged (self):
self.unset_flags (MU_ATTRIBUTE_FLAGGED)
def unset_deleted (self):
self.unset_flags (MU_ATTRIBUTE_DELETED)
def unset_draft (self):
self.unset_flags (MU_ATTRIBUTE_DRAFT)
def unset_seen (self):
self.unset_flags (MU_ATTRIBUTE_SEEN)
def unset_read (self):
self.unset_flags (MU_ATTRIBUTE_READ)
def unset_recent (self):
self.unset_flags (MU_ATTRIBUTE_SEEN)
......
......@@ -32,14 +32,19 @@ class MailboxBase:
if isinstance (mode, types.StringType):
from mailutils import stream
flags = 0
if mode == 'r':
flags = flags | stream.MU_STREAM_READ
elif mode == 'w':
flags = flags | stream.MU_STREAM_WRITE
elif mode == 'a':
flags = flags | stream.MU_STREAM_APPEND
elif mode == 'c':
flags = flags | stream.MU_STREAM_CREAT
for m in mode:
if m == 'r':
flags = flags | stream.MU_STREAM_READ
elif m == 'w':
flags = flags | stream.MU_STREAM_WRITE
elif m == 'a':
flags = flags | stream.MU_STREAM_APPEND
elif m == 'c':
flags = flags | stream.MU_STREAM_CREAT
if flags & stream.MU_STREAM_READ and flags & stream.MU_STREAM_WRITE:
flags = (flags & ~(stream.MU_STREAM_READ | \
stream.MU_STREAM_WRITE)) | \
stream.MU_STREAM_RDWR
mode = flags
status = mailbox.open (self.mbox, mode)
if status:
......