-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathbasic.rs
44 lines (35 loc) · 1017 Bytes
/
basic.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use std::sync::Arc;
use mailfred::{
service::{Request, Response, ResponseResult},
transports::{Imap, Smtp},
};
use tokio::sync::Mutex;
#[derive(Default)]
struct MyState {
counter: u32,
}
type State = Arc<Mutex<MyState>>;
async fn count(req: Request, state: State) -> ResponseResult {
let mut state = state.lock().await;
state.counter += 1;
Response::ok(req.header, format!("Counter: {}", state.counter))
}
#[tokio::main]
async fn main() -> Result<(), anyhow::Error> {
#[cfg(feature = "logger")]
mailfred::util::logger::configure(log::LevelFilter::Trace);
let imap = Imap {
domain: "imap.gmail.com".into(),
port: 993,
user: "[email protected]".into(),
password: "1234".into(),
folder: "inbox".into(),
};
let smtp = Smtp {
domain: "smtp.gmail.com".into(),
port: 587,
user: "[email protected]".into(),
password: "1234".into(),
};
mailfred::serve((imap, smtp), State::default(), count).await
}