mirror of
https://github.com/rustmailer/bichon.git
synced 2026-08-03 07:48:34 +02:00
Fix eml ID conversion issue
This commit is contained in:
@@ -476,9 +476,9 @@ impl EmlIndexManager {
|
||||
Box::new(boolean_query)
|
||||
}
|
||||
|
||||
pub async fn get(&self, account_id: u64, eid: u64) -> BichonResult<Option<Vec<u8>>> {
|
||||
pub async fn get(&self, account_id: u64, eml_id: u64) -> BichonResult<Option<Vec<u8>>> {
|
||||
let searcher = self.reader.searcher();
|
||||
let query = self.envelope_query(account_id, eid);
|
||||
let query = self.envelope_query(account_id, eml_id);
|
||||
let docs = searcher
|
||||
.search(query.as_ref(), &TopDocs::with_limit(1))
|
||||
.map_err(|e| raise_error!(format!("{:#?}", e), ErrorCode::InternalError))?;
|
||||
@@ -510,9 +510,21 @@ impl EmlIndexManager {
|
||||
}
|
||||
|
||||
pub async fn get_reader(&self, account_id: u64, eid: u64) -> BichonResult<File> {
|
||||
let data = self.get(account_id, eid).await?.ok_or_else(|| {
|
||||
let envelope = duckdb()?
|
||||
.get_envelope_by_id(account_id, eid)?
|
||||
.ok_or_else(|| {
|
||||
raise_error!(
|
||||
format!(
|
||||
"Email envelope not found: account_id={} id={}",
|
||||
account_id, eid
|
||||
),
|
||||
ErrorCode::ResourceNotFound
|
||||
)
|
||||
})?;
|
||||
let eml_id = create_hash(account_id, &envelope.message_id);
|
||||
let data = self.get(account_id, eml_id).await?.ok_or_else(|| {
|
||||
raise_error!(
|
||||
format!("Email not found: account_id={}, eid={}", account_id, eid),
|
||||
format!("Eml not found: account_id={}, eid={}", account_id, eid),
|
||||
ErrorCode::ResourceNotFound
|
||||
)
|
||||
})?;
|
||||
@@ -539,7 +551,19 @@ impl EmlIndexManager {
|
||||
eid: u64,
|
||||
file_name: &str,
|
||||
) -> BichonResult<File> {
|
||||
let data = self.get(account_id, eid).await?.ok_or_else(|| {
|
||||
let envelope = duckdb()?
|
||||
.get_envelope_by_id(account_id, eid)?
|
||||
.ok_or_else(|| {
|
||||
raise_error!(
|
||||
format!(
|
||||
"Email envelope not found: account_id={} id={}",
|
||||
account_id, eid
|
||||
),
|
||||
ErrorCode::ResourceNotFound
|
||||
)
|
||||
})?;
|
||||
let eml_id = create_hash(account_id, &envelope.message_id);
|
||||
let data = self.get(account_id, eml_id).await?.ok_or_else(|| {
|
||||
raise_error!(
|
||||
format!("Email not found: account_id={}, eid={}", account_id, eid),
|
||||
ErrorCode::ResourceNotFound
|
||||
|
||||
@@ -5,6 +5,7 @@ use crate::{
|
||||
error::{code::ErrorCode, BichonResult},
|
||||
imap::executor::ImapExecutor,
|
||||
indexer::manager::{EML_INDEX_MANAGER, ENVELOPE_INDEX_MANAGER},
|
||||
utils::create_hash,
|
||||
},
|
||||
raise_error,
|
||||
};
|
||||
@@ -55,16 +56,13 @@ pub async fn restore_emails(account_id: u64, message_ids: Vec<u64>) -> BichonRes
|
||||
ErrorCode::ResourceNotFound
|
||||
)
|
||||
})?;
|
||||
|
||||
let eml_id = create_hash(account_id, &envelope.message_id);
|
||||
let eml = EML_INDEX_MANAGER
|
||||
.get(account_id, message_id)
|
||||
.get(account_id, eml_id)
|
||||
.await?
|
||||
.ok_or_else(|| {
|
||||
raise_error!(
|
||||
format!(
|
||||
"Email record not found: account_id={} id={}",
|
||||
account_id, message_id
|
||||
),
|
||||
format!("Eml not found: account_id={} id={}", account_id, message_id),
|
||||
ErrorCode::ResourceNotFound
|
||||
)
|
||||
})?;
|
||||
|
||||
@@ -206,6 +206,10 @@ pub async fn retrieve_email_content(account_id: u64, id: u64) -> BichonResult<Fu
|
||||
}
|
||||
}
|
||||
}
|
||||
//inline attachment will not be displayed in email attachment list
|
||||
if inline && attachment.content_id().is_some() {
|
||||
continue;
|
||||
}
|
||||
|
||||
attachments.push(AttachmentInfo {
|
||||
filename,
|
||||
|
||||
@@ -203,7 +203,7 @@ impl MessageApi {
|
||||
|
||||
/// Downloads the raw EML file of a specific email.
|
||||
#[oai(
|
||||
path = "/download-message/:account_id/:message_id",
|
||||
path = "/download-message/:account_id/:envelope_id",
|
||||
method = "get",
|
||||
operation_id = "download_message"
|
||||
)]
|
||||
@@ -212,7 +212,7 @@ impl MessageApi {
|
||||
/// The ID of the account.
|
||||
account_id: Path<u64>,
|
||||
/// The ID of the message to download.
|
||||
message_id: Path<u64>,
|
||||
envelope_id: Path<u64>,
|
||||
context: ClientContext,
|
||||
) -> ApiResult<Attachment<Body>> {
|
||||
let account_id = account_id.0;
|
||||
@@ -220,12 +220,12 @@ impl MessageApi {
|
||||
context
|
||||
.require_permission(Some(account_id), Permission::DATA_RAW_DOWNLOAD)
|
||||
.await?;
|
||||
let message_id = message_id.0;
|
||||
let reader = EML_INDEX_MANAGER.get_reader(account_id, message_id).await?;
|
||||
let envelope_id = envelope_id.0;
|
||||
let reader = EML_INDEX_MANAGER.get_reader(account_id, envelope_id).await?;
|
||||
let body = Body::from_async_read(reader);
|
||||
let attachment = Attachment::new(body)
|
||||
.attachment_type(AttachmentType::Attachment)
|
||||
.filename(format!("{message_id}.eml"));
|
||||
.filename(format!("{envelope_id}.eml"));
|
||||
Ok(attachment)
|
||||
}
|
||||
|
||||
@@ -250,7 +250,7 @@ impl MessageApi {
|
||||
|
||||
/// Downloads a specific attachment from an email. Requires `name` query parameter.
|
||||
#[oai(
|
||||
path = "/download-attachment/:account_id/:message_id",
|
||||
path = "/download-attachment/:account_id/:envelope_id",
|
||||
method = "get",
|
||||
operation_id = "download_attachment"
|
||||
)]
|
||||
@@ -259,7 +259,7 @@ impl MessageApi {
|
||||
/// The ID of the account.
|
||||
account_id: Path<u64>,
|
||||
/// The ID of the message containing the attachment.
|
||||
message_id: Path<u64>,
|
||||
envelope_id: Path<u64>,
|
||||
/// The filename of the attachment to download.
|
||||
name: Query<String>,
|
||||
context: ClientContext,
|
||||
@@ -271,7 +271,7 @@ impl MessageApi {
|
||||
.await?;
|
||||
let name = name.0.trim();
|
||||
let reader = EML_INDEX_MANAGER
|
||||
.get_attachment(account_id, message_id.0, name)
|
||||
.get_attachment(account_id, envelope_id.0, name)
|
||||
.await?;
|
||||
let body = Body::from_async_read(reader);
|
||||
let attachment = Attachment::new(body)
|
||||
|
||||
Reference in New Issue
Block a user