/src/pigeonhole/src/lib-sieve/plugins/imap4flags/ext-imap4flags.c
Line | Count | Source |
1 | | /* Copyright (c) Pigeonhole authors, see top-level COPYING file */ |
2 | | |
3 | | /* Extension imap4flags |
4 | | * -------------------- |
5 | | * |
6 | | * Authors: Stephan Bosch |
7 | | * Specification: RFC 5232 |
8 | | * Implementation: full |
9 | | * Status: testing |
10 | | * |
11 | | */ |
12 | | |
13 | | #include "lib.h" |
14 | | #include "mempool.h" |
15 | | #include "str.h" |
16 | | |
17 | | #include "sieve-common.h" |
18 | | |
19 | | #include "sieve-code.h" |
20 | | #include "sieve-extensions.h" |
21 | | #include "sieve-actions.h" |
22 | | #include "sieve-commands.h" |
23 | | #include "sieve-validator.h" |
24 | | #include "sieve-generator.h" |
25 | | #include "sieve-interpreter.h" |
26 | | |
27 | | #include "ext-imap4flags-common.h" |
28 | | |
29 | | /* |
30 | | * Operations |
31 | | */ |
32 | | |
33 | | const struct sieve_operation_def *imap4flags_operations[] = { |
34 | | &setflag_operation, |
35 | | &addflag_operation, |
36 | | &removeflag_operation, |
37 | | &hasflag_operation |
38 | | }; |
39 | | |
40 | | /* |
41 | | * Extension |
42 | | */ |
43 | | |
44 | | static int |
45 | | ext_imap4flags_load(const struct sieve_extension *ext, void **context_r); |
46 | | static void ext_imap4flags_unload(const struct sieve_extension *ext); |
47 | | |
48 | | static bool ext_imap4flags_validator_load |
49 | | (const struct sieve_extension *ext, struct sieve_validator *valdtr); |
50 | | static bool ext_imap4flags_interpreter_load |
51 | | (const struct sieve_extension *ext, const struct sieve_runtime_env *renv, |
52 | | sieve_size_t *address); |
53 | | |
54 | | const struct sieve_extension_def imap4flags_extension = { |
55 | | .name = "imap4flags", |
56 | | .version = 1, |
57 | | .load = ext_imap4flags_load, |
58 | | .unload = ext_imap4flags_unload, |
59 | | .validator_load = ext_imap4flags_validator_load, |
60 | | .interpreter_load = ext_imap4flags_interpreter_load, |
61 | | SIEVE_EXT_DEFINE_OPERATIONS(imap4flags_operations), |
62 | | SIEVE_EXT_DEFINE_OPERAND(flags_side_effect_operand) |
63 | | }; |
64 | | |
65 | | static int |
66 | | ext_imap4flags_load(const struct sieve_extension *ext, void **context_r) |
67 | 0 | { |
68 | 0 | struct sieve_instance *svinst = ext->svinst; |
69 | 0 | const struct sieve_extension *var_ext; |
70 | 0 | struct ext_imap4flags_context *extctx; |
71 | |
|
72 | 0 | if (sieve_ext_variables_get_extension(svinst, &var_ext) < 0) |
73 | 0 | return -1; |
74 | | |
75 | 0 | extctx = i_new(struct ext_imap4flags_context, 1); |
76 | 0 | extctx->var_ext = var_ext; |
77 | |
|
78 | 0 | *context_r = extctx; |
79 | 0 | return 0; |
80 | 0 | } |
81 | | |
82 | | static void ext_imap4flags_unload(const struct sieve_extension *ext) |
83 | 0 | { |
84 | 0 | struct ext_imap4flags_context *extctx = ext->context; |
85 | |
|
86 | 0 | i_free(extctx); |
87 | 0 | } |
88 | | |
89 | | static bool ext_imap4flags_validator_load |
90 | | (const struct sieve_extension *ext, struct sieve_validator *valdtr) |
91 | 0 | { |
92 | | /* Register commands */ |
93 | 0 | sieve_validator_register_command(valdtr, ext, &cmd_setflag); |
94 | 0 | sieve_validator_register_command(valdtr, ext, &cmd_addflag); |
95 | 0 | sieve_validator_register_command(valdtr, ext, &cmd_removeflag); |
96 | 0 | sieve_validator_register_command(valdtr, ext, &tst_hasflag); |
97 | | |
98 | | /* Attach :flags tag to keep and fileinto commands */ |
99 | 0 | ext_imap4flags_attach_flags_tag(valdtr, ext, "keep"); |
100 | 0 | ext_imap4flags_attach_flags_tag(valdtr, ext, "fileinto"); |
101 | | |
102 | | /* Attach flags side-effect to keep and fileinto actions */ |
103 | 0 | sieve_ext_imap4flags_register_side_effect(valdtr, ext, "keep"); |
104 | 0 | sieve_ext_imap4flags_register_side_effect(valdtr, ext, "fileinto"); |
105 | |
|
106 | 0 | return TRUE; |
107 | 0 | } |
108 | | |
109 | | void sieve_ext_imap4flags_interpreter_load |
110 | | (const struct sieve_extension *ext, const struct sieve_runtime_env *renv) |
111 | 0 | { |
112 | 0 | sieve_interpreter_extension_register |
113 | 0 | (renv->interp, ext, &imap4flags_interpreter_extension, NULL); |
114 | 0 | } |
115 | | |
116 | | static bool ext_imap4flags_interpreter_load |
117 | | (const struct sieve_extension *ext, const struct sieve_runtime_env *renv, |
118 | | sieve_size_t *address ATTR_UNUSED) |
119 | 0 | { |
120 | 0 | sieve_ext_imap4flags_interpreter_load(ext, renv); |
121 | 0 | return TRUE; |
122 | 0 | } |
123 | | |
124 | | |
125 | | |