panorama/imap/src/proto/response.rs

171 lines
3.1 KiB
Rust
Raw Normal View History

use std::ops::RangeInclusive;
2021-08-08 02:17:36 +00:00
use chrono::{DateTime, FixedOffset};
use super::bytes::Bytes;
pub type Atom = Bytes;
2021-08-08 23:37:03 +00:00
2021-08-08 05:54:01 +00:00
#[derive(Clone, Debug)]
pub struct Tag(pub Bytes);
2021-08-08 02:17:36 +00:00
2021-08-08 05:54:01 +00:00
#[derive(Debug)]
2021-08-08 19:31:18 +00:00
#[non_exhaustive]
pub enum Response {
Capabilities(Vec<Capability>),
Continue(ResponseText),
Condition(Condition),
Done(ResponseDone),
MailboxData(MailboxData),
Fetch(u32, Vec<MessageAttribute>),
2021-08-08 23:37:03 +00:00
Expunge(u32),
Fatal(Condition),
Tagged(Tag, Condition),
2021-08-08 02:17:36 +00:00
}
2021-08-08 23:37:03 +00:00
#[derive(Debug)]
pub struct ResponseText {
pub code: Option<ResponseCode>,
pub info: Bytes,
2021-08-08 23:37:03 +00:00
}
#[derive(Debug)]
pub enum MessageAttribute {
BodySection,
BodyStructure,
2021-08-08 23:37:03 +00:00
Envelope(Envelope),
Flags(Vec<Flag>),
InternalDate(DateTime<FixedOffset>),
ModSeq(u64), // RFC 4551, section 3.3.2
Rfc822(Option<String>),
Rfc822Header(Option<String>),
Rfc822Size(u32),
Rfc822Text(Option<String>),
Uid(u32),
}
#[derive(Debug)]
pub struct Envelope {
pub date: Option<Bytes>,
pub subject: Option<Bytes>,
pub from: Option<Vec<Address>>,
pub sender: Option<Vec<Address>>,
pub reply_to: Option<Vec<Address>>,
pub to: Option<Vec<Address>>,
pub cc: Option<Vec<Address>>,
pub bcc: Option<Vec<Address>>,
pub in_reply_to: Option<Bytes>,
pub message_id: Option<Bytes>,
2021-08-08 23:37:03 +00:00
}
#[derive(Debug)]
pub struct Address {
pub name: Option<Bytes>,
pub adl: Option<Bytes>,
pub mailbox: Option<Bytes>,
pub host: Option<Bytes>,
}
2021-08-08 23:37:03 +00:00
2021-08-08 05:54:01 +00:00
#[derive(Debug)]
pub struct ResponseDone {
pub tag: Tag,
2021-08-08 02:17:36 +00:00
pub status: Status,
pub code: Option<ResponseCode>,
pub info: Option<Bytes>,
2021-08-08 02:17:36 +00:00
}
2021-08-08 19:31:18 +00:00
#[derive(Debug)]
pub struct Condition {
2021-08-08 19:31:18 +00:00
pub status: Status,
pub code: Option<ResponseCode>,
pub info: Bytes,
2021-08-08 19:31:18 +00:00
}
2021-08-08 05:54:01 +00:00
#[derive(Debug)]
2021-08-08 02:17:36 +00:00
pub enum Status {
Ok,
No,
Bad,
PreAuth,
Bye,
}
2021-08-08 05:54:01 +00:00
#[derive(Debug)]
2021-08-08 19:31:18 +00:00
#[non_exhaustive]
pub enum ResponseCode {
2021-08-08 03:26:42 +00:00
Alert,
BadCharset(Option<Vec<Bytes>>),
Capabilities(Vec<Capability>),
HighestModSeq(u64), // RFC 4551, section 3.1.1
Parse,
PermanentFlags(Vec<Bytes>),
ReadOnly,
ReadWrite,
TryCreate,
UidNext(u32),
UidValidity(u32),
Unseen(u32),
AppendUid(u32, Vec<UidSetMember>),
CopyUid(u32, Vec<UidSetMember>, Vec<UidSetMember>),
UidNotSticky,
Other(Bytes, Option<Bytes>),
2021-08-08 02:17:36 +00:00
}
2021-08-08 05:54:01 +00:00
#[derive(Debug)]
pub enum UidSetMember {
UidRange(RangeInclusive<u32>),
Uid(u32),
}
#[derive(Debug, PartialEq, Eq)]
pub enum Capability {
2021-08-08 02:17:36 +00:00
Imap4rev1,
Auth(Atom),
Atom(Atom),
2021-08-08 23:37:03 +00:00
}
#[derive(Debug)]
pub enum MailboxData {
Flags(Vec<Flag>),
List(MailboxList),
Lsub,
Search(Vec<u32>),
Status,
Exists(u32),
Recent(u32),
2021-08-08 23:37:03 +00:00
}
#[derive(Debug)]
pub enum Mailbox {
2021-08-08 23:37:03 +00:00
Inbox,
Name(Bytes),
2021-08-08 23:37:03 +00:00
}
#[derive(Debug)]
pub enum Flag {
2021-08-08 23:37:03 +00:00
Answered,
Flagged,
Deleted,
Seen,
Draft,
Recent,
Keyword(Atom),
Extension(Atom),
2021-08-08 23:37:03 +00:00
}
#[derive(Debug)]
pub struct MailboxList {
pub flags: Vec<MailboxListFlag>,
2021-08-08 23:37:03 +00:00
pub delimiter: Option<u8>,
pub mailbox: Mailbox,
2021-08-08 23:37:03 +00:00
}
#[derive(Debug)]
pub enum MailboxListFlag {
2021-08-08 23:37:03 +00:00
NoInferiors,
NoSelect,
Marked,
Unmarked,
Extension(Atom),
2021-08-08 02:17:36 +00:00
}