mirror of
https://github.com/rustmailer/bichon.git
synced 2026-08-03 07:48:34 +02:00
feat: add attachment search view
This commit is contained in:
@@ -17,9 +17,9 @@
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::modules::error::BichonResult;
|
||||
use crate::modules::store::tantivy::manager::INDEX_MANAGER;
|
||||
use crate::modules::store::tantivy::envelope::ENVELOPE_MANAGER;
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub async fn delete_messages_impl(request: HashMap<u64, Vec<String>>) -> BichonResult<()> {
|
||||
INDEX_MANAGER.delete_envelopes_multi_account(request).await
|
||||
ENVELOPE_MANAGER.delete_envelopes_multi_account(request).await
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ use crate::modules::{
|
||||
account::migration::AccountModel,
|
||||
error::BichonResult,
|
||||
rest::response::DataPage,
|
||||
store::{envelope::Envelope, tantivy::manager::INDEX_MANAGER},
|
||||
store::{envelope::Envelope, tantivy::envelope::ENVELOPE_MANAGER},
|
||||
};
|
||||
|
||||
pub async fn get_thread_messages(
|
||||
@@ -30,7 +30,7 @@ pub async fn get_thread_messages(
|
||||
page_size: u64,
|
||||
) -> BichonResult<DataPage<Envelope>> {
|
||||
AccountModel::check_account_exists(account_id).await?;
|
||||
INDEX_MANAGER
|
||||
ENVELOPE_MANAGER
|
||||
.list_thread_envelopes(account_id, thread_id, page, page_size, true)
|
||||
.await
|
||||
}
|
||||
|
||||
@@ -24,13 +24,18 @@ use crate::{
|
||||
modules::{
|
||||
error::{code::ErrorCode, BichonResult},
|
||||
rest::response::DataPage,
|
||||
store::{envelope::Envelope, tantivy::manager::INDEX_MANAGER},
|
||||
store::{
|
||||
envelope::Envelope,
|
||||
tantivy::{
|
||||
attachment::ATTACHMENT_MANAGER, envelope::ENVELOPE_MANAGER, model::AttachmentModel,
|
||||
},
|
||||
},
|
||||
},
|
||||
raise_error,
|
||||
};
|
||||
|
||||
#[derive(Debug, Clone, Default, Eq, PartialEq, Serialize, Deserialize, Object)]
|
||||
pub struct SearchFilter {
|
||||
pub struct EmailSearchFilter {
|
||||
pub text: Option<String>,
|
||||
pub subject: Option<String>,
|
||||
pub body: Option<String>,
|
||||
@@ -61,14 +66,14 @@ pub enum SortBy {
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Eq, PartialEq, Serialize, Deserialize, Object)]
|
||||
pub struct SearchRequest {
|
||||
filter: SearchFilter,
|
||||
pub struct EmailSearchRequest {
|
||||
filter: EmailSearchFilter,
|
||||
page: u64,
|
||||
page_size: u64,
|
||||
sort_by: Option<SortBy>,
|
||||
desc: Option<bool>,
|
||||
}
|
||||
impl SearchRequest {
|
||||
impl EmailSearchRequest {
|
||||
pub fn validate(&self) -> BichonResult<()> {
|
||||
if self.page == 0 || self.page_size == 0 {
|
||||
return Err(raise_error!(
|
||||
@@ -89,10 +94,81 @@ impl SearchRequest {
|
||||
|
||||
pub async fn search_messages_impl(
|
||||
accounts: Option<HashSet<u64>>,
|
||||
request: SearchRequest,
|
||||
request: EmailSearchRequest,
|
||||
) -> BichonResult<DataPage<Envelope>> {
|
||||
request.validate()?;
|
||||
INDEX_MANAGER
|
||||
ENVELOPE_MANAGER
|
||||
.search(
|
||||
accounts,
|
||||
request.filter,
|
||||
request.page,
|
||||
request.page_size,
|
||||
request.desc.unwrap_or(true),
|
||||
request.sort_by.unwrap_or(SortBy::DATE),
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Eq, PartialEq, Serialize, Deserialize, Object)]
|
||||
pub struct AttachmentSearchFilter {
|
||||
pub text: Option<String>,
|
||||
pub subject: Option<String>,
|
||||
pub from: Option<String>,
|
||||
pub since: Option<i64>,
|
||||
pub before: Option<i64>,
|
||||
pub account_ids: Option<HashSet<u64>>,
|
||||
pub mailbox_ids: Option<HashSet<u64>>,
|
||||
pub min_size: Option<u64>,
|
||||
pub max_size: Option<u64>,
|
||||
|
||||
pub attachment_name: Option<String>,
|
||||
|
||||
pub tags: Option<HashSet<String>>,
|
||||
pub attachment_extension: Option<String>,
|
||||
pub attachment_category: Option<String>,
|
||||
pub attachment_content_type: Option<String>,
|
||||
|
||||
pub is_ocr: Option<bool>,
|
||||
pub is_message: Option<bool>,
|
||||
pub has_text: Option<bool>,
|
||||
|
||||
pub min_page_count: Option<u64>,
|
||||
pub max_page_count: Option<u64>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Default, Eq, PartialEq, Serialize, Deserialize, Object)]
|
||||
pub struct AttachmentSearchRequest {
|
||||
filter: AttachmentSearchFilter,
|
||||
page: u64,
|
||||
page_size: u64,
|
||||
sort_by: Option<SortBy>,
|
||||
desc: Option<bool>,
|
||||
}
|
||||
impl AttachmentSearchRequest {
|
||||
pub fn validate(&self) -> BichonResult<()> {
|
||||
if self.page == 0 || self.page_size == 0 {
|
||||
return Err(raise_error!(
|
||||
"Both page and page_size must be greater than 0.".into(),
|
||||
ErrorCode::InvalidParameter
|
||||
));
|
||||
}
|
||||
if self.page_size > 500 {
|
||||
return Err(raise_error!(
|
||||
"The page_size exceeds the maximum allowed limit of 500.".into(),
|
||||
ErrorCode::InvalidParameter
|
||||
));
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn search_attachment_impl(
|
||||
accounts: Option<HashSet<u64>>,
|
||||
request: AttachmentSearchRequest,
|
||||
) -> BichonResult<DataPage<AttachmentModel>> {
|
||||
request.validate()?;
|
||||
ATTACHMENT_MANAGER
|
||||
.search(
|
||||
accounts,
|
||||
request.filter,
|
||||
|
||||
@@ -23,7 +23,7 @@ use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Clone, Default, Eq, PartialEq, Serialize, Deserialize, Object)]
|
||||
pub struct TagsRequest {
|
||||
pub updates: HashMap<u64, Vec<String>>, // account_id -> envelope_ids
|
||||
pub updates: HashMap<u64, Vec<String>>,
|
||||
pub tags: Vec<String>,
|
||||
pub action: TagAction,
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user