summaryrefslogtreecommitdiffstats
path: root/pigeonhole/src/lib-sieve/plugins/mime/ext-extracttext.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 09:51:24 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 09:51:24 +0000
commitf7548d6d28c313cf80e6f3ef89aed16a19815df1 (patch)
treea3f6f2a3f247293bee59ecd28e8cd8ceb6ca064a /pigeonhole/src/lib-sieve/plugins/mime/ext-extracttext.c
parentInitial commit. (diff)
downloaddovecot-f7548d6d28c313cf80e6f3ef89aed16a19815df1.tar.xz
dovecot-f7548d6d28c313cf80e6f3ef89aed16a19815df1.zip
Adding upstream version 1:2.3.19.1+dfsg1.upstream/1%2.3.19.1+dfsg1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'pigeonhole/src/lib-sieve/plugins/mime/ext-extracttext.c')
-rw-r--r--pigeonhole/src/lib-sieve/plugins/mime/ext-extracttext.c130
1 files changed, 130 insertions, 0 deletions
diff --git a/pigeonhole/src/lib-sieve/plugins/mime/ext-extracttext.c b/pigeonhole/src/lib-sieve/plugins/mime/ext-extracttext.c
new file mode 100644
index 0000000..4eab76b
--- /dev/null
+++ b/pigeonhole/src/lib-sieve/plugins/mime/ext-extracttext.c
@@ -0,0 +1,130 @@
+/* Copyright (c) 2002-2018 Pigeonhole authors, see the included COPYING file
+ */
+
+/* Extension extracttext
+ * ---------------------
+ *
+ * Authors: Stephan Bosch
+ * Specification: RFC 5703, Section 7
+ * Implementation: full
+ * Status: experimental
+ *
+ */
+
+#include "sieve-common.h"
+
+#include "sieve-code.h"
+#include "sieve-extensions.h"
+#include "sieve-actions.h"
+#include "sieve-commands.h"
+#include "sieve-validator.h"
+#include "sieve-generator.h"
+#include "sieve-interpreter.h"
+#include "sieve-result.h"
+
+#include "sieve-ext-variables.h"
+
+#include "ext-mime-common.h"
+
+/*
+ * Extension
+ */
+
+static bool ext_extracttext_load
+ (const struct sieve_extension *ext, void **context);
+static void ext_extracttext_unload
+ (const struct sieve_extension *ext);
+static bool ext_extracttext_validator_load
+ (const struct sieve_extension *ext, struct sieve_validator *valdtr);
+
+const struct sieve_extension_def extracttext_extension = {
+ .name = "extracttext",
+ .load = ext_extracttext_load,
+ .unload = ext_extracttext_unload,
+ .validator_load = ext_extracttext_validator_load,
+ SIEVE_EXT_DEFINE_OPERATION(extracttext_operation)
+};
+
+static bool ext_extracttext_load
+(const struct sieve_extension *ext, void **context)
+{
+ struct sieve_instance *svinst = ext->svinst;
+ struct ext_extracttext_context *ectx;
+
+ if ( *context != NULL )
+ ext_extracttext_unload(ext);
+
+ ectx = i_new(struct ext_extracttext_context, 1);
+ ectx->var_ext = sieve_ext_variables_get_extension(ext->svinst);
+ ectx->fep_ext = sieve_extension_register
+ (svinst, &foreverypart_extension, FALSE);
+ *context = (void *)ectx;
+ return TRUE;
+}
+
+static void ext_extracttext_unload
+(const struct sieve_extension *ext)
+{
+ struct ext_extracttext_context *ctx =
+ (struct ext_extracttext_context *) ext->context;
+
+ i_free(ctx);
+}
+
+/*
+ * Extension validation
+ */
+
+static bool ext_extracttext_validator_validate
+ (const struct sieve_extension *ext,
+ struct sieve_validator *valdtr, void *context,
+ struct sieve_ast_argument *require_arg,
+ bool required);
+
+const struct sieve_validator_extension
+extracttext_validator_extension = {
+ .ext = &extracttext_extension,
+ .validate = ext_extracttext_validator_validate
+};
+
+static bool ext_extracttext_validator_load
+(const struct sieve_extension *ext, struct sieve_validator *valdtr)
+{
+ /* Register validator extension to check for conflict with eextracttext */
+ sieve_validator_extension_register
+ (valdtr, ext, &extracttext_validator_extension, NULL);
+
+ /* Register new commands */
+ sieve_validator_register_command(valdtr, ext, &cmd_extracttext);
+
+ return TRUE;
+}
+
+static bool ext_extracttext_validator_validate
+(const struct sieve_extension *ext,
+ struct sieve_validator *valdtr, void *context ATTR_UNUSED,
+ struct sieve_ast_argument *require_arg,
+ bool required ATTR_UNUSED)
+{
+ struct ext_extracttext_context *ectx =
+ (struct ext_extracttext_context *)ext->context;
+
+ if ( ectx->var_ext == NULL ||
+ !sieve_ext_variables_is_active
+ (ectx->var_ext, valdtr) ) {
+ sieve_argument_validate_error(valdtr, require_arg,
+ "extracttext extension cannot be used "
+ "without variables extension");
+ return FALSE;
+ }
+ if ( ectx->fep_ext == NULL ||
+ !sieve_validator_extension_loaded
+ (valdtr, ectx->fep_ext) ) {
+ sieve_argument_validate_error(valdtr, require_arg,
+ "extracttext extension cannot be used "
+ "without foreverypart extension");
+ return FALSE;
+ }
+
+ return TRUE;
+}