Skip to content
Snippets Groups Projects
Commit 8c0c5a98 authored by Stephan Bosch's avatar Stephan Bosch
Browse files

Added envelope data to the interpreter environment.

parent d951cfec
No related branches found
No related tags found
No related merge requests found
...@@ -151,23 +151,23 @@ static bool ext_envelope_opcode_dump ...@@ -151,23 +151,23 @@ static bool ext_envelope_opcode_dump
printf("ENVELOPE\n"); printf("ENVELOPE\n");
/* Handle any optional arguments */ /* Handle any optional arguments */
if ( sieve_operand_optional_present(sbin, address) ) { if ( sieve_operand_optional_present(sbin, address) ) {
while ( (opt_code=sieve_operand_optional_read(sbin, address)) ) { while ( (opt_code=sieve_operand_optional_read(sbin, address)) ) {
switch ( opt_code ) { switch ( opt_code ) {
case OPT_COMPARATOR: case OPT_COMPARATOR:
sieve_opr_comparator_dump(interp, sbin, address); sieve_opr_comparator_dump(interp, sbin, address);
break; break;
case OPT_MATCH_TYPE: case OPT_MATCH_TYPE:
sieve_opr_match_type_dump(interp, sbin, address); sieve_opr_match_type_dump(interp, sbin, address);
break; break;
case OPT_ADDRESS_PART: case OPT_ADDRESS_PART:
sieve_opr_address_part_dump(interp, sbin, address); sieve_opr_address_part_dump(interp, sbin, address);
break; break;
default: default:
return FALSE; return FALSE;
} }
} }
} }
return return
sieve_opr_stringlist_dump(sbin, address) && sieve_opr_stringlist_dump(sbin, address) &&
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include <sys/types.h> #include <sys/types.h>
#include <stdint.h> #include <stdint.h>
#include "sieve.h"
/* /*
* Types * Types
*/ */
......
...@@ -30,7 +30,7 @@ struct sieve_interpreter { ...@@ -30,7 +30,7 @@ struct sieve_interpreter {
struct sieve_result *result; struct sieve_result *result;
/* Execution environment */ /* Execution environment */
struct mail *mail; struct sieve_message_data *msgdata;
}; };
struct sieve_interpreter *sieve_interpreter_create(struct sieve_binary *binary) struct sieve_interpreter *sieve_interpreter_create(struct sieve_binary *binary)
...@@ -108,9 +108,10 @@ inline const void *sieve_interpreter_extension_get_context ...@@ -108,9 +108,10 @@ inline const void *sieve_interpreter_extension_get_context
/* Accessing runtinme environment */ /* Accessing runtinme environment */
inline struct mail *sieve_interpreter_get_mail(struct sieve_interpreter *interpreter) inline struct sieve_message_data *
sieve_interpreter_get_msgdata(struct sieve_interpreter *interpreter)
{ {
return interpreter->mail; return interpreter->msgdata;
} }
/* Program counter */ /* Program counter */
...@@ -194,7 +195,7 @@ void sieve_interpreter_dump_code(struct sieve_interpreter *interpreter) ...@@ -194,7 +195,7 @@ void sieve_interpreter_dump_code(struct sieve_interpreter *interpreter)
sieve_interpreter_reset(interpreter); sieve_interpreter_reset(interpreter);
interpreter->result = NULL; interpreter->result = NULL;
interpreter->mail = NULL; interpreter->msgdata = NULL;
while ( interpreter->pc < sieve_binary_get_code_size(interpreter->binary) ) { while ( interpreter->pc < sieve_binary_get_code_size(interpreter->binary) ) {
if ( !sieve_interpreter_dump_operation(interpreter) ) { if ( !sieve_interpreter_dump_operation(interpreter) ) {
...@@ -226,14 +227,14 @@ bool sieve_interpreter_execute_operation ...@@ -226,14 +227,14 @@ bool sieve_interpreter_execute_operation
} }
struct sieve_result *sieve_interpreter_run struct sieve_result *sieve_interpreter_run
(struct sieve_interpreter *interp, struct mail *mail) (struct sieve_interpreter *interp, struct sieve_message_data *msgdata)
{ {
struct sieve_result *result; struct sieve_result *result;
sieve_interpreter_reset(interp); sieve_interpreter_reset(interp);
result = sieve_result_create(); result = sieve_result_create();
interp->result = result; interp->result = result;
interp->mail = mail; interp->msgdata = msgdata;
while ( interp->pc < sieve_binary_get_code_size(interp->binary) ) { while ( interp->pc < sieve_binary_get_code_size(interp->binary) ) {
printf("%08x: ", interp->pc); printf("%08x: ", interp->pc);
......
...@@ -43,7 +43,8 @@ bool sieve_interpreter_read_offset_operand ...@@ -43,7 +43,8 @@ bool sieve_interpreter_read_offset_operand
/* Accessing runtime information */ /* Accessing runtime information */
inline struct mail *sieve_interpreter_get_mail(struct sieve_interpreter *interpreter); inline struct sieve_message_data *
sieve_interpreter_get_msgdata(struct sieve_interpreter *interpreter);
/* Code dump (debugging purposes) */ /* Code dump (debugging purposes) */
...@@ -53,7 +54,7 @@ void sieve_interpreter_dump_code(struct sieve_interpreter *interp); ...@@ -53,7 +54,7 @@ void sieve_interpreter_dump_code(struct sieve_interpreter *interp);
bool sieve_interpreter_execute_operation(struct sieve_interpreter *interp); bool sieve_interpreter_execute_operation(struct sieve_interpreter *interp);
struct sieve_result *sieve_interpreter_run struct sieve_result *sieve_interpreter_run
(struct sieve_interpreter *interp, struct mail *mail); (struct sieve_interpreter *interp, struct sieve_message_data *message);
#endif /* __SIEVE_INTERPRETER_H */ #endif /* __SIEVE_INTERPRETER_H */
...@@ -139,13 +139,14 @@ void sieve_dump(struct sieve_binary *binary) ...@@ -139,13 +139,14 @@ void sieve_dump(struct sieve_binary *binary)
sieve_interpreter_free(interpreter); sieve_interpreter_free(interpreter);
} }
bool sieve_execute(struct sieve_binary *binary, struct mail *mail) bool sieve_execute
(struct sieve_binary *binary, struct sieve_message_data *msgdata)
{ {
struct sieve_interpreter *interpreter = sieve_interpreter_create(binary); struct sieve_interpreter *interpreter = sieve_interpreter_create(binary);
bool result = TRUE; bool result = TRUE;
printf("Code Execute:\n\n"); printf("Code Execute:\n\n");
if ( sieve_interpreter_run(interpreter, mail) == NULL ) { if ( sieve_interpreter_run(interpreter, msgdata) == NULL ) {
result = FALSE; result = FALSE;
} }
......
#ifndef __SIEVE_H #ifndef __SIEVE_H
#define __SIEVE_H #define __SIEVE_H
#include "lib.h"
#include "mail-storage.h" #include "mail-storage.h"
struct sieve_binary; struct sieve_binary;
struct sieve_message_data {
struct mail *mail;
const char *return_path;
const char *rcpt_address;
const char *auth_user;
};
bool sieve_init(const char *plugins); bool sieve_init(const char *plugins);
void sieve_deinit(void); void sieve_deinit(void);
struct sieve_binary *sieve_compile(int fd); struct sieve_binary *sieve_compile(int fd);
void sieve_dump(struct sieve_binary *binary); void sieve_dump(struct sieve_binary *binary);
bool sieve_execute(struct sieve_binary *binary, struct mail *mail); bool sieve_execute
(struct sieve_binary *binary, struct sieve_message_data *msgdata);
#endif #endif
...@@ -151,7 +151,7 @@ static bool tst_address_opcode_dump ...@@ -151,7 +151,7 @@ static bool tst_address_opcode_dump
static bool tst_address_opcode_execute static bool tst_address_opcode_execute
(struct sieve_interpreter *interp, struct sieve_binary *sbin, sieve_size_t *address) (struct sieve_interpreter *interp, struct sieve_binary *sbin, sieve_size_t *address)
{ {
struct mail *mail = sieve_interpreter_get_mail(interp); struct sieve_message_data *msgdata = sieve_interpreter_get_msgdata(interp);
const struct sieve_comparator *cmp = &i_octet_comparator; const struct sieve_comparator *cmp = &i_octet_comparator;
const struct sieve_match_type *mtch = &is_match_type; const struct sieve_match_type *mtch = &is_match_type;
...@@ -202,7 +202,7 @@ static bool tst_address_opcode_execute ...@@ -202,7 +202,7 @@ static bool tst_address_opcode_execute
} }
/* Initialize match context */ /* Initialize match context */
mctx = sieve_match_begin(mtch, cmp, key_list); mctx = sieve_match_begin(mtch, cmp, key_list);
/* Iterate through all requested headers to match */ /* Iterate through all requested headers to match */
hdr_item = NULL; hdr_item = NULL;
...@@ -210,7 +210,7 @@ static bool tst_address_opcode_execute ...@@ -210,7 +210,7 @@ static bool tst_address_opcode_execute
while ( !matched && sieve_coded_stringlist_next_item(hdr_list, &hdr_item) && hdr_item != NULL ) { while ( !matched && sieve_coded_stringlist_next_item(hdr_list, &hdr_item) && hdr_item != NULL ) {
const char *const *headers; const char *const *headers;
if ( mail_get_headers_utf8(mail, str_c(hdr_item), &headers) >= 0 ) { if ( mail_get_headers_utf8(msgdata->mail, str_c(hdr_item), &headers) >= 0 ) {
int i; int i;
for ( i = 0; !matched && headers[i] != NULL; i++ ) { for ( i = 0; !matched && headers[i] != NULL; i++ ) {
...@@ -220,7 +220,7 @@ static bool tst_address_opcode_execute ...@@ -220,7 +220,7 @@ static bool tst_address_opcode_execute
} }
} }
matched = sieve_match_end(mctx) || matched; matched = sieve_match_end(mctx) || matched;
t_pop(); t_pop();
......
...@@ -87,7 +87,7 @@ static bool tst_exists_opcode_dump ...@@ -87,7 +87,7 @@ static bool tst_exists_opcode_dump
static bool tst_exists_opcode_execute static bool tst_exists_opcode_execute
(struct sieve_interpreter *interp, struct sieve_binary *sbin, sieve_size_t *address) (struct sieve_interpreter *interp, struct sieve_binary *sbin, sieve_size_t *address)
{ {
struct mail *mail = sieve_interpreter_get_mail(interp); struct sieve_message_data *msgdata = sieve_interpreter_get_msgdata(interp);
struct sieve_coded_stringlist *hdr_list; struct sieve_coded_stringlist *hdr_list;
string_t *hdr_item; string_t *hdr_item;
bool matched; bool matched;
...@@ -105,10 +105,12 @@ static bool tst_exists_opcode_execute ...@@ -105,10 +105,12 @@ static bool tst_exists_opcode_execute
/* Iterate through all requested headers to match */ /* Iterate through all requested headers to match */
hdr_item = NULL; hdr_item = NULL;
matched = FALSE; matched = FALSE;
while ( !matched && sieve_coded_stringlist_next_item(hdr_list, &hdr_item) && hdr_item != NULL ) { while ( !matched && sieve_coded_stringlist_next_item(hdr_list, &hdr_item) &&
hdr_item != NULL ) {
const char *const *headers; const char *const *headers;
if ( mail_get_headers_utf8(mail, str_c(hdr_item), &headers) >= 0 && headers[0] != NULL ) { if ( mail_get_headers_utf8(msgdata->mail, str_c(hdr_item), &headers) >= 0 &&
headers[0] != NULL ) {
matched = TRUE; matched = TRUE;
} }
} }
......
...@@ -140,7 +140,7 @@ static bool tst_header_opcode_dump ...@@ -140,7 +140,7 @@ static bool tst_header_opcode_dump
static bool tst_header_opcode_execute static bool tst_header_opcode_execute
(struct sieve_interpreter *interp, struct sieve_binary *sbin, sieve_size_t *address) (struct sieve_interpreter *interp, struct sieve_binary *sbin, sieve_size_t *address)
{ {
struct mail *mail = sieve_interpreter_get_mail(interp); struct sieve_message_data *msgdata = sieve_interpreter_get_msgdata(interp);
unsigned int opt_code; unsigned int opt_code;
const struct sieve_comparator *cmp = &i_octet_comparator; const struct sieve_comparator *cmp = &i_octet_comparator;
const struct sieve_match_type *mtch = &is_match_type; const struct sieve_match_type *mtch = &is_match_type;
...@@ -190,7 +190,7 @@ static bool tst_header_opcode_execute ...@@ -190,7 +190,7 @@ static bool tst_header_opcode_execute
while ( !matched && sieve_coded_stringlist_next_item(hdr_list, &hdr_item) && hdr_item != NULL ) { while ( !matched && sieve_coded_stringlist_next_item(hdr_list, &hdr_item) && hdr_item != NULL ) {
const char *const *headers; const char *const *headers;
if ( mail_get_headers_utf8(mail, str_c(hdr_item), &headers) >= 0 ) { if ( mail_get_headers_utf8(msgdata->mail, str_c(hdr_item), &headers) >= 0 ) {
int i; int i;
for ( i = 0; !matched && headers[i] != NULL; i++ ) { for ( i = 0; !matched && headers[i] != NULL; i++ ) {
......
...@@ -195,10 +195,10 @@ static bool tst_size_under_opcode_dump ...@@ -195,10 +195,10 @@ static bool tst_size_under_opcode_dump
static bool tst_size_get(struct sieve_interpreter *interp, sieve_size_t *size) static bool tst_size_get(struct sieve_interpreter *interp, sieve_size_t *size)
{ {
struct mail *mail = sieve_interpreter_get_mail(interp); struct sieve_message_data *msgdata = sieve_interpreter_get_msgdata(interp);
uoff_t psize; uoff_t psize;
if ( mail_get_physical_size(mail, &psize) < 0 ) if ( mail_get_physical_size(msgdata->mail, &psize) < 0 )
return FALSE; return FALSE;
*size = psize; *size = psize;
......
...@@ -117,19 +117,20 @@ static struct istream *create_raw_stream(int fd) ...@@ -117,19 +117,20 @@ static struct istream *create_raw_stream(int fd)
return input; return input;
} }
static void sieve_test(struct sieve_binary *sbin, struct mail *mail) static void sieve_test
(struct sieve_binary *sbin, struct sieve_message_data *msgdata)
{ {
const char *const *headers; const char *const *headers;
printf("HEADERS\n"); printf("HEADERS\n");
if (mail_get_headers_utf8(mail, "from", &headers) >= 0) { if (mail_get_headers_utf8(msgdata->mail, "from", &headers) >= 0) {
int i; int i;
for ( i = 0; headers[i] != NULL; i++ ) { for ( i = 0; headers[i] != NULL; i++ ) {
printf("HEADER: From: %s\n", headers[i]); printf("HEADER: From: %s\n", headers[i]);
} }
} }
sieve_execute(sbin, mail); sieve_execute(sbin, msgdata);
} }
int main(int argc, char **argv) int main(int argc, char **argv)
...@@ -149,6 +150,7 @@ int main(int argc, char **argv) ...@@ -149,6 +150,7 @@ int main(int argc, char **argv)
pool_t namespace_pool; pool_t namespace_pool;
int fd; int fd;
struct sieve_binary *sbin; struct sieve_binary *sbin;
struct sieve_message_data msgdata;
lib_init(); lib_init();
ioloop = io_loop_create(); ioloop = io_loop_create();
...@@ -233,7 +235,11 @@ int main(int argc, char **argv) ...@@ -233,7 +235,11 @@ int main(int argc, char **argv)
/* */ /* */
i_stream_seek(input, 0); i_stream_seek(input, 0);
sieve_test(sbin, mail); msgdata.mail = mail;
msgdata.return_path = "nico@example.com";
msgdata.rcpt_address = "sirius+sieve@rename-it.nl";
msgdata.auth_user = "stephan";
sieve_test(sbin, &msgdata);
sieve_deinit(); sieve_deinit();
//ret = deliver_save(ns, &storage, mailbox, mail, 0, NULL); //ret = deliver_save(ns, &storage, mailbox, mail, 0, NULL);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment

Consent

On this website, we use the web analytics service Matomo to analyze and review the use of our website. Through the collected statistics, we can improve our offerings and make them more appealing for you. Here, you can decide whether to allow us to process your data and set corresponding cookies for these purposes, in addition to technically necessary cookies. Further information on data protection—especially regarding "cookies" and "Matomo"—can be found in our privacy policy. You can withdraw your consent at any time.