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
//! Traits and impls to represent and establish network-like streams
pub mod tls;

#[cfg(unix)]
mod unix;
#[cfg(unix)]
pub use self::unix::*;

mod inet;
pub use self::inet::*;

use self::tls::DefaultTls;
use crate::smtp::extension::ClientId;
use crate::smtp::extension::ServerInfo;
use crate::ClientSecurity;
use crate::{smtp::authentication::Authentication, SyncFuture};
use async_std::io::{self, Read, Write};
use samotop_core::io::tls::MayBeTls;
use std::fmt;
use std::time::Duration;

pub trait Connector: fmt::Debug + Sync + Send {
    type Stream: MayBeTls + Read + Write + Unpin + Sync + Send + 'static;
    /// This provider of connectivity takes care of resolving
    /// given address (which could be an IP, FQDN, URL...),
    /// establishing a connection and enabling (or not) TLS upgrade.

    fn connect<'s, 'c, 'a, C: ConnectionConfiguration>(
        &'s self,
        configuration: &'c C,
    ) -> SyncFuture<'a, io::Result<Self::Stream>>
    where
        's: 'a,
        'c: 'a;
}

pub trait ConnectionConfiguration: Sync + Send {
    fn address(&self) -> String;
    fn timeout(&self) -> Duration;
    fn security(&self) -> ClientSecurity;
    fn hello_name(&self) -> ClientId;
    fn max_reuse_count(&self) -> u16;
    fn get_authentication(
        &self,
        server_info: &ServerInfo,
        encrypted: bool,
    ) -> Option<Box<dyn Authentication>>;
    fn lmtp(&self) -> bool;
}

pub type DefaultConnector = inet::TcpConnector<DefaultTls>;

#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum TlsMode {
    Tls,
    StartTls,
}