diff --git a/src/commands.rs b/src/commands.rs index ecfe991..535b9a6 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -40,6 +40,13 @@ pub fn build_cli(doc: &RestDescription) -> Command { .action(clap::ArgAction::SetTrue) .global(true), ) + .arg( + clap::Arg::new("draft-only") + .long("draft-only") + .help("Draft-only mode: strictly intercept and block any users.messages.send or users.drafts.send requests") + .action(clap::ArgAction::SetTrue) + .global(true), + ) .arg( clap::Arg::new("format") .long("format") diff --git a/src/helpers/gmail/mod.rs b/src/helpers/gmail/mod.rs index 3e8d327..bfcfcc0 100644 --- a/src/helpers/gmail/mod.rs +++ b/src/helpers/gmail/mod.rs @@ -579,6 +579,12 @@ pub(super) async fn send_raw_email( thread_id: Option<&str>, existing_token: Option<&str>, ) -> Result<(), GwsError> { + if matches.get_flag("draft-only") { + return Err(GwsError::Validation( + "Draft-only mode is enabled. Sending emails is blocked.".to_string(), + )); + } + let body = build_raw_send_body(raw_message, thread_id); let body_str = body.to_string(); diff --git a/src/main.rs b/src/main.rs index 9857daf..7acfc2d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -219,6 +219,17 @@ async fn run() -> Result<(), GwsError> { let dry_run = matched_args.get_flag("dry-run"); + let draft_only = matches.get_flag("draft-only") || matched_args.get_flag("draft-only"); + if draft_only { + if let Some(ref id) = method.id { + if id == "gmail.users.messages.send" || id == "gmail.users.drafts.send" { + return Err(GwsError::Validation( + "Draft-only mode is enabled. Sending emails is blocked.".to_string(), + )); + } + } + } + // Build pagination config from flags let pagination = parse_pagination_config(matched_args);