{"thread":{"id":"58789","subject":"[PATCH v2 0/2] Update sendemail-validate hook docs to add header file parameter","startedAt":"2022-11-11T19:30:56Z","lastAt":"2022-11-11T19:31:08Z","messageCount":3,"participants":["Strawbridge, Michael"],"isPatch":true,"patchVersion":2,"patchTotal":2},"messages":[{"id":"467154","messageId":"20221111193042.641898-1-michael.strawbridge@amd.com","threadId":"58789","inReplyTo":null,"subject":"[PATCH v2 0/2] Update sendemail-validate hook docs to add header file parameter","fromName":"Strawbridge, Michael","fromEmail":"michael.strawbridge@amd.com","sentAt":"2022-11-11T19:30:48Z","receivedAt":"2022-11-11T19:30:56Z","isPatch":true,"sender":{"key":"michael.strawbridge@amd.com","avatar":null},"body":"Changed smtp to SMTP.\n\nCc: Luben Tuikov <luben.tuikov@amd.com>\nCc: brian m. carlson <sandals@crustytoothpaste.net>\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\n-- \n2.34.1\n"},{"id":"467155","messageId":"20221111193042.641898-2-michael.strawbridge@amd.com","threadId":"58789","inReplyTo":"20221111193042.641898-1-michael.strawbridge@amd.com","subject":"[PATCH v2 1/2] Expose header information to git-send-email's sendemail-validate hook","fromName":"Strawbridge, Michael","fromEmail":"michael.strawbridge@amd.com","sentAt":"2022-11-11T19:30:58Z","receivedAt":"2022-11-11T19:31:05Z","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":"467156","messageId":"20221111193042.641898-3-michael.strawbridge@amd.com","threadId":"58789","inReplyTo":"20221111193042.641898-1-michael.strawbridge@amd.com","subject":"[PATCH v2 2/2] Update sendemail-validate hook docs to add header file parameter","fromName":"Strawbridge, Michael","fromEmail":"michael.strawbridge@amd.com","sentAt":"2022-11-11T19:31:00Z","receivedAt":"2022-11-11T19:31:08Z","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..346e536cbe 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"}]}