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

Added mail-file parameter to the sieve-test and sieve-exec binaries.

parent 77344245
No related branches found
No related tags found
No related merge requests found
...@@ -15,13 +15,14 @@ sievec <sieve-file> ...@@ -15,13 +15,14 @@ sievec <sieve-file>
Compiles the script and produces various dumps of intermittent compilation Compiles the script and produces various dumps of intermittent compilation
results. This already works pretty good for all supported features. results. This already works pretty good for all supported features.
sieve_test <sieve-file> sieve-test <sieve-file> [<mailfile>/-]
Reads mail message from standard input and executes the sieve script to Reads mail message from the specified mailfile (- = stdin) and executes the
produce a verdict. Currently only prints an execution dump with the sieve script to produce a verdict. This prints an execution dump with the
instructions encountered during execution. instructions encountered during execution and finally it prints a list of
actions that would have been performed on this message.
In the directory ./sieve various example scripts are bundled. Various example scripts are bundled in the directory 'sieve'.
Features Features
-------- --------
......
...@@ -241,7 +241,6 @@ bool sieve_interpreter_run ...@@ -241,7 +241,6 @@ bool sieve_interpreter_run
*result = sieve_result_create(); *result = sieve_result_create();
else { else {
sieve_result_ref(*result); sieve_result_ref(*result);
printf("REF\n");
} }
interp->runenv.msgdata = msgdata; interp->runenv.msgdata = msgdata;
interp->runenv.result = *result; interp->runenv.result = *result;
......
...@@ -31,7 +31,7 @@ static int sieve_send_forward ...@@ -31,7 +31,7 @@ static int sieve_send_forward
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
int fd; int sfd, mfd;
struct mail_raw *mailr; struct mail_raw *mailr;
struct sieve_binary *sbin; struct sieve_binary *sbin;
struct sieve_message_data msgdata; struct sieve_message_data msgdata;
...@@ -40,17 +40,34 @@ int main(int argc, char **argv) ...@@ -40,17 +40,34 @@ int main(int argc, char **argv)
bin_init(); bin_init();
if ( argc < 2 ) { if ( argc < 2 ) {
printf( "Usage: sieve_test <filename>\n"); printf( "Usage: sieve-exec <sieve-file> [<mailfile>/-]\n");
exit(1); exit(1);
} }
/* Compile sieve script */ /* Open sieve script */
if ( (fd = open(argv[1], O_RDONLY)) < 0 ) { if ( (sfd = open(argv[1], O_RDONLY)) < 0 ) {
perror("open()"); perror("open()");
exit(1); exit(1);
} }
/* Open mail file */
if ( argc > 2 )
{
if ( *(argv[2]) == '-' && *(argv[2]+1) == '\0' )
mfd = 0;
else {
if ( (mfd = open(argv[2], O_RDONLY)) < 0 ) {
perror("Failed to open mail file");
exit(1);
}
}
} else
mfd = 0;
/* Compile sieve script */
printf("Parsing sieve script '%s'...\n", argv[1]); printf("Parsing sieve script '%s'...\n", argv[1]);
if ( !sieve_init("") ) { if ( !sieve_init("") ) {
...@@ -58,18 +75,18 @@ int main(int argc, char **argv) ...@@ -58,18 +75,18 @@ int main(int argc, char **argv)
exit(1); exit(1);
} }
if ( (sbin = sieve_compile(fd, FALSE)) == NULL ) { if ( (sbin = sieve_compile(sfd, FALSE)) == NULL ) {
printf("Failed to compile sieve script\n"); printf("Failed to compile sieve script\n");
exit(1); exit(1);
} }
(void) sieve_dump(sbin); (void) sieve_dump(sbin);
close(fd); close(sfd);
mail_raw_init(); mail_raw_init();
mailr = mail_raw_open(0); mailr = mail_raw_open(mfd);
/* Collect necessary message data */ /* Collect necessary message data */
memset(&msgdata, 0, sizeof(msgdata)); memset(&msgdata, 0, sizeof(msgdata));
...@@ -89,6 +106,7 @@ int main(int argc, char **argv) ...@@ -89,6 +106,7 @@ int main(int argc, char **argv)
sieve_deinit(); sieve_deinit();
mail_raw_close(mailr); mail_raw_close(mailr);
close(mfd);
mail_raw_deinit(); mail_raw_deinit();
bin_deinit(); bin_deinit();
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
int fd; int sfd, mfd;
struct mail_raw *mailr; struct mail_raw *mailr;
struct sieve_binary *sbin; struct sieve_binary *sbin;
struct sieve_message_data msgdata; struct sieve_message_data msgdata;
...@@ -22,17 +22,33 @@ int main(int argc, char **argv) ...@@ -22,17 +22,33 @@ int main(int argc, char **argv)
bin_init(); bin_init();
if ( argc < 2 ) { if ( argc < 2 ) {
printf( "Usage: sieve_test <filename>\n"); printf( "Usage: sieve-test <sieve-file> [<mailfile>/-]\n");
exit(1); exit(1);
} }
/* Compile sieve script */ /* Open sieve script */
if ( (fd = open(argv[1], O_RDONLY)) < 0 ) { if ( (sfd = open(argv[1], O_RDONLY)) < 0 ) {
perror("open()"); perror("Failed to open sieve script");
exit(1); exit(1);
} }
/* Open mail file */
if ( argc > 2 )
{
if ( *(argv[2]) == '-' && *(argv[2]+1) == '\0' )
mfd = 0;
else {
if ( (mfd = open(argv[2], O_RDONLY)) < 0 ) {
perror("Failed to open mail file");
exit(1);
}
}
} else
mfd = 0;
/* Compile sieve script */
printf("Parsing sieve script '%s'...\n", argv[1]); printf("Parsing sieve script '%s'...\n", argv[1]);
if ( !sieve_init("") ) { if ( !sieve_init("") ) {
...@@ -40,18 +56,18 @@ int main(int argc, char **argv) ...@@ -40,18 +56,18 @@ int main(int argc, char **argv)
exit(1); exit(1);
} }
if ( (sbin = sieve_compile(fd, TRUE)) == NULL ) { if ( (sbin = sieve_compile(sfd, TRUE)) == NULL ) {
printf("Failed to compile sieve script\n"); printf("Failed to compile sieve script\n");
exit(1); exit(1);
} }
(void) sieve_dump(sbin); (void) sieve_dump(sbin);
close(fd); close(sfd);
mail_raw_init(); mail_raw_init();
mailr = mail_raw_open(0); mailr = mail_raw_open(mfd);
/* Collect necessary message data */ /* Collect necessary message data */
memset(&msgdata, 0, sizeof(msgdata)); memset(&msgdata, 0, sizeof(msgdata));
...@@ -67,6 +83,8 @@ int main(int argc, char **argv) ...@@ -67,6 +83,8 @@ int main(int argc, char **argv)
sieve_deinit(); sieve_deinit();
mail_raw_close(mailr); mail_raw_close(mailr);
if ( mfd > 0 )
close(mfd);
mail_raw_deinit(); mail_raw_deinit();
bin_deinit(); bin_deinit();
......
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.