{"thread":{"id":"60670","subject":"[BUG] Asks for \"To\" even if \"To\" already specified in letter","startedAt":"2023-12-30T03:21:22Z","lastAt":"2024-01-02T22:23:30Z","messageCount":2,"participants":["Askar Safin","Taylor Blau"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"486166","messageId":"CAPnZJGBbA1VLAdP5mZnbF77-x-87JjU3Ku2MhrQu0SFoJL7ggw@mail.gmail.com","threadId":"60670","inReplyTo":null,"subject":"[BUG] Asks for \"To\" even if \"To\" already specified in letter","fromName":"Askar Safin","fromEmail":"safinaskar@gmail.com","sentAt":"2023-12-30T03:20:43Z","receivedAt":"2023-12-30T03:21:22Z","isPatch":false,"sender":{"key":"safinaskar@gmail.com","avatar":null},"body":"Hi. I found a bug. Steps to reproduce:\n- Create file /tmp/m with following text:\n===\nSubject: subj\nTo: example@example.com\n\ntext\n===\n- Send it using command \"git send-email /tmp/m\"\n\nYou will see that git asks for \"To\". git says: \"To whom should the\nemails be sent (if anyone)?\"\nI don't like this. git should just use \"To\" from /tmp/m without asking.\n\nSeen with git 2.43.0.\n\nIf I execute \"git send-email --to-cmd='#' /tmp/m\" or\n\"git send-email --to-cmd=':' /tmp/m\" or\n\"git send-email --to-cmd='true' /tmp/m\", then \"To\" is not asked.\n\nSame happens when I send one single patch without cover letter. Steps\nto reproduce:\n- Clone some repo\n- Make some (single) commit\n- Execute in the repo \"git send-email --annotate HEAD^\"\n- Editor will be spawned. Add header \"To: example@example.com\", then\nsave and exit from the editor\n\nYou will see the question \"To whom should the emails be sent (if\nanyone)?\", too. And again you can workaround using --to-cmd tricks.\n\n-- \nAskar Safin\n"},{"id":"486222","messageId":"ZZSM17hDYFklS9C8@nand.local","threadId":"60670","inReplyTo":"CAPnZJGBbA1VLAdP5mZnbF77-x-87JjU3Ku2MhrQu0SFoJL7ggw@mail.gmail.com","subject":"Re: [BUG] Asks for \"To\" even if \"To\" already specified in letter","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2024-01-02T22:23:19Z","receivedAt":"2024-01-02T22:23:30Z","isPatch":false,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"On Sat, Dec 30, 2023 at 06:20:43AM +0300, Askar Safin wrote:\n> Hi. I found a bug. Steps to reproduce:\n> - Create file /tmp/m with following text:\n> ===\n> Subject: subj\n> To: example@example.com\n>\n> text\n> ===\n> - Send it using command \"git send-email /tmp/m\"\n>\n> You will see that git asks for \"To\". git says: \"To whom should the\n> emails be sent (if anyone)?\"\n> I don't like this. git should just use \"To\" from /tmp/m without asking.\n>\n> Seen with git 2.43.0.\n>\n> If I execute \"git send-email --to-cmd='#' /tmp/m\" or\n> \"git send-email --to-cmd=':' /tmp/m\" or\n> \"git send-email --to-cmd='true' /tmp/m\", then \"To\" is not asked.\n\nI was going to suggest that you use the `--to-cmd=true` trick. I'm\ndefinitely not an expert in the send-email code, but from a cursory\nlook, I think that this is do-able.\n\nOne thing you could do is read all of the messages ahead of time, parse\ntheir headers, and then extract any \"To:\" headers that you find. This is\npretty similar to what the pre_process_file() function is already doing.\nBut this might not be the right approach, since FIFOs can only be read\nonce, and we already have some logic to handle FIFOs specially (see\n3c8d3adeae (send-email: export patch counters in validate environment,\n2023-04-14)).\n\nBut I think that something much simpler would work, which to avoid\nasking for a \"To:\" value altogether, even if one isn't provided. If you\ndid something like:\n\n--- 8< ---\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex 821b2b3a13..2941278315 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -1018,13 +1018,6 @@ sub file_declares_8bit_cte {\n\n my $to_whom = __(\"To whom should the emails be sent (if anyone)?\");\n my $prompting = 0;\n-if (!@initial_to && !defined $to_cmd) {\n-\tmy $to = ask(\"$to_whom \",\n-\t\t     default => \"\",\n-\t\t     valid_re => qr/\\@.*\\./, confirm_only => 1);\n-\tpush @initial_to, parse_address_line($to) if defined $to; # sanitized/validated later\n-\t$prompting++;\n-}\n\n sub expand_aliases {\n \treturn map { expand_one_alias($_) } @_;\n--- >8 ---\n\nI think that would more or less do the trick. send-email will happily\ncontinue on even without an initial $to value, and validate it later\nwhen it's actually needed.\n\nI'm not familiar enough with the code to know if this is the right\napproach, so hopefully some other send-email experts can chime in and\nlet me know if I'm on the right track ;-).\n\nThanks,\nTaylor\n"}]}