This commit is contained in:
rustmailer
2026-04-05 16:06:07 +08:00
parent 8b4dc44c07
commit 286ae16057
38 changed files with 2634 additions and 3640 deletions
+1 -25
View File
@@ -22,7 +22,7 @@ use crate::modules::envelope::extractor::{
extract_envelope_from_nested_message, reattach_eml_content,
};
use crate::modules::error::code::ErrorCode;
use crate::modules::blob::envelope::Envelope;
use crate::modules::store::envelope::Envelope;
use crate::modules::utils::compute_content_hash;
use crate::{modules::error::BichonResult, raise_error};
use mail_parser::{MessageParser, MimeHeaders};
@@ -121,30 +121,6 @@ impl AttachmentInfo {
"other"
}
}
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct AttachmentDetail {
pub shard_id: usize,
pub info: AttachmentInfo,
}
impl AttachmentDetail {
pub fn from_row(row: &duckdb::Row) -> duckdb::Result<Self> {
Ok(Self {
shard_id: row.get("shard_id")?,
info: AttachmentInfo {
file_type: row.get("content_type")?,
inline: row.get("is_inline")?,
filename: row.get("filename")?,
size: row.get("size_bytes")?,
content_id: row.get("cid")?,
content_hash: row.get("content_hash")?,
is_message: row.get("is_message")?,
},
})
}
}
/// Represents the content of an email message in both plain text and HTML formats.
///
/// This struct contains optional fields for plain text and HTML versions of
+2 -11
View File
@@ -16,19 +16,10 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
use crate::modules::blob::manager::ENVELOPE_INDEX_MANAGER;
use crate::modules::blob::storage::BLOB_MANAGER;
use crate::modules::error::BichonResult;
use crate::modules::store::tantivy::manager::INDEX_MANAGER;
use std::collections::HashMap;
pub async fn delete_messages_impl(request: HashMap<u64, Vec<String>>) -> BichonResult<()> {
let content_hashes = ENVELOPE_INDEX_MANAGER
.get_orphan_hashes_in_memory(request.clone())
.await?;
if !content_hashes.is_empty() {
BLOB_MANAGER.delete(&content_hashes, &content_hashes)?;
}
ENVELOPE_INDEX_MANAGER
.delete_envelopes_multi_account(request)
.await
INDEX_MANAGER.delete_envelopes_multi_account(request).await
}
+7 -39
View File
@@ -16,53 +16,21 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
use crate::{
modules::{
account::migration::AccountModel,
error::{code::ErrorCode, BichonResult},
blob::{envelope::Envelope, manager::ENVELOPE_INDEX_MANAGER},
rest::response::DataPage,
},
raise_error,
use crate::modules::{
account::migration::AccountModel,
error::BichonResult,
rest::response::DataPage,
store::{envelope::Envelope, tantivy::manager::INDEX_MANAGER},
};
pub async fn list_messages_impl(
account_id: u64,
mailbox_id: u64,
page: u64,
page_size: u64,
) -> BichonResult<DataPage<Envelope>> {
AccountModel::check_account_exists(account_id).await?;
validate_pagination_params(page, page_size)?;
ENVELOPE_INDEX_MANAGER
.list_mailbox_envelopes(account_id, mailbox_id, page, page_size, true)
.await
}
fn validate_pagination_params(page: u64, page_size: u64) -> BichonResult<()> {
if page == 0 || page_size == 0 {
return Err(raise_error!(
"Both page and page_size must be greater than 0.".into(),
ErrorCode::InvalidParameter
));
}
if page_size > 500 {
return Err(raise_error!(
"The page_size exceeds the maximum allowed limit of 500.".into(),
ErrorCode::InvalidParameter
));
}
Ok(())
}
pub async fn get_thread_messages(
account_id: u64,
thread_id: String,
thread_id: &str,
page: u64,
page_size: u64,
) -> BichonResult<DataPage<Envelope>> {
AccountModel::check_account_exists(account_id).await?;
ENVELOPE_INDEX_MANAGER
INDEX_MANAGER
.list_thread_envelopes(account_id, thread_id, page, page_size, true)
.await
}
+3 -23
View File
@@ -16,17 +16,15 @@
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
use std::collections::HashSet;
use poem_openapi::{Enum, Object};
use serde::{Deserialize, Serialize};
use std::collections::HashSet;
use crate::{
modules::{
duckdb::init::duckdb,
error::{code::ErrorCode, BichonResult},
blob::{envelope::Envelope, manager::ENVELOPE_INDEX_MANAGER},
rest::response::DataPage,
store::{envelope::Envelope, tantivy::manager::INDEX_MANAGER},
},
raise_error,
};
@@ -85,24 +83,6 @@ impl SearchRequest {
));
}
let validate = |pattern: &Option<String>| -> BichonResult<()> {
if let Some(ref p) = pattern {
if duckdb()?.validate_regex(p).is_err() {
return Err(raise_error!(
"Invalid search pattern: The regular expression is not supported by DuckDB.".into(),
ErrorCode::InvalidParameter
));
}
}
Ok(())
};
validate(&self.filter.text)?;
validate(&self.filter.subject)?;
validate(&self.filter.body)?;
validate(&self.filter.from)?;
validate(&self.filter.to)?;
Ok(())
}
}
@@ -112,7 +92,7 @@ pub async fn search_messages_impl(
request: SearchRequest,
) -> BichonResult<DataPage<Envelope>> {
request.validate()?;
ENVELOPE_INDEX_MANAGER
INDEX_MANAGER
.search(
accounts,
request.filter,