14
16
struct client *client = cmd->client;
15
17
struct sieve_storage *storage = client->storage;
16
18
const char *scriptname;
17
struct sieve_script *script;;
19
struct sieve_script *script;
21
23
if ( !client_read_string_args(cmd, 1, TRUE, &scriptname) )
24
27
if ( *scriptname != '\0' ) {
28
string_t *errors = NULL;
29
bool warnings = FALSE;
25
32
script = sieve_storage_script_init(storage, scriptname);
27
33
if ( script == NULL ) {
28
34
client_send_storage_error(client, storage);
38
if ( sieve_storage_script_is_active(script) <= 0 ) {
39
/* Script is first being activated; compile it again without the UPLOAD
43
struct sieve_error_handler *ehandler;
44
enum sieve_compile_flags cpflags =
45
SIEVE_COMPILE_FLAG_NOGLOBAL | SIEVE_COMPILE_FLAG_ACTIVATED;
46
struct sieve_binary *sbin;
48
/* Prepare error handler */
49
errors = str_new(default_pool, 1024);
50
ehandler = sieve_strbuf_ehandler_create(client->svinst, errors, TRUE,
51
client->set->managesieve_max_compile_errors);
54
if ( (sbin=sieve_compile_script
55
(script, ehandler, cpflags, NULL)) == NULL ) {
61
warnings = ( sieve_get_warnings(ehandler) > 0 );
62
sieve_error_handler_unref(&ehandler);
32
ret = sieve_storage_script_activate(script);
34
client_send_storage_error(client, storage);
36
client_send_ok(client, ret ?
37
"Setactive completed." :
38
"Script is already active.");
66
/* Activate only when script is valid (or already active) */
68
/* Refresh activation no matter what; this can also resolve some erroneous
71
ret = sieve_storage_script_activate(script);
73
client_send_storage_error(client, storage);
76
client_send_okresp(client, "WARNINGS", str_c(errors));
78
client_send_ok(client, ( ret > 0 ?
79
"Setactive completed." :
80
"Script is already active." ));
84
client_send_no(client, str_c(errors));
40
89
sieve_script_unref(&script);
42
93
ret = sieve_storage_deactivate(storage);
45
96
client_send_storage_error(client, storage);
47
client_send_ok(client, ret ?
98
client_send_ok(client, ( ret > 0 ?
48
99
"Active script is now deactivated." :
49
"No scripts currently active.");
100
"No scripts currently active." ));