feat: Display Name / Alias for IMAP Accounts #306

This commit is contained in:
rustmailer
2026-06-25 02:00:20 +08:00
parent af089958e9
commit 8542ba0d28
12 changed files with 88 additions and 312 deletions
+9 -15
View File
@@ -87,14 +87,10 @@ impl FilterRule {
}
fn matches_exact(&self, value: &str) -> bool {
if !self.include.is_empty()
&& !self.include.iter().any(|e| e.eq_ignore_ascii_case(value))
{
if !self.include.is_empty() && !self.include.iter().any(|e| e.eq_ignore_ascii_case(value)) {
return false;
}
if !self.exclude.is_empty()
&& self.exclude.iter().any(|e| e.eq_ignore_ascii_case(value))
{
if !self.exclude.is_empty() && self.exclude.iter().any(|e| e.eq_ignore_ascii_case(value)) {
return false;
}
true
@@ -263,9 +259,11 @@ impl ArchiveRules {
}
fn matches_any_regex(patterns: &[String], value: &str) -> bool {
patterns
.iter()
.any(|p| regex::Regex::new(p).map(|re| re.is_match(value)).unwrap_or(false))
patterns.iter().any(|p| {
regex::Regex::new(p)
.map(|re| re.is_match(value))
.unwrap_or(false)
})
}
fn validate_patterns(patterns: &[String], field_name: &str) -> Result<(), String> {
@@ -584,6 +582,7 @@ impl Account {
.map(|account: AccountModel| MinimalAccount {
id: account.id,
email: account.email,
name: account.account_name,
})
.collect::<Vec<MinimalAccount>>();
Ok(result)
@@ -868,12 +867,7 @@ mod tests {
enabled: false,
..Default::default()
};
assert!(rules.should_archive(
Some("spam@x.com"),
Some("BUY NOW"),
999,
false
));
assert!(rules.should_archive(Some("spam@x.com"), Some("BUY NOW"), 999, false));
}
#[test]
+12 -3
View File
@@ -19,7 +19,9 @@
use std::str::FromStr;
use crate::account::entity::ImapConfig;
use crate::account::migration::{AccountModel, AccountType, ArchiveRules, ExtractionRules, QuotaWindow};
use crate::account::migration::{
AccountModel, AccountType, ArchiveRules, ExtractionRules, QuotaWindow,
};
use crate::account::since::{DateSince, RelativeDate};
use crate::error::code::ErrorCode;
use crate::error::BichonResult;
@@ -114,7 +116,10 @@ impl AccountCreateRequest {
}
if let Some(ref rules) = self.extraction_rules {
rules.validate().map_err(|e| {
raise_error!(format!("extraction_rules: {}", e), ErrorCode::InvalidParameter)
raise_error!(
format!("extraction_rules: {}", e),
ErrorCode::InvalidParameter
)
})?;
}
if let Some(ref rules) = self.archive_rules {
@@ -259,7 +264,10 @@ impl AccountUpdateRequest {
}
if let Some(ref rules) = self.extraction_rules {
rules.validate().map_err(|e| {
raise_error!(format!("extraction_rules: {}", e), ErrorCode::InvalidParameter)
raise_error!(
format!("extraction_rules: {}", e),
ErrorCode::InvalidParameter
)
})?;
}
if let Some(ref rules) = self.archive_rules {
@@ -293,6 +301,7 @@ fn validate_cron_expression(expr: &str) -> BichonResult<()> {
pub struct MinimalAccount {
pub id: u64,
pub email: String,
pub name: Option<String>,
}
pub fn filter_accessible_accounts<'a>(
+2
View File
@@ -296,6 +296,7 @@ async fn extract_envelope_core(
account_email: None,
mailbox_name: None,
content_hash: email_content_hash.clone(),
account_name: None,
};
// 'attachments' contains both regular and inline attachments
let ea = EnvelopeWithAttachments {
@@ -390,6 +391,7 @@ pub fn extract_envelope_from_nested_message(
regular_attachment_count: Default::default(),
tags: Default::default(),
account_email: Default::default(),
account_name: Default::default(),
mailbox_name: Default::default(),
content_hash: Default::default(),
};
+1
View File
@@ -404,6 +404,7 @@ impl NewIndexWriter {
regular_attachment_count: attachment_docs.len(),
tags: None,
account_email: None,
account_name: None,
mailbox_name: None,
content_hash: email_content_hash,
};
+1
View File
@@ -27,6 +27,7 @@ pub struct Envelope {
pub message_id: String,
pub account_id: u64,
pub account_email: Option<String>,
pub account_name: Option<String>,
pub mailbox_id: u64,
pub mailbox_name: Option<String>,
pub uid: u32,
+2 -1
View File
@@ -155,7 +155,8 @@ impl EnvelopeWithAttachments {
id: extract_string_field(doc, fields.f_id, F_ID)?,
message_id: extract_string_field(doc, fields.f_message_id, F_MESSAGE_ID)?,
account_id,
account_email: Some(account.email),
account_email: Some(account.email), //https://github.com/rustmailer/bichon/issues/306
account_name: account.account_name,
mailbox_id,
mailbox_name: Some(mailbox.name),
uid: extract_u64_field(doc, fields.f_uid, F_UID)? as u32,