Merge pull request #13 from miquelruiz/master

Try connection instead of unwrapping
This commit is contained in:
Matt McCoy 2016-06-05 19:20:39 -04:00
commit 8477a858f2

View file

@ -31,7 +31,7 @@ impl IMAPStream {
pub fn connect<S: Into<String>>(host: S, port: u16, ssl_context: Option<SslContext>) -> Result<IMAPStream> { pub fn connect<S: Into<String>>(host: S, port: u16, ssl_context: Option<SslContext>) -> Result<IMAPStream> {
let host_string = host.into(); let host_string = host.into();
let connect_string = format!("{}:{}", host_string, port); let connect_string = format!("{}:{}", host_string, port);
let tcp_stream = TcpStream::connect(&*connect_string).unwrap(); let tcp_stream = try!(TcpStream::connect(&*connect_string));
let mut socket = match ssl_context { let mut socket = match ssl_context {
Some(context) => IMAPStream { stream: IMAPStreamTypes::Ssl(SslStream::connect(&context, tcp_stream).unwrap()), host: host_string, port: port, tag: 1, tag_prefix: "a"}, Some(context) => IMAPStream { stream: IMAPStreamTypes::Ssl(SslStream::connect(&context, tcp_stream).unwrap()), host: host_string, port: port, tag: 1, tag_prefix: "a"},
None => IMAPStream { stream: IMAPStreamTypes::Basic(tcp_stream), host: host_string, port: port, tag: 1, tag_prefix: "a"}, None => IMAPStream { stream: IMAPStreamTypes::Basic(tcp_stream), host: host_string, port: port, tag: 1, tag_prefix: "a"},
@ -334,3 +334,9 @@ impl IMAPStream {
return command; return command;
} }
} }
#[test]
fn connect() {
let imap = IMAPStream::connect("this-is-not-an-imap-server", 143, None);
assert!(imap.is_err());
}