Skip to main content

rs_smtp/
backend.rs

1use crate::{conn::Conn, sasl};
2
3use async_trait::async_trait;
4
5use anyhow::Result;
6
7use tokio::io::AsyncRead;
8
9type BodyType = String;
10
11//const BODY_7BIT: BodyType = "7BIT".to_owned();
12//const BODY_8BIT_MIME: BodyType = "8BITMIME".to_string();
13//const BODY_BINARY_MIME: BodyType = "BINARYMIME".to_string();
14
15pub trait Backend: Send + Sync + 'static + Sized {
16    type S: Session + Send;
17
18    fn new_session(&self, c: &mut Conn<Self>) -> Result<Self::S>;
19}
20
21pub struct MailOptions {
22    pub body: BodyType,
23    pub size: usize,
24    pub require_tls: bool,
25    pub utf8: bool,
26    pub auth: String,
27}
28
29impl MailOptions {
30    pub fn new() -> Self {
31        MailOptions {
32            body: "7BIT".to_string(),
33            size: 0,
34            require_tls: false,
35            utf8: false,
36            auth: String::new(),
37        }
38    }
39}
40
41#[async_trait]
42pub trait Session {
43    fn authenticators(&mut self) -> Vec<Box<dyn sasl::Server>> {
44        Vec::new()
45    }
46
47    async fn mail(&mut self, from: &str, opts: &MailOptions) -> Result<()>;
48
49    async fn rcpt(&mut self, to: &str) -> Result<()>;
50
51    async fn data<R: AsyncRead + Send + Unpin>(&mut self, r: R) -> Result<()>;
52
53    fn reset(&mut self);
54
55    fn logout(&mut self) -> Result<()>;
56}