Store message headers in message metadata

This commit is contained in:
mdecimus
2024-03-02 16:45:41 +01:00
parent 875b1fa744
commit 62a4f70ac8
4 changed files with 33 additions and 49 deletions

View File

@@ -130,24 +130,17 @@ impl JMAP {
};
// Check if we need to fetch the raw headers or body
let mut needs_headers = false;
let mut needs_body = false;
for property in &properties {
match property {
Property::Header(_) | Property::Headers => {
needs_headers = true;
}
if matches!(
property,
Property::BodyValues
| Property::TextBody
| Property::HtmlBody
| Property::Attachments
| Property::BodyStructure => {
needs_body = true;
}
_ => (),
}
if needs_body {
| Property::TextBody
| Property::HtmlBody
| Property::Attachments
| Property::BodyStructure
) {
needs_body = true;
break;
}
}
@@ -175,14 +168,8 @@ impl JMAP {
};
// Retrieve raw message if needed
let raw_message = if needs_body || needs_headers {
let offset = if !needs_body {
metadata.contents.parts[0].offset_body as u32
} else {
u32::MAX
};
if let Some(raw_message) = self.get_blob(&metadata.blob_hash, 0..offset).await? {
let raw_message = if needs_body {
if let Some(raw_message) = self.get_blob(&metadata.blob_hash, 0..u32::MAX).await? {
raw_message
} else {
tracing::warn!(event = "not-found",
@@ -195,7 +182,7 @@ impl JMAP {
continue;
}
} else {
vec![]
metadata.raw_headers
};
let blob_id = BlobId {
hash: metadata.blob_hash.clone(),

View File

@@ -161,11 +161,18 @@ impl IndexMessage for BatchBuilder {
);
// Store message metadata
let root_part = message.root_part();
self.value(
Property::BodyStructure,
Bincode::new(MessageMetadata {
preview: preview.unwrap_or_default().into_owned(),
size: message.raw_message.len(),
raw_headers: message
.raw_message
.as_ref()
.get(root_part.offset_header..root_part.offset_body)
.unwrap_or_default()
.to_vec(),
contents: message.into(),
received_at,
has_attachments,

View File

@@ -42,6 +42,7 @@ pub struct MessageMetadata<'x> {
pub received_at: u64,
pub preview: String,
pub has_attachments: bool,
pub raw_headers: Vec<u8>,
}
#[derive(Debug, Serialize, Deserialize)]