more shit
This commit is contained in:
parent
5aa54dbfe3
commit
22411cf4e3
1 changed files with 79 additions and 2 deletions
|
@ -16,6 +16,10 @@ pub type Atom = Bytes;
|
|||
#[cfg_attr(feature = "fuzzing", derive(Arbitrary))]
|
||||
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)]
|
||||
pub struct Timestamp(DateTime<FixedOffset>);
|
||||
|
||||
|
@ -64,10 +68,23 @@ impl DisplayBytes for Response {
|
|||
}
|
||||
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::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!(),
|
||||
}
|
||||
}
|
||||
|
@ -80,6 +97,15 @@ pub struct ResponseText {
|
|||
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)]
|
||||
#[cfg_attr(feature = "fuzzing", derive(Arbitrary))]
|
||||
pub enum MessageAttribute {
|
||||
|
@ -96,6 +122,14 @@ pub enum MessageAttribute {
|
|||
Uid(u32),
|
||||
}
|
||||
|
||||
impl DisplayBytes for MessageAttribute {
|
||||
fn display_bytes(&self, w: &mut dyn Write) -> io::Result<()> {
|
||||
match self {
|
||||
_ => todo!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[cfg_attr(feature = "fuzzing", derive(Arbitrary))]
|
||||
pub struct Envelope {
|
||||
|
@ -194,6 +228,7 @@ pub enum ResponseCode {
|
|||
impl DisplayBytes for ResponseCode {
|
||||
fn display_bytes(&self, w: &mut dyn Write) -> io::Result<()> {
|
||||
match self {
|
||||
ResponseCode::Alert => write_bytes!(w, b"ALERT"),
|
||||
_ => todo!(),
|
||||
}
|
||||
}
|
||||
|
@ -249,6 +284,9 @@ impl DisplayBytes for MailboxData {
|
|||
}
|
||||
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!(),
|
||||
}
|
||||
}
|
||||
|
@ -261,6 +299,15 @@ pub enum Mailbox {
|
|||
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)]
|
||||
#[cfg_attr(feature = "fuzzing", derive(Arbitrary))]
|
||||
pub enum Flag {
|
||||
|
@ -297,6 +344,24 @@ pub struct MailboxList {
|
|||
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)]
|
||||
#[cfg_attr(feature = "fuzzing", derive(Arbitrary))]
|
||||
pub enum MailboxListFlag {
|
||||
|
@ -306,3 +371,15 @@ pub enum MailboxListFlag {
|
|||
Unmarked,
|
||||
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),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue