/src/pigeonhole/src/lib-sieve/plugins/vnd.dovecot/environment/ext-vnd-environment-items.c
Line | Count | Source |
1 | | /* Copyright (c) Pigeonhole authors, see top-level COPYING file */ |
2 | | |
3 | | #include "lib.h" |
4 | | #include "array.h" |
5 | | |
6 | | #include "sieve-extensions.h" |
7 | | #include "sieve-commands.h" |
8 | | #include "sieve-comparators.h" |
9 | | #include "sieve-match-types.h" |
10 | | #include "sieve-address-parts.h" |
11 | | |
12 | | #include "sieve-validator.h" |
13 | | #include "sieve-generator.h" |
14 | | #include "sieve-binary.h" |
15 | | #include "sieve-interpreter.h" |
16 | | #include "sieve-dump.h" |
17 | | |
18 | | #include "ext-vnd-environment-common.h" |
19 | | |
20 | | /* |
21 | | * Environment items |
22 | | */ |
23 | | |
24 | | /* default_mailbox */ |
25 | | |
26 | | static const char * |
27 | | envit_default_mailbox_get_value( |
28 | | const struct sieve_runtime_env *renv, |
29 | | const struct sieve_environment_item *item ATTR_UNUSED, |
30 | | const char *name ATTR_UNUSED) |
31 | 0 | { |
32 | 0 | const struct sieve_execute_env *eenv = renv->exec_env; |
33 | |
|
34 | 0 | i_assert(eenv->scriptenv->default_mailbox != NULL); |
35 | 0 | return eenv->scriptenv->default_mailbox; |
36 | 0 | } |
37 | | |
38 | | const struct sieve_environment_item_def default_mailbox_env_item = { |
39 | | .name = "vnd.dovecot.default-mailbox", |
40 | | .get_value = envit_default_mailbox_get_value, |
41 | | }; |
42 | | |
43 | | /* username */ |
44 | | |
45 | | static const char * |
46 | | envit_username_get_value(const struct sieve_runtime_env *renv, |
47 | | const struct sieve_environment_item *item ATTR_UNUSED, |
48 | | const char *name ATTR_UNUSED) |
49 | 0 | { |
50 | 0 | const struct sieve_execute_env *eenv = renv->exec_env; |
51 | |
|
52 | 0 | return eenv->svinst->username; |
53 | 0 | } |
54 | | |
55 | | const struct sieve_environment_item_def username_env_item = { |
56 | | .name = "vnd.dovecot.username", |
57 | | .get_value = envit_username_get_value, |
58 | | }; |
59 | | |
60 | | /* config.* */ |
61 | | |
62 | | static const char * |
63 | | envit_config_get_value(const struct sieve_runtime_env *renv ATTR_UNUSED, |
64 | | const struct sieve_environment_item *item, |
65 | | const char *name) |
66 | 0 | { |
67 | 0 | const struct sieve_extension *this_ext = item->ext; |
68 | 0 | struct ext_vnd_environment_context *extctx = this_ext->context; |
69 | |
|
70 | 0 | if (*name == '\0') |
71 | 0 | return NULL; |
72 | 0 | if (!array_is_created(&extctx->set->envs)) |
73 | 0 | return NULL; |
74 | | |
75 | 0 | const char *const *envs; |
76 | 0 | unsigned int envs_count, i; |
77 | |
|
78 | 0 | envs = array_get(&extctx->set->envs, &envs_count); |
79 | 0 | i_assert(envs_count % 2 == 0); |
80 | 0 | for (i = 0; i < envs_count; i += 2) { |
81 | 0 | if (strcasecmp(name, envs[i]) == 0) |
82 | 0 | return envs[i + 1]; |
83 | 0 | } |
84 | 0 | return NULL; |
85 | 0 | } |
86 | | |
87 | | const struct sieve_environment_item_def config_env_item = { |
88 | | .name = "vnd.dovecot.config", |
89 | | .prefix = TRUE, |
90 | | .get_value = envit_config_get_value, |
91 | | }; |
92 | | |
93 | | /* |
94 | | * Register |
95 | | */ |
96 | | |
97 | | void ext_vnd_environment_items_register(const struct sieve_extension *ext, |
98 | | const struct sieve_runtime_env *renv) |
99 | 0 | { |
100 | 0 | struct ext_vnd_environment_context *extctx = ext->context; |
101 | |
|
102 | 0 | sieve_environment_item_register(extctx->env_ext, renv->interp, ext, |
103 | 0 | &default_mailbox_env_item); |
104 | 0 | sieve_environment_item_register(extctx->env_ext, renv->interp, ext, |
105 | 0 | &username_env_item); |
106 | 0 | sieve_environment_item_register(extctx->env_ext, renv->interp, ext, |
107 | 0 | &config_env_item); |
108 | 0 | } |