Commit da546ae1 da546ae1358654cb568b983a2bb2e79f2f508c2b by Wojciech Polak

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.
1 parent fe1fe383
......@@ -64,5 +64,6 @@ LDADD =\
${MU_LIB_MAILDIR}\
${MU_LIB_AUTH}\
${MU_LIB_MAILER}\
${MU_LIB_SIEVE}\
@MU_AUTHLIBS@\
${MU_LIB_MAILUTILS}
......
......@@ -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);
}
......
......@@ -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)
......
......@@ -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]"
......
......@@ -38,6 +38,7 @@ MU_CXX_INCLUDES = \
pop3.h\
registrar.h\
secret.h\
sieve.h\
stream.h\
url.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
......
......@@ -37,6 +37,8 @@ class MailboxBase
protected:
mu_mailbox_t mbox;
friend class SieveMachine;
public:
void open ();
void open (int flag);
......
......@@ -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>
......
......@@ -42,6 +42,7 @@ class Message
friend class MailboxBase;
friend class Mailer;
friend class Mime;
friend class SieveMachine;
public:
Message ();
......
/*
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
......@@ -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);
......
......@@ -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);
......
......@@ -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,
......
......@@ -43,6 +43,7 @@ libmu_cpp_la_SOURCES = \
pop3.cc\
registrar.cc\
secret.cc\
sieve.cc\
stream.cc\
url.cc
......
/*
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);
}
......@@ -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;
}
......
......@@ -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}
......
......@@ -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 ();
......
......@@ -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);
......
......@@ -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)
{
......
......@@ -37,6 +37,7 @@ MU_PY_PKGPYTHON_LIST=\
nls.py \
registrar.py \
secret.py \
sieve.py \
stream.py \
url.py \
util.py
......
......@@ -35,6 +35,7 @@ __all__ = [
"nls",
"registrar",
"secret",
"sieve",
"stream",
"url",
"util",
......
......@@ -43,6 +43,7 @@ class MailcapError (Error): pass
class MessageError (Error): pass
class MimeError (Error): pass
class SecretError (Error): pass
class SieveMachineError (Error): pass
class StreamError (Error): pass
class UrlError (Error): pass
......
#
# 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
#
from mailutils.c_api import sieve
from mailutils.error import SieveMachineError
class Machine:
def __init__ (self):
self.mach = sieve.SieveMachineType ()
status = sieve.machine_init (self.mach)
if status:
raise SieveMachineError (status)
def __del__ (self):
sieve.machine_destroy (self.mach)
del self.mach
def set_debug (self, fnc):
status = sieve.set_debug (self.mach, fnc)
if status:
raise SieveMachineError (status)
def set_error (self, fnc):
status = sieve.set_error (self.mach, fnc)
if status:
raise SieveMachineError (status)
def set_parse_error (self, fnc):
status = sieve.set_parse_error (self.mach, fnc)
if status:
raise SieveMachineError (status)
def set_logger (self, fnc):
status = sieve.set_logger (self.mach, fnc)
if status:
raise SieveMachineError (status)
def compile (self, name):
"""Compile the sieve script from the file NAME."""
status = sieve.compile (self.mach, name)
if status:
raise SieveMachineError (status)
def disass (self):
"""Dump the disassembled code of the sieve machine."""
status = sieve.disass (self.mach)
if status:
raise SieveMachineError (status)
def mailbox (self, mbox):
"""Execute the code from the given instance of sieve machine
over each message in the mailbox."""
status = sieve.mailbox (self.mach, mbox.mbox)
if status:
raise SieveMachineError (status)
def message (self, msg):
"""Execute the code from the given instance of sieve machine
over the MSG."""
status = sieve.message (self.mach, msg.msg)
if status:
raise SieveMachineError (status)