Skip to main content

RspamdAsyncClient

Struct RspamdAsyncClient 

Source
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

Source

pub fn new(config: Config) -> Result<Self, RspamdError>

Create a persistent client from a configuration.

Source

pub fn config(&self) -> &Config

The configuration this client was built from.

Source

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.

Source

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).

Source

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).

Source

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.

Source

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

Source§

fn clone(&self) -> RspamdAsyncClient

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more