pub struct MessageRouter { /* private fields */ }Expand description
Routes incoming email messages to handlers based on recipient address rules.
Rules are evaluated in specificity order: exact address > domain > wildcard domain. If no rule matches, the default handler is used.
Implementations§
Source§impl MessageRouter
impl MessageRouter
Sourcepub fn new(
rules: Vec<RoutingRule>,
default_handler: Arc<dyn MessageHandler>,
default_transformers: Vec<Box<dyn MessageTransformer>>,
) -> Self
pub fn new( rules: Vec<RoutingRule>, default_handler: Arc<dyn MessageHandler>, default_transformers: Vec<Box<dyn MessageTransformer>>, ) -> Self
Creates a new MessageRouter with the given rules, default handler, and
default transformers.
Rules are automatically sorted by specificity (exact > domain > wildcard).
Sourcepub fn resolve(&self, recipient: &str) -> &Arc<dyn MessageHandler>
pub fn resolve(&self, recipient: &str) -> &Arc<dyn MessageHandler>
Resolves which handler should process a message for the given recipient.
Sourcepub async fn route(&self, message: &mut EmailMessage) -> HandlerResult<()>
pub async fn route(&self, message: &mut EmailMessage) -> HandlerResult<()>
Routes a message to the appropriate handler based on the recipient address.
Applies transformers before dispatching to the handler.
Sourcepub fn resolve_auth_required(
&self,
recipient: &str,
global_default: bool,
) -> bool
pub fn resolve_auth_required( &self, recipient: &str, global_default: bool, ) -> bool
Resolves whether authentication is required for a recipient.
Returns the rule’s RoutingRule::auth_required if the matching rule defines it,
otherwise returns the provided global default.
Sourcepub fn default_handler(&self) -> &Arc<dyn MessageHandler>
pub fn default_handler(&self) -> &Arc<dyn MessageHandler>
Returns a reference to the default handler.
Sourcepub fn rejection_for(&self, recipient: &str) -> Option<(u16, String)>
pub fn rejection_for(&self, recipient: &str) -> Option<(u16, String)>
Probes the handler that would process recipient and, if that handler
refuses every delivery, returns the SMTP reply (code, message) it
would emit.
Used by SMTP front-ends to short-circuit at RCPT TO time so the
client receives a proper rejection instead of a post-DATA bounce.