static int
cmd_sieve_activate_run(struct doveadm_sieve_cmd_context *_ctx)
{
	struct doveadm_sieve_activate_cmd_context *ctx =
		(struct doveadm_sieve_activate_cmd_context *)_ctx;
	struct sieve_storage *storage = _ctx->storage;
	struct sieve_script *script;
	enum sieve_error error;
	int ret = 0;

	script = sieve_storage_open_script
		(storage, ctx->scriptname, NULL);
	if ( script == NULL ) {
		i_error("Failed to activate Sieve script: %s",
			sieve_storage_get_last_error(storage, &error));
		doveadm_sieve_cmd_failed_error(_ctx, error);
		return -1;
	}

	if ( sieve_script_is_active(script) <= 0 ) {
		/* Script is first being activated; compile it again without the UPLOAD
		 * flag.
		 */
		struct sieve_error_handler *ehandler;
		enum sieve_compile_flags cpflags =
			SIEVE_COMPILE_FLAG_NOGLOBAL | SIEVE_COMPILE_FLAG_ACTIVATED;
		struct sieve_binary *sbin;
		enum sieve_error error;

		/* Compile */
		ehandler = sieve_master_ehandler_create(ctx->ctx.svinst, NULL, 0);
		if ( (sbin=sieve_compile_script
			(script, ehandler, cpflags, &error)) == NULL ) {
			doveadm_sieve_cmd_failed_error(_ctx, error);
			ret = -1;
		} else {
			sieve_close(&sbin);
		}
		sieve_error_handler_unref(&ehandler);
	}

	/* Activate only when script is valid (or already active) */
	if ( ret == 0 ) {
		/* Refresh activation no matter what; this can also resolve some erroneous
		 * situations.
		 */
		ret = sieve_script_activate(script, (time_t)-1);
		if ( ret < 0 ) {
			i_error("Failed to activate Sieve script: %s",
				sieve_storage_get_last_error(storage, &error));
			doveadm_sieve_cmd_failed_error(_ctx, error);
			ret = -1;
		}
	}

	sieve_script_unref(&script);
	return ret;
}
Пример #2
0
struct imap_sieve *imap_sieve_init(struct mail_user *user,
                                   const struct lda_settings *lda_set)
{
    struct sieve_environment svenv;
    struct imap_sieve *isieve;
    bool debug = user->mail_debug;
    pool_t pool;

    pool = pool_alloconly_create("imap_sieve", 256);
    isieve = p_new(pool, struct imap_sieve, 1);
    isieve->pool = pool;
    isieve->user = user;
    isieve->lda_set = lda_set;

    isieve->dup_ctx = duplicate_init(user);

    memset(&svenv, 0, sizeof(svenv));
    svenv.username = user->username;
    (void)mail_user_get_home(user, &svenv.home_dir);
    svenv.hostname = lda_set->hostname;
    svenv.base_dir = user->set->base_dir;
    svenv.flags = SIEVE_FLAG_HOME_RELATIVE;
    svenv.location = SIEVE_ENV_LOCATION_MS;
    svenv.delivery_phase = SIEVE_DELIVERY_PHASE_POST;

    isieve->home_dir = p_strdup(pool, svenv.home_dir);

    isieve->svinst = sieve_init
                     (&svenv, &mail_sieve_callbacks, isieve, debug);

    isieve->ext_imapsieve = sieve_extension_replace
                            (isieve->svinst, &imapsieve_extension, TRUE);

    isieve->master_ehandler = sieve_master_ehandler_create
                              (isieve->svinst, NULL, 0); // FIXME: prefix?
    sieve_system_ehandler_set(isieve->master_ehandler);
    sieve_error_handler_accept_infolog(isieve->master_ehandler, TRUE);
    sieve_error_handler_accept_debuglog(isieve->master_ehandler, debug);

    return isieve;
}
Пример #3
0
void sieve_errors_init(struct sieve_instance *svinst)
{
	svinst->system_ehandler = sieve_master_ehandler_create(svinst, NULL, 0);
}