diff --git a/src/lib-sieve/Makefile.am b/src/lib-sieve/Makefile.am index 84f2675a055fecc23b0a22ddbb6360c1ae5f5068..31d87cc3e11750c0c39a56623e93ca27f2e05402 100644 --- a/src/lib-sieve/Makefile.am +++ b/src/lib-sieve/Makefile.am @@ -39,6 +39,7 @@ sievec_SOURCES = \ sieve-validator.c \ sieve-generator.c \ sieve-interpreter.c \ + sieve-result.c \ sieve-error.c \ sieve-commands.c \ sieve-code.c \ @@ -51,10 +52,12 @@ sievec_SOURCES = \ noinst_HEADERS = \ sieve-lexer.h \ sieve-ast.h \ + sieve-binary.h \ sieve-parser.h \ sieve-validator.h \ sieve-generator.h \ sieve-interpreter.h \ + sieve-result.h sieve-error.h \ sieve-commands.h \ sieve-code.h diff --git a/src/lib-sieve/ext-fileinto.c b/src/lib-sieve/ext-fileinto.c index 8c6cd58f418ac7bc6f100995d3070eca77bb5c30..c4fc2b58f28ad44b495758b5eea5ca93ca85e375 100644 --- a/src/lib-sieve/ext-fileinto.c +++ b/src/lib-sieve/ext-fileinto.c @@ -79,3 +79,32 @@ static bool ext_fileinto_opcode_dump(struct sieve_interpreter *interpreter) return TRUE; } +/* + * Execution + */ + +static bool ext_fileinto_opcode_execute(struct sieve_interpreter *interpreter) +{ +} + +/* +static int sieve_fileinto(void *ac, + void *ic ATTR_UNUSED, + void *sc, + void *mc, + const char **errmsg ATTR_UNUSED) +{ + sieve_fileinto_context_t *fc = (sieve_fileinto_context_t *) ac; + script_data_t *sd = (script_data_t *) sc; + sieve_msgdata_t *md = (sieve_msgdata_t *) mc; + enum mail_flags flags; + const char *const *keywords; + + get_flags(fc->imapflags, &flags, &keywords); + + if (deliver_save(sd->namespaces, sd->storage_r, fc->mailbox, + md->mail, flags, keywords) < 0) + return SIEVE_FAIL; + + return SIEVE_OK; +}*/ diff --git a/src/lib-sieve/sieve-interpreter.h b/src/lib-sieve/sieve-interpreter.h index 28cdcba9794fe4880417edfd6cfe2e0dc20f69da..7f8906a84d5b98a2de37fa162cf0ca8d259ccb44 100644 --- a/src/lib-sieve/sieve-interpreter.h +++ b/src/lib-sieve/sieve-interpreter.h @@ -3,6 +3,7 @@ #include "lib.h" #include "buffer.h" +#include "mail-storage.h" #include "sieve-binary.h" @@ -10,6 +11,14 @@ struct sieve_coded_stringlist; struct sieve_interpreter; +struct sieve_mail_context { + struct mail_namespace *namespaces; + struct mail_storage **storage_r; + struct mail *mail; + const char *destaddr; + const char *mailbox; +}; + struct sieve_interpreter *sieve_interpreter_create(struct sieve_binary *binary); void sieve_interpreter_free(struct sieve_interpreter *interpreter); diff --git a/src/plugins/Makefile.am b/src/plugins/Makefile.am new file mode 100644 index 0000000000000000000000000000000000000000..4623241f10b80b21cf7a3d5a02d12c744ba74ecc --- /dev/null +++ b/src/plugins/Makefile.am @@ -0,0 +1 @@ +SUBDIRS = lda-sieve diff --git a/src/plugins/lda-sieve/Makefile.am b/src/plugins/lda-sieve/Makefile.am new file mode 100644 index 0000000000000000000000000000000000000000..706b00fb8bd1465c9762996a63e54cfb410916dc --- /dev/null +++ b/src/plugins/lda-sieve/Makefile.am @@ -0,0 +1,33 @@ +SUBDIRS = libsieve + +AM_CPPFLAGS = \ + -I$(top_srcdir)/src/lib-sieve \ + -I$(dovecot_incdir) \ + -I$(dovecot_incdir)/src/lib \ + -I$(dovecot_incdir)/src/lib-dict \ + -I$(dovecot_incdir)/src/lib-mail \ + -I$(dovecot_incdir)/src/lib-storage \ + -I$(dovecot_incdir)/src/deliver + +lda_moduledir = $(moduledir)/lda + +lib90_cmusieve_plugin_la_LDFLAGS = -module -avoid-version + +lda_module_LTLIBRARIES = \ + lib90_cmusieve_plugin.la + +lib90_cmusieve_plugin_la_LIBADD = \ + libsieve/libsieve.la + +lib90_cmusieve_plugin_la_SOURCES = \ + cmusieve-plugin.c \ + imparse.c \ + map.c \ + sieve-cmu.c + +noinst_HEADERS = \ + cmusieve-plugin.h \ + imparse.h \ + libconfig.h \ + map.h \ + xmalloc.h diff --git a/src/plugins/lda-sieve/lda-sieve-plugin.c b/src/plugins/lda-sieve/lda-sieve-plugin.c new file mode 100644 index 0000000000000000000000000000000000000000..01a9809ac93aa88892c6e138317ba78caad2099f --- /dev/null +++ b/src/plugins/lda-sieve/lda-sieve-plugin.c @@ -0,0 +1,91 @@ +/* Copyright (C) 2006 Timo Sirainen */ + +#include "lib.h" +#include "home-expand.h" +#include "deliver.h" +#include "sieve-compiler.h" + +#include "lda-sieve-plugin.h" + +#include <stdlib.h> +#include <sys/stat.h> + +#define SIEVE_SCRIPT_PATH "~/.dovecot.sieve" + +static deliver_mail_func_t *next_deliver_mail; +struct et_list *_et_list = NULL; + +static const char *get_sieve_path(void) +{ + const char *script_path, *home; + struct stat st; + + home = getenv("HOME"); + + /* userdb may specify Sieve path */ + script_path = getenv("SIEVE"); + if (script_path != NULL) { + if (*script_path == '\0') { + /* disabled */ + return NULL; + } + + if (*script_path != '/' && *script_path != '\0') { + /* relative path. change to absolute. */ + script_path = t_strconcat(getenv("HOME"), "/", + script_path, NULL); + } + } else { + if (home == NULL) { + i_error("Per-user script path is unknown. See " + "http://wiki.dovecot.org/LDA/Sieve#location"); + return NULL; + } + + script_path = home_expand(SIEVE_SCRIPT_PATH); + } + + if (stat(script_path, &st) < 0) { + if (errno != ENOENT) + i_error("stat(%s) failed: %m", script_path); + + /* use global script instead, if one exists */ + script_path = getenv("SIEVE_GLOBAL_PATH"); + if (script_path == NULL) { + /* for backwards compatibility */ + script_path = getenv("GLOBAL_SCRIPT_PATH"); + } + } + + return script_path; +} + +static int +lda_sieve_deliver_mail(struct mail_namespace *namespaces, + struct mail_storage **storage_r, + struct mail *mail, + const char *destaddr, const char *mailbox) +{ + const char *script_path; + + script_path = get_sieve_path(); + if (script_path == NULL) + return 0; + + if (getenv("DEBUG") != NULL) + i_info("sieve: Using sieve path: %s", script_path); + + return sieve_run(namespaces, storage_r, mail, script_path, + destaddr, getenv("USER"), mailbox); +} + +void lda_sieve_plugin_init(void) +{ + next_deliver_mail = deliver_mail; + deliver_mail = lda_sieve_deliver_mail; +} + +void lda_sieve_plugin_deinit(void) +{ + deliver_mail = next_deliver_mail; +} diff --git a/src/plugins/lda-sieve/lda-sieve-plugin.h b/src/plugins/lda-sieve/lda-sieve-plugin.h new file mode 100644 index 0000000000000000000000000000000000000000..a138d15b8154ac5d08239e548405a8a0b2baf492 --- /dev/null +++ b/src/plugins/lda-sieve/lda-sieve-plugin.h @@ -0,0 +1,12 @@ +#ifndef __LDA_SIEVE_PLUGIN_H +#define __LDA_SIEVE_PLUGIN_H + +int lda_sieve_run(struct mail_namespace *namespaces, + struct mail_storage **storage_r, struct mail *mail, + const char *script_path, const char *destaddr, + const char *username, const char *mailbox); + +void lda_sieve_plugin_init(void); +void lda_sieve_plugin_deinit(void); + +#endif