Struct vsmtp_rule_engine::RuleEngine
pub struct RuleEngine { /* private fields */ }Expand description
a sharable rhai engine. contains an ast representation of the user’s parsed .vsl script files, and modules / packages to create a cheap rhai runtime.
Implementations§
§impl RuleEngine
impl RuleEngine
pub fn new(
config: Arc<Config>,
resolvers: Arc<DnsResolvers>,
queue_manager: Arc<dyn GenericQueueManager>
) -> Result<Self>
pub fn new(
config: Arc<Config>,
resolvers: Arc<DnsResolvers>,
queue_manager: Arc<dyn GenericQueueManager>
) -> Result<Self>
creates a new instance of the rule engine, reading all files in the
script_path parameter.
if script_path is None, a warning is emitted and a deny-all script
is loaded.
Errors
- failed to register
script_pathas a valid module folder. - failed to compile or load any script located at
script_path.
pub fn with_hierarchy(
config: Arc<Config>,
input: impl Fn(Builder<'_>) -> Result<SubDomainHierarchy> + 'static,
resolvers: Arc<DnsResolvers>,
queue_manager: Arc<dyn GenericQueueManager>
) -> Result<Self>
pub fn with_hierarchy(
config: Arc<Config>,
input: impl Fn(Builder<'_>) -> Result<SubDomainHierarchy> + 'static,
resolvers: Arc<DnsResolvers>,
queue_manager: Arc<dyn GenericQueueManager>
) -> Result<Self>
create a rule engine instance using a callback that creates a sub domain hierarchy.
Errors
- failed to compile scripts.
pub fn spawn_with(
&self,
mail_context: Context,
message: MessageBody
) -> Arc<RuleState>
pub fn spawn_with(
&self,
mail_context: Context,
message: MessageBody
) -> Arc<RuleState>
build a cheap rhai engine with vsl’s api.
pub fn run_when(
&self,
rule_state: &RuleState,
skipped: &mut Option<Status>,
smtp_state: ExecutionStage
) -> Status
pub fn run_when(
&self,
rule_state: &RuleState,
skipped: &mut Option<Status>,
smtp_state: ExecutionStage
) -> Status
Runs all rules from a stage using the current transaction state.
the server_address parameter is used to distinguish logs from each other,
printing the address & port associated with this run session, not the current
context. (because the context could have been pulled from the filesystem when
receiving delegation results)
Panics
pub fn just_run_when(
&self,
skipped: &mut Option<Status>,
state: ExecutionStage,
mail_context: Context,
mail_message: MessageBody
) -> (Context, MessageBody, Status)
pub fn just_run_when(
&self,
skipped: &mut Option<Status>,
state: ExecutionStage,
mail_context: Context,
mail_message: MessageBody
) -> (Context, MessageBody, Status)
pub fn new_rhai_engine() -> Engine
pub fn new_rhai_engine() -> Engine
create a rhai engine to compile all scripts with vsl’s configuration.
pub fn build_static_modules(
engine: &mut Engine,
config: &Config
) -> Result<Vec<(String, Shared<Module>)>>
pub fn build_static_modules(
engine: &mut Engine,
config: &Config
) -> Result<Vec<(String, Shared<Module>)>>
pub fn compile_api(engine: &Engine) -> Result<Module>
pub fn compile_api(engine: &Engine) -> Result<Module>
compile vsl’s api into a module.
Errors
- Failed to compile the API.
- Failed to create a module from the API.
pub fn is_handled_domain(&self, address: &Address) -> bool
pub fn is_handled_domain(&self, address: &Address) -> bool
Check if the rule engine have configuration available for the domain of the given address.
NOTE: Check recursively all parents of the given domain, return true if any parent domain is handled by the configuration.
pub fn get_delegation_directive_bound_to_address(
&self,
socket: SocketAddr
) -> Option<&Directive>
pub fn get_delegation_directive_bound_to_address(
&self,
socket: SocketAddr
) -> Option<&Directive>
Find the delegate directive that matches the given socket.