From c7be16692e62dbaeedbbe8ec11ce81a455f95fc7 Mon Sep 17 00:00:00 2001 From: mdecimus Date: Tue, 9 Jan 2024 12:26:30 +0100 Subject: [PATCH] Fixed IMAP retrieval of auto-encrypted emails (fixes #203) --- crates/jmap/src/email/crypto.rs | 3 +-- crates/jmap/src/email/ingest.rs | 8 ++++++- resources/config/store/mysql.toml | 5 ++-- tests/resources/scripts/create_test_users.sh | 24 ++++++++++---------- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/crates/jmap/src/email/crypto.rs b/crates/jmap/src/email/crypto.rs index 5218668ba..3020721ec 100644 --- a/crates/jmap/src/email/crypto.rs +++ b/crates/jmap/src/email/crypto.rs @@ -87,13 +87,12 @@ pub struct EncryptionParams { pub certs: Vec>, } -#[async_trait::async_trait] +#[allow(async_fn_in_trait)] pub trait EncryptMessage { async fn encrypt(&self, params: &EncryptionParams) -> Result, EncryptMessageError>; fn is_encrypted(&self) -> bool; } -#[async_trait::async_trait] impl EncryptMessage for Message<'_> { async fn encrypt(&self, params: &EncryptionParams) -> Result, EncryptMessageError> { let root = self.root_part(); diff --git a/crates/jmap/src/email/ingest.rs b/crates/jmap/src/email/ingest.rs index 5f6132d0a..c55b8513e 100644 --- a/crates/jmap/src/email/ingest.rs +++ b/crates/jmap/src/email/ingest.rs @@ -31,7 +31,7 @@ use jmap_proto::{ }, }; use mail_parser::{ - parsers::fields::thread::thread_name, HeaderName, HeaderValue, Message, PartType, + parsers::fields::thread::thread_name, HeaderName, HeaderValue, Message, MessageParser, PartType, }; use rand::Rng; @@ -221,6 +221,12 @@ impl JMAP { Ok(new_raw_message) => { raw_message = Cow::from(new_raw_message); raw_message_len = raw_message.len() as i64; + message = MessageParser::default() + .parse(raw_message.as_ref()) + .ok_or_else(|| IngestError::Permanent { + code: [5, 5, 0], + reason: "Failed to parse encrypted e-mail message.".to_string(), + })?; // Remove contents from parsed message for part in &mut message.parts { diff --git a/resources/config/store/mysql.toml b/resources/config/store/mysql.toml index 356f4e185..1b291dafc 100644 --- a/resources/config/store/mysql.toml +++ b/resources/config/store/mysql.toml @@ -10,9 +10,10 @@ database = "stalwart" user = "root" password = "password" disable = true +#max-allowed-packet = 1073741824 -[store."mysql".timeout] -wait = "15s" +#[store."mysql".timeout] +#wait = "15s" #[store."mysql".pool] #max-connections = 10 diff --git a/tests/resources/scripts/create_test_users.sh b/tests/resources/scripts/create_test_users.sh index 177efb18d..508c4e30d 100644 --- a/tests/resources/scripts/create_test_users.sh +++ b/tests/resources/scripts/create_test_users.sh @@ -2,15 +2,15 @@ cargo run -p stalwart-cli -- -u https://127.0.0.1:443 -c admin:secret domain create example.org cargo run -p stalwart-cli -- -u https://127.0.0.1:443 -c admin:secret account create john 12345 -d "John Doe" -a john@example.org -a john.doe@example.org -#cargo run -p stalwart-cli -- -u https://127.0.0.1:8080 -c admin:secret account create jane abcde -d "Jane Doe" -a jane@example.org -#cargo run -p stalwart-cli -- -u https://127.0.0.1:8080 -c admin:secret account create bill xyz12 -d "Bill Foobar" -a bill@example.org -#cargo run -p stalwart-cli -- -u https://127.0.0.1:8080 -c admin:secret group create sales -d "Sales Department" -#cargo run -p stalwart-cli -- -u https://127.0.0.1:8080 -c admin:secret group create support -d "Technical Support" -#cargo run -p stalwart-cli -- -u https://127.0.0.1:8080 -c admin:secret account add-to-group john sales support -#cargo run -p stalwart-cli -- -u https://127.0.0.1:8080 -c admin:secret account remove-from-group john support -#cargo run -p stalwart-cli -- -u https://127.0.0.1:8080 -c admin:secret account add-email jane jane.doe@example.org -#cargo run -p stalwart-cli -- -u https://127.0.0.1:8080 -c admin:secret list create everyone everyone@example.org -#cargo run -p stalwart-cli -- -u https://127.0.0.1:8080 -c admin:secret list add-members everyone jane john bill -#cargo run -p stalwart-cli -- -u https://127.0.0.1:8080 -c admin:secret account list -#cargo run -p stalwart-cli -- -u https://127.0.0.1:8080 -c admin:secret import messages --format mbox john _ignore/dovecot-crlf -#cargo run -p stalwart-cli -- -u https://127.0.0.1:8080 -c admin:secret import messages --format maildir john /var/mail/john +#cargo run -p stalwart-cli -- -u https://127.0.0.1:443 -c admin:secret account create jane abcde -d "Jane Doe" -a jane@example.org +#cargo run -p stalwart-cli -- -u https://127.0.0.1:443 -c admin:secret account create bill xyz12 -d "Bill Foobar" -a bill@example.org +#cargo run -p stalwart-cli -- -u https://127.0.0.1:443 -c admin:secret group create sales -d "Sales Department" +#cargo run -p stalwart-cli -- -u https://127.0.0.1:443 -c admin:secret group create support -d "Technical Support" +#cargo run -p stalwart-cli -- -u https://127.0.0.1:443 -c admin:secret account add-to-group john sales support +#cargo run -p stalwart-cli -- -u https://127.0.0.1:443 -c admin:secret account remove-from-group john support +#cargo run -p stalwart-cli -- -u https://127.0.0.1:443 -c admin:secret account add-email jane jane.doe@example.org +#cargo run -p stalwart-cli -- -u https://127.0.0.1:443 -c admin:secret list create everyone everyone@example.org +#cargo run -p stalwart-cli -- -u https://127.0.0.1:443 -c admin:secret list add-members everyone jane john bill +#cargo run -p stalwart-cli -- -u https://127.0.0.1:443 -c admin:secret account list +#cargo run -p stalwart-cli -- -u https://127.0.0.1:443 -c admin:secret import messages --format mbox john _ignore/dovecot-crlf +#cargo run -p stalwart-cli -- -u https://127.0.0.1:443 -c admin:secret import messages --format maildir john /var/mail/john