Skip to content

Commit

Permalink
Fixed IMAP retrieval of auto-encrypted emails (fixes #203)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdecimus committed Jan 9, 2024
1 parent f53ef18 commit c7be166
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 17 deletions.
3 changes: 1 addition & 2 deletions crates/jmap/src/email/crypto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,12 @@ pub struct EncryptionParams {
pub certs: Vec<Vec<u8>>,
}

#[async_trait::async_trait]
#[allow(async_fn_in_trait)]
pub trait EncryptMessage {
async fn encrypt(&self, params: &EncryptionParams) -> Result<Vec<u8>, EncryptMessageError>;
fn is_encrypted(&self) -> bool;
}

#[async_trait::async_trait]
impl EncryptMessage for Message<'_> {
async fn encrypt(&self, params: &EncryptionParams) -> Result<Vec<u8>, EncryptMessageError> {
let root = self.root_part();
Expand Down
8 changes: 7 additions & 1 deletion crates/jmap/src/email/ingest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions resources/config/store/mysql.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 12 additions & 12 deletions tests/resources/scripts/create_test_users.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 [email protected] -a [email protected]
#cargo run -p stalwart-cli -- -u https://127.0.0.1:8080 -c admin:secret account create jane abcde -d "Jane Doe" -a [email protected]
#cargo run -p stalwart-cli -- -u https://127.0.0.1:8080 -c admin:secret account create bill xyz12 -d "Bill Foobar" -a [email protected]
#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 [email protected]
#cargo run -p stalwart-cli -- -u https://127.0.0.1:8080 -c admin:secret list create everyone [email protected]
#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 [email protected]
#cargo run -p stalwart-cli -- -u https://127.0.0.1:443 -c admin:secret account create bill xyz12 -d "Bill Foobar" -a [email protected]
#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 [email protected]
#cargo run -p stalwart-cli -- -u https://127.0.0.1:443 -c admin:secret list create everyone [email protected]
#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

0 comments on commit c7be166

Please sign in to comment.