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"]
|
||||
|
||||
[features]
|
||||
tls = ["native-tls"]
|
||||
rustls-tls = ["rustls-connector"]
|
||||
default = ["tls"]
|
||||
default = ["native-tls"]
|
||||
|
||||
[dependencies]
|
||||
native-tls = { version = "0.2.2", optional = true }
|
||||
|
|
|
|||
|
|
@ -284,7 +284,7 @@ impl<T: Read + Write> Client<T> {
|
|||
/// # use imap::Client;
|
||||
/// # use std::io;
|
||||
/// # use std::net::TcpStream;
|
||||
/// # {} #[cfg(feature = "tls")]
|
||||
/// # {} #[cfg(feature = "native-tls")]
|
||||
/// # fn main() {
|
||||
/// # let server = "imap.example.com";
|
||||
/// # let username = "";
|
||||
|
|
@ -325,7 +325,7 @@ impl<T: Read + Write> Client<T> {
|
|||
/// transferred back to the caller.
|
||||
///
|
||||
/// ```rust,no_run
|
||||
/// # {} #[cfg(feature = "tls")]
|
||||
/// # {} #[cfg(feature = "native-tls")]
|
||||
/// # fn main() {
|
||||
/// let client = imap::ClientBuilder::new("imap.example.org", 993)
|
||||
/// .native_tls().unwrap();
|
||||
|
|
@ -376,7 +376,7 @@ impl<T: Read + Write> Client<T> {
|
|||
/// }
|
||||
/// }
|
||||
///
|
||||
/// # {} #[cfg(feature = "tls")]
|
||||
/// # {} #[cfg(feature = "native-tls")]
|
||||
/// fn main() {
|
||||
/// let auth = OAuth2 {
|
||||
/// user: String::from("me@example.com"),
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use crate::{Client, Result};
|
|||
use std::io::{Read, Write};
|
||||
use std::net::TcpStream;
|
||||
|
||||
#[cfg(feature = "tls")]
|
||||
#[cfg(feature = "native-tls")]
|
||||
use native_tls::{TlsConnector, TlsStream};
|
||||
#[cfg(feature = "rustls-tls")]
|
||||
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:
|
||||
/// ```no_run
|
||||
/// # use imap::ClientBuilder;
|
||||
/// # {} #[cfg(feature = "tls")]
|
||||
/// # {} #[cfg(feature = "native-tls")]
|
||||
/// # fn main() -> Result<(), imap::Error> {
|
||||
/// let client = ClientBuilder::new("imap.example.com", 993).native_tls()?;
|
||||
/// # Ok(())
|
||||
|
|
@ -66,15 +66,15 @@ where
|
|||
}
|
||||
|
||||
/// 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 {
|
||||
self.starttls = true;
|
||||
self
|
||||
}
|
||||
|
||||
/// Return a new [`Client`] using a `native-tls` transport.
|
||||
#[cfg(feature = "tls")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "tls")))]
|
||||
#[cfg(feature = "native-tls")]
|
||||
#[cfg_attr(docsrs, doc(cfg(feature = "native-tls")))]
|
||||
pub fn native_tls(&mut self) -> Result<Client<TlsStream<TcpStream>>> {
|
||||
self.connect(|domain, tcp| {
|
||||
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 bufstream::IntoInnerError as BufError;
|
||||
use imap_proto::{types::ResponseCode, Response};
|
||||
#[cfg(feature = "tls")]
|
||||
#[cfg(feature = "native-tls")]
|
||||
use native_tls::Error as TlsError;
|
||||
#[cfg(feature = "tls")]
|
||||
#[cfg(feature = "native-tls")]
|
||||
use native_tls::HandshakeError as TlsHandshakeError;
|
||||
#[cfg(feature = "rustls-tls")]
|
||||
use rustls_connector::HandshakeError as RustlsHandshakeError;
|
||||
|
|
@ -62,10 +62,10 @@ pub enum Error {
|
|||
#[cfg(feature = "rustls-tls")]
|
||||
RustlsHandshake(RustlsHandshakeError<TcpStream>),
|
||||
/// An error from the `native_tls` library during the TLS handshake.
|
||||
#[cfg(feature = "tls")]
|
||||
#[cfg(feature = "native-tls")]
|
||||
TlsHandshake(TlsHandshakeError<TcpStream>),
|
||||
/// An error from the `native_tls` library while managing the socket.
|
||||
#[cfg(feature = "tls")]
|
||||
#[cfg(feature = "native-tls")]
|
||||
Tls(TlsError),
|
||||
/// A BAD response from the IMAP server.
|
||||
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 {
|
||||
fn from(err: TlsHandshakeError<TcpStream>) -> Error {
|
||||
Error::TlsHandshake(err)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "tls")]
|
||||
#[cfg(feature = "native-tls")]
|
||||
impl From<TlsError> for Error {
|
||||
fn from(err: TlsError) -> Error {
|
||||
Error::Tls(err)
|
||||
|
|
@ -140,9 +140,9 @@ impl fmt::Display for Error {
|
|||
Error::Io(ref e) => fmt::Display::fmt(e, f),
|
||||
#[cfg(feature = "rustls-tls")]
|
||||
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),
|
||||
#[cfg(feature = "tls")]
|
||||
#[cfg(feature = "native-tls")]
|
||||
Error::TlsHandshake(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),
|
||||
|
|
@ -163,9 +163,9 @@ impl StdError for Error {
|
|||
Error::Io(ref e) => e.description(),
|
||||
#[cfg(feature = "rustls-tls")]
|
||||
Error::RustlsHandshake(ref e) => e.description(),
|
||||
#[cfg(feature = "tls")]
|
||||
#[cfg(feature = "native-tls")]
|
||||
Error::Tls(ref e) => e.description(),
|
||||
#[cfg(feature = "tls")]
|
||||
#[cfg(feature = "native-tls")]
|
||||
Error::TlsHandshake(ref e) => e.description(),
|
||||
Error::Parse(ref e) => e.description(),
|
||||
Error::Validate(ref e) => e.description(),
|
||||
|
|
@ -183,9 +183,9 @@ impl StdError for Error {
|
|||
Error::Io(ref e) => Some(e),
|
||||
#[cfg(feature = "rustls-tls")]
|
||||
Error::RustlsHandshake(ref e) => Some(e),
|
||||
#[cfg(feature = "tls")]
|
||||
#[cfg(feature = "native-tls")]
|
||||
Error::Tls(ref e) => Some(e),
|
||||
#[cfg(feature = "tls")]
|
||||
#[cfg(feature = "native-tls")]
|
||||
Error::TlsHandshake(ref e) => Some(e),
|
||||
Error::Parse(ParseError::DataNotUtf8(_, ref e)) => Some(e),
|
||||
_ => None,
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use crate::client::Session;
|
|||
use crate::error::{Error, Result};
|
||||
use crate::parse::parse_idle;
|
||||
use crate::types::UnsolicitedResponse;
|
||||
#[cfg(feature = "tls")]
|
||||
#[cfg(feature = "native-tls")]
|
||||
use native_tls::TlsStream;
|
||||
#[cfg(feature = "rustls-tls")]
|
||||
use rustls_connector::TlsStream as RustlsStream;
|
||||
|
|
@ -28,7 +28,7 @@ use std::time::Duration;
|
|||
///
|
||||
/// ```no_run
|
||||
/// use imap::extensions::idle;
|
||||
/// # #[cfg(feature = "tls")]
|
||||
/// # #[cfg(feature = "native-tls")]
|
||||
/// # {
|
||||
/// let client = imap::ClientBuilder::new("example.com", 993).native_tls()
|
||||
/// .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> {
|
||||
fn set_read_timeout(&mut self, timeout: Option<Duration>) -> Result<()> {
|
||||
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.
|
||||
//!
|
||||
//! ```no_run
|
||||
//! # #[cfg(feature = "tls")]
|
||||
//! # #[cfg(feature = "native-tls")]
|
||||
//! fn fetch_inbox_top() -> imap::error::Result<Option<String>> {
|
||||
//!
|
||||
//! let client = imap::ClientBuilder::new("imap.example.com", 993).native_tls()?;
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ use std::ops::RangeInclusive;
|
|||
///
|
||||
/// # Examples
|
||||
/// ```no_run
|
||||
/// # {} #[cfg(feature = "tls")]
|
||||
/// # {} #[cfg(feature = "native-tls")]
|
||||
/// # fn main() {
|
||||
/// # let client = imap::ClientBuilder::new("imap.example.com", 993)
|
||||
/// .native_tls().unwrap();
|
||||
|
|
|
|||
|
|
@ -456,7 +456,9 @@ fn status() {
|
|||
|
||||
// Test all valid fields except HIGHESTMODSEQ, which apparently
|
||||
// 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.exists, 0);
|
||||
assert_eq!(mb.recent, 0);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue