-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change the client builder so that it abstracts away connecting to TLS…
… or non-TLS connections and what TLS provider is used. - this allows a more transparent and versatile usage of the library as one can simply compile it as-is and then use the builder to configure where we connect and how we connect without having to be concerned about what type is used for the imap::Client / imap::Session
- Loading branch information
Showing
17 changed files
with
595 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -340,11 +340,23 @@ impl<T: Read + Write> Client<T> { | |
/// | ||
/// This consumes `self` since the Client is not much use without | ||
/// an underlying transport. | ||
pub(crate) fn into_inner(self) -> Result<T> { | ||
pub fn into_inner(self) -> Result<T> { | ||
let res = self.conn.stream.into_inner()?; | ||
Ok(res) | ||
} | ||
|
||
/// The [`CAPABILITY` command](https://tools.ietf.org/html/rfc3501#section-6.1.1) requests a | ||
/// listing of capabilities that the server supports. The server will include "IMAP4rev1" as | ||
/// one of the listed capabilities. See [`Capabilities`] for further details. | ||
/// | ||
/// This allows reading capabilities before authentication. | ||
pub fn capabilities(&mut self) -> Result<Capabilities> { | ||
// Create a temporary channel as we do not care about out of band responses before login | ||
let (mut tx, _rx) = mpsc::channel(); | ||
self.run_command_and_read_response("CAPABILITY") | ||
.and_then(|lines| Capabilities::parse(lines, &mut tx)) | ||
} | ||
|
||
/// Log in to the IMAP server. Upon success a [`Session`](struct.Session.html) instance is | ||
/// returned; on error the original `Client` instance is returned in addition to the error. | ||
/// This is because `login` takes ownership of `self`, so in order to try again (e.g. after | ||
|
@@ -355,7 +367,7 @@ impl<T: Read + Write> Client<T> { | |
/// # {} #[cfg(feature = "native-tls")] | ||
/// # fn main() { | ||
/// let client = imap::ClientBuilder::new("imap.example.org", 993) | ||
/// .native_tls().unwrap(); | ||
/// .connect().unwrap(); | ||
/// | ||
/// match client.login("user", "pass") { | ||
/// Ok(s) => { | ||
|
@@ -412,7 +424,7 @@ impl<T: Read + Write> Client<T> { | |
/// user: String::from("[email protected]"), | ||
/// access_token: String::from("<access_token>"), | ||
/// }; | ||
/// let client = imap::ClientBuilder::new("imap.example.com", 993).native_tls() | ||
/// let client = imap::ClientBuilder::new("imap.example.com", 993).connect() | ||
/// .expect("Could not connect to server"); | ||
/// | ||
/// match client.authenticate("XOAUTH2", &auth) { | ||
|
@@ -1821,6 +1833,31 @@ mod tests { | |
); | ||
} | ||
|
||
#[test] | ||
fn pre_login_capability() { | ||
let response = b"* CAPABILITY IMAP4rev1 STARTTLS AUTH=GSSAPI LOGINDISABLED\r\n\ | ||
a1 OK CAPABILITY completed\r\n" | ||
.to_vec(); | ||
let expected_capabilities = vec![ | ||
Capability::Imap4rev1, | ||
Capability::Atom(Cow::Borrowed("STARTTLS")), | ||
Capability::Auth(Cow::Borrowed("GSSAPI")), | ||
Capability::Atom(Cow::Borrowed("LOGINDISABLED")), | ||
]; | ||
let mock_stream = MockStream::new(response); | ||
let mut client = Client::new(mock_stream); | ||
let capabilities = client.capabilities().unwrap(); | ||
assert_eq!( | ||
client.stream.get_ref().written_buf, | ||
b"a1 CAPABILITY\r\n".to_vec(), | ||
"Invalid capability command" | ||
); | ||
assert_eq!(capabilities.len(), 4); | ||
for e in expected_capabilities { | ||
assert!(capabilities.has(&e)); | ||
} | ||
} | ||
|
||
#[test] | ||
fn login() { | ||
let response = b"a1 OK Logged in\r\n".to_vec(); | ||
|
Oops, something went wrong.