@@ -7,13 +7,13 @@ use std::net::TcpStream;
77use std:: result;
88use std:: str:: Utf8Error ;
99
10- use base64:: DecodeError ;
1110use bufstream:: IntoInnerError as BufError ;
1211use imap_proto:: { types:: ResponseCode , Response } ;
1312#[ cfg( feature = "native-tls" ) ]
1413use native_tls:: Error as TlsError ;
1514#[ cfg( feature = "native-tls" ) ]
1615use native_tls:: HandshakeError as TlsHandshakeError ;
16+ use rsasl:: prelude:: { SASLError , SessionError as SASLSessionError } ;
1717#[ cfg( feature = "rustls-tls" ) ]
1818use rustls_connector:: HandshakeError as RustlsHandshakeError ;
1919
@@ -92,6 +92,10 @@ pub enum Error {
9292 ConnectionLost ,
9393 /// Error parsing a server response.
9494 Parse ( ParseError ) ,
95+ /// Error occurred when tyring to set up authentication
96+ AuthenticationSetup ( SASLError ) ,
97+ /// Error occurred during authentication
98+ Authentication ( SASLSessionError ) ,
9599 /// Command inputs were not valid [IMAP
96100 /// strings](https://tools.ietf.org/html/rfc3501#section-4.3).
97101 Validate ( ValidateError ) ,
@@ -118,6 +122,17 @@ impl From<ParseError> for Error {
118122 }
119123}
120124
125+ impl From < SASLError > for Error {
126+ fn from ( err : SASLError ) -> Self {
127+ Error :: AuthenticationSetup ( err)
128+ }
129+ }
130+ impl From < SASLSessionError > for Error {
131+ fn from ( err : SASLSessionError ) -> Self {
132+ Error :: Authentication ( err)
133+ }
134+ }
135+
121136impl < T > From < BufError < T > > for Error {
122137 fn from ( err : BufError < T > ) -> Error {
123138 Error :: Io ( err. into ( ) )
@@ -170,6 +185,8 @@ impl fmt::Display for Error {
170185 Error :: Append => f. write_str ( "Could not append mail to mailbox" ) ,
171186 Error :: Unexpected ( ref r) => write ! ( f, "Unexpected Response: {:?}" , r) ,
172187 Error :: MissingStatusResponse => write ! ( f, "Missing STATUS Response" ) ,
188+ Error :: AuthenticationSetup ( ref e) => fmt:: Display :: fmt ( e, f) ,
189+ Error :: Authentication ( ref e) => fmt:: Display :: fmt ( e, f) ,
173190 }
174191 }
175192}
@@ -194,6 +211,8 @@ impl StdError for Error {
194211 Error :: Append => "Could not append mail to mailbox" ,
195212 Error :: Unexpected ( _) => "Unexpected Response" ,
196213 Error :: MissingStatusResponse => "Missing STATUS Response" ,
214+ Error :: AuthenticationSetup ( _) => "Failed to setup authentication" ,
215+ Error :: Authentication ( _) => "Authentication Failed" ,
197216 }
198217 }
199218
@@ -207,6 +226,8 @@ impl StdError for Error {
207226 #[ cfg( feature = "native-tls" ) ]
208227 Error :: TlsHandshake ( ref e) => Some ( e) ,
209228 Error :: Parse ( ParseError :: DataNotUtf8 ( _, ref e) ) => Some ( e) ,
229+ Error :: AuthenticationSetup ( ref e) => Some ( e) ,
230+ Error :: Authentication ( ref e) => Some ( e) ,
210231 _ => None ,
211232 }
212233 }
@@ -218,7 +239,7 @@ pub enum ParseError {
218239 /// Indicates an error parsing the status response. Such as OK, NO, and BAD.
219240 Invalid ( Vec < u8 > ) ,
220241 /// The client could not find or decode the server's authentication challenge.
221- Authentication ( String , Option < DecodeError > ) ,
242+ Authentication ( String ) ,
222243 /// The client received data that was not UTF-8 encoded.
223244 DataNotUtf8 ( Vec < u8 > , Utf8Error ) ,
224245}
@@ -227,7 +248,7 @@ impl fmt::Display for ParseError {
227248 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
228249 match * self {
229250 ParseError :: Invalid ( _) => f. write_str ( "Unable to parse status response" ) ,
230- ParseError :: Authentication ( _, _ ) => {
251+ ParseError :: Authentication ( _) => {
231252 f. write_str ( "Unable to parse authentication response" )
232253 }
233254 ParseError :: DataNotUtf8 ( _, _) => f. write_str ( "Unable to parse data as UTF-8 text" ) ,
@@ -239,17 +260,10 @@ impl StdError for ParseError {
239260 fn description ( & self ) -> & str {
240261 match * self {
241262 ParseError :: Invalid ( _) => "Unable to parse status response" ,
242- ParseError :: Authentication ( _, _ ) => "Unable to parse authentication response" ,
263+ ParseError :: Authentication ( _) => "Unable to parse authentication response" ,
243264 ParseError :: DataNotUtf8 ( _, _) => "Unable to parse data as UTF-8 text" ,
244265 }
245266 }
246-
247- fn cause ( & self ) -> Option < & dyn StdError > {
248- match * self {
249- ParseError :: Authentication ( _, Some ( ref e) ) => Some ( e) ,
250- _ => None ,
251- }
252- }
253267}
254268
255269/// An [invalid character](https://tools.ietf.org/html/rfc3501#section-4.3) was found in a command
0 commit comments