-pub fn middleware(input: &[u8]) -> Vec<u8> {
- let command = String::from_utf8_lossy(input);
- if command.contains("FIND MAILBOXES /*") {
- if let Some(tag) = command.split("FIND MAILBOXES /*").next() {
- let replacement = format!("{} LIST \"\" \"*\"\r\n", tag.trim());
- debug!("### {replacement}");
- return replacement.into_bytes();
+pub struct FindMailboxesCompatibility {
+ tags: Vec<String>,
+}
+
+impl FindMailboxesCompatibility {
+ pub fn new() -> Self {
+ FindMailboxesCompatibility { tags: vec![] }
+ }
+}
+
+impl Middleware for FindMailboxesCompatibility {
+ fn client_message(&mut self, input: &[u8]) -> Vec<u8> {
+ let command = String::from_utf8_lossy(input);
+ if command.contains("FIND MAILBOXES /*") {
+ if let Some(tag) = command.split("FIND MAILBOXES /*").next() {
+ // We'll need to convert the LIST to a FIND
+ self.tags.push(tag.to_string());
+ let replacement = format!("{} LIST \"\" \"*\"\r\n", tag.trim());
+ debug!("### {replacement}");
+ return replacement.into_bytes();
+ }
+ }
+ input.to_vec()
+ }
+
+ fn server_message(&mut self, input: &[u8]) -> Vec<u8> {
+ let command = String::from_utf8_lossy(input);
+ let contains_ok_completed = self
+ .tags
+ .iter()
+ .any(|tag| command.contains(&format!("{} OK Completed", tag)));
+
+ // We want to only modify responses that were a result of a MAILBOX call.
+ if !contains_ok_completed {
+ return input.to_vec();