more shit

This commit is contained in:
Michael Zhang 2021-08-23 02:27:45 -05:00
parent 5aa54dbfe3
commit 22411cf4e3
Signed by: michael
GPG key ID: BDA47A31A3C8EE6B

View file

@ -16,6 +16,10 @@ pub type Atom = Bytes;
#[cfg_attr(feature = "fuzzing", derive(Arbitrary))] #[cfg_attr(feature = "fuzzing", derive(Arbitrary))]
pub struct Tag(pub Bytes); pub struct Tag(pub Bytes);
impl DisplayBytes for Tag {
fn display_bytes(&self, w: &mut dyn Write) -> io::Result<()> { write_bytes!(w, b"{}", self.0) }
}
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub struct Timestamp(DateTime<FixedOffset>); pub struct Timestamp(DateTime<FixedOffset>);
@ -64,10 +68,23 @@ impl DisplayBytes for Response {
} }
Ok(()) Ok(())
} }
Response::Condition(cond) => write_bytes!(w, b"* {}", cond), Response::Continue(cont) => write_bytes!(w, b"+ {}\r\n", cont),
Response::Condition(cond) => write_bytes!(w, b"* {}\r\n", cond),
Response::Done(done) => write_bytes!(w, b""), Response::Done(done) => write_bytes!(w, b""),
Response::MailboxData(data) => write_bytes!(w, b"* {}\r\n", data), Response::MailboxData(data) => write_bytes!(w, b"* {}\r\n", data),
Response::Expunge(n) => write_bytes!(w, b"{} EXPUNGE", n), Response::Fetch(n, attrs) => {
write_bytes!(w, b"{} FETCH (", n)?;
for (i, attr) in attrs.iter().enumerate() {
if i != 0 {
write_bytes!(w, b" ")?;
}
write_bytes!(w, b"{}", attr)?;
}
write_bytes!(w, b")\r\n")
}
Response::Expunge(n) => write_bytes!(w, b"{} EXPUNGE\r\n", n),
Response::Fatal(cond) => write_bytes!(w, b"* {}\r\n", cond),
Response::Tagged(tag, cond) => write_bytes!(w, b"{} {}\r\n", tag, cond),
_ => todo!(), _ => todo!(),
} }
} }
@ -80,6 +97,15 @@ pub struct ResponseText {
pub info: Bytes, pub info: Bytes,
} }
impl DisplayBytes for ResponseText {
fn display_bytes(&self, w: &mut dyn Write) -> io::Result<()> {
if let Some(code) = &self.code {
write_bytes!(w, b"[{}] ", code)?;
}
write_bytes!(w, b"{}", self.info)
}
}
#[derive(Debug)] #[derive(Debug)]
#[cfg_attr(feature = "fuzzing", derive(Arbitrary))] #[cfg_attr(feature = "fuzzing", derive(Arbitrary))]
pub enum MessageAttribute { pub enum MessageAttribute {
@ -96,6 +122,14 @@ pub enum MessageAttribute {
Uid(u32), Uid(u32),
} }
impl DisplayBytes for MessageAttribute {
fn display_bytes(&self, w: &mut dyn Write) -> io::Result<()> {
match self {
_ => todo!(),
}
}
}
#[derive(Debug)] #[derive(Debug)]
#[cfg_attr(feature = "fuzzing", derive(Arbitrary))] #[cfg_attr(feature = "fuzzing", derive(Arbitrary))]
pub struct Envelope { pub struct Envelope {
@ -194,6 +228,7 @@ pub enum ResponseCode {
impl DisplayBytes for ResponseCode { impl DisplayBytes for ResponseCode {
fn display_bytes(&self, w: &mut dyn Write) -> io::Result<()> { fn display_bytes(&self, w: &mut dyn Write) -> io::Result<()> {
match self { match self {
ResponseCode::Alert => write_bytes!(w, b"ALERT"),
_ => todo!(), _ => todo!(),
} }
} }
@ -249,6 +284,9 @@ impl DisplayBytes for MailboxData {
} }
write_bytes!(w, b")") write_bytes!(w, b")")
} }
MailboxData::List(list) => write_bytes!(w, b"{}", list),
MailboxData::Exists(n) => write_bytes!(w, b"{} EXISTS", n),
MailboxData::Recent(n) => write_bytes!(w, b"{} RECENT", n),
_ => todo!(), _ => todo!(),
} }
} }
@ -261,6 +299,15 @@ pub enum Mailbox {
Name(Bytes), Name(Bytes),
} }
impl DisplayBytes for Mailbox {
fn display_bytes(&self, w: &mut dyn Write) -> io::Result<()> {
match self {
Mailbox::Inbox => write_bytes!(w, b"INBOX"),
Mailbox::Name(b) => write_bytes!(w, b"{}", b),
}
}
}
#[derive(Debug)] #[derive(Debug)]
#[cfg_attr(feature = "fuzzing", derive(Arbitrary))] #[cfg_attr(feature = "fuzzing", derive(Arbitrary))]
pub enum Flag { pub enum Flag {
@ -297,6 +344,24 @@ pub struct MailboxList {
pub mailbox: Mailbox, pub mailbox: Mailbox,
} }
impl DisplayBytes for MailboxList {
fn display_bytes(&self, w: &mut dyn Write) -> io::Result<()> {
write_bytes!(w, b"(")?;
for (i, flag) in self.flags.iter().enumerate() {
if i != 0 {
write_bytes!(w, b" ")?;
}
write_bytes!(w, b"{}", flag)?;
}
write_bytes!(w, b") ")?;
match self.delimiter {
Some(d) => write_bytes!(w, b"\"{}\"", d)?,
None => write_bytes!(w, b"NIL")?,
}
write_bytes!(w, b" {}", self.mailbox)
}
}
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, PartialEq, Eq)]
#[cfg_attr(feature = "fuzzing", derive(Arbitrary))] #[cfg_attr(feature = "fuzzing", derive(Arbitrary))]
pub enum MailboxListFlag { pub enum MailboxListFlag {
@ -306,3 +371,15 @@ pub enum MailboxListFlag {
Unmarked, Unmarked,
Extension(Atom), Extension(Atom),
} }
impl DisplayBytes for MailboxListFlag {
fn display_bytes(&self, w: &mut dyn Write) -> io::Result<()> {
match self {
MailboxListFlag::NoInferiors => write_bytes!(w, b"\\Noinferiors"),
MailboxListFlag::NoSelect => write_bytes!(w, b"\\NoSelect"),
MailboxListFlag::Marked => write_bytes!(w, b"\\Marked"),
MailboxListFlag::Unmarked => write_bytes!(w, b"\\Unmarked"),
MailboxListFlag::Extension(a) => write_bytes!(w, b"\\{}", a),
}
}
}