diff --git a/src/client.rs b/src/client.rs index a1206ac..01f4abd 100644 --- a/src/client.rs +++ b/src/client.rs @@ -31,7 +31,7 @@ impl IMAPStream { pub fn connect>(host: S, port: u16, ssl_context: Option) -> Result { let host_string = host.into(); 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 { 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"}, @@ -334,3 +334,9 @@ impl IMAPStream { return command; } } + +#[test] +fn connect() { + let imap = IMAPStream::connect("this-is-not-an-imap-server", 143, None); + assert!(imap.is_err()); +}