pub struct RspamdAsyncClient { /* private fields */ }Expand description
Persistent asynchronous Rspamd client.
Owns the underlying reqwest::Client, so TCP (and TLS, when enabled)
connections are pooled and reused across calls, unlike the one-shot
scan_async wrapper which pays a fresh connection setup on every call.
Cheap to clone (reqwest::Client is internally reference-counted and the
configuration is shared through an Arc); Send + Sync + 'static, so it
is suitable for stashing in a static or an LRU cache keyed by Config.
use rspamd_client::config::Config;
use rspamd_client::RspamdAsyncClient;
let config = Config::builder()
.base_url("http://localhost:11333".to_string())
.build();
let client = RspamdAsyncClient::new(config)?;
for email in ["first message", "second message"] {
let reply = client.scan(email, Default::default()).await?;
println!("action: {}", reply.action);
}Implementations§
Source§impl RspamdAsyncClient
impl RspamdAsyncClient
Sourcepub fn new(config: Config) -> Result<Self, RspamdError>
pub fn new(config: Config) -> Result<Self, RspamdError>
Create a persistent client from a configuration.
Sourcepub async fn scan<B: AsRef<[u8]> + Send>(
&self,
body: B,
envelope_data: EnvelopeData,
) -> Result<RspamdScanReply, RspamdError>
pub async fn scan<B: AsRef<[u8]> + Send>( &self, body: B, envelope_data: EnvelopeData, ) -> Result<RspamdScanReply, RspamdError>
Scan an email, returning the parsed scan reply.
Sourcepub async fn learn_spam<B: AsRef<[u8]> + Send>(
&self,
body: B,
envelope_data: EnvelopeData,
) -> Result<RspamdLearnReply, RspamdError>
pub async fn learn_spam<B: AsRef<[u8]> + Send>( &self, body: B, envelope_data: EnvelopeData, ) -> Result<RspamdLearnReply, RspamdError>
Learn an email as spam (requires the controller endpoint and password).
Sourcepub async fn learn_ham<B: AsRef<[u8]> + Send>(
&self,
body: B,
envelope_data: EnvelopeData,
) -> Result<RspamdLearnReply, RspamdError>
pub async fn learn_ham<B: AsRef<[u8]> + Send>( &self, body: B, envelope_data: EnvelopeData, ) -> Result<RspamdLearnReply, RspamdError>
Learn an email as ham (requires the controller endpoint and password).
Sourcepub async fn fuzzy_add<B: AsRef<[u8]> + Send>(
&self,
body: B,
envelope_data: EnvelopeData,
) -> Result<RspamdLearnReply, RspamdError>
pub async fn fuzzy_add<B: AsRef<[u8]> + Send>( &self, body: B, envelope_data: EnvelopeData, ) -> Result<RspamdLearnReply, RspamdError>
Add an email to fuzzy storage; pass Flag/Weight via
EnvelopeData::additional_headers.
Sourcepub async fn fuzzy_del<B: AsRef<[u8]> + Send>(
&self,
body: B,
envelope_data: EnvelopeData,
) -> Result<RspamdLearnReply, RspamdError>
pub async fn fuzzy_del<B: AsRef<[u8]> + Send>( &self, body: B, envelope_data: EnvelopeData, ) -> Result<RspamdLearnReply, RspamdError>
Remove an email from fuzzy storage; pass Flag via
EnvelopeData::additional_headers.
Trait Implementations§
Source§impl Clone for RspamdAsyncClient
impl Clone for RspamdAsyncClient
Source§fn clone(&self) -> RspamdAsyncClient
fn clone(&self) -> RspamdAsyncClient
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more