1 /* interp.h -- interpreter definition
2  * Larry Greenfield
3  *
4  * Copyright (c) 1994-2008 Carnegie Mellon University.  All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in
15  *    the documentation and/or other materials provided with the
16  *    distribution.
17  *
18  * 3. The name "Carnegie Mellon University" must not be used to
19  *    endorse or promote products derived from this software without
20  *    prior written permission. For permission or any legal
21  *    details, please contact
22  *      Carnegie Mellon University
23  *      Center for Technology Transfer and Enterprise Creation
24  *      4615 Forbes Avenue
25  *      Suite 302
26  *      Pittsburgh, PA  15213
27  *      (412) 268-7393, fax: (412) 268-7395
28  *      innovation@andrew.cmu.edu
29  *
30  * 4. Redistributions of any form whatsoever must retain the following
31  *    acknowledgment:
32  *    "This product includes software developed by Computing Services
33  *     at Carnegie Mellon University (http://www.cmu.edu/computing/)."
34  *
35  * CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
36  * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
37  * AND FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE
38  * FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
39  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
40  * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
41  * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
42  */
43 
44 #ifndef SIEVE_INTERP_H
45 #define SIEVE_INTERP_H
46 
47 #include "sieve_interface.h"
48 
49 struct sieve_interp {
50     /* standard callbacks for actions */
51     sieve_callback *redirect, *discard, *reject, *fileinto, *snooze, *keep;
52     sieve_callback *notify;
53     sieve_vacation_t *vacation;
54 
55     sieve_get_size *getsize;
56     sieve_get_header *getheader;
57     sieve_get_headersection *getheadersection;
58     sieve_add_header *addheader;
59     sieve_delete_header *deleteheader;
60     sieve_get_envelope *getenvelope;
61     sieve_get_environment *getenvironment;
62     sieve_get_body *getbody;
63     sieve_get_include *getinclude;
64     sieve_get_fname *getfname;
65     sieve_get_mailboxexists *getmailboxexists;
66     sieve_get_mailboxidexists *getmailboxidexists;
67     sieve_get_specialuseexists *getspecialuseexists;
68     sieve_get_metadata *getmetadata;
69 
70     sieve_logger *log;
71 
72     sieve_list_validator *isvalidlist;
73     sieve_list_comparator *listcompare;
74 
75     sieve_duplicate_t *duplicate;
76     sieve_jmapquery *jmapquery;
77 
78     sieve_parse_error *err;
79 
80     const strarray_t *notifymethods;
81 
82     sieve_execute_error *execute_err;
83 
84     char *lastitem;
85 
86     /* context to pass along */
87     void *interp_context;
88     strarray_t *extensions;
89 
90     /* time when allocated */
91     time_t time;
92 
93     /* have we addedd/deleted any headers? */
94     unsigned edited_headers : 1;
95 };
96 
97 
98 /* Sieve capabilities bitmask */
99 enum sieve_capa_flag {
100     /* Sieve "base" - RFC 5228 */
101     SIEVE_CAPA_BASE         = 1LL<<0,
102     SIEVE_CAPA_COMP_NUMERIC = 1LL<<1,
103     SIEVE_CAPA_ENCODED_CHAR = 1LL<<2,
104     SIEVE_CAPA_ENVELOPE     = 1LL<<3,
105     SIEVE_CAPA_FILEINTO     = 1LL<<4,
106 
107     /* Regular Expressions - draft-ietf-sieve-regex */
108 #ifdef ENABLE_REGEX
109     SIEVE_CAPA_REGEX        = 1LL<<5,
110 #else
111     SIEVE_CAPA_REGEX        = 0LL<<5, /* disabled at compile-time */
112 #endif
113 
114     /* Copy - RFC 3894 */
115     SIEVE_CAPA_COPY         = 1LL<<6,
116 
117     /* Body - RFC 5173 */
118     SIEVE_CAPA_BODY         = 1LL<<7,
119 
120     /* Environment - RFC 5183 */
121     SIEVE_CAPA_ENVIRONMENT  = 1LL<<8,
122 
123     /* Variables - RFC 5229 */
124     SIEVE_CAPA_VARIABLES    = 1LL<<9,
125 
126     /* Vacation - RFC 5230 */
127     SIEVE_CAPA_VACATION     = 1LL<<10,
128 
129     /* Relational - RFC 5231 */
130     SIEVE_CAPA_RELATIONAL   = 1LL<<11,
131 
132     /* IMAP4 Flags - RFC 5232 */
133     SIEVE_CAPA_IMAP4FLAGS   = 1LL<<12,
134     SIEVE_CAPA_IMAPFLAGS    = 0LL<<13, /* deprecated */
135 
136     /* Subaddress - RFC 5233 */
137     SIEVE_CAPA_SUBADDRESS   = 1LL<<14,
138 
139     /* Spamtest & Virustest - RFC 5235 */
140     SIEVE_CAPA_SPAM         = 0LL<<15, /* currently unsupported */
141     SIEVE_CAPA_SPAMPLUS     = 0LL<<16, /* currently unsupported */
142     SIEVE_CAPA_VIRUS        = 0LL<<17, /* currently unsupported */
143 
144     /* Date & Index - RFC 5260 */
145     SIEVE_CAPA_DATE         = 1LL<<18,
146     SIEVE_CAPA_INDEX        = 1LL<<19,
147 
148     /* Editheader - RFC 5293 */
149     SIEVE_CAPA_EDITHEADER   = 1LL<<20,
150 
151     /* [Extended] Reject - RFC 5429 */
152     SIEVE_CAPA_EREJECT      = 1LL<<21,
153     SIEVE_CAPA_REJECT       = 1LL<<22,
154 
155     /* Notifications - RFC 5435 */
156     SIEVE_CAPA_ENOTIFY      = 1LL<<23,
157     SIEVE_CAPA_NOTIFY       = 1LL<<24, /* draft-martin-sieve-notify-01 */
158 
159     /* Ihave - RFC 5463 */
160     SIEVE_CAPA_IHAVE        = 1LL<<25,
161 
162     /* Mailbox & Metadata - RFC 5490 */
163     SIEVE_CAPA_MAILBOX      = 1LL<<26,
164     SIEVE_CAPA_MBOXMETA     = 1LL<<27,
165     SIEVE_CAPA_SERVERMETA   = 1LL<<28,
166 
167     /* MIME Part Handling - RFC 5703 */
168     SIEVE_CAPA_ENCLOSE      = 0LL<<29, /* currently unsupported */
169     SIEVE_CAPA_EXTRACT      = 0LL<<30, /* currently unsupported */
170     SIEVE_CAPA_FOREVERYPART = 0LL<<31, /* currently unsupported */
171     SIEVE_CAPA_MIME         = 0LL<<32, /* currently unsupported */
172     SIEVE_CAPA_REPLACE      = 0LL<<33, /* currently unsupported */
173 
174     /* DSN & Deliver-By - RFC 6009 */
175     SIEVE_CAPA_ENV_DELBY    = 0LL<<34, /* currently unsupported */
176     SIEVE_CAPA_ENV_DSN      = 0LL<<35, /* currently unsupported */
177     SIEVE_CAPA_REDIR_DELBY  = 1LL<<36,
178     SIEVE_CAPA_REDIR_DSN    = 1LL<<37,
179 
180     /* Vacation :seconds - RFC 6131 */
181     SIEVE_CAPA_VACATION_SEC = 1LL<<38,
182 
183     /* External Lists - RFC 6134 */
184     SIEVE_CAPA_EXTLISTS     = 1LL<<39,
185 
186     /* Convert - RFC 6558 */
187     SIEVE_CAPA_CONVERT      = 0LL<<40, /* currently unsupported */
188 
189     /* Include - RFC 6609 */
190     SIEVE_CAPA_INCLUDE      = 1LL<<41,
191 
192     /* IMAP Events - RFC 6785 */
193     SIEVE_CAPA_IMAP         = 0LL<<42, /* currently unsupported */
194 
195     /* Duplicate - RFC 7352 */
196     SIEVE_CAPA_DUPLICATE    = 1LL<<43,
197 
198     /* Special-Use - RFC 8579 */
199     SIEVE_CAPA_SPECIAL_USE  = 1LL<<44,
200 
201     /* Fcc - RFC 8580 */
202     SIEVE_CAPA_FCC          = 1LL<<45,
203 
204     /* Mailboxid - draft-ietf-extra-sieve-mailboxid */
205     SIEVE_CAPA_MAILBOXID    = 1LL<<46,
206 
207     /* Log - vnd.cyrus.log */
208     SIEVE_CAPA_LOG          = 1LL<<47,
209 
210     /* JMAP Query - vnd.cyrus.jmapquery */
211 #ifdef WITH_JMAP
212     SIEVE_CAPA_JMAPQUERY    = 1LL<<48,
213 #else
214     SIEVE_CAPA_JMAPQUERY    = 0LL<<48, /* disabled at compile-time */
215 #endif
216 
217     /* Snooze - draft-ietf-extra-sieve-snooze */
218     SIEVE_CAPA_SNOOZE       = 1LL<<49,
219 };
220 
221 #define SIEVE_CAPA_ALL (SIEVE_CAPA_BASE           \
222                         | SIEVE_CAPA_COMP_NUMERIC \
223                         | SIEVE_CAPA_ENCODED_CHAR \
224                         | SIEVE_CAPA_ENVELOPE     \
225                         | SIEVE_CAPA_FILEINTO     \
226                         | SIEVE_CAPA_REGEX        \
227                         | SIEVE_CAPA_COPY         \
228                         | SIEVE_CAPA_BODY         \
229                         | SIEVE_CAPA_ENVIRONMENT  \
230                         | SIEVE_CAPA_VARIABLES    \
231                         | SIEVE_CAPA_VACATION     \
232                         | SIEVE_CAPA_RELATIONAL   \
233                         | SIEVE_CAPA_IMAP4FLAGS   \
234                         | SIEVE_CAPA_IMAPFLAGS    \
235                         | SIEVE_CAPA_SUBADDRESS   \
236                         | SIEVE_CAPA_SPAM         \
237                         | SIEVE_CAPA_SPAMPLUS     \
238                         | SIEVE_CAPA_VIRUS        \
239                         | SIEVE_CAPA_DATE         \
240                         | SIEVE_CAPA_INDEX        \
241                         | SIEVE_CAPA_EDITHEADER   \
242                         | SIEVE_CAPA_EREJECT      \
243                         | SIEVE_CAPA_REJECT       \
244                         | SIEVE_CAPA_ENOTIFY      \
245                         | SIEVE_CAPA_NOTIFY       \
246                         | SIEVE_CAPA_IHAVE        \
247                         | SIEVE_CAPA_MAILBOX      \
248                         | SIEVE_CAPA_MBOXMETA     \
249                         | SIEVE_CAPA_SERVERMETA   \
250                         | SIEVE_CAPA_ENCLOSE      \
251                         | SIEVE_CAPA_EXTRACT      \
252                         | SIEVE_CAPA_FOREVERYPART \
253                         | SIEVE_CAPA_MIME         \
254                         | SIEVE_CAPA_REPLACE      \
255                         | SIEVE_CAPA_ENV_DELBY    \
256                         | SIEVE_CAPA_ENV_DSN      \
257                         | SIEVE_CAPA_REDIR_DELBY  \
258                         | SIEVE_CAPA_REDIR_DSN    \
259                         | SIEVE_CAPA_VACATION_SEC \
260                         | SIEVE_CAPA_EXTLISTS     \
261                         | SIEVE_CAPA_CONVERT      \
262                         | SIEVE_CAPA_INCLUDE      \
263                         | SIEVE_CAPA_IMAP         \
264                         | SIEVE_CAPA_DUPLICATE    \
265                         | SIEVE_CAPA_SPECIAL_USE  \
266                         | SIEVE_CAPA_FCC          \
267                         | SIEVE_CAPA_MAILBOXID    \
268                         | SIEVE_CAPA_LOG          \
269                         | SIEVE_CAPA_JMAPQUERY    \
270                         | SIEVE_CAPA_SNOOZE       \
271                         )
272 
273 #define SIEVE_CAPA_IHAVE_INCOMPAT (SIEVE_CAPA_ENCODED_CHAR | SIEVE_CAPA_VARIABLES)
274 
275 extern const char *lookup_capability_string(unsigned long long capa);
276 unsigned long long lookup_capability(const char *str);
277 unsigned long long extension_isactive(sieve_interp_t *interp, const char *str);
278 int interp_verify(sieve_interp_t *interp);
279 
280 #endif
281