Fixed IMAP retrieval of auto-encrypted emails (fixes #203)

This commit is contained in:
mdecimus 2024-01-09 12:26:30 +01:00
parent f53ef18f61
commit c7be16692e
4 changed files with 23 additions and 17 deletions

View file

@ -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();

View file

@ -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 {

View file

@ -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

View file

@ -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