Skip to content

Commit c1fd96c

Browse files
committed
Make async-native-tls dependency optional
It is still possible to make connections using Rustls or without TLS outside the library.
1 parent 85ff7a3 commit c1fd96c

File tree

4 files changed

+21
-15
lines changed

4 files changed

+21
-15
lines changed

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ is-it-maintained-open-issues = { repository = "async-email/async-imap" }
2121
[features]
2222
default = ["runtime-async-std"]
2323

24-
runtime-async-std = ["async-std", "async-native-tls/runtime-async-std"]
25-
runtime-tokio = ["tokio", "async-native-tls/runtime-tokio"]
24+
runtime-async-std = ["async-std", "async-native-tls?/runtime-async-std"]
25+
runtime-tokio = ["tokio", "async-native-tls?/runtime-tokio"]
2626

2727
[dependencies]
2828
imap-proto = "0.16.1"
@@ -39,9 +39,9 @@ log = "0.4.8"
3939
thiserror = "1.0.9"
4040
async-channel = "1.6.1"
4141

42-
async-native-tls = { version = "0.4", default-features = false }
42+
async-native-tls = { version = "0.4", default-features = false, optional = true }
4343
async-std = { version = "1.8.0", default-features = false, features = ["std"], optional = true }
44-
tokio = { version = "1", features = ["net", "sync", "time"], optional = true }
44+
tokio = { version = "1", features = ["net", "sync", "time", "io-util"], optional = true }
4545

4646

4747
[dev-dependencies]

src/client.rs

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,24 @@ use std::ops::{Deref, DerefMut};
44
use std::pin::Pin;
55
use std::str;
66

7-
use async_channel::{self as channel, bounded};
7+
#[cfg(feature = "async-native-tls")]
88
use async_native_tls::{TlsConnector, TlsStream};
9+
10+
#[cfg(all(feature = "async-native-tls", feature = "runtime-tokio"))]
11+
use tokio::net::{TcpStream, ToSocketAddrs};
12+
13+
#[cfg(all(feature = "async-native-tls", feature = "runtime-async-std"))]
14+
use async_std::net::{TcpStream, ToSocketAddrs};
15+
16+
use async_channel::{self as channel, bounded};
917
#[cfg(feature = "runtime-async-std")]
10-
use async_std::{
11-
io::{Read, Write, WriteExt},
12-
net::{TcpStream, ToSocketAddrs},
13-
};
18+
use async_std::io::{Read, Write, WriteExt};
1419
use extensions::id::{format_identification, parse_id};
1520
use extensions::quota::parse_get_quota_root;
1621
use futures::{io, Stream, StreamExt};
1722
use imap_proto::{RequestId, Response};
1823
#[cfg(feature = "runtime-tokio")]
19-
use tokio::{
20-
io::{AsyncRead as Read, AsyncWrite as Write, AsyncWriteExt},
21-
net::{TcpStream, ToSocketAddrs},
22-
};
24+
use tokio::io::{AsyncRead as Read, AsyncWrite as Write, AsyncWriteExt};
2325

2426
use super::authenticator::Authenticator;
2527
use super::error::{Error, ParseError, Result, ValidateError};
@@ -136,6 +138,7 @@ impl<T: Read + Write + Unpin + fmt::Debug> DerefMut for Session<T> {
136138
/// # Ok(())
137139
/// # }) }
138140
/// ```
141+
#[cfg(feature = "async-native-tls")]
139142
pub async fn connect<A: ToSocketAddrs, S: AsRef<str>>(
140143
addr: A,
141144
domain: S,
@@ -161,6 +164,7 @@ impl<T: Read + Write + Unpin + fmt::Debug + Send> Client<T> {
161164
/// This will upgrade an IMAP client from using a regular TCP connection to use TLS.
162165
///
163166
/// The domain parameter is required to perform hostname verification.
167+
#[cfg(feature = "async-native-tls")]
164168
pub async fn secure<S: AsRef<str>>(
165169
mut self,
166170
domain: S,
@@ -223,7 +227,7 @@ impl<T: Read + Write + Unpin + fmt::Debug + Send> Client<T> {
223227
/// prompting the user for credetials), ownership of the original `Client` needs to be
224228
/// transferred back to the caller.
225229
///
226-
/// ```no_run
230+
/// ```ignore
227231
/// # fn main() -> async_imap::error::Result<()> {
228232
/// # async_std::task::block_on(async {
229233
///
@@ -267,7 +271,7 @@ impl<T: Read + Write + Unpin + fmt::Debug + Send> Client<T> {
267271
/// Authenticate with the server using the given custom `authenticator` to handle the server's
268272
/// challenge.
269273
///
270-
/// ```no_run
274+
/// ```ignore
271275
/// struct OAuth2 {
272276
/// user: String,
273277
/// access_token: String,

src/error.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub enum Error {
3232
#[error("validate: {0}")]
3333
Validate(#[from] ValidateError),
3434
/// `async_native_tls` error
35+
#[cfg(feature = "async-native-tls")]
3536
#[error("async_native_tls: {0}")]
3637
NativeTlsError(#[from] async_native_tls::Error),
3738
/// Error appending an e-mail.

src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
//! use futures::prelude::*;
2020
//! use async_imap::error::Result;
2121
//!
22+
//! #[cfg(feature = "async-native-tls")]
2223
//! async fn fetch_inbox_top() -> Result<Option<String>> {
2324
//! let domain = "imap.example.com";
2425
//! let tls = async_native_tls::TlsConnector::new();

0 commit comments

Comments
 (0)