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.
Showing
25 changed files
with
296 additions
and
15 deletions
... | @@ -66,7 +66,7 @@ main (int argc, char *argv[]) | ... | @@ -66,7 +66,7 @@ main (int argc, char *argv[]) |
66 | { | 66 | { |
67 | string folder; | 67 | string folder; |
68 | string ref; | 68 | string ref; |
69 | char *pattern = "*"; | 69 | const char *pattern = "*"; |
70 | int level = 0; | 70 | int level = 0; |
71 | 71 | ||
72 | switch (argc) | 72 | switch (argc) |
... | @@ -87,6 +87,6 @@ main (int argc, char *argv[]) | ... | @@ -87,6 +87,6 @@ main (int argc, char *argv[]) |
87 | 87 | ||
88 | register_all_mbox_formats (); | 88 | register_all_mbox_formats (); |
89 | 89 | ||
90 | return ls_folders (folder, ref, pattern, level); | 90 | return ls_folders (folder, ref, (char *)pattern, level); |
91 | } | 91 | } |
92 | 92 | ... | ... |
... | @@ -41,7 +41,7 @@ main (int argc, char *argv[]) | ... | @@ -41,7 +41,7 @@ main (int argc, char *argv[]) |
41 | { | 41 | { |
42 | int opt; | 42 | int opt; |
43 | int optdebug = 0; | 43 | int optdebug = 0; |
44 | char *optmailer = "sendmail:"; | 44 | const char *optmailer = "sendmail:"; |
45 | char *optfrom = 0; | 45 | char *optfrom = 0; |
46 | 46 | ||
47 | while ((opt = getopt (argc, argv, "hdm:f:")) != -1) | 47 | while ((opt = getopt (argc, argv, "hdm:f:")) != -1) | ... | ... |
... | @@ -53,6 +53,7 @@ if __name__ == '__main__': | ... | @@ -53,6 +53,7 @@ if __name__ == '__main__': |
53 | ref = sys.argv[2] | 53 | ref = sys.argv[2] |
54 | fname = sys.argv[1] | 54 | fname = sys.argv[1] |
55 | elif argc == 2: | 55 | elif argc == 2: |
56 | ref = None | ||
56 | fname = sys.argv[1] | 57 | fname = sys.argv[1] |
57 | else: | 58 | else: |
58 | print "usage: lsf folder [ref] [pattern] [recursion-level]" | 59 | print "usage: lsf folder [ref] [pattern] [recursion-level]" | ... | ... |
... | @@ -18,8 +18,8 @@ | ... | @@ -18,8 +18,8 @@ |
18 | Boston, MA 02110-1301 USA | 18 | Boston, MA 02110-1301 USA |
19 | */ | 19 | */ |
20 | 20 | ||
21 | #ifndef _ADDRESS_H | 21 | #ifndef _MUCPP_ADDRESS_H |
22 | #define _ADDRESS_H | 22 | #define _MUCPP_ADDRESS_H |
23 | 23 | ||
24 | #include <ostream> | 24 | #include <ostream> |
25 | #include <errno.h> | 25 | #include <errno.h> |
... | @@ -72,5 +72,5 @@ class Address | ... | @@ -72,5 +72,5 @@ class Address |
72 | 72 | ||
73 | } | 73 | } |
74 | 74 | ||
75 | #endif // not _ADDRESS_H | 75 | #endif // not _MUCPP_ADDRESS_H |
76 | 76 | ... | ... |
... | @@ -37,6 +37,8 @@ class MailboxBase | ... | @@ -37,6 +37,8 @@ class MailboxBase |
37 | protected: | 37 | protected: |
38 | mu_mailbox_t mbox; | 38 | mu_mailbox_t mbox; |
39 | 39 | ||
40 | friend class SieveMachine; | ||
41 | |||
40 | public: | 42 | public: |
41 | void open (); | 43 | void open (); |
42 | void open (int flag); | 44 | void open (int flag); | ... | ... |
... | @@ -36,6 +36,7 @@ | ... | @@ -36,6 +36,7 @@ |
36 | #include <mailutils/cpp/pop3.h> | 36 | #include <mailutils/cpp/pop3.h> |
37 | #include <mailutils/cpp/registrar.h> | 37 | #include <mailutils/cpp/registrar.h> |
38 | #include <mailutils/cpp/secret.h> | 38 | #include <mailutils/cpp/secret.h> |
39 | #include <mailutils/cpp/sieve.h> | ||
39 | #include <mailutils/cpp/stream.h> | 40 | #include <mailutils/cpp/stream.h> |
40 | #include <mailutils/cpp/url.h> | 41 | #include <mailutils/cpp/url.h> |
41 | 42 | ... | ... |
... | @@ -42,6 +42,7 @@ class Message | ... | @@ -42,6 +42,7 @@ class Message |
42 | friend class MailboxBase; | 42 | friend class MailboxBase; |
43 | friend class Mailer; | 43 | friend class Mailer; |
44 | friend class Mime; | 44 | friend class Mime; |
45 | friend class SieveMachine; | ||
45 | 46 | ||
46 | public: | 47 | public: |
47 | Message (); | 48 | Message (); | ... | ... |
include/mailutils/cpp/sieve.h
0 → 100644
1 | /* | ||
2 | GNU Mailutils -- a suite of utilities for electronic mail | ||
3 | Copyright (C) 2009 Free Software Foundation, Inc. | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Lesser General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 3 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General | ||
16 | Public License along with this library; if not, write to the | ||
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301 USA | ||
19 | */ | ||
20 | |||
21 | #ifndef _MUCPP_SIEVE_H | ||
22 | #define _MUCPP_SIEVE_H | ||
23 | |||
24 | #include <string> | ||
25 | #include <errno.h> | ||
26 | #include <mailutils/sieve.h> | ||
27 | #include <mailutils/cpp/error.h> | ||
28 | #include <mailutils/cpp/mailbox.h> | ||
29 | #include <mailutils/cpp/message.h> | ||
30 | |||
31 | namespace mailutils | ||
32 | { | ||
33 | |||
34 | class SieveMachine | ||
35 | { | ||
36 | protected: | ||
37 | mu_sieve_machine_t mach; | ||
38 | |||
39 | public: | ||
40 | SieveMachine (); | ||
41 | SieveMachine (const mu_sieve_machine_t); | ||
42 | ~SieveMachine (); | ||
43 | |||
44 | SieveMachine& operator = (const SieveMachine&); | ||
45 | |||
46 | void compile (const std::string& name); | ||
47 | void disass (); | ||
48 | void mailbox (const Mailbox& mbox); | ||
49 | void message (const Message& msg); | ||
50 | void set_debug (mu_sieve_printf_t printer); | ||
51 | void set_error (mu_sieve_printf_t printer); | ||
52 | void set_parse_error (mu_sieve_parse_error_t printer); | ||
53 | void set_logger (mu_sieve_action_log_t printer); | ||
54 | }; | ||
55 | |||
56 | } | ||
57 | |||
58 | #endif // not _MUCPP_SIEVE_H | ||
59 |
... | @@ -28,15 +28,15 @@ int mu_strupper (char *); | ... | @@ -28,15 +28,15 @@ int mu_strupper (char *); |
28 | int mu_c_strcasecmp (const char *a, const char *b); | 28 | int mu_c_strcasecmp (const char *a, const char *b); |
29 | int mu_c_strncasecmp (const char *a, const char *b, size_t n); | 29 | int mu_c_strncasecmp (const char *a, const char *b, size_t n); |
30 | 30 | ||
31 | size_t mu_rtrim_class (char *str, int class); | 31 | size_t mu_rtrim_class (char *str, int __class); |
32 | size_t mu_rtrim_cset (char *str, const char *cset); | 32 | size_t mu_rtrim_cset (char *str, const char *cset); |
33 | size_t mu_ltrim_class (char *str, int class); | 33 | size_t mu_ltrim_class (char *str, int __class); |
34 | size_t mu_ltrim_cset (char *str, const char *cset); | 34 | size_t mu_ltrim_cset (char *str, const char *cset); |
35 | 35 | ||
36 | char *mu_str_skip_class (const char *str, int class); | 36 | char *mu_str_skip_class (const char *str, int __class); |
37 | char *mu_str_skip_cset (const char *str, const char *cset); | 37 | char *mu_str_skip_cset (const char *str, const char *cset); |
38 | 38 | ||
39 | char *mu_str_skip_class_comp (const char *str, int class); | 39 | char *mu_str_skip_class_comp (const char *str, int __class); |
40 | char *mu_str_skip_cset_comp (const char *str, const char *cset); | 40 | char *mu_str_skip_cset_comp (const char *str, const char *cset); |
41 | 41 | ||
42 | char *mu_str_stripws (char *string); | 42 | char *mu_str_stripws (char *string); | ... | ... |
... | @@ -117,6 +117,11 @@ typedef struct { | ... | @@ -117,6 +117,11 @@ typedef struct { |
117 | 117 | ||
118 | typedef struct { | 118 | typedef struct { |
119 | PyObject_HEAD; | 119 | PyObject_HEAD; |
120 | mu_sieve_machine_t mach; | ||
121 | } PySieveMachine; | ||
122 | |||
123 | typedef struct { | ||
124 | PyObject_HEAD; | ||
120 | mu_stream_t stm; | 125 | mu_stream_t stm; |
121 | } PyStream; | 126 | } PyStream; |
122 | 127 | ||
... | @@ -143,6 +148,7 @@ extern int mu_py_init_mailcap (void); | ... | @@ -143,6 +148,7 @@ extern int mu_py_init_mailcap (void); |
143 | extern int mu_py_init_message (void); | 148 | extern int mu_py_init_message (void); |
144 | extern int mu_py_init_mime (void); | 149 | extern int mu_py_init_mime (void); |
145 | extern int mu_py_init_secret (void); | 150 | extern int mu_py_init_secret (void); |
151 | extern int mu_py_init_sieve (void); | ||
146 | extern int mu_py_init_stream (void); | 152 | extern int mu_py_init_stream (void); |
147 | extern int mu_py_init_url (void); | 153 | extern int mu_py_init_url (void); |
148 | 154 | ||
... | @@ -175,6 +181,7 @@ extern int PyAuthority_Check (PyObject *x); | ... | @@ -175,6 +181,7 @@ extern int PyAuthority_Check (PyObject *x); |
175 | extern int PyTicket_Check (PyObject *x); | 181 | extern int PyTicket_Check (PyObject *x); |
176 | extern int PyWicket_Check (PyObject *x); | 182 | extern int PyWicket_Check (PyObject *x); |
177 | extern int PyAuthData_Check (PyObject *x); | 183 | extern int PyAuthData_Check (PyObject *x); |
184 | extern int PyMailbox_Check (PyObject *x); | ||
178 | extern int PyMessage_Check (PyObject *x); | 185 | extern int PyMessage_Check (PyObject *x); |
179 | extern int PySecret_Check (PyObject *x); | 186 | extern int PySecret_Check (PyObject *x); |
180 | extern int PyStream_Check (PyObject *x); | 187 | extern int PyStream_Check (PyObject *x); | ... | ... |
... | @@ -52,7 +52,7 @@ extern void mu_deinit_tls_libs (void); | ... | @@ -52,7 +52,7 @@ extern void mu_deinit_tls_libs (void); |
52 | typedef int (*mu_tls_readline_fn) (void *iodata); | 52 | typedef int (*mu_tls_readline_fn) (void *iodata); |
53 | typedef int (*mu_tls_writeline_fn) (void *iodata, char *buf); | 53 | typedef int (*mu_tls_writeline_fn) (void *iodata, char *buf); |
54 | typedef void (*mu_tls_stream_ctl_fn) (void *iodata, mu_stream_t *pold, | 54 | typedef void (*mu_tls_stream_ctl_fn) (void *iodata, mu_stream_t *pold, |
55 | mu_stream_t new); | 55 | mu_stream_t __new); |
56 | 56 | ||
57 | extern int mu_tls_begin (void *iodata, mu_tls_readline_fn reader, | 57 | extern int mu_tls_begin (void *iodata, mu_tls_readline_fn reader, |
58 | mu_tls_writeline_fn writer, | 58 | mu_tls_writeline_fn writer, | ... | ... |
libmu_cpp/sieve.cc
0 → 100644
1 | /* | ||
2 | GNU Mailutils -- a suite of utilities for electronic mail | ||
3 | Copyright (C) 2009 Free Software Foundation, Inc. | ||
4 | |||
5 | This library is free software; you can redistribute it and/or | ||
6 | modify it under the terms of the GNU Lesser General Public | ||
7 | License as published by the Free Software Foundation; either | ||
8 | version 3 of the License, or (at your option) any later version. | ||
9 | |||
10 | This library is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | Lesser General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU Lesser General | ||
16 | Public License along with this library; if not, write to the | ||
17 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | Boston, MA 02110-1301 USA | ||
19 | */ | ||
20 | |||
21 | #include <mailutils/cpp/sieve.h> | ||
22 | |||
23 | using namespace mailutils; | ||
24 | |||
25 | // | ||
26 | // SieveMachine | ||
27 | // | ||
28 | |||
29 | SieveMachine :: SieveMachine () | ||
30 | { | ||
31 | int status = mu_sieve_machine_init (&mach, NULL); | ||
32 | if (status) | ||
33 | throw Exception ("SieveMachine::SieveMachine", status); | ||
34 | } | ||
35 | |||
36 | SieveMachine :: SieveMachine (const mu_sieve_machine_t mach) | ||
37 | { | ||
38 | if (mach == 0) | ||
39 | throw Exception ("SieveMachine::SieveMachine", EINVAL); | ||
40 | |||
41 | this->mach = mach; | ||
42 | } | ||
43 | |||
44 | SieveMachine :: ~SieveMachine () | ||
45 | { | ||
46 | if (mach) | ||
47 | mu_sieve_machine_destroy (&mach); | ||
48 | } | ||
49 | |||
50 | SieveMachine& | ||
51 | SieveMachine :: operator = (const SieveMachine& m) | ||
52 | { | ||
53 | if (this != &m) | ||
54 | { | ||
55 | if (this->mach) | ||
56 | mu_sieve_machine_destroy (&this->mach); | ||
57 | mu_sieve_machine_dup (m.mach, &this->mach); | ||
58 | } | ||
59 | return *this; | ||
60 | } | ||
61 | |||
62 | void | ||
63 | SieveMachine :: compile (const std::string& name) | ||
64 | { | ||
65 | int status = mu_sieve_compile (mach, name.c_str ()); | ||
66 | if (status) | ||
67 | throw Exception ("SieveMachine::compile", status); | ||
68 | } | ||
69 | |||
70 | void | ||
71 | SieveMachine :: disass () | ||
72 | { | ||
73 | int status = mu_sieve_disass (mach); | ||
74 | if (status) | ||
75 | throw Exception ("SieveMachine::disass", status); | ||
76 | } | ||
77 | |||
78 | void | ||
79 | SieveMachine :: mailbox (const Mailbox& mbox) | ||
80 | { | ||
81 | int status = mu_sieve_mailbox (mach, mbox.mbox); | ||
82 | if (status) | ||
83 | throw Exception ("SieveMachine::mailbox", status); | ||
84 | } | ||
85 | |||
86 | void | ||
87 | SieveMachine :: message (const Message& msg) | ||
88 | { | ||
89 | int status = mu_sieve_message (mach, msg.msg); | ||
90 | if (status) | ||
91 | throw Exception ("SieveMachine::message", status); | ||
92 | } | ||
93 | |||
94 | void | ||
95 | SieveMachine :: set_debug (mu_sieve_printf_t printer) | ||
96 | { | ||
97 | mu_sieve_set_debug (mach, printer); | ||
98 | } | ||
99 | |||
100 | void | ||
101 | SieveMachine :: set_error (mu_sieve_printf_t printer) | ||
102 | { | ||
103 | mu_sieve_set_error (mach, printer); | ||
104 | } | ||
105 | |||
106 | void | ||
107 | SieveMachine :: set_parse_error (mu_sieve_parse_error_t printer) | ||
108 | { | ||
109 | mu_sieve_set_parse_error (mach, printer); | ||
110 | } | ||
111 | |||
112 | void | ||
113 | SieveMachine :: set_logger (mu_sieve_action_log_t printer) | ||
114 | { | ||
115 | mu_sieve_set_logger (mach, printer); | ||
116 | } | ||
117 |
... | @@ -614,8 +614,6 @@ mu_sieve_compile (mu_sieve_machine_t mach, const char *name) | ... | @@ -614,8 +614,6 @@ mu_sieve_compile (mu_sieve_machine_t mach, const char *name) |
614 | rc = 1; | 614 | rc = 1; |
615 | 615 | ||
616 | mu_sieve_machine_finish (mach); | 616 | mu_sieve_machine_finish (mach); |
617 | if (rc) | ||
618 | mu_sieve_machine_destroy (&mach); | ||
619 | return rc; | 617 | return rc; |
620 | } | 618 | } |
621 | 619 | ||
... | @@ -639,8 +637,6 @@ mu_sieve_compile_buffer (mu_sieve_machine_t mach, | ... | @@ -639,8 +637,6 @@ mu_sieve_compile_buffer (mu_sieve_machine_t mach, |
639 | rc = 1; | 637 | rc = 1; |
640 | 638 | ||
641 | mu_sieve_machine_finish (mach); | 639 | mu_sieve_machine_finish (mach); |
642 | if (rc) | ||
643 | mu_sieve_machine_destroy (&mach); | ||
644 | return rc; | 640 | return rc; |
645 | } | 641 | } |
646 | 642 | ... | ... |
... | @@ -45,6 +45,7 @@ libmu_py_la_SOURCES = \ | ... | @@ -45,6 +45,7 @@ libmu_py_la_SOURCES = \ |
45 | nls.c \ | 45 | nls.c \ |
46 | script.c \ | 46 | script.c \ |
47 | secret.c \ | 47 | secret.c \ |
48 | sieve.c \ | ||
48 | stream.c \ | 49 | stream.c \ |
49 | registrar.c \ | 50 | registrar.c \ |
50 | url.c \ | 51 | url.c \ |
... | @@ -61,6 +62,7 @@ libmu_py_la_LIBADD = $(PYTHON_LIBS) @MU_COMMON_LIBRARIES@ \ | ... | @@ -61,6 +62,7 @@ libmu_py_la_LIBADD = $(PYTHON_LIBS) @MU_COMMON_LIBRARIES@ \ |
61 | ${MU_LIB_MAILDIR}\ | 62 | ${MU_LIB_MAILDIR}\ |
62 | ${MU_LIB_AUTH}\ | 63 | ${MU_LIB_AUTH}\ |
63 | ${MU_LIB_MAILER}\ | 64 | ${MU_LIB_MAILER}\ |
65 | ${MU_LIB_SIEVE}\ | ||
64 | @MU_AUTHLIBS@\ | 66 | @MU_AUTHLIBS@\ |
65 | ${MU_LIB_MAILUTILS} | 67 | ${MU_LIB_MAILUTILS} |
66 | 68 | ... | ... |
... | @@ -85,6 +85,7 @@ mu_py_init (void) | ... | @@ -85,6 +85,7 @@ mu_py_init (void) |
85 | mu_py_init_message (); | 85 | mu_py_init_message (); |
86 | mu_py_init_mime (); | 86 | mu_py_init_mime (); |
87 | mu_py_init_secret (); | 87 | mu_py_init_secret (); |
88 | mu_py_init_sieve (); | ||
88 | mu_py_init_stream (); | 89 | mu_py_init_stream (); |
89 | mu_py_init_url (); | 90 | mu_py_init_url (); |
90 | } | 91 | } |
... | @@ -126,6 +127,7 @@ mu_py_attach_modules (void) | ... | @@ -126,6 +127,7 @@ mu_py_attach_modules (void) |
126 | _mu_py_attach_nls (); | 127 | _mu_py_attach_nls (); |
127 | _mu_py_attach_registrar (); | 128 | _mu_py_attach_registrar (); |
128 | _mu_py_attach_secret (); | 129 | _mu_py_attach_secret (); |
130 | _mu_py_attach_sieve (); | ||
129 | _mu_py_attach_stream (); | 131 | _mu_py_attach_stream (); |
130 | _mu_py_attach_url (); | 132 | _mu_py_attach_url (); |
131 | _mu_py_attach_util (); | 133 | _mu_py_attach_util (); | ... | ... |
... | @@ -44,6 +44,7 @@ | ... | @@ -44,6 +44,7 @@ |
44 | #include <mailutils/registrar.h> | 44 | #include <mailutils/registrar.h> |
45 | #include <mailutils/tls.h> | 45 | #include <mailutils/tls.h> |
46 | #include <mailutils/secret.h> | 46 | #include <mailutils/secret.h> |
47 | #include <mailutils/sieve.h> | ||
47 | #include <mailutils/stream.h> | 48 | #include <mailutils/stream.h> |
48 | #include <mailutils/url.h> | 49 | #include <mailutils/url.h> |
49 | #include <mailutils/python.h> | 50 | #include <mailutils/python.h> |
... | @@ -77,6 +78,7 @@ extern void _mu_py_attach_mime (void); | ... | @@ -77,6 +78,7 @@ extern void _mu_py_attach_mime (void); |
77 | extern void _mu_py_attach_nls (void); | 78 | extern void _mu_py_attach_nls (void); |
78 | extern void _mu_py_attach_registrar (void); | 79 | extern void _mu_py_attach_registrar (void); |
79 | extern void _mu_py_attach_secret (void); | 80 | extern void _mu_py_attach_secret (void); |
81 | extern void _mu_py_attach_sieve (void); | ||
80 | extern void _mu_py_attach_stream (void); | 82 | extern void _mu_py_attach_stream (void); |
81 | extern void _mu_py_attach_url (void); | 83 | extern void _mu_py_attach_url (void); |
82 | extern void _mu_py_attach_util (void); | 84 | extern void _mu_py_attach_util (void); | ... | ... |
... | @@ -79,6 +79,12 @@ PyMailbox_NEW () | ... | @@ -79,6 +79,12 @@ PyMailbox_NEW () |
79 | return (PyMailbox *)PyObject_NEW (PyMailbox, &PyMailboxType); | 79 | return (PyMailbox *)PyObject_NEW (PyMailbox, &PyMailboxType); |
80 | } | 80 | } |
81 | 81 | ||
82 | int | ||
83 | PyMailbox_Check (PyObject *x) | ||
84 | { | ||
85 | return x->ob_type == &PyMailboxType; | ||
86 | } | ||
87 | |||
82 | static PyObject * | 88 | static PyObject * |
83 | api_mailbox_create (PyObject *self, PyObject *args) | 89 | api_mailbox_create (PyObject *self, PyObject *args) |
84 | { | 90 | { | ... | ... |
python/libmu_py/sieve.c
0 → 100644
This diff is collapsed.
Click to expand it.
... | @@ -43,6 +43,7 @@ class MailcapError (Error): pass | ... | @@ -43,6 +43,7 @@ class MailcapError (Error): pass |
43 | class MessageError (Error): pass | 43 | class MessageError (Error): pass |
44 | class MimeError (Error): pass | 44 | class MimeError (Error): pass |
45 | class SecretError (Error): pass | 45 | class SecretError (Error): pass |
46 | class SieveMachineError (Error): pass | ||
46 | class StreamError (Error): pass | 47 | class StreamError (Error): pass |
47 | class UrlError (Error): pass | 48 | class UrlError (Error): pass |
48 | 49 | ... | ... |
python/mailutils/sieve.py
0 → 100644
1 | # | ||
2 | # GNU Mailutils -- a suite of utilities for electronic mail | ||
3 | # Copyright (C) 2009 Free Software Foundation, Inc. | ||
4 | # | ||
5 | # This library is free software; you can redistribute it and/or | ||
6 | # modify it under the terms of the GNU Lesser General Public | ||
7 | # License as published by the Free Software Foundation; either | ||
8 | # version 3 of the License, or (at your option) any later version. | ||
9 | # | ||
10 | # This library is distributed in the hope that it will be useful, | ||
11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
13 | # Lesser General Public License for more details. | ||
14 | # | ||
15 | # You should have received a copy of the GNU Lesser General | ||
16 | # Public License along with this library; if not, write to the | ||
17 | # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
18 | # Boston, MA 02110-1301 USA | ||
19 | # | ||
20 | |||
21 | from mailutils.c_api import sieve | ||
22 | from mailutils.error import SieveMachineError | ||
23 | |||
24 | class Machine: | ||
25 | def __init__ (self): | ||
26 | self.mach = sieve.SieveMachineType () | ||
27 | status = sieve.machine_init (self.mach) | ||
28 | if status: | ||
29 | raise SieveMachineError (status) | ||
30 | |||
31 | def __del__ (self): | ||
32 | sieve.machine_destroy (self.mach) | ||
33 | del self.mach | ||
34 | |||
35 | def set_debug (self, fnc): | ||
36 | status = sieve.set_debug (self.mach, fnc) | ||
37 | if status: | ||
38 | raise SieveMachineError (status) | ||
39 | |||
40 | def set_error (self, fnc): | ||
41 | status = sieve.set_error (self.mach, fnc) | ||
42 | if status: | ||
43 | raise SieveMachineError (status) | ||
44 | |||
45 | def set_parse_error (self, fnc): | ||
46 | status = sieve.set_parse_error (self.mach, fnc) | ||
47 | if status: | ||
48 | raise SieveMachineError (status) | ||
49 | |||
50 | def set_logger (self, fnc): | ||
51 | status = sieve.set_logger (self.mach, fnc) | ||
52 | if status: | ||
53 | raise SieveMachineError (status) | ||
54 | |||
55 | def compile (self, name): | ||
56 | """Compile the sieve script from the file NAME.""" | ||
57 | status = sieve.compile (self.mach, name) | ||
58 | if status: | ||
59 | raise SieveMachineError (status) | ||
60 | |||
61 | def disass (self): | ||
62 | """Dump the disassembled code of the sieve machine.""" | ||
63 | status = sieve.disass (self.mach) | ||
64 | if status: | ||
65 | raise SieveMachineError (status) | ||
66 | |||
67 | def mailbox (self, mbox): | ||
68 | """Execute the code from the given instance of sieve machine | ||
69 | over each message in the mailbox.""" | ||
70 | status = sieve.mailbox (self.mach, mbox.mbox) | ||
71 | if status: | ||
72 | raise SieveMachineError (status) | ||
73 | |||
74 | def message (self, msg): | ||
75 | """Execute the code from the given instance of sieve machine | ||
76 | over the MSG.""" | ||
77 | status = sieve.message (self.mach, msg.msg) | ||
78 | if status: | ||
79 | raise SieveMachineError (status) |
-
Please register or sign in to post a comment