threads / bug / 60670

[BUG] Asks for "To" even if "To" already specified in letter

Subject: [BUG] Asks for "To" even if "To" already specified in letter

## tl;dr

2 messages between Dec 30, 2023 and Jan 2, 2024.

replies: 1people: 2as markdown or json

Askar Safin· Dec 30, 2023, 03:20 UTC · lore
Hi. I found a bug. Steps to reproduce:
- Create file /tmp/m with following text:
===
Subject: subj
To: example@example.com
text
===
- Send it using command "git send-email /tmp/m"

You will see that git asks for "To". git says: "To whom should the emails be sent (if anyone)?" I don't like this. git should just use "To" from /tmp/m without asking.

Seen with git 2.43.0.

If I execute "git send-email --to-cmd='#' /tmp/m" or "git send-email --to-cmd=':' /tmp/m" or "git send-email --to-cmd='true' /tmp/m", then "To" is not asked.

Same happens when I send one single patch without cover letter. Steps
to reproduce:
- Clone some repo
- Make some (single) commit
- Execute in the repo "git send-email --annotate HEAD^"
- Editor will be spawned. Add header "To: example@example.com", then
save and exit from the editor

You will see the question "To whom should the emails be sent (if anyone)?", too. And again you can workaround using --to-cmd tricks.

-- 
Askar Safin
Taylor Blau· Jan 2, 2024, 22:23 UTC · re: Askar Safin · lore

Re: [BUG] Asks for "To" even if "To" already specified in letter

On Sat, Dec 30, 2023 at 06:20:43AM +0300, Askar Safin wrote:
Show 19 quoted lines
> Hi. I found a bug. Steps to reproduce:
> - Create file /tmp/m with following text:
> ===
> Subject: subj
> To: example@example.com
>
> text
> ===
> - Send it using command "git send-email /tmp/m"
>
> You will see that git asks for "To". git says: "To whom should the
> emails be sent (if anyone)?"
> I don't like this. git should just use "To" from /tmp/m without asking.
>
> Seen with git 2.43.0.
>
> If I execute "git send-email --to-cmd='#' /tmp/m" or
> "git send-email --to-cmd=':' /tmp/m" or
> "git send-email --to-cmd='true' /tmp/m", then "To" is not asked.

I was going to suggest that you use the `--to-cmd=true` trick. I'm definitely not an expert in the send-email code, but from a cursory look, I think that this is do-able.

One thing you could do is read all of the messages ahead of time, parse their headers, and then extract any "To:" headers that you find. This is pretty similar to what the pre_process_file() function is already doing. But this might not be the right approach, since FIFOs can only be read once, and we already have some logic to handle FIFOs specially (see 3c8d3adeae (send-email: export patch counters in validate environment, 2023-04-14)).

But I think that something much simpler would work, which to avoid asking for a "To:" value altogether, even if one isn't provided. If you did something like:

--- 8< ---
diff --git a/git-send-email.perl b/git-send-email.perl
index 821b2b3a13..2941278315 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -1018,13 +1018,6 @@ sub file_declares_8bit_cte {

 my $to_whom = __("To whom should the emails be sent (if anyone)?");
 my $prompting = 0;
-if (!@initial_to && !defined $to_cmd) {
-	my $to = ask("$to_whom ",
-		     default => "",
-		     valid_re => qr/\@.*\./, confirm_only => 1);
-	push @initial_to, parse_address_line($to) if defined $to; # sanitized/validated later
-	$prompting++;
-}

 sub expand_aliases {
 	return map { expand_one_alias($_) } @_;
--- >8 ---

I think that would more or less do the trick. send-email will happily
continue on even without an initial $to value, and validate it later
when it's actually needed.

I'm not familiar enough with the code to know if this is the right
approach, so hopefully some other send-email experts can chime in and
let me know if I'm on the right track ;-).

Thanks,
Taylor

← back to recent threads