rspamd_client/
lib.rs

1//!# Rspamd Client for Rust
2//!
3//! This crate provides an HTTP client for interacting with the Rspamd service in Rust.
4//! It supports both synchronous and asynchronous operations using the `attohttpc` and
5//! `reqwest` libraries, respectively.
6//!
7//! ## Features
8//!
9//! - **Sync**: Synchronous client using `attohttpc`.
10//! - **Async**: Asynchronous client using `reqwest`.
11//! - Easily configurable with support for proxy, encryption, TLS and ZSTD compression.
12//! - Supports scanning emails for spam scores and other metrics.
13
14pub mod config;
15pub mod error;
16pub mod protocol;
17
18pub mod backend;
19
20/// ### Synchronous Client
21///
22/// This example demonstrates how to scan an email using the synchronous client.
23///
24/// ```rust
25/// use rspamd_client::{config, scan_sync};
26///
27/// fn main() {
28///    let config = config::Config::builder()
29///         .base_url("http://localhost:11333".to_string())
30///         .build();
31///     let email = "From: user@example.com\nTo: recipient@example.com\nSubject: Test\n\nThis is a test email.";
32///
33///     match scan_sync(&config, email, Default::default()) {
34///         Ok(response) => println!("Scan result: {:?}", response),
35///         Err(e) => eprintln!("Error scanning email: {}", e),
36///     }
37/// }
38/// ```
39///
40#[cfg(feature = "sync")]
41pub use backend::sync_client::SyncClient;
42#[cfg(feature = "sync")]
43pub use backend::sync_client::scan_sync;
44
45/// ### Asynchronous Client
46///
47/// This example demonstrates how to scan an email using the asynchronous client.
48///
49/// ```rust
50/// use rspamd_client::{config, scan_async};
51/// use tokio;
52///
53/// #[tokio::main]
54/// async fn main() {
55///     let config = config::Config::builder()
56///         .base_url("http://localhost:11333".to_string())
57///         .build();
58///     let email = "From: user@example.com\nTo: recipient@example.com\nSubject: Test\n\nThis is a test email.";
59///
60///     match scan_async(&config, email, Default::default()).await {
61///         Ok(response) => println!("Scan result: {:?}", response),
62///         Err(e) => eprintln!("Error scanning email: {}", e),
63///     }
64/// }
65/// ```
66#[cfg(feature = "async")]
67pub use backend::async_client::AsyncClient;
68#[cfg(feature = "async")]
69pub use backend::async_client::scan_async;