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

testsuite: added test_message_print command to print the current message content.

parent 5831629a
No related branches found
No related tags found
No related merge requests found
/* Copyright (c) 2002-2011 Pigeonhole authors, see the included COPYING file
*/
#include "lib.h"
#include "istream.h"
#include "sieve-common.h"
#include "sieve-commands.h"
#include "sieve-message.h"
#include "sieve-validator.h"
#include "sieve-generator.h"
#include "sieve-interpreter.h"
......@@ -15,7 +19,10 @@
#include "testsuite-mailstore.h"
/*
* Test_message command
* Commands
*/
/* Test_message command
*
* Syntax:
* test_message ( :smtp / :mailbox <mailbox: string> ) <index: number>
......@@ -41,6 +48,25 @@ const struct sieve_command_def cmd_test_message = {
NULL
};
/* Test_message_print command
*
* Syntax:
* test_message_print
*/
static bool cmd_test_message_print_generate
(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd);
const struct sieve_command_def cmd_test_message_print = {
"test_message_print",
SCT_COMMAND,
0, 0, FALSE, FALSE,
NULL, NULL, NULL, NULL,
cmd_test_message_print_generate
, NULL
};
/*
* Operations
*/
......@@ -75,6 +101,21 @@ const struct sieve_operation_def test_message_mailbox_operation = {
cmd_test_message_mailbox_operation_execute
};
/* Test_message_print operation */
static bool cmd_test_message_print_operation_dump
(const struct sieve_dumptime_env *denv, sieve_size_t *address);
static int cmd_test_message_print_operation_execute
(const struct sieve_runtime_env *renv, sieve_size_t *address);
const struct sieve_operation_def test_message_print_operation = {
"TEST_MESSAGE_PRINT",
&testsuite_extension,
TESTSUITE_OPERATION_TEST_MESSAGE_PRINT,
cmd_test_message_print_operation_dump,
cmd_test_message_print_operation_execute
};
/*
* Compiler context data
*/
......@@ -254,6 +295,15 @@ static bool cmd_test_message_generate
return TRUE;
}
static bool cmd_test_message_print_generate
(const struct sieve_codegen_env *cgenv, struct sieve_command *cmd)
{
/* Emit operation */
sieve_operation_emit
(cgenv->sblock, cmd->ext, &test_message_print_operation);
return TRUE;
}
/*
* Code dump
*/
......@@ -292,6 +342,15 @@ static bool cmd_test_message_mailbox_operation_dump
sieve_opr_number_dump(denv, address, "index");
}
static bool cmd_test_message_print_operation_dump
(const struct sieve_dumptime_env *denv, sieve_size_t *address ATTR_UNUSED)
{
sieve_code_dumpf(denv, "TEST_MESSAGE_PRINT");
return TRUE;
}
/*
* Intepretation
*/
......@@ -420,6 +479,34 @@ static int cmd_test_message_mailbox_operation_execute
return SIEVE_EXEC_OK;
}
static int cmd_test_message_print_operation_execute
(const struct sieve_runtime_env *renv, sieve_size_t *address ATTR_UNUSED)
{
struct mail *mail = sieve_message_get_mail(renv->msgctx);
struct istream *input;
const unsigned char *data;
size_t size;
int ret;
if (mail_get_stream(mail, NULL, NULL, &input) < 0) {
sieve_runtime_error(renv, NULL,
"test_message_print: failed to read current message");
return SIEVE_EXEC_OK;
}
printf("\n--MESSAGE: \n");
/* Pipe the message to the outgoing SMTP transport */
while ((ret=i_stream_read_data(input, &data, &size, 0)) > 0) {
write(1, data, size);
i_stream_skip(input, size);
}
printf("\n--MESSAGE--\n");
return SIEVE_EXEC_OK;
}
......
......@@ -69,6 +69,7 @@ const struct sieve_operation_def *testsuite_operations[] = {
&test_result_print_operation,
&test_message_smtp_operation,
&test_message_mailbox_operation,
&test_message_print_operation,
&test_mailbox_create_operation,
&test_mailbox_delete_operation,
&test_binary_load_operation,
......@@ -125,6 +126,7 @@ static bool ext_testsuite_validator_load
sieve_validator_register_command(valdtr, ext, &cmd_test_result_print);
sieve_validator_register_command(valdtr, ext, &cmd_test_result_reset);
sieve_validator_register_command(valdtr, ext, &cmd_test_message);
sieve_validator_register_command(valdtr, ext, &cmd_test_message_print);
sieve_validator_register_command(valdtr, ext, &cmd_test_mailbox_create);
sieve_validator_register_command(valdtr, ext, &cmd_test_mailbox_delete);
sieve_validator_register_command(valdtr, ext, &cmd_test_binary_load);
......
......@@ -57,6 +57,7 @@ extern const struct sieve_command_def cmd_test_set;
extern const struct sieve_command_def cmd_test_result_reset;
extern const struct sieve_command_def cmd_test_result_print;
extern const struct sieve_command_def cmd_test_message;
extern const struct sieve_command_def cmd_test_message_print;
extern const struct sieve_command_def cmd_test_mailbox;
extern const struct sieve_command_def cmd_test_mailbox_create;
extern const struct sieve_command_def cmd_test_mailbox_delete;
......@@ -96,6 +97,7 @@ enum testsuite_operation_code {
TESTSUITE_OPERATION_TEST_RESULT_PRINT,
TESTSUITE_OPERATION_TEST_MESSAGE_SMTP,
TESTSUITE_OPERATION_TEST_MESSAGE_MAILBOX,
TESTSUITE_OPERATION_TEST_MESSAGE_PRINT,
TESTSUITE_OPERATION_TEST_MAILBOX_CREATE,
TESTSUITE_OPERATION_TEST_MAILBOX_DELETE,
TESTSUITE_OPERATION_TEST_BINARY_LOAD,
......@@ -119,6 +121,7 @@ extern const struct sieve_operation_def test_result_reset_operation;
extern const struct sieve_operation_def test_result_print_operation;
extern const struct sieve_operation_def test_message_smtp_operation;
extern const struct sieve_operation_def test_message_mailbox_operation;
extern const struct sieve_operation_def test_message_print_operation;
extern const struct sieve_operation_def test_mailbox_create_operation;
extern const struct sieve_operation_def test_mailbox_delete_operation;
extern const struct sieve_operation_def test_binary_load_operation;
......
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.