Ejemplo n.º 1
0
static int cmd_test_config_unset_operation_execute
(const struct sieve_runtime_env *renv, sieve_size_t *address)
{
    string_t *setting;
    int ret;

    /*
     * Read operands
     */

    /* Setting */
    if ( (ret=sieve_opr_string_read(renv, address, "setting", &setting)) <= 0 )
        return ret;

    /*
     * Perform operation
     */

    if ( sieve_runtime_trace_active(renv, SIEVE_TRLVL_COMMANDS) ) {
        sieve_runtime_trace(renv, 0,
                            "testsuite: test_config_unset command");
        sieve_runtime_trace_descend(renv);
        sieve_runtime_trace(renv, 0, "unset config `%s'", str_c(setting));
    }

    testsuite_setting_unset(str_c(setting));

    return SIEVE_EXEC_OK;
}
Ejemplo n.º 2
0
static int cmd_test_set_operation_execute
(const struct sieve_runtime_env *renv, sieve_size_t *address)
{
	struct testsuite_object tobj;
	string_t *value;
	int member_id;
	int ret;

	if ( !testsuite_object_read_member
		(renv->sblock, address, &tobj, &member_id) ) {
		sieve_runtime_trace_error(renv, "invalid testsuite object member");
		return SIEVE_EXEC_BIN_CORRUPT;
	}

	if ( (ret=sieve_opr_string_read(renv, address, "string", &value)) <= 0 )
		return ret;

	if ( sieve_runtime_trace_active(renv, SIEVE_TRLVL_COMMANDS) ) {
		sieve_runtime_trace(renv, 0, "testsuite: test_set command");
		sieve_runtime_trace_descend(renv);
		sieve_runtime_trace(renv, 0,
			"set test parameter '%s' = \"%s\"",
				testsuite_object_member_name(&tobj, member_id), str_c(value));
	}

	if ( tobj.def == NULL || tobj.def->set_member == NULL ) {
		sieve_runtime_trace_error(renv, "unimplemented testsuite object");
		return SIEVE_EXEC_FAILURE;
	}

	tobj.def->set_member(renv, member_id, value);
	return SIEVE_EXEC_OK;
}
Ejemplo n.º 3
0
static int ext_fileinto_operation_execute
(const struct sieve_runtime_env *renv, sieve_size_t *address)
{
	struct sieve_side_effects_list *slist = NULL;
	string_t *folder;
	bool folder_literal;
	bool trace = sieve_runtime_trace_active(renv, SIEVE_TRLVL_ACTIONS);
	int ret = 0;

	/*
	 * Read operands
	 */

	/* Optional operands (side effects only) */
	if ( sieve_action_opr_optional_read(renv, address, NULL, &ret, &slist) != 0 )
		return ret;

	/* Folder operand */
	if ( (ret=sieve_opr_string_read_ex
		(renv, address, "folder", FALSE, &folder, &folder_literal)) <= 0 )
		return ret;

	/*
	 * Perform operation
	 */

	if ( trace ) {
		sieve_runtime_trace(renv, 0, "fileinto action");
		sieve_runtime_trace_descend(renv);
	}

	if ( !folder_literal && !uni_utf8_str_is_valid(str_c(folder)) ) {
		sieve_runtime_error(renv, NULL,
			"folder name specified for fileinto command is not utf-8: %s",
			str_c(folder));
		return SIEVE_EXEC_FAILURE;
	}


	if ( trace ) {
		sieve_runtime_trace(renv, 0, "store message in mailbox `%s'",
			str_sanitize(str_c(folder), 80));
	}

	/* Add action to result */
	if ( sieve_act_store_add_to_result
		(renv, slist, str_c(folder)) < 0 )
		return SIEVE_EXEC_FAILURE;

	sieve_message_snapshot(renv->msgctx);

	return SIEVE_EXEC_OK;
}
Ejemplo n.º 4
0
static int mcht_count_match
(struct sieve_match_context *mctx, struct sieve_stringlist *value_list,
	struct sieve_stringlist *key_list)
{
	const struct sieve_runtime_env *renv = mctx->runenv;
	bool trace = sieve_runtime_trace_active(renv, SIEVE_TRLVL_MATCHING);
	int count;
	string_t *key_item;
	int match, ret;

	if ( (count=sieve_stringlist_get_length(value_list)) < 0 ) {
		mctx->exec_status = value_list->exec_status;
		return -1;
	}

	sieve_stringlist_reset(key_list);

	string_t *value = t_str_new(20);
	str_printfa(value, "%d", count);

	if ( trace ) {
		sieve_runtime_trace(renv, 0,
			"matching count value `%s'", str_sanitize(str_c(value), 80));
	}

	sieve_runtime_trace_descend(renv);

  /* Match to all key values */
  key_item = NULL;
	match = 0;
  while ( match == 0 &&
		(ret=sieve_stringlist_next_item(key_list, &key_item)) > 0 )
  {
		match = mcht_value_match_key
			(mctx, str_c(value), str_len(value), str_c(key_item), str_len(key_item));

		if ( trace ) {
			sieve_runtime_trace(renv, 0,
				"with key `%s' => %d", str_sanitize(str_c(key_item), 80), ret);
		}
	}

	sieve_runtime_trace_ascend(renv);

	if ( ret < 0 ) {
		mctx->exec_status = key_list->exec_status;
		match = -1;
	}

	return match;
}
Ejemplo n.º 5
0
struct sieve_match_context *sieve_match_begin
(const struct sieve_runtime_env *renv,
	const struct sieve_match_type *mcht,
	const struct sieve_comparator *cmp)
{
	struct sieve_match_context *mctx;
	pool_t pool;

	/* Reject unimplemented match-type */
	if ( mcht->def == NULL || (mcht->def->match == NULL &&
			mcht->def->match_keys == NULL && mcht->def->match_key == NULL) )
			return NULL;

	/* Create match context */
	pool = pool_alloconly_create("sieve_match_context", 1024);
	mctx = p_new(pool, struct sieve_match_context, 1);
	mctx->pool = pool;
	mctx->runenv = renv;
	mctx->match_type = mcht;
	mctx->comparator = cmp;
	mctx->exec_status = SIEVE_EXEC_OK;
	mctx->trace = sieve_runtime_trace_active(renv, SIEVE_TRLVL_MATCHING);

	/* Trace */
	if ( mctx->trace ) {
		sieve_runtime_trace_descend(renv);
		sieve_runtime_trace(renv, 0,
			"starting `:%s' match with `%s' comparator:",
			sieve_match_type_name(mcht), sieve_comparator_name(cmp));
	}

	/* Initialize match type */
	if ( mcht->def != NULL && mcht->def->match_init != NULL ) {
		mcht->def->match_init(mctx);
	}

	return mctx;
}
static int cmd_test_imap_metadata_operation_execute
(const struct sieve_runtime_env *renv, sieve_size_t *address)
{
	const struct sieve_operation *oprtn = renv->oprtn;
	int opt_code = 0;
	string_t *mailbox = NULL, *annotation = NULL, *value = NULL;
	int ret;

	/*
	 * Read operands
	 */

	/* Optional operands */

	for (;;) {
		int opt;

		if ( (opt=sieve_opr_optional_read(renv, address, &opt_code)) < 0 )
			return SIEVE_EXEC_BIN_CORRUPT;

		if ( opt == 0 ) break;

		switch ( opt_code ) {
		case OPT_MAILBOX:
			ret = sieve_opr_string_read(renv, address, "mailbox", &mailbox);
			break;
		default:
			sieve_runtime_trace_error(renv, "unknown optional operand");
			ret = SIEVE_EXEC_BIN_CORRUPT;
		}

		if ( ret <= 0 ) return ret;
	}

	/* Fixed operands */

	if ( (ret=sieve_opr_string_read
		(renv, address, "annotation", &annotation)) <= 0 )
		return ret;
	if ( (ret=sieve_opr_string_read
		(renv, address, "value", &value)) <= 0 )
		return ret;

	/*
	 * Perform operation
	 */

	if ( sieve_operation_is(oprtn, test_imap_metadata_set_operation) ) {
		if ( sieve_runtime_trace_active(renv, SIEVE_TRLVL_COMMANDS) ) {
			sieve_runtime_trace(renv, 0, "testsuite/test_imap_metadata_set command");
			sieve_runtime_trace_descend(renv);
			if (mailbox == NULL) {
				sieve_runtime_trace(renv, 0,
					"set server annotation `%s'", str_c(annotation));
			} else {
				sieve_runtime_trace(renv, 0,
					"set annotation `%s' for mailbox `%s'",
					str_c(annotation), str_c(mailbox));
			}
		}

		if (testsuite_mailstore_set_imap_metadata
			(( mailbox == NULL ? NULL : str_c(mailbox) ),
				str_c(annotation), str_c(value)) < 0)
			return SIEVE_EXEC_FAILURE;
	}

	return SIEVE_EXEC_OK;
}
Ejemplo n.º 7
0
static int cmd_test_binary_operation_execute
(const struct sieve_runtime_env *renv, sieve_size_t *address)
{
	const struct sieve_operation *oprtn = renv->oprtn;
	string_t *binary_name = NULL;
	int ret;

	/* 
	 * Read operands 
	 */

	/* Binary Name */

	if ( (ret=sieve_opr_string_read(renv, address, "binary-name", &binary_name))
		<= 0 )
		return ret;

	/*
	 * Perform operation
	 */

	if ( sieve_operation_is(oprtn, test_binary_load_operation) ) {
		struct sieve_binary *sbin = testsuite_binary_load(str_c(binary_name));

		if ( sieve_runtime_trace_active(renv, SIEVE_TRLVL_COMMANDS) ) {
			sieve_runtime_trace(renv, 0, "testsuite: test_binary_load command");
			sieve_runtime_trace_descend(renv);
			sieve_runtime_trace(renv, 0, "load binary `%s'", str_c(binary_name));
		}

		if ( sbin != NULL ) {
			testsuite_script_set_binary(sbin);

			sieve_binary_unref(&sbin);
		} else {
			sieve_sys_error(testsuite_sieve_instance,
				"failed to load binary %s", str_c(binary_name));
			return SIEVE_EXEC_FAILURE;
		}

	} else if ( sieve_operation_is(oprtn, test_binary_save_operation) ) {
		struct sieve_binary *sbin = testsuite_script_get_binary();

		if ( sieve_runtime_trace_active(renv, SIEVE_TRLVL_COMMANDS) ) {
			sieve_runtime_trace(renv, 0, "testsuite: test_binary_save command");
			sieve_runtime_trace_descend(renv);
			sieve_runtime_trace(renv, 0, "save binary `%s'", str_c(binary_name));
		}

		if ( sbin != NULL ) 
			testsuite_binary_save(sbin, str_c(binary_name));
		else {
			sieve_sys_error(testsuite_sieve_instance,
				"no compiled binary to save as %s", str_c(binary_name));
			return SIEVE_EXEC_FAILURE;
		}
	} else {
		i_unreached();
	}

	return SIEVE_EXEC_OK;
}
static int tst_mailboxexists_operation_execute
(const struct sieve_runtime_env *renv, sieve_size_t *address)
{
	struct sieve_stringlist *mailbox_names;
	string_t *mailbox_item;
	bool trace = FALSE;
	bool all_exist = TRUE;
	int ret;

	/*
	 * Read operands
	 */

	/* Read notify uris */
	if ( (ret=sieve_opr_stringlist_read
		(renv, address, "mailbox-names", &mailbox_names)) <= 0 )
		return ret;

	/*
	 * Perform operation
	 */

	if ( sieve_runtime_trace_active(renv, SIEVE_TRLVL_TESTS) ) {
		sieve_runtime_trace(renv, 0, "mailboxexists test");
		sieve_runtime_trace_descend(renv);

		trace = sieve_runtime_trace_active(renv, SIEVE_TRLVL_MATCHING);
	}

	if ( renv->scriptenv->user != NULL ) {
		int ret;

		mailbox_item = NULL;
		while ( (ret=sieve_stringlist_next_item(mailbox_names, &mailbox_item)) > 0 )
			{
			struct mail_namespace *ns;
			const char *mailbox = str_c(mailbox_item);
			struct mailbox *box;

			/* Find the namespace */
			ns = mail_namespace_find(renv->scriptenv->user->namespaces, mailbox);
			if ( ns == NULL) {
				if ( trace ) {
					sieve_runtime_trace(renv, 0, "mailbox `%s' not found",
						str_sanitize(mailbox, 80));
				}

				all_exist = FALSE;
				break;
			}

			/* Open the box */
			box = mailbox_alloc(ns->list, mailbox, 0);
			if ( mailbox_open(box) < 0 ) {
				if ( trace ) {
					sieve_runtime_trace(renv, 0, "mailbox `%s' cannot be opened",
						str_sanitize(mailbox, 80));
				}

				all_exist = FALSE;
				mailbox_free(&box);
				break;
			}

			/* Also fail when it is readonly */
			if ( mailbox_is_readonly(box) ) {
				if ( trace ) {
					sieve_runtime_trace(renv, 0, "mailbox `%s' is read-only",
						str_sanitize(mailbox, 80));
				}

				all_exist = FALSE;
				mailbox_free(&box);
				break;
			}

			/* FIXME: check acl for 'p' or 'i' ACL permissions as required by RFC */

			if ( trace ) {
				sieve_runtime_trace(renv, 0, "mailbox `%s' exists",
					str_sanitize(mailbox, 80));
			}

			/* Close mailbox */
			mailbox_free(&box);
		}

		if ( ret < 0 ) {
			sieve_runtime_trace_error(renv, "invalid mailbox name item");
			return SIEVE_EXEC_BIN_CORRUPT;
		}
	}

	if ( trace ) {
		if ( all_exist )
			sieve_runtime_trace(renv, 0, "all mailboxes are available");
		else
			sieve_runtime_trace(renv, 0, "some mailboxes are unavailable");
	}

	sieve_interpreter_set_test_result(renv->interp, all_exist);
	return SIEVE_EXEC_OK;
}
Ejemplo n.º 9
0
static int cmd_test_config_reload_operation_execute
(const struct sieve_runtime_env *renv, sieve_size_t *address)
{
    const struct sieve_extension *ext;
    int opt_code = 0;
    string_t *extension = NULL;
    int ret;

    /*
     * Read operands
     */

    /* Optional operands */
    for (;;) {
        int opt;

        if ( (opt=sieve_opr_optional_read(renv, address, &opt_code)) < 0 )
            return SIEVE_EXEC_BIN_CORRUPT;

        if ( opt == 0 ) break;

        switch ( opt_code ) {
        case OPT_EXTENSION:
            ret = sieve_opr_string_read(renv, address, "extension", &extension);
            break;
        default:
            sieve_runtime_trace_error(renv, "unknown optional operand");
            ret = SIEVE_EXEC_BIN_CORRUPT;
        }

        if ( ret <= 0 ) return ret;
    }

    /*
     * Perform operation
     */

    if ( sieve_runtime_trace_active(renv, SIEVE_TRLVL_COMMANDS) ) {
        sieve_runtime_trace(renv, 0,
                            "testsuite: test_config_reload command");
        sieve_runtime_trace_descend(renv);
    }

    if ( extension == NULL ) {
        if ( sieve_runtime_trace_active(renv, SIEVE_TRLVL_COMMANDS) ) {
            sieve_runtime_trace(renv, 0,
                                "reload configuration for sieve engine");
        }

        sieve_settings_load(renv->svinst);

    } else {
        if ( sieve_runtime_trace_active(renv, SIEVE_TRLVL_COMMANDS) ) {
            sieve_runtime_trace(renv, 0,
                                "reload configuration for extension `%s'",
                                str_c(extension));
        }

        ext = sieve_extension_get_by_name(renv->svinst, str_c(extension));
        if ( ext == NULL ) {
            testsuite_test_failf("test_config_reload: "
                                 "unknown extension '%s'", str_c(extension));
            return SIEVE_EXEC_OK;
        }

        sieve_extension_reload(ext);
    }

    return SIEVE_EXEC_OK;
}
Ejemplo n.º 10
0
static int cmd_report_operation_execute
(const struct sieve_runtime_env *renv, sieve_size_t *address)
{
	struct act_report_data *act;
	string_t *fbtype, *message, *to_address;
	const char *norm_address, *feedback_type, *error;
	int opt_code = 0, ret = 0;
	bool headers_only = FALSE;
	pool_t pool;

	/*
	 * Read operands
	 */

	/* Optional operands */

	for (;;) {
		int opt;

		if ( (opt=sieve_opr_optional_read(renv, address, &opt_code)) < 0 )
			return SIEVE_EXEC_BIN_CORRUPT;

		if ( opt == 0 ) break;

		switch ( opt_code ) {
		case OPT_HEADERS_ONLY:
			headers_only = TRUE;
			break;
		default:
			sieve_runtime_trace_error(renv, "unknown optional operand");
			return SIEVE_EXEC_BIN_CORRUPT;
		}
	}

	/* Fixed operands */

	if ( (ret=sieve_opr_string_read
		(renv, address, "feedback-type", &fbtype)) <= 0 )
		return ret;

	if ( (ret=sieve_opr_string_read
		(renv, address, "message", &message)) <= 0 )
		return ret;

	if ( (ret=sieve_opr_string_read
		(renv, address, "address", &to_address)) <= 0 )
		return ret;

	/*
	 * Perform operation
	 */

	/* Verify and trim feedback type */
	feedback_type = ext_vnd_report_parse_feedback_type(str_c(fbtype));
	if ( feedback_type == NULL ) {
		sieve_runtime_error(renv, NULL,
			"specified report feedback type `%s' is invalid",
			str_sanitize(str_c(fbtype), 256));
		return SIEVE_EXEC_FAILURE;
	}

	/* Verify and normalize the address to 'local_part@domain' */
	norm_address = sieve_address_normalize(to_address, &error);
	if ( norm_address == NULL ) {
		sieve_runtime_error(renv, NULL,
			"specified report address `%s' is invalid: %s",
			str_sanitize(str_c(to_address), 256), error);
		return SIEVE_EXEC_FAILURE;
	}

	/* Trace */
	if ( sieve_runtime_trace_active(renv, SIEVE_TRLVL_ACTIONS) ) {
		sieve_runtime_trace(renv, 0, "report action");
		sieve_runtime_trace_descend(renv);
		sieve_runtime_trace(renv, 0,
			"report incoming message as `%s' to address `%s'",
			str_sanitize(str_c(fbtype), 32),
			str_sanitize(norm_address, 80));
	}

	/* Add report action to the result */

	pool = sieve_result_pool(renv->result);
	act = p_new(pool, struct act_report_data, 1);
	act->headers_only = headers_only;
	act->feedback_type = p_strdup(pool, feedback_type);
	act->message = p_strdup(pool, str_c(message));
	act->to_address = p_strdup(pool, norm_address);

	if ( sieve_result_add_action(renv,
		NULL, &act_report, NULL, (void *) act, 0, TRUE) < 0 )
		return SIEVE_EXEC_FAILURE;

	return SIEVE_EXEC_OK;
}