From 9f042df91b4a987dcb899f073d1a1d72a0dd016b Mon Sep 17 00:00:00 2001
From: Ben Wong <ben@wongs.net>
Date: Sun, 5 Jul 2026 16:44:39 -0700
Subject: [PATCH 2/3] Prevent argument injection from recipient address

Also, add a way to test both calls to _send_message() using prove.
---
 lib/Debbugs/Mail.pm | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/lib/Debbugs/Mail.pm b/lib/Debbugs/Mail.pm
index e4c8bf7..92f4954 100644
--- a/lib/Debbugs/Mail.pm
+++ b/lib/Debbugs/Mail.pm
@@ -368,9 +368,10 @@ sub send_mail_message{
 	  _send_message($param{message},
 			@sendmail_arguments,
 			$param{parse_for_recipients}?q(-t):(),
+			'--',
 			@recipients);
      };
-     return 1 unless $@;
+     return 1 unless $@ or $ENV{DEBUG_MAIL_RETRY_LOOP};
      # If there's only one recipient, there's nothing more we can do,
      # so bail out.
      warn $@ and return 0 if $@ and @recipients == 0;
@@ -379,9 +380,15 @@ sub send_mail_message{
      # case one of the @recipients is ok, but the addresses in the
      # mail message itself are malformed.
      my @errors;
-     for my $recipient ($param{parse_for_recipients}?q(-t):(),@recipients) {
+     if ($param{parse_for_recipients}) {
 	  eval {
-	       _send_message($param{message},@sendmail_arguments,$recipient);
+	       _send_message($param{message},@sendmail_arguments,'-t');
+	  };
+	  push @errors, "Sending with -t failed with $@" if $@;
+     }
+     for my $recipient (@recipients) {
+	  eval {
+	       _send_message($param{message},@sendmail_arguments,"--",$recipient);
 	  };
 	  push @errors, "Sending to $recipient failed with $@" if $@;
      }
-- 
2.53.0

