struct sieve_extprograms_config *sieve_extprograms_config_init (const struct sieve_extension *ext) { struct sieve_instance *svinst = ext->svinst; struct sieve_extprograms_config *ext_config; const char *extname = sieve_extension_name(ext); const char *bin_dir, *socket_dir, *input_eol; sieve_number_t execute_timeout; extname = strrchr(extname, '.'); i_assert(extname != NULL); extname++; bin_dir = sieve_setting_get (svinst, t_strdup_printf("sieve_%s_bin_dir", extname)); socket_dir = sieve_setting_get (svinst, t_strdup_printf("sieve_%s_socket_dir", extname)); input_eol = sieve_setting_get (svinst, t_strdup_printf("sieve_%s_input_eol", extname)); ext_config = i_new(struct sieve_extprograms_config, 1); ext_config->execute_timeout = SIEVE_EXTPROGRAMS_DEFAULT_EXEC_TIMEOUT_SECS; if ( bin_dir == NULL && socket_dir == NULL ) { if ( svinst->debug ) { sieve_sys_debug(svinst, "%s extension: " "no bin or socket directory specified; extension is unconfigured " "(both sieve_%s_bin_dir and sieve_%s_socket_dir are not set)", sieve_extension_name(ext), extname, extname); } } else { ext_config->bin_dir = i_strdup(bin_dir); ext_config->socket_dir = i_strdup(socket_dir); if (sieve_setting_get_duration_value (svinst, t_strdup_printf("sieve_%s_exec_timeout", extname), &execute_timeout)) { ext_config->execute_timeout = execute_timeout; } ext_config->default_input_eol = SIEVE_EXTPROGRAMS_EOL_CRLF; if (input_eol != NULL && strcasecmp(input_eol, "lf") == 0) ext_config->default_input_eol = SIEVE_EXTPROGRAMS_EOL_LF; } if ( sieve_extension_is(ext, vnd_pipe_extension) ) ext_config->copy_ext = sieve_ext_copy_get_extension(ext->svinst); if ( sieve_extension_is(ext, vnd_execute_extension) ) ext_config->var_ext = sieve_ext_variables_get_extension(ext->svinst); return ext_config; }
static bool ext_extracttext_load (const struct sieve_extension *ext, void **context) { struct sieve_instance *svinst = ext->svinst; struct ext_extracttext_context *ectx; if ( *context != NULL ) ext_extracttext_unload(ext); ectx = i_new(struct ext_extracttext_context, 1); ectx->var_ext = sieve_ext_variables_get_extension(ext->svinst); ectx->fep_ext = sieve_extension_register (svinst, &foreverypart_extension, FALSE); *context = (void *)ectx; return TRUE; }
static bool ext_enotify_load(const struct sieve_extension *ext, void **context) { struct ext_enotify_context *ectx; if ( *context != NULL ) { ext_enotify_unload(ext); } ectx = i_new(struct ext_enotify_context, 1); ectx->var_ext = sieve_ext_variables_get_extension(ext->svinst); *context = (void *) ectx; ext_enotify_methods_init(ext->svinst, ectx); sieve_extension_capabilities_register(ext, ¬ify_capabilities); return TRUE; }
bool ext_imap4flags_command_validate (struct sieve_validator *valdtr, struct sieve_command *cmd) { struct sieve_ast_argument *arg = cmd->first_positional; struct sieve_ast_argument *arg2; const struct sieve_extension *var_ext; /* Check arguments */ if ( arg == NULL ) { sieve_command_validate_error(valdtr, cmd, "the %s %s expects at least one argument, but none was found", sieve_command_identifier(cmd), sieve_command_type_name(cmd)); return FALSE; } if ( sieve_ast_argument_type(arg) != SAAT_STRING && sieve_ast_argument_type(arg) != SAAT_STRING_LIST ) { sieve_argument_validate_error(valdtr, arg, "the %s %s expects either a string (variable name) or " "a string-list (list of flags) as first argument, but %s was found", sieve_command_identifier(cmd), sieve_command_type_name(cmd), sieve_ast_argument_name(arg)); return FALSE; } arg2 = sieve_ast_argument_next(arg); if ( arg2 != NULL ) { /* First, check syntax sanity */ if ( sieve_ast_argument_type(arg) != SAAT_STRING ) { if ( sieve_command_is(cmd, tst_hasflag) ) { if ( sieve_ast_argument_type(arg) != SAAT_STRING_LIST ) { sieve_argument_validate_error(valdtr, arg, "if a second argument is specified for the hasflag, the first " "must be a string-list (variable-list), but %s was found", sieve_ast_argument_name(arg)); return FALSE; } } else { sieve_argument_validate_error(valdtr, arg, "if a second argument is specified for the %s %s, the first " "must be a string (variable name), but %s was found", sieve_command_identifier(cmd), sieve_command_type_name(cmd), sieve_ast_argument_name(arg)); return FALSE; } } /* Then, check whether the second argument is permitted */ var_ext = sieve_ext_variables_get_extension(cmd->ext->svinst); if ( var_ext == NULL || !sieve_ext_variables_is_active(var_ext, valdtr) ) { sieve_argument_validate_error(valdtr,arg, "the %s %s only allows for the specification of a " "variable name when the variables extension is active", sieve_command_identifier(cmd), sieve_command_type_name(cmd)); return FALSE; } if ( !sieve_variable_argument_activate (var_ext, valdtr, cmd, arg, !sieve_command_is(cmd, tst_hasflag) ) ) return FALSE; if ( sieve_ast_argument_type(arg2) != SAAT_STRING && sieve_ast_argument_type(arg2) != SAAT_STRING_LIST ) { sieve_argument_validate_error(valdtr, arg2, "the %s %s expects a string list (list of flags) as " "second argument when two arguments are specified, " "but %s was found", sieve_command_identifier(cmd), sieve_command_type_name(cmd), sieve_ast_argument_name(arg2)); return FALSE; } } else arg2 = arg; if ( !sieve_validator_argument_activate(valdtr, cmd, arg2, FALSE) ) return FALSE; if ( !sieve_command_is(cmd, tst_hasflag) && sieve_argument_is_string_literal(arg2) ) { struct ext_imap4flags_iter fiter; const char *flag; /* Warn the user about validity of verifiable flags */ ext_imap4flags_iter_init(&fiter, sieve_ast_argument_str(arg)); while ( (flag=ext_imap4flags_iter_get_flag(&fiter)) != NULL ) { if ( !sieve_ext_imap4flags_flag_is_valid(flag) ) { sieve_argument_validate_warning(valdtr, arg, "IMAP flag '%s' specified for the %s command is invalid " "and will be ignored (only first invalid is reported)", str_sanitize(flag, 64), sieve_command_identifier(cmd)); break; } } } return TRUE; }