{"thread":{"id":"58787","subject":"[PATCH 0/2] Expose header information to git-send-email's sendemail-validate hook","startedAt":"2022-11-11T02:15:27Z","lastAt":"2022-11-11T19:12:14Z","messageCount":5,"participants":["Strawbridge, Michael","Ævar Arnfjörð Bjarmason","Luben Tuikov"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"467107","messageId":"20221111021502.449662-1-michael.strawbridge@amd.com","threadId":"58787","inReplyTo":null,"subject":"[PATCH 0/2] Expose header information to git-send-email's sendemail-validate hook","fromName":"Strawbridge, Michael","fromEmail":"michael.strawbridge@amd.com","sentAt":"2022-11-11T02:15:20Z","receivedAt":"2022-11-11T02:15:27Z","isPatch":true,"sender":{"key":"michael.strawbridge@amd.com","avatar":null},"body":"Sure.  Thank you for the quick feedback.  Let me see if I can explain the idea.\n\nSometimes it can be helpful to react to special keywords in a git send-email subject line or specific email address.  Like perhaps one wants to do some kind of sorting of patches by mailing list or \"to\" email address.  You could use the sendemail-validate hook as a way to copy the patch to a specific location locally based on who you are emailing.  I'm sure there could be other uses for the smtp header information as well.  Presumably the header information is printed to stdout before sending an email, for other reasons too (this happens already).  My patch makes it possible to now automate any checks one might be doing manually with these headers.\n\nWith some testing I can confirm that encoded headers (like a utf8 string) get passed in encoded form.  The random example I tried was with the subject \"Rhyddhewch y racŵn\" and it is showns as \"Subject: [PATCH] =?UTF-8?q?Rhyddhewch=20y=20rac=C5=B5n?=\".  However, the original print of the smtp headers doesn't handle encoded text either, so it is no worse than current.\n\nLastly, with the validate code moving later there are some changes in output.  After my change, the user will get asked about: composed email (compose argument code), 8 bit encoding, who to send to, and which message-ID to reply to before validation.  Since these change the header information, validation needs to happen after.\n\nMichael\nPS- I fixed the Signed-off-by as well.\n\n\nMichael Strawbridge (2):\n  Expose header information to git-send-email's sendemail-validate hook\n  Update sendemail-validate hook docs to add header file parameter\n\n Documentation/githooks.txt |  8 +++---\n git-send-email.perl        | 57 +++++++++++++++++++++++++-------------\n 2 files changed, 41 insertions(+), 24 deletions(-)\n\nCc: Luben Tuikov <luben.tuikov@amd.com>\nCc: brian m. carlson <sandals@crustytoothpaste.net>\n\n-- \n2.34.1\n"},{"id":"467108","messageId":"20221111021502.449662-2-michael.strawbridge@amd.com","threadId":"58787","inReplyTo":"20221111021502.449662-1-michael.strawbridge@amd.com","subject":"[PATCH 1/2] Expose header information to git-send-email's sendemail-validate hook","fromName":"Strawbridge, Michael","fromEmail":"michael.strawbridge@amd.com","sentAt":"2022-11-11T02:15:25Z","receivedAt":"2022-11-11T02:15:36Z","isPatch":true,"sender":{"key":"michael.strawbridge@amd.com","avatar":null},"body":"To allow further flexibility in the git hook, the smtp header\ninformation of the email that git-send-email intends to send, is now\npassed as a 2nd argument to the sendemail-validate hook.\n\nAs an example, this can be useful for acting upon keywords in the\nsubject or specific email addresses.\n\nCc: Luben Tuikov <luben.tuikov@amd.com>\nCc: brian m. carlson <sandals@crustytoothpaste.net>\nSigned-off-by: Michael Strawbridge <michael.strawbridge@amd.com>\n---\n git-send-email.perl | 57 +++++++++++++++++++++++++++++----------------\n 1 file changed, 37 insertions(+), 20 deletions(-)\n\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex 5861e99a6e..3ce5b1aad3 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -787,14 +787,6 @@ sub is_format_patch_arg {\n \n @files = handle_backup_files(@files);\n \n-if ($validate) {\n-\tforeach my $f (@files) {\n-\t\tunless (-p $f) {\n-\t\t\tvalidate_patch($f, $target_xfer_encoding);\n-\t\t}\n-\t}\n-}\n-\n if (@files) {\n \tunless ($quiet) {\n \t\tprint $_,\"\\n\" for (@files);\n@@ -1495,16 +1487,7 @@ sub file_name_is_absolute {\n \treturn File::Spec::Functions::file_name_is_absolute($path);\n }\n \n-# Prepares the email, then asks the user what to do.\n-#\n-# If the user chooses to send the email, it's sent and 1 is returned.\n-# If the user chooses not to send the email, 0 is returned.\n-# If the user decides they want to make further edits, -1 is returned and the\n-# caller is expected to call send_message again after the edits are performed.\n-#\n-# If an error occurs sending the email, this just dies.\n-\n-sub send_message {\n+sub gen_header {\n \tmy @recipients = unique_email_list(@to);\n \t@cc = (grep { my $cc = extract_valid_address_or_die($_);\n \t\t      not grep { $cc eq $_ || $_ =~ /<\\Q${cc}\\E>$/ } @recipients\n@@ -1546,6 +1529,22 @@ sub send_message {\n \tif (@xh) {\n \t\t$header .= join(\"\\n\", @xh) . \"\\n\";\n \t}\n+\treturn $header;\n+}\n+\n+# Prepares the email, then asks the user what to do.\n+#\n+# If the user chooses to send the email, it's sent and 1 is returned.\n+# If the user chooses not to send the email, 0 is returned.\n+# If the user decides they want to make further edits, -1 is returned and the\n+# caller is expected to call send_message again after the edits are performed.\n+#\n+# If an error occurs sending the email, this just dies.\n+\n+sub send_message {\n+\tmy @recipients = unique_email_list(@to);\n+\n+        my $header = gen_header();\n \n \tmy @sendmail_parameters = ('-i', @recipients);\n \tmy $raw_from = $sender;\n@@ -1955,6 +1954,15 @@ sub process_file {\n \t\t}\n \t}\n \n+\n+\tif ($validate) {\n+\t\tforeach my $f (@files) {\n+\t\t\tunless (-p $f) {\n+\t\t\t\tvalidate_patch($f, $target_xfer_encoding);\n+\t\t\t}\n+\t\t}\n+\t}\n+\n \tmy $message_was_sent = send_message();\n \tif ($message_was_sent == -1) {\n \t\tdo_edit($t);\n@@ -2088,11 +2096,20 @@ sub validate_patch {\n \t\t\tchdir($repo->wc_path() or $repo->repo_path())\n \t\t\t\tor die(\"chdir: $!\");\n \t\t\tlocal $ENV{\"GIT_DIR\"} = $repo->repo_path();\n+\n+\t\t\tmy $header = gen_header();\n+\n+\t\t\trequire File::Temp;\n+\t\t\tmy ($header_filehandle, $header_filename) = File::Temp::tempfile(\n+                            \".gitsendemail.header.XXXXXX\", DIR => $repo->repo_path());\n+\t\t\tprint $header_filehandle $header;\n+\n \t\t\tmy @cmd = (\"git\", \"hook\", \"run\", \"--ignore-missing\",\n \t\t\t\t    $hook_name, \"--\");\n-\t\t\tmy @cmd_msg = (@cmd, \"<patch>\");\n-\t\t\tmy @cmd_run = (@cmd, $target);\n+\t\t\tmy @cmd_msg = (@cmd, \"<patch>\", \"<header>\");\n+\t\t\tmy @cmd_run = (@cmd, $target, $header_filename);\n \t\t\t$hook_error = system_or_msg(\\@cmd_run, undef, \"@cmd_msg\");\n+\t\t\tunlink($header_filehandle);\n \t\t\tchdir($cwd_save) or die(\"chdir: $!\");\n \t\t}\n \t\tif ($hook_error) {\n-- \n2.34.1\n"},{"id":"467109","messageId":"20221111021502.449662-3-michael.strawbridge@amd.com","threadId":"58787","inReplyTo":"20221111021502.449662-1-michael.strawbridge@amd.com","subject":"[PATCH 2/2] Update sendemail-validate hook docs to add header file parameter","fromName":"Strawbridge, Michael","fromEmail":"michael.strawbridge@amd.com","sentAt":"2022-11-11T02:15:27Z","receivedAt":"2022-11-11T02:15:39Z","isPatch":true,"sender":{"key":"michael.strawbridge@amd.com","avatar":null},"body":"Add documentation for the new smtp header file parameter used by the\nsendemail-validate git-send-email hook.\n\nsendemail-validate accepts the patch file as the first parameter (same as\nbefore) and now also adds the smtp header information as the second parameter.\n\nCc: Luben Tuikov <luben.tuikov@amd.com>\nCc: brian m. carlson <sandals@crustytoothpaste.net>\nSigned-off-by: Michael Strawbridge <michael.strawbridge@amd.com>\n---\n Documentation/githooks.txt | 8 ++++----\n 1 file changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/Documentation/githooks.txt b/Documentation/githooks.txt\nindex a16e62bc8c..c1baf34454 100644\n--- a/Documentation/githooks.txt\n+++ b/Documentation/githooks.txt\n@@ -583,10 +583,10 @@ processed by rebase.\n sendemail-validate\n ~~~~~~~~~~~~~~~~~~\n \n-This hook is invoked by linkgit:git-send-email[1].  It takes a single parameter,\n-the name of the file that holds the e-mail to be sent.  Exiting with a\n-non-zero status causes `git send-email` to abort before sending any\n-e-mails.\n+This hook is invoked by linkgit:git-send-email[1].  It takes two parameters,\n+the name of a file that holds the patch and the name of a file that holds the\n+smtp headers.  Exiting with a non-zero status causes `git send-email` to abort\n+before sending any e-mails.\n \n fsmonitor-watchman\n ~~~~~~~~~~~~~~~~~~\n-- \n2.34.1\n"},{"id":"467144","messageId":"221111.86sfipmsoe.gmgdl@evledraar.gmail.com","threadId":"58787","inReplyTo":"20221111021502.449662-3-michael.strawbridge@amd.com","subject":"Re: [PATCH 2/2] Update sendemail-validate hook docs to add header file parameter","fromName":"Ævar Arnfjörð Bjarmason","fromEmail":"avarab@gmail.com","sentAt":"2022-11-11T15:10:29Z","receivedAt":"2022-11-11T15:14:45Z","isPatch":true,"sender":{"key":"avarab@gmail.com","avatar":"https://avatars.githubusercontent.com/u/45301?v=4"},"body":"\nOn Fri, Nov 11 2022, Strawbridge, Michael wrote:\n\n> Add documentation for the new smtp header file parameter used by the\n> sendemail-validate git-send-email hook.\n>\n> sendemail-validate accepts the patch file as the first parameter (same as\n> before) and now also adds the smtp header information as the second parameter.\n>\n> Cc: Luben Tuikov <luben.tuikov@amd.com>\n> Cc: brian m. carlson <sandals@crustytoothpaste.net>\n> Signed-off-by: Michael Strawbridge <michael.strawbridge@amd.com>\n> ---\n>  Documentation/githooks.txt | 8 ++++----\n>  1 file changed, 4 insertions(+), 4 deletions(-)\n>\n> diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt\n> index a16e62bc8c..c1baf34454 100644\n> --- a/Documentation/githooks.txt\n> +++ b/Documentation/githooks.txt\n> @@ -583,10 +583,10 @@ processed by rebase.\n>  sendemail-validate\n>  ~~~~~~~~~~~~~~~~~~\n>  \n> -This hook is invoked by linkgit:git-send-email[1].  It takes a single parameter,\n> -the name of the file that holds the e-mail to be sent.  Exiting with a\n> -non-zero status causes `git send-email` to abort before sending any\n> -e-mails.\n> +This hook is invoked by linkgit:git-send-email[1].  It takes two parameters,\n> +the name of a file that holds the patch and the name of a file that holds the\n> +smtp headers.  Exiting with a non-zero status causes `git send-email` to abort\n> +before sending any e-mails.\n>  \n>  fsmonitor-watchman\n>  ~~~~~~~~~~~~~~~~~~\n\nAs this is just documenting the change in 1/2 after-the-fact, we really\nshould squash it into that.\n\nIf you are doing another commit, the better thing to do would be to\nfirst change the docs to say e.g.:\n\t\n\tThis hook is invoked by linkgit:git-send-email[1]. It's provided with\n\tthese parameters, in order:\n\t\n\t* A file that holds the....\n\t\nThen instead of your \"actual\" change being a reword change etc. you can\njust add another bullet-point.\n\nOr you could just squash this as-is...\n"},{"id":"467153","messageId":"3b73fc69-e6a4-125c-e101-bc0021801994@amd.com","threadId":"58787","inReplyTo":"20221111021502.449662-3-michael.strawbridge@amd.com","subject":"Re: [PATCH 2/2] Update sendemail-validate hook docs to add header file parameter","fromName":"Luben Tuikov","fromEmail":"luben.tuikov@amd.com","sentAt":"2022-11-11T19:12:06Z","receivedAt":"2022-11-11T19:12:14Z","isPatch":true,"sender":{"key":"luben.tuikov@amd.com","avatar":null},"body":"On 2022-11-10 21:15, Strawbridge, Michael wrote:\n> Add documentation for the new smtp header file parameter used by the\n> sendemail-validate git-send-email hook.\n> \n> sendemail-validate accepts the patch file as the first parameter (same as\n> before) and now also adds the smtp header information as the second parameter.\n> \n> Cc: Luben Tuikov <luben.tuikov@amd.com>\n> Cc: brian m. carlson <sandals@crustytoothpaste.net>\n> Signed-off-by: Michael Strawbridge <michael.strawbridge@amd.com>\n> ---\n>  Documentation/githooks.txt | 8 ++++----\n>  1 file changed, 4 insertions(+), 4 deletions(-)\n> \n> diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt\n> index a16e62bc8c..c1baf34454 100644\n> --- a/Documentation/githooks.txt\n> +++ b/Documentation/githooks.txt\n> @@ -583,10 +583,10 @@ processed by rebase.\n>  sendemail-validate\n>  ~~~~~~~~~~~~~~~~~~\n>  \n> -This hook is invoked by linkgit:git-send-email[1].  It takes a single parameter,\n> -the name of the file that holds the e-mail to be sent.  Exiting with a\n> -non-zero status causes `git send-email` to abort before sending any\n> -e-mails.\n> +This hook is invoked by linkgit:git-send-email[1].  It takes two parameters,\n> +the name of a file that holds the patch and the name of a file that holds the\n> +smtp headers.  Exiting with a non-zero status causes `git send-email` to abort\n> +before sending any e-mails.\n\nFix this: smtp --> SMTP\n\nRegards,\nLuben\n\n>  \n>  fsmonitor-watchman\n>  ~~~~~~~~~~~~~~~~~~\n\n"}]}