1 
2 /* * * *
3  * Copyright 2003, 2005 by Aaron Stone
4  *
5  * Licensed under the GNU Lesser General Public License (LGPL)
6  * version 2.1, and other versions at the author's discretion.
7  * * * */
8 
9 #ifndef SIEVE2_H
10 #define SIEVE2_H
11 
12 #include "sieve2_error.h"
13 
14 typedef struct sieve2_context sieve2_context_t;
15 
16 /* At a minimum, you must register redirect, keep,
17  * getsize and either getheader or getallheaders.
18  * If not, you will receive SIEVE2_ERROR_NOT_FINALIZED.
19  * */
20 
21 typedef enum {
22 	SIEVE2_VALUE_FIRST,
23 
24 	SIEVE2_ACTION_REDIRECT,
25 	SIEVE2_ACTION_REJECT,
26 	SIEVE2_ACTION_DISCARD,
27 	SIEVE2_ACTION_FILEINTO,
28 	SIEVE2_ACTION_KEEP,
29 	SIEVE2_ACTION_NOTIFY,
30 	SIEVE2_ACTION_DENOTIFY,       // DEPRECATED since 2.1.11
31 	SIEVE2_ACTION_VACATION,
32 	SIEVE2_ACTION_SETFLAG,        // DEPRECATED since 2.1.11
33 	SIEVE2_ACTION_ADDFLAG,        // DEPRECATED since 2.1.11
34 	SIEVE2_ACTION_REMOVEFLAG,     // DEPRECATED since 2.1.11
35 	SIEVE2_ACTION_MARK,           // DEPRECATED since 2.1.11
36 	SIEVE2_ACTION_UNMARK,         // DEPRECATED since 2.1.11
37 
38 	SIEVE2_ERRCALL_RUNTIME,
39 	SIEVE2_ERRCALL_PARSE,
40 	SIEVE2_DEBUG_TRACE,           // NEW in 2.1.11
41 
42 	SIEVE2_SCRIPT_GETSCRIPT,
43 	SIEVE2_SCRIPT_GETSIZE,        // DEPRECATED since 2.2.6 (was never implemented!)
44 
45 	SIEVE2_MESSAGE_GETHEADER,
46 	SIEVE2_MESSAGE_GETALLHEADERS,
47 	SIEVE2_MESSAGE_GETENVELOPE,
48 	SIEVE2_MESSAGE_GETSIZE,
49 	SIEVE2_MESSAGE_GETBODY,
50 	SIEVE2_MESSAGE_GETSUBADDRESS, // NEW in 2.1.11
51 
52 	SIEVE2_ERRCALL_HEADER,        // NEW in 2.2.6
53 	SIEVE2_ERRCALL_ADDRESS,       // NEW in 2.2.6
54 
55 	SIEVE2_VALUE_LAST             // Use this as an API version check
56 } sieve2_values_t;
57 
58 typedef int (*sieve2_callback_func) (
59 	sieve2_context_t * sieve2_context,
60 	void * user_data
61 );
62 
63 typedef struct {
64 	sieve2_values_t value;
65 	sieve2_callback_func func;
66 } sieve2_callback_t;
67 
68 
69 /* From here below only functions thar be! */
70 #if defined(c_plusplus) || defined(__cplusplus)
71  extern "C" {
72 #endif
73 
74 /* Allocate and free your libSieve context. Any memory that
75  * libSieve allocated along the way will be freed here. */
76 /* Pass the pointer by reference for both of these;
77  * it will be set to NULL when it's freed. */
78 extern int sieve2_alloc(sieve2_context_t **sieve2_context);
79 extern int sieve2_free(sieve2_context_t **sieve2_context);
80 
81 /* Attach the callbacks array to the libSieve context. */
82 extern int sieve2_callbacks(sieve2_context_t *sieve2_context,
83                             sieve2_callback_t *callbacks);
84 
85 /* Get a space separated list of extensions that libSieve
86  * supports and for which you have registered a callback. */
87 /* libSieve will free this memory for you, don't worry about it. */
88 extern char * sieve2_listextensions(sieve2_context_t *sieve2_context);
89 
90 /* Validate a script for syntax and feature support */
91 extern int sieve2_validate(sieve2_context_t *sieve2_context,
92                            void *user_data);
93 
94 /* Execute a script on a message, producing an action list */
95 extern int sieve2_execute(sieve2_context_t *sieve2_context,
96                           void *user_data);
97 
98 /* libSieve will free this memory for you, don't worry about it. */
99 extern const char *
100 sieve2_getvalue_string(
101 	sieve2_context_t *sieve2_context,
102 	const char * const value);
103 
104 /* libSieve will free this memory for you, don't worry about it. */
105 extern char * *
106 sieve2_getvalue_stringlist(
107 	sieve2_context_t *sieve2_context,
108 	const char * const name);
109 
110 extern int sieve2_getvalue_int(
111 	sieve2_context_t *sieve2_context,
112 	const char * const name);
113 
114 /* If you allocated the memory, you have to free it. */
115 extern int sieve2_setvalue_string(
116 	sieve2_context_t *sieve2_context,
117 	const char * const name, const char * const value);
118 
119 /* If you allocated the memory, you have to free it. */
120 extern int sieve2_setvalue_stringlist(
121 	sieve2_context_t *sieve2_context,
122 	const char * const name, char ** const value);
123 
124 extern int sieve2_setvalue_int(
125 	sieve2_context_t *sieve2_context,
126 	const char * const name, const int value);
127 
128 /* This translates the error numbers into static strings.
129  * For fancier errors, callbacks from the context are used,
130  * and that allows the context to manage the memory. */
131 extern char * sieve2_errstr(int errval);
132 
133 /* Get a list of Credits about who writes libSieve. */
134 /* Does not allocate memory; points to static strings. */
135 extern char * sieve2_credits(void);
136 
137 /* Get the License under which libSieve is distributed. */
138 /* Does not allocate memory; points to static strings. */
139 extern char * sieve2_license(void);
140 
141 #if defined(c_plusplus) || defined(__cplusplus)
142  } /* extern "C" */
143 #endif
144 
145 #endif /* SIEVE2_H */
146