interp.c
5.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/* interp.c -- sieve script interpretor builder
* Larry Greenfield
* $Id$
*/
/***********************************************************
Copyright 1999 by Carnegie Mellon University
All Rights Reserved
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of Carnegie Mellon
University not be used in advertising or publicity pertaining to
distribution of the software without specific, written prior
permission.
CARNEGIE MELLON UNIVERSITY DISCLAIMS ALL WARRANTIES WITH REGARD TO
THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS, IN NO EVENT SHALL CARNEGIE MELLON UNIVERSITY BE LIABLE FOR
ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
******************************************************************/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdlib.h>
#include <xalloc.h>
#include "sieve_interface.h"
#include "interp.h"
const char *sieve_version = "cmu-sieve 2.0";
/* build a sieve interpretor */
int sieve_interp_alloc(sieve_interp_t **interp, void *interp_context)
{
sieve_interp_t *i;
static int initonce;
if (!initonce) {
initialize_siev_error_table();
initonce = 1;
}
*interp = NULL;
i = (sieve_interp_t *) xmalloc(sizeof(sieve_interp_t));
if (i == NULL) {
return SIEVE_NOMEM;
}
i->redirect = i->discard = i->reject = i->fileinto = i->keep = NULL;
i->getsize = NULL;
i->getheader = NULL;
i->getenvelope = NULL;
i->vacation = NULL;
i->notify = NULL;
i->curflags.flag = NULL; i->curflags.nflags = 0;
i->markflags = NULL;
i->interp_context = interp_context;
i->err = NULL;
*interp = i;
return SIEVE_OK;
}
static const char *sieve_extensions = "fileinto reject envelope vacation"
" imapflags notify subaddress"
#ifdef ENABLE_REGEX
" regex";
#else
"";
#endif /* ENABLE_REGEX */
const char *sieve_listextensions(void)
{
return sieve_extensions;
}
void free_imapflags(sieve_imapflags_t *imapflags)
{
while (imapflags->nflags)
free(imapflags->flag[--imapflags->nflags]);
free(imapflags->flag);
imapflags->flag = NULL;
}
int sieve_interp_free(sieve_interp_t **interp)
{
free_imapflags(&(*interp)->curflags);
free(*interp);
return SIEVE_OK;
}
/* add the callbacks */
int sieve_register_redirect(sieve_interp_t *interp, sieve_callback *f)
{
interp->redirect = f;
return SIEVE_OK;
}
int sieve_register_discard(sieve_interp_t *interp, sieve_callback *f)
{
interp->discard = f;
return SIEVE_OK;
}
int sieve_register_reject(sieve_interp_t *interp, sieve_callback *f)
{
interp->reject = f;
return SIEVE_OK;
}
int sieve_register_fileinto(sieve_interp_t *interp, sieve_callback *f)
{
interp->fileinto = f;
return SIEVE_OK;
}
int sieve_register_keep(sieve_interp_t *interp, sieve_callback *f)
{
interp->keep = f;
return SIEVE_OK;
}
static char *default_markflags[] = { "\\flagged" };
static sieve_imapflags_t default_mark = { default_markflags, 1 };
int sieve_register_imapflags(sieve_interp_t *interp, sieve_imapflags_t *mark)
{
interp->markflags =
(mark && mark->flag && mark->nflags) ? mark : &default_mark;
return SIEVE_OK;
}
int sieve_register_notify(sieve_interp_t *interp, sieve_callback *f)
{
interp->notify = f;
return SIEVE_OK;
}
/* add the callbacks for messages. again, undefined if used after
sieve_script_parse */
int sieve_register_size(sieve_interp_t *interp, sieve_get_size *f)
{
interp->getsize = f;
return SIEVE_OK;
}
int sieve_register_header(sieve_interp_t *interp, sieve_get_header *f)
{
interp->getheader = f;
return SIEVE_OK;
}
int sieve_register_envelope(sieve_interp_t *interp, sieve_get_envelope *f)
{
interp->getenvelope = f;
return SIEVE_OK;
}
int sieve_register_vacation(sieve_interp_t *interp, sieve_vacation_t *v)
{
if (!interp->getenvelope) {
return SIEVE_NOT_FINALIZED; /* we need envelope for vacation! */
}
if (v->min_response == 0) v->min_response = 3;
if (v->max_response == 0) v->max_response = 90;
if (v->min_response < 0 || v->max_response < 7 || !v->autorespond
|| !v->send_response) {
return SIEVE_FAIL;
}
interp->vacation = v;
return SIEVE_OK;
}
int sieve_register_parse_error(sieve_interp_t *interp, sieve_parse_error *f)
{
interp->err = f;
return SIEVE_OK;
}
int sieve_register_execute_error(sieve_interp_t *interp, sieve_execute_error *f)
{
interp->execute_err = f;
return SIEVE_OK;
}
int sieve_register_summary(sieve_interp_t *interp, sieve_execute_error *f)
{
interp->summary = f;
return SIEVE_OK;
}
int interp_verify(sieve_interp_t *i)
{
if (i->redirect && i->keep && i->getsize && i->getheader) {
return SIEVE_OK;
} else {
return SIEVE_NOT_FINALIZED;
}
}