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
45
46
47
48
49
50
51
52
53
54
55
56
57
use async_trait::async_trait;
use log::info;
use crate::SendableEmail;
use crate::Transport;
use std::time::Duration;
#[derive(Debug, Clone, Copy)]
pub struct StubTransport {
response: StubResult,
}
impl StubTransport {
pub fn new(response: StubResult) -> StubTransport {
StubTransport { response }
}
pub fn new_positive() -> StubTransport {
StubTransport { response: Ok(()) }
}
}
pub type StubResult = Result<(), ()>;
#[async_trait]
impl<'a> Transport<'a> for StubTransport {
type Result = StubResult;
async fn send(&mut self, email: SendableEmail) -> StubResult {
info!(
"{}: from=<{}> to=<{:?}>",
email.message_id(),
match email.envelope().from() {
Some(address) => address.to_string(),
None => "".to_string(),
},
email.envelope().to()
);
self.response
}
async fn send_with_timeout(
&mut self,
email: SendableEmail,
timeout: Option<&Duration>,
) -> Self::Result {
info!("Timeout: {:?}", timeout);
self.send(email).await
}
}