fix: align forward params with backend, use Option<bool> for default handling

This commit is contained in:
rustmailer
2025-07-22 20:54:30 +08:00
parent 67285d3451
commit 4e80c6d979
6 changed files with 35 additions and 31 deletions
+1 -1
View File
@@ -105,7 +105,7 @@ impl TryFrom<&TaskMetaEntity> for SendEmailTask {
attachment_count: smtp_task.attachment_count,
cache_key: smtp_task.cache_key,
envelope: smtp_task.control.envelope,
save_to_sent: smtp_task.control.save_to_sent,
save_to_sent: smtp_task.control.save_to_sent.unwrap_or(false),
sent_folder: smtp_task.control.sent_folder,
send_at: smtp_task.control.send_at,
mta: smtp_task.control.mta,
+5 -5
View File
@@ -426,13 +426,13 @@ pub struct SendControl {
/// The email envelope containing sender and recipient addresses (SMTP `MAIL FROM` and `RCPT TO`).
pub envelope: Option<MailEnvelope>,
/// Whether to save a copy of the email to the sent folder after successful delivery.
pub save_to_sent: bool,
pub save_to_sent: Option<bool>,
/// The name of the folder where the email should be saved if `save_to_sent` is true.
/// If `None` and `save_to_sent` is true, a default folder (e.g., "Sent") may be used.
pub sent_folder: Option<String>,
/// Whether to perform a dry run (simulate sending without actual delivery).
/// Useful for testing email configurations without sending emails.
pub dry_run: bool,
pub dry_run: Option<bool>,
/// An optional Unix timestamp (milliseconds since epoch) specifying when to send the email.
/// If `None`, the email is sent immediately.
pub send_at: Option<i64>,
@@ -456,7 +456,7 @@ pub struct SendControl {
/// Note: This field only takes effect **if system-wide tracking is enabled** (`SETTINGS.rustmailer_email_tracking_enabled == true`).
/// If system tracking is disabled, this flag has no effect and no tracking will be inserted.
/// - This field is **only used when sending new emails**
pub enable_tracking: bool,
pub enable_tracking: Option<bool>,
}
impl SendControl {
@@ -522,7 +522,7 @@ impl SendControl {
account_id: u64,
body: &[u8],
) -> RustMailerResult<()> {
if self.save_to_sent {
if let Some(true) = self.save_to_sent {
let encoded_sent_folder = self.resolve_sent_mailbox(account_id).await?;
let executor = RUST_MAIL_CONTEXT.imap(account_id).await?;
executor
@@ -761,7 +761,7 @@ impl EmailHandler {
)
})?;
// Skip sending if dry_run is enabled; used for testing or simulation.
if send_control.dry_run {
if let Some(true) = send_control.dry_run {
return Ok(());
}
+20 -18
View File
@@ -212,26 +212,28 @@ impl EmailBuilder for SendEmailRequest {
}
let mut tracker: Option<EmailTracker> = None;
if self.send_control.enable_tracking && SETTINGS.rustmailer_email_tracking_enabled {
let campaign_id = self
.send_control
.campaign_id
.clone()
.unwrap_or_else(|| "default".to_string());
if let Some(true) = self.send_control.enable_tracking {
if SETTINGS.rustmailer_email_tracking_enabled {
let campaign_id = self
.send_control
.campaign_id
.clone()
.unwrap_or_else(|| "default".to_string());
let recipient_address = recipient
.to
.first()
.map(|r| r.address.clone())
.unwrap_or_default();
let recipient_address = recipient
.to
.first()
.map(|r| r.address.clone())
.unwrap_or_default();
tracker = Some(EmailTracker::new(
campaign_id,
message_id.clone(),
recipient_address,
account_id.into(),
account.email.clone(),
));
tracker = Some(EmailTracker::new(
campaign_id,
message_id.clone(),
recipient_address,
account_id.into(),
account.email.clone(),
));
}
}
builder = match &self.eml {