From 4e80c6d979d7c6be1cfc64ecc04060ba22f7c0ce Mon Sep 17 00:00:00 2001 From: rustmailer Date: Tue, 22 Jul 2025 20:54:30 +0800 Subject: [PATCH] fix: align forward params with backend, use Option for default handling --- protos/rustmailer.proto | 6 +-- src/modules/smtp/queue/message.rs | 2 +- src/modules/smtp/request/mod.rs | 10 ++--- src/modules/smtp/request/new.rs | 38 ++++++++++--------- .../event-hooks/components/mutate-drawer.tsx | 4 +- .../components/email-action-dialog.tsx | 6 ++- 6 files changed, 35 insertions(+), 31 deletions(-) diff --git a/protos/rustmailer.proto b/protos/rustmailer.proto index ba1d325..769efc5 100644 --- a/protos/rustmailer.proto +++ b/protos/rustmailer.proto @@ -1698,11 +1698,11 @@ message SendControl { // Optional: The mail envelope details for the SMTP transaction. optional MailEnvelope envelope = 1; // If true, saves the sent email to the 'Sent' folder of the sending account. - bool save_to_sent = 2; + optional bool save_to_sent = 2; // Optional: The name of the folder where the sent email should be saved (e.g., "Sent Items"). optional string sent_folder = 3; // If true, simulates the email sending process without actually sending. - bool dry_run = 4; + optional bool dry_run = 4; // Optional: The specific timestamp to schedule the email for sending (Unix timestamp). optional int64 send_at = 5; // Optional: The retry policy to apply if sending fails. @@ -1714,7 +1714,7 @@ message SendControl { // Optional: A campaign ID to associate with this email for tracking purposes. optional string campaign_id = 9; // If true, enables tracking (e.g., open tracking, link click tracking) for this email. - bool enable_tracking = 10; + optional bool enable_tracking = 10; } // MailEnvelope defines the sender and recipients for the SMTP transaction. diff --git a/src/modules/smtp/queue/message.rs b/src/modules/smtp/queue/message.rs index e4e15c2..8469852 100644 --- a/src/modules/smtp/queue/message.rs +++ b/src/modules/smtp/queue/message.rs @@ -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, diff --git a/src/modules/smtp/request/mod.rs b/src/modules/smtp/request/mod.rs index 0ec9e8e..e6d6bd0 100644 --- a/src/modules/smtp/request/mod.rs +++ b/src/modules/smtp/request/mod.rs @@ -426,13 +426,13 @@ pub struct SendControl { /// The email envelope containing sender and recipient addresses (SMTP `MAIL FROM` and `RCPT TO`). pub envelope: Option, /// 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, /// 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, /// 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, /// An optional Unix timestamp (milliseconds since epoch) specifying when to send the email. /// If `None`, the email is sent immediately. pub send_at: Option, @@ -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, } 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(()); } diff --git a/src/modules/smtp/request/new.rs b/src/modules/smtp/request/new.rs index 0848ac0..4b1baf1 100644 --- a/src/modules/smtp/request/new.rs +++ b/src/modules/smtp/request/new.rs @@ -212,26 +212,28 @@ impl EmailBuilder for SendEmailRequest { } let mut tracker: Option = 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 { diff --git a/web/src/features/event-hooks/components/mutate-drawer.tsx b/web/src/features/event-hooks/components/mutate-drawer.tsx index 8d928aa..70110f3 100644 --- a/web/src/features/event-hooks/components/mutate-drawer.tsx +++ b/web/src/features/event-hooks/components/mutate-drawer.tsx @@ -85,7 +85,7 @@ export function EventHooksMutateDrawer({ open, onOpenChange, currentRow }: Props const httpForm = useForm({ resolver: zodResolver(httpFormSchema), defaultValues: currentRow ? { - account_id: currentRow.account_id, + account_id: currentRow.account_id ?? undefined, description: currentRow.description ?? undefined, enabled: currentRow.enabled, global: currentRow.global === 1, @@ -101,7 +101,7 @@ export function EventHooksMutateDrawer({ open, onOpenChange, currentRow }: Props const natsForm = useForm({ resolver: zodResolver(natsFormSchema), defaultValues: currentRow ? { - account_id: currentRow.account_id, + account_id: currentRow.account_id ?? undefined, description: currentRow.description, enabled: currentRow.enabled, global: currentRow.global === 1, diff --git a/web/src/features/mailbox/components/email-action-dialog.tsx b/web/src/features/mailbox/components/email-action-dialog.tsx index 91ef6ea..a3173b6 100644 --- a/web/src/features/mailbox/components/email-action-dialog.tsx +++ b/web/src/features/mailbox/components/email-action-dialog.tsx @@ -131,7 +131,8 @@ export function EmailActionDialog({ include_all_attachments: false, send_control: { save_to_sent: false, - dry_run: false + dry_run: false, + enable_tracking: false } }); } else { @@ -145,7 +146,8 @@ export function EmailActionDialog({ include_all_attachments: false, send_control: { save_to_sent: false, - dry_run: false + dry_run: false, + enable_tracking: false } }); }