summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWojciech Polak <polak@gnu.org>2009-07-29 15:27:55 +0200
committerWojciech Polak <polak@gnu.org>2009-07-29 22:55:02 +0200
commitda546ae1358654cb568b983a2bb2e79f2f508c2b (patch)
tree44d83fd227a97b2528ddecb1bf3fdf7f6ba646f8
parentfe1fe3832d7d6febcd163f4854f3a5438db2074c (diff)
downloadmailutils-da546ae1358654cb568b983a2bb2e79f2f508c2b.tar.gz
mailutils-da546ae1358654cb568b983a2bb2e79f2f508c2b.tar.bz2
Add SieveMachine to C++/Python.
* include/mailutils/cpp/sieve.h: New file. * libmu_cpp/sieve.cc: New file. * python/libmu_py/sieve.c: New file. * python/mailutils/sieve.py: New file. * include/mailutils/cstr.h: Do not use C++ keywords. * include/mailutils/tls.h: Likewise.
-rw-r--r--examples/cpp/Makefile.am1
-rw-r--r--examples/cpp/lsf.cc4
-rw-r--r--examples/cpp/msg-send.cc2
-rw-r--r--examples/python/lsf.py1
-rw-r--r--include/mailutils/cpp/Makefile.am1
-rw-r--r--include/mailutils/cpp/address.h6
-rw-r--r--include/mailutils/cpp/mailbox.h2
-rw-r--r--include/mailutils/cpp/mailutils.h1
-rw-r--r--include/mailutils/cpp/message.h1
-rw-r--r--include/mailutils/cpp/sieve.h59
-rw-r--r--include/mailutils/cstr.h8
-rw-r--r--include/mailutils/python.h7
-rw-r--r--include/mailutils/tls.h2
-rw-r--r--libmu_cpp/Makefile.am1
-rw-r--r--libmu_cpp/sieve.cc117
-rw-r--r--libmu_sieve/sieve.y4
-rw-r--r--python/libmu_py/Makefile.am2
-rw-r--r--python/libmu_py/libmu_py.c2
-rw-r--r--python/libmu_py/libmu_py.h2
-rw-r--r--python/libmu_py/mailbox.c6
-rw-r--r--python/libmu_py/sieve.c487
-rw-r--r--python/mailutils/Makefile.am1
-rw-r--r--python/mailutils/__init__.py1
-rw-r--r--python/mailutils/error.py1
-rw-r--r--python/mailutils/sieve.py79
25 files changed, 783 insertions, 15 deletions
diff --git a/examples/cpp/Makefile.am b/examples/cpp/Makefile.am
index 78179e57e..3bee7f6b0 100644
--- a/examples/cpp/Makefile.am
+++ b/examples/cpp/Makefile.am
@@ -64,5 +64,6 @@ LDADD =\
${MU_LIB_MAILDIR}\
${MU_LIB_AUTH}\
${MU_LIB_MAILER}\
+ ${MU_LIB_SIEVE}\
@MU_AUTHLIBS@\
${MU_LIB_MAILUTILS}
diff --git a/examples/cpp/lsf.cc b/examples/cpp/lsf.cc
index d22d00f68..6e1111c32 100644
--- a/examples/cpp/lsf.cc
+++ b/examples/cpp/lsf.cc
@@ -66,7 +66,7 @@ main (int argc, char *argv[])
{
string folder;
string ref;
- char *pattern = "*";
+ const char *pattern = "*";
int level = 0;
switch (argc)
@@ -87,6 +87,6 @@ main (int argc, char *argv[])
register_all_mbox_formats ();
- return ls_folders (folder, ref, pattern, level);
+ return ls_folders (folder, ref, (char *)pattern, level);
}
diff --git a/examples/cpp/msg-send.cc b/examples/cpp/msg-send.cc
index b7ec83709..993ce65ba 100644
--- a/examples/cpp/msg-send.cc
+++ b/examples/cpp/msg-send.cc
@@ -41,7 +41,7 @@ main (int argc, char *argv[])
{
int opt;
int optdebug = 0;
- char *optmailer = "sendmail:";
+ const char *optmailer = "sendmail:";
char *optfrom = 0;
while ((opt = getopt (argc, argv, "hdm:f:")) != -1)
diff --git a/examples/python/lsf.py b/examples/python/lsf.py
index 84c29240c..c40a100e4 100644
--- a/examples/python/lsf.py
+++ b/examples/python/lsf.py
@@ -53,6 +53,7 @@ if __name__ == '__main__':
ref = sys.argv[2]
fname = sys.argv[1]
elif argc == 2:
+ ref = None
fname = sys.argv[1]
else:
print "usage: lsf folder [ref] [pattern] [recursion-level]"
diff --git a/include/mailutils/cpp/Makefile.am b/include/mailutils/cpp/Makefile.am
index 5b3ef1371..69c15b639 100644
--- a/include/mailutils/cpp/Makefile.am
+++ b/include/mailutils/cpp/Makefile.am
@@ -38,6 +38,7 @@ MU_CXX_INCLUDES = \
pop3.h\
registrar.h\
secret.h\
+ sieve.h\
stream.h\
url.h
diff --git a/include/mailutils/cpp/address.h b/include/mailutils/cpp/address.h
index a41e99167..066343440 100644
--- a/include/mailutils/cpp/address.h
+++ b/include/mailutils/cpp/address.h
@@ -18,8 +18,8 @@
Boston, MA 02110-1301 USA
*/
-#ifndef _ADDRESS_H
-#define _ADDRESS_H
+#ifndef _MUCPP_ADDRESS_H
+#define _MUCPP_ADDRESS_H
#include <ostream>
#include <errno.h>
@@ -72,5 +72,5 @@ class Address
}
-#endif // not _ADDRESS_H
+#endif // not _MUCPP_ADDRESS_H
diff --git a/include/mailutils/cpp/mailbox.h b/include/mailutils/cpp/mailbox.h
index e0a0b0b6c..e8d7c5cc1 100644
--- a/include/mailutils/cpp/mailbox.h
+++ b/include/mailutils/cpp/mailbox.h
@@ -37,6 +37,8 @@ class MailboxBase
protected:
mu_mailbox_t mbox;
+ friend class SieveMachine;
+
public:
void open ();
void open (int flag);
diff --git a/include/mailutils/cpp/mailutils.h b/include/mailutils/cpp/mailutils.h
index 04e34bc47..da14cce3b 100644
--- a/include/mailutils/cpp/mailutils.h
+++ b/include/mailutils/cpp/mailutils.h
@@ -36,6 +36,7 @@
#include <mailutils/cpp/pop3.h>
#include <mailutils/cpp/registrar.h>
#include <mailutils/cpp/secret.h>
+#include <mailutils/cpp/sieve.h>
#include <mailutils/cpp/stream.h>
#include <mailutils/cpp/url.h>
diff --git a/include/mailutils/cpp/message.h b/include/mailutils/cpp/message.h
index a901eb85a..dbe227141 100644
--- a/include/mailutils/cpp/message.h
+++ b/include/mailutils/cpp/message.h
@@ -42,6 +42,7 @@ class Message
friend class MailboxBase;
friend class Mailer;
friend class Mime;
+ friend class SieveMachine;
public:
Message ();
diff --git a/include/mailutils/cpp/sieve.h b/include/mailutils/cpp/sieve.h
new file mode 100644
index 000000000..3dd2a0256
--- /dev/null
+++ b/include/mailutils/cpp/sieve.h
@@ -0,0 +1,59 @@
+/*
+ GNU Mailutils -- a suite of utilities for electronic mail
+ Copyright (C) 2009 Free Software Foundation, Inc.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 3 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General
+ Public License along with this library; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301 USA
+*/
+
+#ifndef _MUCPP_SIEVE_H
+#define _MUCPP_SIEVE_H
+
+#include <string>
+#include <errno.h>
+#include <mailutils/sieve.h>
+#include <mailutils/cpp/error.h>
+#include <mailutils/cpp/mailbox.h>
+#include <mailutils/cpp/message.h>
+
+namespace mailutils
+{
+
+class SieveMachine
+{
+ protected:
+ mu_sieve_machine_t mach;
+
+ public:
+ SieveMachine ();
+ SieveMachine (const mu_sieve_machine_t);
+ ~SieveMachine ();
+
+ SieveMachine& operator = (const SieveMachine&);
+
+ void compile (const std::string& name);
+ void disass ();
+ void mailbox (const Mailbox& mbox);
+ void message (const Message& msg);
+ void set_debug (mu_sieve_printf_t printer);
+ void set_error (mu_sieve_printf_t printer);
+ void set_parse_error (mu_sieve_parse_error_t printer);
+ void set_logger (mu_sieve_action_log_t printer);
+};
+
+}
+
+#endif // not _MUCPP_SIEVE_H
+
diff --git a/include/mailutils/cstr.h b/include/mailutils/cstr.h
index 2077647d3..b4934941f 100644
--- a/include/mailutils/cstr.h
+++ b/include/mailutils/cstr.h
@@ -28,15 +28,15 @@ int mu_strupper (char *);
int mu_c_strcasecmp (const char *a, const char *b);
int mu_c_strncasecmp (const char *a, const char *b, size_t n);
-size_t mu_rtrim_class (char *str, int class);
+size_t mu_rtrim_class (char *str, int __class);
size_t mu_rtrim_cset (char *str, const char *cset);
-size_t mu_ltrim_class (char *str, int class);
+size_t mu_ltrim_class (char *str, int __class);
size_t mu_ltrim_cset (char *str, const char *cset);
-char *mu_str_skip_class (const char *str, int class);
+char *mu_str_skip_class (const char *str, int __class);
char *mu_str_skip_cset (const char *str, const char *cset);
-char *mu_str_skip_class_comp (const char *str, int class);
+char *mu_str_skip_class_comp (const char *str, int __class);
char *mu_str_skip_cset_comp (const char *str, const char *cset);
char *mu_str_stripws (char *string);
diff --git a/include/mailutils/python.h b/include/mailutils/python.h
index 83865984e..e24501d5d 100644
--- a/include/mailutils/python.h
+++ b/include/mailutils/python.h
@@ -117,6 +117,11 @@ typedef struct {
typedef struct {
PyObject_HEAD;
+ mu_sieve_machine_t mach;
+} PySieveMachine;
+
+typedef struct {
+ PyObject_HEAD;
mu_stream_t stm;
} PyStream;
@@ -143,6 +148,7 @@ extern int mu_py_init_mailcap (void);
extern int mu_py_init_message (void);
extern int mu_py_init_mime (void);
extern int mu_py_init_secret (void);
+extern int mu_py_init_sieve (void);
extern int mu_py_init_stream (void);
extern int mu_py_init_url (void);
@@ -175,6 +181,7 @@ extern int PyAuthority_Check (PyObject *x);
extern int PyTicket_Check (PyObject *x);
extern int PyWicket_Check (PyObject *x);
extern int PyAuthData_Check (PyObject *x);
+extern int PyMailbox_Check (PyObject *x);
extern int PyMessage_Check (PyObject *x);
extern int PySecret_Check (PyObject *x);
extern int PyStream_Check (PyObject *x);
diff --git a/include/mailutils/tls.h b/include/mailutils/tls.h
index b070dcc83..e4d400586 100644
--- a/include/mailutils/tls.h
+++ b/include/mailutils/tls.h
@@ -52,7 +52,7 @@ extern void mu_deinit_tls_libs (void);
typedef int (*mu_tls_readline_fn) (void *iodata);
typedef int (*mu_tls_writeline_fn) (void *iodata, char *buf);
typedef void (*mu_tls_stream_ctl_fn) (void *iodata, mu_stream_t *pold,
- mu_stream_t new);
+ mu_stream_t __new);
extern int mu_tls_begin (void *iodata, mu_tls_readline_fn reader,
mu_tls_writeline_fn writer,
diff --git a/libmu_cpp/Makefile.am b/libmu_cpp/Makefile.am
index b91e90d89..15a30ab59 100644
--- a/libmu_cpp/Makefile.am
+++ b/libmu_cpp/Makefile.am
@@ -43,6 +43,7 @@ libmu_cpp_la_SOURCES = \
pop3.cc\
registrar.cc\
secret.cc\
+ sieve.cc\
stream.cc\
url.cc
diff --git a/libmu_cpp/sieve.cc b/libmu_cpp/sieve.cc
new file mode 100644
index 000000000..8a7bcdf91
--- /dev/null
+++ b/libmu_cpp/sieve.cc
@@ -0,0 +1,117 @@
+/*
+ GNU Mailutils -- a suite of utilities for electronic mail
+ Copyright (C) 2009 Free Software Foundation, Inc.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 3 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General
+ Public License along with this library; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301 USA
+*/
+
+#include <mailutils/cpp/sieve.h>
+
+using namespace mailutils;
+
+//
+// SieveMachine
+//
+
+SieveMachine :: SieveMachine ()
+{
+ int status = mu_sieve_machine_init (&mach, NULL);
+ if (status)
+ throw Exception ("SieveMachine::SieveMachine", status);
+}
+
+SieveMachine :: SieveMachine (const mu_sieve_machine_t mach)
+{
+ if (mach == 0)
+ throw Exception ("SieveMachine::SieveMachine", EINVAL);
+
+ this->mach = mach;
+}
+
+SieveMachine :: ~SieveMachine ()
+{
+ if (mach)
+ mu_sieve_machine_destroy (&mach);
+}
+
+SieveMachine&
+SieveMachine :: operator = (const SieveMachine& m)
+{
+ if (this != &m)
+ {
+ if (this->mach)
+ mu_sieve_machine_destroy (&this->mach);
+ mu_sieve_machine_dup (m.mach, &this->mach);
+ }
+ return *this;
+}
+
+void
+SieveMachine :: compile (const std::string& name)
+{
+ int status = mu_sieve_compile (mach, name.c_str ());
+ if (status)
+ throw Exception ("SieveMachine::compile", status);
+}
+
+void
+SieveMachine :: disass ()
+{
+ int status = mu_sieve_disass (mach);
+ if (status)
+ throw Exception ("SieveMachine::disass", status);
+}
+
+void
+SieveMachine :: mailbox (const Mailbox& mbox)
+{
+ int status = mu_sieve_mailbox (mach, mbox.mbox);
+ if (status)
+ throw Exception ("SieveMachine::mailbox", status);
+}
+
+void
+SieveMachine :: message (const Message& msg)
+{
+ int status = mu_sieve_message (mach, msg.msg);
+ if (status)
+ throw Exception ("SieveMachine::message", status);
+}
+
+void
+SieveMachine :: set_debug (mu_sieve_printf_t printer)
+{
+ mu_sieve_set_debug (mach, printer);
+}
+
+void
+SieveMachine :: set_error (mu_sieve_printf_t printer)
+{
+ mu_sieve_set_error (mach, printer);
+}
+
+void
+SieveMachine :: set_parse_error (mu_sieve_parse_error_t printer)
+{
+ mu_sieve_set_parse_error (mach, printer);
+}
+
+void
+SieveMachine :: set_logger (mu_sieve_action_log_t printer)
+{
+ mu_sieve_set_logger (mach, printer);
+}
+
diff --git a/libmu_sieve/sieve.y b/libmu_sieve/sieve.y
index 358579938..3b25465cb 100644
--- a/libmu_sieve/sieve.y
+++ b/libmu_sieve/sieve.y
@@ -614,8 +614,6 @@ mu_sieve_compile (mu_sieve_machine_t mach, const char *name)
rc = 1;
mu_sieve_machine_finish (mach);
- if (rc)
- mu_sieve_machine_destroy (&mach);
return rc;
}
@@ -639,8 +637,6 @@ mu_sieve_compile_buffer (mu_sieve_machine_t mach,
rc = 1;
mu_sieve_machine_finish (mach);
- if (rc)
- mu_sieve_machine_destroy (&mach);
return rc;
}
diff --git a/python/libmu_py/Makefile.am b/python/libmu_py/Makefile.am
index 0b5480aa5..0aef8df60 100644
--- a/python/libmu_py/Makefile.am
+++ b/python/libmu_py/Makefile.am
@@ -45,6 +45,7 @@ libmu_py_la_SOURCES = \
nls.c \
script.c \
secret.c \
+ sieve.c \
stream.c \
registrar.c \
url.c \
@@ -61,6 +62,7 @@ libmu_py_la_LIBADD = $(PYTHON_LIBS) @MU_COMMON_LIBRARIES@ \
${MU_LIB_MAILDIR}\
${MU_LIB_AUTH}\
${MU_LIB_MAILER}\
+ ${MU_LIB_SIEVE}\
@MU_AUTHLIBS@\
${MU_LIB_MAILUTILS}
diff --git a/python/libmu_py/libmu_py.c b/python/libmu_py/libmu_py.c
index 7fd1cb3cb..35088b0bc 100644
--- a/python/libmu_py/libmu_py.c
+++ b/python/libmu_py/libmu_py.c
@@ -85,6 +85,7 @@ mu_py_init (void)
mu_py_init_message ();
mu_py_init_mime ();
mu_py_init_secret ();
+ mu_py_init_sieve ();
mu_py_init_stream ();
mu_py_init_url ();
}
@@ -126,6 +127,7 @@ mu_py_attach_modules (void)
_mu_py_attach_nls ();
_mu_py_attach_registrar ();
_mu_py_attach_secret ();
+ _mu_py_attach_sieve ();
_mu_py_attach_stream ();
_mu_py_attach_url ();
_mu_py_attach_util ();
diff --git a/python/libmu_py/libmu_py.h b/python/libmu_py/libmu_py.h
index e30e32d5f..0a4df4047 100644
--- a/python/libmu_py/libmu_py.h
+++ b/python/libmu_py/libmu_py.h
@@ -44,6 +44,7 @@
#include <mailutils/registrar.h>
#include <mailutils/tls.h>
#include <mailutils/secret.h>
+#include <mailutils/sieve.h>
#include <mailutils/stream.h>
#include <mailutils/url.h>
#include <mailutils/python.h>
@@ -77,6 +78,7 @@ extern void _mu_py_attach_mime (void);
extern void _mu_py_attach_nls (void);
extern void _mu_py_attach_registrar (void);
extern void _mu_py_attach_secret (void);
+extern void _mu_py_attach_sieve (void);
extern void _mu_py_attach_stream (void);
extern void _mu_py_attach_url (void);
extern void _mu_py_attach_util (void);
diff --git a/python/libmu_py/mailbox.c b/python/libmu_py/mailbox.c
index 6874f81f6..f0579bb59 100644
--- a/python/libmu_py/mailbox.c
+++ b/python/libmu_py/mailbox.c
@@ -79,6 +79,12 @@ PyMailbox_NEW ()
return (PyMailbox *)PyObject_NEW (PyMailbox, &PyMailboxType);
}
+int
+PyMailbox_Check (PyObject *x)
+{
+ return x->ob_type == &PyMailboxType;
+}
+
static PyObject *
api_mailbox_create (PyObject *self, PyObject *args)
{
diff --git a/python/libmu_py/sieve.c b/python/libmu_py/sieve.c
new file mode 100644
index 000000000..38c1d370d
--- /dev/null
+++ b/python/libmu_py/sieve.c
@@ -0,0 +1,487 @@
+/*
+ GNU Mailutils -- a suite of utilities for electronic mail
+ Copyright (C) 2009 Free Software Foundation, Inc.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 3 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General
+ Public License along with this library; if not, write to the
+ Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ Boston, MA 02110-1301 USA
+*/
+
+#include "libmu_py.h"
+
+#define PY_MODULE "sieve"
+#define PY_CSNAME "SieveMachineType"
+
+static PyObject *
+_repr (PyObject *self)
+{
+ char buf[80];
+ sprintf (buf, "<" PY_MODULE "." PY_CSNAME " instance at %p>", self);
+ return PyString_FromString (buf);
+}
+
+static PyTypeObject PySieveMachineType = {
+ PyObject_HEAD_INIT(NULL)
+ 0, /* ob_size */
+ PY_MODULE "." PY_CSNAME, /* tp_name */
+ sizeof (PySieveMachine), /* tp_basicsize */
+ 0, /* tp_itemsize */
+ (destructor)_py_dealloc, /* tp_dealloc */
+ 0, /* tp_print */
+ 0, /* tp_getattr; __getattr__ */
+ 0, /* tp_setattr; __setattr__ */
+ 0, /* tp_compare; __cmp__ */
+ _repr, /* tp_repr; __repr__ */
+ 0, /* tp_as_number */
+ 0, /* tp_as_sequence */
+ 0, /* tp_as_mapping */
+ 0, /* tp_hash; __hash__ */
+ 0, /* tp_call; __call__ */
+ _repr, /* tp_str; __str__ */
+ 0, /* tp_getattro */
+ 0, /* tp_setattro */
+ 0, /* tp_as_buffer */
+ Py_TPFLAGS_DEFAULT, /* tp_flags */
+ "", /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ 0, /* tp_methods */
+ 0, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ 0, /* tp_init */
+ 0, /* tp_alloc */
+ 0, /* tp_new */
+};
+
+PySieveMachine *
+PySieveMachine_NEW ()
+{
+ return (PySieveMachine *)PyObject_NEW (PySieveMachine, &PySieveMachineType);
+}
+
+int
+PySieveMachine_Check (PyObject *x)
+{
+ return x->ob_type == &PySieveMachineType;
+}
+
+struct _mu_py_sieve_logger {
+ PyObject *py_debug_printer;
+ PyObject *py_error_printer;
+ PyObject *py_parse_error_printer;
+ PyObject *py_action_printer;
+};
+
+static PyObject *
+api_sieve_machine_init (PyObject *self, PyObject *args)
+{
+ int status;
+ PySieveMachine *py_mach;
+ struct _mu_py_sieve_logger *s;
+
+ if (!PyArg_ParseTuple (args, "O!", &PySieveMachineType, &py_mach))
+ return NULL;
+
+ if (!(s = calloc (1, sizeof (*s))))
+ return NULL;
+
+ status = mu_sieve_machine_init (&py_mach->mach, s);
+ return _ro (PyInt_FromLong (status));
+}
+
+static PyObject *
+api_sieve_machine_destroy (PyObject *self, PyObject *args)
+{
+ PySieveMachine *py_mach;
+
+ if (!PyArg_ParseTuple (args, "O!", &PySieveMachineType, &py_mach))
+ return NULL;
+
+ if (py_mach->mach) {
+ struct _mu_py_sieve_logger *s = mu_sieve_get_data (py_mach->mach);
+ if (s)
+ free (s);
+ mu_sieve_machine_destroy (&py_mach->mach);
+ }
+ return _ro (Py_None);
+}
+
+static PyObject *
+api_sieve_compile (PyObject *self, PyObject *args)
+{
+ int status;
+ char *name;
+ PySieveMachine *py_mach;
+
+ if (!PyArg_ParseTuple (args, "O!s", &PySieveMachineType, &py_mach, &name))
+ return NULL;
+
+ status = mu_sieve_compile (py_mach->mach, name);
+ return _ro (PyInt_FromLong (status));
+}
+
+static PyObject *
+api_sieve_disass (PyObject *self, PyObject *args)
+{
+ int status;
+ PySieveMachine *py_mach;
+
+ if (!PyArg_ParseTuple (args, "O!", &PySieveMachineType, &py_mach))
+ return NULL;
+
+ status = mu_sieve_disass (py_mach->mach);
+ return _ro (PyInt_FromLong (status));
+}
+
+static PyObject *
+api_sieve_mailbox (PyObject *self, PyObject *args)
+{
+ int status;
+ PySieveMachine *py_mach;
+ PyMailbox *py_mbox;
+
+ if (!PyArg_ParseTuple (args, "O!O", &PySieveMachineType, &py_mach, &py_mbox))
+ return NULL;
+
+ if (!PyMailbox_Check ((PyObject *)py_mbox))
+ {
+ PyErr_SetString (PyExc_TypeError, "");
+ return NULL;
+ }
+
+ status = mu_sieve_mailbox (py_mach->mach, py_mbox->mbox);
+ return _ro (PyInt_FromLong (status));
+}
+
+static PyObject *
+api_sieve_message (PyObject *self, PyObject *args)
+{
+ int status;
+ PySieveMachine *py_mach;
+ PyMessage *py_msg;
+
+ if (!PyArg_ParseTuple (args, "O!O", &PySieveMachineType, &py_mach, &py_msg))
+ return NULL;
+
+ if (!PyMessage_Check ((PyObject *)py_msg))
+ {
+ PyErr_SetString (PyExc_TypeError, "");
+ return NULL;
+ }
+
+ status = mu_sieve_message (py_mach->mach, py_msg->msg);
+ return _ro (PyInt_FromLong (status));
+}
+
+static int
+_sieve_error_printer (void *data, const char *fmt, va_list ap)
+{
+ char *buf = NULL;
+ size_t buflen = 0;
+ PyObject *py_args = PyTuple_New (1);
+
+ if (py_args)
+ {
+ struct _mu_py_sieve_logger *s = data;
+ PyObject *py_fnc = s->py_error_printer;
+
+ if (mu_vasnprintf (&buf, &buflen, fmt, ap))
+ return;
+ PyTuple_SetItem (py_args, 0, PyString_FromString (buf ? buf : ""));
+ if (buf)
+ free (buf);
+
+ if (py_fnc && PyCallable_Check (py_fnc))
+ PyObject_CallObject (py_fnc, py_args);
+
+ Py_DECREF (py_args);
+ }
+ return 0;
+}
+
+static int
+_sieve_parse_error_printer (void *data, const char *filename, int lineno,
+ const char *fmt, va_list ap)
+{
+ PyObject *py_args;
+ PyObject *py_dict;
+
+ py_dict = PyDict_New ();
+ if (py_dict)
+ {
+ char *buf = NULL;
+ size_t buflen = 0;
+
+ PyDict_SetItemString (py_dict, "filename",
+ PyString_FromString (filename));
+ PyDict_SetItemString (py_dict, "lineno", PyInt_FromLong (lineno));
+
+ if (mu_vasnprintf (&buf, &buflen, fmt, ap))
+ return;
+ PyDict_SetItemString (py_dict, "text",
+ PyString_FromString (buf ? buf : ""));
+ if (buf)
+ free (buf);
+
+ py_args = PyTuple_New (1);
+ if (py_args)
+ {
+ struct _mu_py_sieve_logger *s = data;
+ PyObject *py_fnc = s->py_parse_error_printer;
+
+ Py_INCREF (py_dict);
+ PyTuple_SetItem (py_args, 0, py_dict);
+
+ if (py_fnc && PyCallable_Check (py_fnc))
+ PyObject_CallObject (py_fnc, py_args);
+
+ Py_DECREF (py_dict);
+ Py_DECREF (py_args);
+ }
+ }
+}
+
+static int
+_sieve_debug_printer (void *data, const char *fmt, va_list ap)
+{
+ char *buf = NULL;
+ size_t buflen = 0;
+ PyObject *py_args = PyTuple_New (1);
+
+ if (py_args)
+ {
+ struct _mu_py_sieve_logger *s = data;
+ PyObject *py_fnc = s->py_debug_printer;
+
+ if (mu_vasnprintf (&buf, &buflen, fmt, ap))
+ return;
+ PyTuple_SetItem (py_args, 0, PyString_FromString (buf ? buf : ""));
+ if (buf)
+ free (buf);
+
+ if (py_fnc && PyCallable_Check (py_fnc))
+ PyObject_CallObject (py_fnc, py_args);
+
+ Py_DECREF (py_args);
+ }
+ return 0;
+}
+
+static void
+_sieve_action_printer (void *data, const mu_sieve_locus_t *locus,
+ size_t msgno, mu_message_t msg,
+ const char *action, const char *fmt, va_list ap)
+{
+ PyObject *py_args;
+ PyObject *py_dict;
+
+ py_dict = PyDict_New ();
+ if (py_dict)
+ {
+ char *buf = NULL;
+ size_t buflen = 0;
+ PyMessage *py_msg = PyMessage_NEW ();
+
+ py_msg->msg = msg;
+ Py_INCREF (py_msg);
+
+ PyDict_SetItemString (py_dict, "source_file",
+ PyString_FromString (locus->source_file));
+ PyDict_SetItemString (py_dict, "source_line",
+ PyInt_FromLong (locus->source_line));
+ PyDict_SetItemString (py_dict, "msgno",
+ PyInt_FromLong (msgno));
+ PyDict_SetItemString (py_dict, "msg", (PyObject *)py_msg);
+ PyDict_SetItemString (py_dict, "action",
+ PyString_FromString (action ? action : ""));
+
+ if (mu_vasnprintf (&buf, &buflen, fmt, ap))
+ return;
+ PyDict_SetItemString (py_dict, "text",
+ PyString_FromString (buf ? buf : ""));
+ if (buf)
+ free (buf);
+
+ py_args = PyTuple_New (1);
+ if (py_args)
+ {
+ struct _mu_py_sieve_logger *s = data;
+ PyObject *py_fnc = s->py_action_printer;
+
+ Py_INCREF (py_dict);
+ PyTuple_SetItem (py_args, 0, py_dict);
+
+ if (py_fnc && PyCallable_Check (py_fnc))
+ PyObject_CallObject (py_fnc, py_args);
+
+ Py_DECREF (py_dict);
+ Py_DECREF (py_args);
+ }
+ }
+}
+
+static PyObject *
+api_sieve_set_error (PyObject *self, PyObject *args)
+{
+ PySieveMachine *py_mach;
+ PyObject *py_fnc;
+
+ if (!PyArg_ParseTuple (args, "O!O", &PySieveMachineType, &py_mach, &py_fnc))
+ return NULL;
+
+ if (py_fnc && PyCallable_Check (py_fnc)) {
+ mu_sieve_machine_t mach = py_mach->mach;
+ struct _mu_py_sieve_logger *s = mu_sieve_get_data (mach);
+ s->py_error_printer = py_fnc;
+ Py_INCREF (py_fnc);
+ mu_sieve_set_error (py_mach->mach, _sieve_error_printer);
+ }
+ else {
+ PyErr_SetString (PyExc_TypeError, "");
+ return NULL;
+ }
+ return _ro (Py_None);
+}
+
+static PyObject *
+api_sieve_set_parse_error (PyObject *self, PyObject *args)
+{
+ PySieveMachine *py_mach;
+ PyObject *py_fnc;
+
+ if (!PyArg_ParseTuple (args, "O!O", &PySieveMachineType, &py_mach, &py_fnc))
+ return NULL;
+
+ if (py_fnc && PyCallable_Check (py_fnc)) {
+ mu_sieve_machine_t mach = py_mach->mach;
+ struct _mu_py_sieve_logger *s = mu_sieve_get_data (mach);