aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.rs1
-rw-r--r--src/middleware/find_mailboxes_compatibility.rs14
-rw-r--r--src/middleware/mod.rs7
-rw-r--r--src/proxy.rs9
4 files changed, 30 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index 930f7e5..832b6e2 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -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
index 0000000..f1a450b
--- /dev/null
+++ b/src/middleware/find_mailboxes_compatibility.rs
@@ -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
index 0000000..a1070f4
--- /dev/null
+++ b/src/middleware/mod.rs
@@ -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];
diff --git a/src/proxy.rs b/src/proxy.rs
index 2551015..2798df3 100644
--- a/src/proxy.rs
+++ b/src/proxy.rs
@@ -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");