diff --git a/crates/core/src/envelope/extractor.rs b/crates/core/src/envelope/extractor.rs index 9398f84..63b7ba3 100644 --- a/crates/core/src/envelope/extractor.rs +++ b/crates/core/src/envelope/extractor.rs @@ -89,6 +89,7 @@ async fn extract_envelope_core( account_id: u64, mailbox_id: u64, ) -> BichonResult<()> { + //The content hash of the original raw EML let email_content_hash = compute_content_hash(body); let message: Message<'_> = MessageParser::new().parse(body).ok_or_else(|| { raise_error!( @@ -391,8 +392,10 @@ pub async fn detach_and_store_attachments( for (raw_start, raw_end, att) in ranges { // Step 2: Extract raw bytes and store them as standalone documents let raw_bytes = &original_body[raw_start..raw_end]; + //This is the content hash of the decoded attachment, not the undecoded one. let content_hash = compute_content_hash(att.contents()); + //"The actual content stored in the blob is the raw undecoded data, to avoid the reconstructed EML differing from the original due to decoding and re-encoding. attachments.push((content_hash.clone(), Bytes::copy_from_slice(raw_bytes)));// // Step 3: Replace raw attachment content with a hash-based placeholder diff --git a/crates/core/src/store/tantivy/envelope.rs b/crates/core/src/store/tantivy/envelope.rs index c84be76..b73f967 100644 --- a/crates/core/src/store/tantivy/envelope.rs +++ b/crates/core/src/store/tantivy/envelope.rs @@ -214,7 +214,9 @@ impl IndexManager { } pub async fn queue(&self, doc: TantivyDocument) { - let _ = self.sender.send(doc).await; + if let Err(e) = self.sender.send(doc).await { + tracing::warn!(error = %e, "Failed to queue document into Tantivy writer channel"); + } } fn open_or_create_index(index_dir: &PathBuf) -> Index { @@ -887,11 +889,10 @@ impl IndexManager { eml.insert(content_hash); } } - let mut attachments: HashSet = HashSet::new(); for content_hash in attachments_content_hashes { // Check if any other emails still reference this content hash - let hash_term = Term::from_field_text(fields.f_content_hash, &content_hash); + let hash_term = Term::from_field_text(fields.f_attachment_content_hash, &content_hash); let hash_query = TermQuery::new(hash_term, IndexRecordOption::Basic); let count = searcher .search(&hash_query, &Count)