Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
6 changes: 3 additions & 3 deletions src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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"),
Expand Down
10 changes: 5 additions & 5 deletions src/client_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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(())
Expand Down Expand Up @@ -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()?;
Expand Down
24 changes: 12 additions & 12 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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)
Expand All @@ -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),
Expand All @@ -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(),
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/extensions/idle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?;
Expand Down
2 changes: 1 addition & 1 deletion src/types/deleted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 3 additions & 1 deletion tests/imap_integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down