-
Notifications
You must be signed in to change notification settings - Fork 88
Placed SSL/TLS dependencies behind a default feature flag #124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
extern crate imap; | ||
#[cfg(feature = "ssl")] | ||
extern crate native_tls; | ||
|
||
fn main() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
extern crate base64; | ||
extern crate imap; | ||
#[cfg(feature = "ssl")] | ||
extern crate native_tls; | ||
|
||
#[cfg(feature = "ssl")] | ||
use native_tls::TlsConnector; | ||
|
||
struct GmailOAuth2 { | ||
|
@@ -20,6 +21,7 @@ impl imap::Authenticator for GmailOAuth2 { | |
} | ||
} | ||
|
||
#[cfg(feature = "ssl")] | ||
fn main() { | ||
let gmail_auth = GmailOAuth2 { | ||
user: String::from("[email protected]"), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,9 @@ use std::string::FromUtf8Error; | |
use base64::DecodeError; | ||
use bufstream::IntoInnerError as BufError; | ||
use imap_proto::Response; | ||
#[cfg(feature = "ssl")] | ||
use native_tls::Error as TlsError; | ||
#[cfg(feature = "ssl")] | ||
use native_tls::HandshakeError as TlsHandshakeError; | ||
|
||
/// A convenience wrapper around `Result` for `imap::Error`. | ||
|
@@ -22,8 +24,10 @@ pub enum Error { | |
/// An `io::Error` that occurred while trying to read or write to a network stream. | ||
Io(IoError), | ||
/// An error from the `native_tls` library during the TLS handshake. | ||
#[cfg(feature = "ssl")] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This (and some of the other changes) would make the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes this is a tricky one to solve cleanly, especially without any breaking changes (split the enum into subset/superset relationship). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately crate authors do not have the option of choosing. Since |
||
TlsHandshake(TlsHandshakeError<TcpStream>), | ||
/// An error from the `native_tls` library while managing the socket. | ||
#[cfg(feature = "ssl")] | ||
Tls(TlsError), | ||
/// A BAD response from the IMAP server. | ||
Bad(String), | ||
|
@@ -58,12 +62,14 @@ impl<T> From<BufError<T>> for Error { | |
} | ||
} | ||
|
||
#[cfg(feature = "ssl")] | ||
impl From<TlsHandshakeError<TcpStream>> for Error { | ||
fn from(err: TlsHandshakeError<TcpStream>) -> Error { | ||
Error::TlsHandshake(err) | ||
} | ||
} | ||
|
||
#[cfg(feature = "ssl")] | ||
impl From<TlsError> for Error { | ||
fn from(err: TlsError) -> Error { | ||
Error::Tls(err) | ||
|
@@ -80,7 +86,9 @@ impl fmt::Display for Error { | |
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
match *self { | ||
Error::Io(ref e) => fmt::Display::fmt(e, f), | ||
#[cfg(feature = "ssl")] | ||
Error::Tls(ref e) => fmt::Display::fmt(e, f), | ||
#[cfg(feature = "ssl")] | ||
Error::TlsHandshake(ref e) => fmt::Display::fmt(e, f), | ||
Error::Validate(ref e) => fmt::Display::fmt(e, f), | ||
Error::No(ref data) | Error::Bad(ref data) => { | ||
|
@@ -95,7 +103,9 @@ impl StdError for Error { | |
fn description(&self) -> &str { | ||
match *self { | ||
Error::Io(ref e) => e.description(), | ||
#[cfg(feature = "ssl")] | ||
Error::Tls(ref e) => e.description(), | ||
#[cfg(feature = "ssl")] | ||
Error::TlsHandshake(ref e) => e.description(), | ||
Error::Parse(ref e) => e.description(), | ||
Error::Validate(ref e) => e.description(), | ||
|
@@ -109,7 +119,9 @@ impl StdError for Error { | |
fn cause(&self) -> Option<&StdError> { | ||
match *self { | ||
Error::Io(ref e) => Some(e), | ||
#[cfg(feature = "ssl")] | ||
Error::Tls(ref e) => Some(e), | ||
#[cfg(feature = "ssl")] | ||
Error::TlsHandshake(ref e) => Some(e), | ||
Error::Parse(ParseError::DataNotUtf8(ref e)) => Some(e), | ||
_ => None, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,21 @@ | ||
extern crate imap; | ||
extern crate lettre; | ||
extern crate lettre_email; | ||
#[cfg(feature = "ssl")] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it's probably fine for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good pickup, that makes sense. |
||
extern crate native_tls; | ||
|
||
use lettre::Transport; | ||
use std::net::TcpStream; | ||
|
||
#[cfg(feature = "ssl")] | ||
fn tls() -> native_tls::TlsConnector { | ||
native_tls::TlsConnector::builder() | ||
.danger_accept_invalid_certs(true) | ||
.build() | ||
.unwrap() | ||
} | ||
|
||
#[cfg(feature = "ssl")] | ||
fn session(user: &str) -> imap::Session<native_tls::TlsStream<TcpStream>> { | ||
let mut s = imap::connect("127.0.0.1:3993", "imap.example.com", &tls()) | ||
.unwrap() | ||
|
@@ -22,6 +25,7 @@ fn session(user: &str) -> imap::Session<native_tls::TlsStream<TcpStream>> { | |
s | ||
} | ||
|
||
#[cfg(feature = "ssl")] | ||
fn smtp(user: &str) -> lettre::SmtpTransport { | ||
let creds = lettre::smtp::authentication::Credentials::new(user.to_string(), user.to_string()); | ||
lettre::SmtpClient::new( | ||
|
@@ -43,6 +47,7 @@ fn connect_insecure() { | |
|
||
#[test] | ||
#[ignore] | ||
#[cfg(feature = "ssl")] | ||
fn connect_insecure_then_secure() { | ||
// ignored because of https://github.com/greenmail-mail-test/greenmail/issues/135 | ||
imap::connect_insecure("127.0.0.1:3143") | ||
|
@@ -52,6 +57,7 @@ fn connect_insecure_then_secure() { | |
} | ||
|
||
#[test] | ||
#[cfg(feature = "ssl")] | ||
fn connect_secure() { | ||
imap::connect("127.0.0.1:3993", "imap.example.com", &tls()).unwrap(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably better here to list the example in
Cargo.toml
withrequired-features = ["ssl"]
(assuming that works).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't know about
required-features
. Seems like that's a much better solution, thanks.