1use std::io::Error as IoError;
4use std::str::Utf8Error;
5
6use base64::DecodeError;
7
8pub type Result<T> = std::result::Result<T, Error>;
10
11#[derive(thiserror::Error, Debug)]
13#[non_exhaustive]
14pub enum Error {
15 #[error("io: {0}")]
17 Io(#[from] IoError),
18 #[error("bad response: {0}")]
20 Bad(String),
21 #[error("no response: {0}")]
23 No(String),
24 #[error("connection lost")]
26 ConnectionLost,
27 #[error("parse: {0}")]
29 Parse(#[from] ParseError),
30 #[error("validate: {0}")]
33 Validate(#[from] ValidateError),
34 #[error("could not append mail to mailbox")]
36 Append,
37}
38
39#[derive(thiserror::Error, Debug)]
41pub enum ParseError {
42 #[error("unable to parse status response")]
44 Invalid(Vec<u8>),
45 #[error("encountered unexpected parsed response: {0}")]
47 Unexpected(String),
48 #[error("unable to parse authentication response: {0} - {1:?}")]
50 Authentication(String, Option<DecodeError>),
51 #[error("unable to parse data ({0:?}) as UTF-8 text: {1:?}")]
53 DataNotUtf8(Vec<u8>, #[source] Utf8Error),
54 #[error("expected response not found for: {0}")]
56 ExpectedResponseNotFound(String),
57}
58
59#[derive(thiserror::Error, Debug)]
62#[error("invalid character in input: '{0}'")]
63pub struct ValidateError(pub char);
64
65#[cfg(test)]
66mod tests {
67 use super::*;
68
69 fn is_send<T: Send>(_t: T) {}
70
71 #[test]
72 fn test_send() {
73 is_send::<Result<usize>>(Ok(3));
74 }
75}