Files
bichon/crates/cli/src/api/search.rs
rustmailer d40ba90b54 fix: inline attachment detection and account-scoped export
- Treat MIME parts with Content-ID but no Content-Disposition as inline
  - Add account_ids filter to CLI export search to avoid pulling all accounts
  - Skip failed emails during export instead of aborting the entire batch
2026-05-29 16:13:19 +08:00

59 lines
1.6 KiB
Rust

use bichon_core::{
common::paginated::DataPage,
message::search::{EmailSearchFilter, EmailSearchRequest, SortBy},
store::envelope::Envelope,
};
use reqwest::Client;
use crate::BichonCliConfig;
pub async fn search_messages(
client: &Client,
config: &BichonCliConfig,
account_ids: Option<std::collections::HashSet<u64>>,
page: u64,
page_size: u64,
) -> Option<DataPage<Envelope>> {
let url = format!("{}/api/v1/search-messages", config.base_url);
let payload = EmailSearchRequest {
filter: EmailSearchFilter {
account_ids,
..Default::default()
},
page,
page_size,
sort_by: Some(SortBy::DATE),
desc: Some(false),
};
match client
.post(&url)
.header("Authorization", format!("Bearer {}", config.api_token))
.json(&payload)
.send()
.await
{
Ok(res) if res.status().is_success() => match res.json::<DataPage<Envelope>>().await {
Ok(data) => Some(data),
Err(e) => {
eprintln!(" ✘ Failed to parse search response: {}", e);
None
}
},
Ok(res) => {
let status = res.status();
let error_body = res.text().await.unwrap_or_default();
eprintln!(
" ✘ Failed to search messages. Status: {}\n Server error: {}",
status, error_body
);
None
}
Err(e) => {
eprintln!(" ✘ Network error performing search: {}", e);
None
}
}
}