IMAP LIST-STATUS (RFC 5819) returns items in wrong order (fixes #1129)

This commit is contained in:
mdecimus 2025-01-27 19:31:34 +01:00
parent 14e3b3a852
commit b39d807600

View file

@ -150,15 +150,15 @@ impl TryFrom<&str> for Attribute {
type Error = (); type Error = ();
fn try_from(value: &str) -> Result<Self, Self::Error> { fn try_from(value: &str) -> Result<Self, Self::Error> {
match value { hashify::tiny_map!(value.as_bytes(),
"archive" => Ok(Attribute::Archive), "archive" => Attribute::Archive,
"drafts" => Ok(Attribute::Drafts), "drafts" => Attribute::Drafts,
"junk" => Ok(Attribute::Junk), "junk" => Attribute::Junk,
"sent" => Ok(Attribute::Sent), "sent" => Attribute::Sent,
"trash" => Ok(Attribute::Trash), "trash" => Attribute::Trash,
"important" => Ok(Attribute::Important), "important" => Attribute::Important,
_ => Err(()), )
} .ok_or(())
} }
} }
@ -249,13 +249,27 @@ impl ImapResponse for Response {
fn serialize(self) -> Vec<u8> { fn serialize(self) -> Vec<u8> {
let mut buf = Vec::with_capacity(100); let mut buf = Vec::with_capacity(100);
match (self.list_items.is_empty(), self.status_items.is_empty()) {
(false, false) => {
for (list_item, status_item) in self.list_items.iter().zip(self.status_items.iter())
{
list_item.serialize(&mut buf, self.is_rev2, self.is_lsub);
status_item.serialize(&mut buf, self.is_rev2);
}
}
(false, true) => {
for list_item in &self.list_items { for list_item in &self.list_items {
list_item.serialize(&mut buf, self.is_rev2, self.is_lsub); list_item.serialize(&mut buf, self.is_rev2, self.is_lsub);
} }
}
(true, false) => {
for status_item in &self.status_items { for status_item in &self.status_items {
status_item.serialize(&mut buf, self.is_rev2); status_item.serialize(&mut buf, self.is_rev2);
} }
}
_ => (),
}
buf buf
} }
} }
@ -365,8 +379,8 @@ mod tests {
}; };
let expected_v2 = concat!( let expected_v2 = concat!(
"* LIST (\\Subscribed) \"/\" \"INBOX\"\r\n", "* LIST (\\Subscribed) \"/\" \"INBOX\"\r\n",
"* LIST () \"/\" \"foo\" (\"CHILDINFO\" (\"SUBSCRIBED\"))\r\n",
"* STATUS \"INBOX\" (MESSAGES 17)\r\n", "* STATUS \"INBOX\" (MESSAGES 17)\r\n",
"* LIST () \"/\" \"foo\" (\"CHILDINFO\" (\"SUBSCRIBED\"))\r\n",
"* STATUS \"foo\" (MESSAGES 30 UNSEEN 29)\r\n", "* STATUS \"foo\" (MESSAGES 30 UNSEEN 29)\r\n",
); );
let expected_v1 = concat!( let expected_v1 = concat!(