]> git.r.bdr.sh - rbdr/olden-mail/commitdiff
Add compatibility middleware
authorRuben Beltran del Rio <redacted>
Mon, 27 Jan 2025 15:55:41 +0000 (16:55 +0100)
committerRuben Beltran del Rio <redacted>
Mon, 27 Jan 2025 15:55:41 +0000 (16:55 +0100)
src/main.rs
src/middleware/find_mailboxes_compatibility.rs [new file with mode: 0644]
src/middleware/mod.rs [new file with mode: 0644]
src/proxy.rs

index 930f7e56fb1cbe05f274943101022ab4f6658667..832b6e239053cafbb52947d6baf198fb7d099373 100644 (file)
@@ -71,6 +71,7 @@ use std::process::exit;
 use std::sync::mpsc;
 
 mod configuration;
+mod middleware;
 mod proxy;
 
 use configuration::Configuration;
diff --git a/src/middleware/find_mailboxes_compatibility.rs b/src/middleware/find_mailboxes_compatibility.rs
new file mode 100644 (file)
index 0000000..f1a450b
--- /dev/null
@@ -0,0 +1,14 @@
+use log::debug;
+
+/// MailDrop can't find folders to sync because it sends FIND MAILBOXES /*
+/// which is not understood by modern servers. It instead replaces it with
+/// a LIST command.
+pub fn middleware(input: &[u8]) -> Vec<u8> {
+    let command = String::from_utf8_lossy(input);
+    if let Some(tag) = command.split("FIND MAILBOXES /*").next() {
+        let replacement = format!("{} LIST \"/INBOX\" \"*\"\r\n", tag.trim());
+        debug!("### {replacement}");
+        return replacement.into_bytes();
+    }
+    return input.to_vec();
+}
diff --git a/src/middleware/mod.rs b/src/middleware/mod.rs
new file mode 100644 (file)
index 0000000..a1070f4
--- /dev/null
@@ -0,0 +1,7 @@
+mod find_mailboxes_compatibility;
+
+use find_mailboxes_compatibility::middleware as find_mailboxes_compatibility_middleware;
+
+type Middleware = fn(&[u8]) -> Vec<u8>;
+
+pub const MIDDLEWARE: [Middleware; 1] = [find_mailboxes_compatibility_middleware];
index 255101531ad92be0a52e73d23d55a7bdc1998ea6..2798df372642f4abf497706ab8ad9cbe8624489a 100644 (file)
@@ -42,6 +42,7 @@ use std::thread::{sleep, spawn, JoinHandle};
 use std::time::Duration;
 
 use crate::configuration::Proxy;
+use crate::middleware::MIDDLEWARE;
 
 /// A proxy server that listens for plaintext connections and forwards them
 /// via TLS.
@@ -226,7 +227,13 @@ fn handle_client(client_stream: TcpStream, configuration: &Arc<Proxy>) {
                 }
             };
 
-            let debug_str = String::from_utf8_lossy(&buffer[..bytes_read])
+            let mut command = buffer[..bytes_read].to_vec();
+
+            for middleware in MIDDLEWARE {
+                command = middleware(&command);
+            }
+
+            let debug_str = String::from_utf8_lossy(&command)
                 .replace('\n', "\\n")
                 .replace('\r', "\\r")
                 .replace('\t', "\\t");