1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
//! IMAP error types.
use std::io::Error as IoError;
use std::str::Utf8Error;
use base64::DecodeError;
/// A convenience wrapper around `Result` for `imap::Error`.
pub type Result<T> = std::result::Result<T, Error>;
/// A set of errors that can occur in the IMAP client
#[derive(thiserror::Error, Debug)]
#[non_exhaustive]
pub enum Error {
/// An `io::Error` that occurred while trying to read or write to a network stream.
#[error("io: {0}")]
Io(#[from] IoError),
/// A BAD response from the IMAP server.
#[error("bad response: {0}")]
Bad(String),
/// A NO response from the IMAP server.
#[error("no response: {0}")]
No(String),
/// The connection was terminated unexpectedly.
#[error("connection lost")]
ConnectionLost,
/// Error parsing a server response.
#[error("parse: {0}")]
Parse(#[from] ParseError),
/// Command inputs were not valid [IMAP
/// strings](https://tools.ietf.org/html/rfc3501#section-4.3).
#[error("validate: {0}")]
Validate(#[from] ValidateError),
/// Error appending an e-mail.
#[error("could not append mail to mailbox")]
Append,
}
/// An error occured while trying to parse a server response.
#[derive(thiserror::Error, Debug)]
pub enum ParseError {
/// Indicates an error parsing the status response. Such as OK, NO, and BAD.
#[error("unable to parse status response")]
Invalid(Vec<u8>),
/// An unexpected response was encountered.
#[error("encountered unexpected parsed response: {0}")]
Unexpected(String),
/// The client could not find or decode the server's authentication challenge.
#[error("unable to parse authentication response: {0} - {1:?}")]
Authentication(String, Option<DecodeError>),
/// The client received data that was not UTF-8 encoded.
#[error("unable to parse data ({0:?}) as UTF-8 text: {1:?}")]
DataNotUtf8(Vec<u8>, #[source] Utf8Error),
/// The expected response for X was not found
#[error("expected response not found for: {0}")]
ExpectedResponseNotFound(String),
}
/// An [invalid character](https://tools.ietf.org/html/rfc3501#section-4.3) was found in an input
/// string.
#[derive(thiserror::Error, Debug)]
#[error("invalid character in input: '{0}'")]
pub struct ValidateError(pub char);
#[cfg(test)]
mod tests {
use super::*;
fn is_send<T: Send>(_t: T) {}
#[test]
fn test_send() {
is_send::<Result<usize>>(Ok(3));
}
}