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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#![deny(
missing_copy_implementations,
trivial_casts,
trivial_numeric_casts,
unsafe_code,
unstable_features,
unused_import_braces,
missing_debug_implementations,
clippy::unwrap_used
)]
#[macro_use]
extern crate log;
pub mod delivery;
pub mod dir;
#[cfg(feature = "file-transport")]
pub mod file;
#[cfg(feature = "sendmail-transport")]
pub mod sendmail;
#[cfg(feature = "smtp-transport")]
pub mod smtp;
pub mod stub;
pub mod types;
pub mod prelude {
#[cfg(feature = "file-transport")]
pub use crate::file::FileTransport;
#[cfg(feature = "sendmail-transport")]
pub use crate::sendmail::SendmailTransport;
#[cfg(feature = "smtp-transport")]
pub use crate::smtp::{ClientSecurity, SmtpClient, SmtpTransport};
pub use crate::types::*;
pub use crate::{MailDataStream, Transport};
}
use crate::prelude::*;
use async_std::io::{copy, Read, Write};
use futures::{io::AsyncWriteExt, Future};
use std::{fmt, pin::Pin};
pub type SyncFuture<'a, T> = Pin<Box<dyn Future<Output = T> + Sync + Send + 'a>>;
type SendResult<T> = Result<<T as MailDataStream>::Output, <T as MailDataStream>::Error>;
pub trait Transport: std::fmt::Debug {
type DataStream: MailDataStream;
fn send_stream<'s, 'a>(
&'s self,
envelope: Envelope,
) -> SyncFuture<'a, Result<Self::DataStream, <Self::DataStream as MailDataStream>::Error>>
where
's: 'a;
fn send<'s, 'r, 'a, R>(
&'s self,
envelope: Envelope,
message: R,
) -> SyncFuture<'a, SendResult<Self::DataStream>>
where
Self::DataStream: Unpin + Send + Sync,
<Self::DataStream as MailDataStream>::Error: From<std::io::Error>,
R: Read + Unpin + Send + Sync + 'r,
's: 'a,
'r: 'a,
{
let stream = self.send_stream(envelope);
Box::pin(async move {
let mut stream = stream.await?;
copy(message, &mut stream).await?;
stream.close().await?;
stream.result()
})
}
}
pub trait MailDataStream: fmt::Debug + Write {
type Output;
type Error;
fn result(&self) -> Result<Self::Output, Self::Error>;
}