use crate::types::fetch::FetchResponse;
use crate::types::mailbox::MailboxInfo;
use crate::types::response::{Capability, ResponseCode, UidRange, UntaggedResponse};
#[derive(Debug, Clone)]
pub enum TypedEvent {
Alert(String),
Bye {
code: Option<ResponseCode>,
text: String,
},
NotificationOverflow { code: Option<String>, text: String },
QueueOverflow {
dropped_count: usize,
since: std::time::Instant,
},
Exists(u32),
Recent(u32),
Expunge(u32),
Vanished { earlier: bool, uids: Vec<UidRange> },
FetchUpdate(Box<FetchResponse>),
MailboxEvent(MailboxInfo),
MetadataChange {},
ServerMetadataChange {},
CapabilityChange(Vec<Capability>),
Extension(Box<UntaggedResponse>),
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(in crate::connection) enum Priority {
Critical,
Requeryable,
Resyncable,
}
impl From<UntaggedResponse> for TypedEvent {
fn from(resp: UntaggedResponse) -> Self {
match resp {
UntaggedResponse::Status {
status: crate::types::response::UntaggedStatus::Bye,
code,
text,
} => Self::Bye { code, text },
UntaggedResponse::Status {
code: Some(ResponseCode::Capability(caps)),
..
}
| UntaggedResponse::Capability(caps) => Self::CapabilityChange(caps),
UntaggedResponse::Exists(n) => Self::Exists(n),
UntaggedResponse::Recent(n) => Self::Recent(n),
UntaggedResponse::Expunge(n) => Self::Expunge(n),
UntaggedResponse::Fetch(f) => Self::FetchUpdate(f),
UntaggedResponse::List(info) | UntaggedResponse::Lsub(info) => Self::MailboxEvent(info),
UntaggedResponse::Vanished { earlier, uids } => Self::Vanished { earlier, uids },
other => Self::Extension(Box::new(other)),
}
}
}
impl TypedEvent {
pub(in crate::connection) fn priority(&self) -> Priority {
match self {
Self::Alert(_)
| Self::Bye { .. }
| Self::NotificationOverflow { .. }
| Self::QueueOverflow { .. } => Priority::Critical,
Self::CapabilityChange(_) => Priority::Requeryable,
Self::Exists(_)
| Self::Recent(_)
| Self::Expunge(_)
| Self::Vanished { .. }
| Self::FetchUpdate(_)
| Self::MailboxEvent(_)
| Self::MetadataChange { .. }
| Self::ServerMetadataChange { .. }
| Self::Extension(_) => Priority::Resyncable,
}
}
}