Change "tls" feature to "native-tls" (#201)
Change "tls" feature to "native-tls" for clarity and obvious distinction with rustls-tls.
This commit is contained in:
parent
55cd6465c7
commit
b7a2641725
8 changed files with 29 additions and 28 deletions
|
|
@ -14,9 +14,8 @@ keywords = ["email", "imap"]
|
||||||
categories = ["email", "network-programming"]
|
categories = ["email", "network-programming"]
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
tls = ["native-tls"]
|
|
||||||
rustls-tls = ["rustls-connector"]
|
rustls-tls = ["rustls-connector"]
|
||||||
default = ["tls"]
|
default = ["native-tls"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
native-tls = { version = "0.2.2", optional = true }
|
native-tls = { version = "0.2.2", optional = true }
|
||||||
|
|
|
||||||
|
|
@ -284,7 +284,7 @@ impl<T: Read + Write> Client<T> {
|
||||||
/// # use imap::Client;
|
/// # use imap::Client;
|
||||||
/// # use std::io;
|
/// # use std::io;
|
||||||
/// # use std::net::TcpStream;
|
/// # use std::net::TcpStream;
|
||||||
/// # {} #[cfg(feature = "tls")]
|
/// # {} #[cfg(feature = "native-tls")]
|
||||||
/// # fn main() {
|
/// # fn main() {
|
||||||
/// # let server = "imap.example.com";
|
/// # let server = "imap.example.com";
|
||||||
/// # let username = "";
|
/// # let username = "";
|
||||||
|
|
@ -325,7 +325,7 @@ impl<T: Read + Write> Client<T> {
|
||||||
/// transferred back to the caller.
|
/// transferred back to the caller.
|
||||||
///
|
///
|
||||||
/// ```rust,no_run
|
/// ```rust,no_run
|
||||||
/// # {} #[cfg(feature = "tls")]
|
/// # {} #[cfg(feature = "native-tls")]
|
||||||
/// # fn main() {
|
/// # fn main() {
|
||||||
/// let client = imap::ClientBuilder::new("imap.example.org", 993)
|
/// let client = imap::ClientBuilder::new("imap.example.org", 993)
|
||||||
/// .native_tls().unwrap();
|
/// .native_tls().unwrap();
|
||||||
|
|
@ -376,7 +376,7 @@ impl<T: Read + Write> Client<T> {
|
||||||
/// }
|
/// }
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// # {} #[cfg(feature = "tls")]
|
/// # {} #[cfg(feature = "native-tls")]
|
||||||
/// fn main() {
|
/// fn main() {
|
||||||
/// let auth = OAuth2 {
|
/// let auth = OAuth2 {
|
||||||
/// user: String::from("me@example.com"),
|
/// user: String::from("me@example.com"),
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ use crate::{Client, Result};
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
use std::net::TcpStream;
|
use std::net::TcpStream;
|
||||||
|
|
||||||
#[cfg(feature = "tls")]
|
#[cfg(feature = "native-tls")]
|
||||||
use native_tls::{TlsConnector, TlsStream};
|
use native_tls::{TlsConnector, TlsStream};
|
||||||
#[cfg(feature = "rustls-tls")]
|
#[cfg(feature = "rustls-tls")]
|
||||||
use rustls_connector::{RustlsConnector, TlsStream as RustlsStream};
|
use rustls_connector::{RustlsConnector, TlsStream as RustlsStream};
|
||||||
|
|
@ -12,7 +12,7 @@ use rustls_connector::{RustlsConnector, TlsStream as RustlsStream};
|
||||||
/// Creating a [`Client`] using `native-tls` transport is straightforward:
|
/// Creating a [`Client`] using `native-tls` transport is straightforward:
|
||||||
/// ```no_run
|
/// ```no_run
|
||||||
/// # use imap::ClientBuilder;
|
/// # use imap::ClientBuilder;
|
||||||
/// # {} #[cfg(feature = "tls")]
|
/// # {} #[cfg(feature = "native-tls")]
|
||||||
/// # fn main() -> Result<(), imap::Error> {
|
/// # fn main() -> Result<(), imap::Error> {
|
||||||
/// let client = ClientBuilder::new("imap.example.com", 993).native_tls()?;
|
/// let client = ClientBuilder::new("imap.example.com", 993).native_tls()?;
|
||||||
/// # Ok(())
|
/// # Ok(())
|
||||||
|
|
@ -66,15 +66,15 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Use [`STARTTLS`](https://tools.ietf.org/html/rfc2595) for this connection.
|
/// Use [`STARTTLS`](https://tools.ietf.org/html/rfc2595) for this connection.
|
||||||
#[cfg(any(feature = "tls", feature = "rustls-tls"))]
|
#[cfg(any(feature = "native-tls", feature = "rustls-tls"))]
|
||||||
pub fn starttls(&mut self) -> &mut Self {
|
pub fn starttls(&mut self) -> &mut Self {
|
||||||
self.starttls = true;
|
self.starttls = true;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return a new [`Client`] using a `native-tls` transport.
|
/// Return a new [`Client`] using a `native-tls` transport.
|
||||||
#[cfg(feature = "tls")]
|
#[cfg(feature = "native-tls")]
|
||||||
#[cfg_attr(docsrs, doc(cfg(feature = "tls")))]
|
#[cfg_attr(docsrs, doc(cfg(feature = "native-tls")))]
|
||||||
pub fn native_tls(&mut self) -> Result<Client<TlsStream<TcpStream>>> {
|
pub fn native_tls(&mut self) -> Result<Client<TlsStream<TcpStream>>> {
|
||||||
self.connect(|domain, tcp| {
|
self.connect(|domain, tcp| {
|
||||||
let ssl_conn = TlsConnector::builder().build()?;
|
let ssl_conn = TlsConnector::builder().build()?;
|
||||||
|
|
|
||||||
24
src/error.rs
24
src/error.rs
|
|
@ -10,9 +10,9 @@ use std::str::Utf8Error;
|
||||||
use base64::DecodeError;
|
use base64::DecodeError;
|
||||||
use bufstream::IntoInnerError as BufError;
|
use bufstream::IntoInnerError as BufError;
|
||||||
use imap_proto::{types::ResponseCode, Response};
|
use imap_proto::{types::ResponseCode, Response};
|
||||||
#[cfg(feature = "tls")]
|
#[cfg(feature = "native-tls")]
|
||||||
use native_tls::Error as TlsError;
|
use native_tls::Error as TlsError;
|
||||||
#[cfg(feature = "tls")]
|
#[cfg(feature = "native-tls")]
|
||||||
use native_tls::HandshakeError as TlsHandshakeError;
|
use native_tls::HandshakeError as TlsHandshakeError;
|
||||||
#[cfg(feature = "rustls-tls")]
|
#[cfg(feature = "rustls-tls")]
|
||||||
use rustls_connector::HandshakeError as RustlsHandshakeError;
|
use rustls_connector::HandshakeError as RustlsHandshakeError;
|
||||||
|
|
@ -62,10 +62,10 @@ pub enum Error {
|
||||||
#[cfg(feature = "rustls-tls")]
|
#[cfg(feature = "rustls-tls")]
|
||||||
RustlsHandshake(RustlsHandshakeError<TcpStream>),
|
RustlsHandshake(RustlsHandshakeError<TcpStream>),
|
||||||
/// An error from the `native_tls` library during the TLS handshake.
|
/// An error from the `native_tls` library during the TLS handshake.
|
||||||
#[cfg(feature = "tls")]
|
#[cfg(feature = "native-tls")]
|
||||||
TlsHandshake(TlsHandshakeError<TcpStream>),
|
TlsHandshake(TlsHandshakeError<TcpStream>),
|
||||||
/// An error from the `native_tls` library while managing the socket.
|
/// An error from the `native_tls` library while managing the socket.
|
||||||
#[cfg(feature = "tls")]
|
#[cfg(feature = "native-tls")]
|
||||||
Tls(TlsError),
|
Tls(TlsError),
|
||||||
/// A BAD response from the IMAP server.
|
/// A BAD response from the IMAP server.
|
||||||
Bad(Bad),
|
Bad(Bad),
|
||||||
|
|
@ -114,14 +114,14 @@ impl From<RustlsHandshakeError<TcpStream>> for Error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "tls")]
|
#[cfg(feature = "native-tls")]
|
||||||
impl From<TlsHandshakeError<TcpStream>> for Error {
|
impl From<TlsHandshakeError<TcpStream>> for Error {
|
||||||
fn from(err: TlsHandshakeError<TcpStream>) -> Error {
|
fn from(err: TlsHandshakeError<TcpStream>) -> Error {
|
||||||
Error::TlsHandshake(err)
|
Error::TlsHandshake(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "tls")]
|
#[cfg(feature = "native-tls")]
|
||||||
impl From<TlsError> for Error {
|
impl From<TlsError> for Error {
|
||||||
fn from(err: TlsError) -> Error {
|
fn from(err: TlsError) -> Error {
|
||||||
Error::Tls(err)
|
Error::Tls(err)
|
||||||
|
|
@ -140,9 +140,9 @@ impl fmt::Display for Error {
|
||||||
Error::Io(ref e) => fmt::Display::fmt(e, f),
|
Error::Io(ref e) => fmt::Display::fmt(e, f),
|
||||||
#[cfg(feature = "rustls-tls")]
|
#[cfg(feature = "rustls-tls")]
|
||||||
Error::RustlsHandshake(ref e) => fmt::Display::fmt(e, f),
|
Error::RustlsHandshake(ref e) => fmt::Display::fmt(e, f),
|
||||||
#[cfg(feature = "tls")]
|
#[cfg(feature = "native-tls")]
|
||||||
Error::Tls(ref e) => fmt::Display::fmt(e, f),
|
Error::Tls(ref e) => fmt::Display::fmt(e, f),
|
||||||
#[cfg(feature = "tls")]
|
#[cfg(feature = "native-tls")]
|
||||||
Error::TlsHandshake(ref e) => fmt::Display::fmt(e, f),
|
Error::TlsHandshake(ref e) => fmt::Display::fmt(e, f),
|
||||||
Error::Validate(ref e) => fmt::Display::fmt(e, f),
|
Error::Validate(ref e) => fmt::Display::fmt(e, f),
|
||||||
Error::Parse(ref e) => fmt::Display::fmt(e, f),
|
Error::Parse(ref e) => fmt::Display::fmt(e, f),
|
||||||
|
|
@ -163,9 +163,9 @@ impl StdError for Error {
|
||||||
Error::Io(ref e) => e.description(),
|
Error::Io(ref e) => e.description(),
|
||||||
#[cfg(feature = "rustls-tls")]
|
#[cfg(feature = "rustls-tls")]
|
||||||
Error::RustlsHandshake(ref e) => e.description(),
|
Error::RustlsHandshake(ref e) => e.description(),
|
||||||
#[cfg(feature = "tls")]
|
#[cfg(feature = "native-tls")]
|
||||||
Error::Tls(ref e) => e.description(),
|
Error::Tls(ref e) => e.description(),
|
||||||
#[cfg(feature = "tls")]
|
#[cfg(feature = "native-tls")]
|
||||||
Error::TlsHandshake(ref e) => e.description(),
|
Error::TlsHandshake(ref e) => e.description(),
|
||||||
Error::Parse(ref e) => e.description(),
|
Error::Parse(ref e) => e.description(),
|
||||||
Error::Validate(ref e) => e.description(),
|
Error::Validate(ref e) => e.description(),
|
||||||
|
|
@ -183,9 +183,9 @@ impl StdError for Error {
|
||||||
Error::Io(ref e) => Some(e),
|
Error::Io(ref e) => Some(e),
|
||||||
#[cfg(feature = "rustls-tls")]
|
#[cfg(feature = "rustls-tls")]
|
||||||
Error::RustlsHandshake(ref e) => Some(e),
|
Error::RustlsHandshake(ref e) => Some(e),
|
||||||
#[cfg(feature = "tls")]
|
#[cfg(feature = "native-tls")]
|
||||||
Error::Tls(ref e) => Some(e),
|
Error::Tls(ref e) => Some(e),
|
||||||
#[cfg(feature = "tls")]
|
#[cfg(feature = "native-tls")]
|
||||||
Error::TlsHandshake(ref e) => Some(e),
|
Error::TlsHandshake(ref e) => Some(e),
|
||||||
Error::Parse(ParseError::DataNotUtf8(_, ref e)) => Some(e),
|
Error::Parse(ParseError::DataNotUtf8(_, ref e)) => Some(e),
|
||||||
_ => None,
|
_ => None,
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ use crate::client::Session;
|
||||||
use crate::error::{Error, Result};
|
use crate::error::{Error, Result};
|
||||||
use crate::parse::parse_idle;
|
use crate::parse::parse_idle;
|
||||||
use crate::types::UnsolicitedResponse;
|
use crate::types::UnsolicitedResponse;
|
||||||
#[cfg(feature = "tls")]
|
#[cfg(feature = "native-tls")]
|
||||||
use native_tls::TlsStream;
|
use native_tls::TlsStream;
|
||||||
#[cfg(feature = "rustls-tls")]
|
#[cfg(feature = "rustls-tls")]
|
||||||
use rustls_connector::TlsStream as RustlsStream;
|
use rustls_connector::TlsStream as RustlsStream;
|
||||||
|
|
@ -28,7 +28,7 @@ use std::time::Duration;
|
||||||
///
|
///
|
||||||
/// ```no_run
|
/// ```no_run
|
||||||
/// use imap::extensions::idle;
|
/// use imap::extensions::idle;
|
||||||
/// # #[cfg(feature = "tls")]
|
/// # #[cfg(feature = "native-tls")]
|
||||||
/// # {
|
/// # {
|
||||||
/// let client = imap::ClientBuilder::new("example.com", 993).native_tls()
|
/// let client = imap::ClientBuilder::new("example.com", 993).native_tls()
|
||||||
/// .expect("Could not connect to imap server");
|
/// .expect("Could not connect to imap server");
|
||||||
|
|
@ -281,7 +281,7 @@ impl<'a> SetReadTimeout for TcpStream {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "tls")]
|
#[cfg(feature = "native-tls")]
|
||||||
impl<'a> SetReadTimeout for TlsStream<TcpStream> {
|
impl<'a> SetReadTimeout for TlsStream<TcpStream> {
|
||||||
fn set_read_timeout(&mut self, timeout: Option<Duration>) -> Result<()> {
|
fn set_read_timeout(&mut self, timeout: Option<Duration>) -> Result<()> {
|
||||||
self.get_ref().set_read_timeout(timeout).map_err(Error::Io)
|
self.get_ref().set_read_timeout(timeout).map_err(Error::Io)
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
//! Below is a basic client example. See the `examples/` directory for more.
|
//! Below is a basic client example. See the `examples/` directory for more.
|
||||||
//!
|
//!
|
||||||
//! ```no_run
|
//! ```no_run
|
||||||
//! # #[cfg(feature = "tls")]
|
//! # #[cfg(feature = "native-tls")]
|
||||||
//! fn fetch_inbox_top() -> imap::error::Result<Option<String>> {
|
//! fn fetch_inbox_top() -> imap::error::Result<Option<String>> {
|
||||||
//!
|
//!
|
||||||
//! let client = imap::ClientBuilder::new("imap.example.com", 993).native_tls()?;
|
//! let client = imap::ClientBuilder::new("imap.example.com", 993).native_tls()?;
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ use std::ops::RangeInclusive;
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
/// ```no_run
|
/// ```no_run
|
||||||
/// # {} #[cfg(feature = "tls")]
|
/// # {} #[cfg(feature = "native-tls")]
|
||||||
/// # fn main() {
|
/// # fn main() {
|
||||||
/// # let client = imap::ClientBuilder::new("imap.example.com", 993)
|
/// # let client = imap::ClientBuilder::new("imap.example.com", 993)
|
||||||
/// .native_tls().unwrap();
|
/// .native_tls().unwrap();
|
||||||
|
|
|
||||||
|
|
@ -456,7 +456,9 @@ fn status() {
|
||||||
|
|
||||||
// Test all valid fields except HIGHESTMODSEQ, which apparently
|
// Test all valid fields except HIGHESTMODSEQ, which apparently
|
||||||
// isn't supported by the IMAP server used for this test.
|
// isn't supported by the IMAP server used for this test.
|
||||||
let mb = s.status("INBOX", "(MESSAGES RECENT UIDNEXT UIDVALIDITY UNSEEN)").unwrap();
|
let mb = s
|
||||||
|
.status("INBOX", "(MESSAGES RECENT UIDNEXT UIDVALIDITY UNSEEN)")
|
||||||
|
.unwrap();
|
||||||
assert_eq!(mb.flags, Vec::new());
|
assert_eq!(mb.flags, Vec::new());
|
||||||
assert_eq!(mb.exists, 0);
|
assert_eq!(mb.exists, 0);
|
||||||
assert_eq!(mb.recent, 0);
|
assert_eq!(mb.recent, 0);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue