From patchwork Fri Jan 6 21:51:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Strawbridge X-Patchwork-Id: 13091836 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 46ED4C61DB3 for ; Fri, 6 Jan 2023 21:51:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236318AbjAFVvT (ORCPT ); Fri, 6 Jan 2023 16:51:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236034AbjAFVvP (ORCPT ); Fri, 6 Jan 2023 16:51:15 -0500 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2073.outbound.protection.outlook.com [40.107.220.73]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1494B44C72 for ; Fri, 6 Jan 2023 13:51:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ONkyuEapnbfzwhrwfsKGCTGlVW0GGfWn6CwlO/Hg17OIKOQn/VS1+1pR94QhQmS/zim7WWyH2+4LDV/fA8gC4lnSYC+5jshznWIXw1jnrNusiFRsGuhdcAn3TRdOwa3p+/Qdjya9NZkUYW+EMnRRJjytRvu/KSVIPYy8MA4kIXuKxGrxIPTxULoaeZRwEZ50Z0TpQc7ef4V+ZCVnjHEZ94eY5Fv78yVRMo1MM//JyjEcVw5ZdJThiXwk88/whhlufeQR+s4rlKo2V6WZdqkfr3VgOtpg0S6G8PA3Nv7v9OFx1V2pq2iALFKikVpgj4G7Qif8zigQ531KYvzITkmjww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=qYGAcDlatxRfocLH8Cj92E0Ez4ooFz2+8Nc0ljxVcjo=; b=aNyJcKSh7yaJaWTmF4fPxWMReTkOuTryJ3uSBOnKRRmBFuZlVfUoeILVyIdkflLMHZA5VXbITrpADQwIRGZUAFNUQezxFD3gC5Eza6KprmolMlABnukc5DY8/VI8g09O+PDL95Vb6ZekWIBcUyyRJBrANezhLT5eRlpARkrgCc91bzvlT/nh4KWodGcYgwtzcCr2scNuPnKXo73az1xtC9AC+v87kepcyk4No1f82ta6yqUp0r6Y9W5JLQiV+xKZ9zpFSW0RJ1IX3pfvwsWT0HgxzQOPWu5T7+fZM9PyJ7ugjvYdWDXIOZxOXOvd5evIVffR4td4Sle+YgkVCK1BIA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=amd.com; dmarc=pass action=none header.from=amd.com; dkim=pass header.d=amd.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=qYGAcDlatxRfocLH8Cj92E0Ez4ooFz2+8Nc0ljxVcjo=; b=DrEgRrrPxtEk80yCPMYzSuem9+T4+wzoeAOd2ZXfTwJzIaxUPLIdd2rIL7llciibSGRwMvdTc5FqjpfCR5R3CtrvsQQDznxM6EC5iJa7zGoBM2PuF+mTJNKiUK7fPeMWPsOzzNHpK1zDzZbej4iAoxhfn5ZIV1/Vjz82oQn8Vs4= Received: from DM6PR12MB4356.namprd12.prod.outlook.com (2603:10b6:5:2aa::8) by PH7PR12MB5976.namprd12.prod.outlook.com (2603:10b6:510:1db::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5944.19; Fri, 6 Jan 2023 21:51:10 +0000 Received: from DM6PR12MB4356.namprd12.prod.outlook.com ([fe80::b282:6c4:7660:583f]) by DM6PR12MB4356.namprd12.prod.outlook.com ([fe80::b282:6c4:7660:583f%7]) with mapi id 15.20.5944.019; Fri, 6 Jan 2023 21:51:10 +0000 From: "Strawbridge, Michael" To: "git@vger.kernel.org" CC: "Strawbridge, Michael" , "Tuikov, Luben" , "brian m . carlson" Subject: [PATCH v4 1/1] Expose header information to git-send-email's sendemail-validate hook Thread-Topic: [PATCH v4 1/1] Expose header information to git-send-email's sendemail-validate hook Thread-Index: AQHZIhj8wH+O6ZIJ1kuC1RewChzNZA== Date: Fri, 6 Jan 2023 21:51:09 +0000 Message-ID: <20230106215012.1079319-2-michael.strawbridge@amd.com> References: <20230106215012.1079319-1-michael.strawbridge@amd.com> In-Reply-To: <20230106215012.1079319-1-michael.strawbridge@amd.com> Accept-Language: en-GB, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.34.1 authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=amd.com; x-ms-publictraffictype: Email x-ms-traffictypediagnostic: DM6PR12MB4356:EE_|PH7PR12MB5976:EE_ x-ms-office365-filtering-correlation-id: 11de4563-968c-42dc-0ba2-08daf0301f56 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: ChxVCgVmWTIVD/83ygydPy8Ij9zdPIF4QmB4VS/kMgRMf6/2D3LSE2U7YJkgHVOzrZIvQx8aqZ8eohsqWP5L41AaZunNgObu+Sm4S1EqtwKoLGCVU8tNOutZIVFq2u/ESaGx79CziyP/DNW5deZouJDB3g/kb3kv656VZd0zuSVqR4jeutAAXriXJaPJiavrdvuOpDfdB40JxMSPHMEYzIvU9ifTJRvt2vUsj0jPSFMTgVAATK6Tky+aQVFnGcfY/7171pv5aoZRxYObvZZmnPrcl48rpKfp8S+wYAObKTVWSeTvxptr18FQ708lhKdhMurbnXXBaRGQvaGNXlcbuPVBj8hkPm4yKEtN5ieElCEqvIfnirD3RMOLIW2FZBAYNodSvKIomIBI4YNBAC4XQcvFQTXUu8aocXH/VmxJfa0ewZSNkgOZbYT1o12+bl73xDsYkvzfgSqFJPYKpOFON8kOSbwQ9yWFuAOPnLM8rkFBSLWHYL7fLpNcxOGqdZsKQrOsOny25njQWCsIxY8D3Ws7seDQewdU2o4ow3OkM4l76YAFRBbvq0/YfaOlAqeKenQRGgG+lQgiqCEF//qvCHRD2DO8mSc9Jvw+wnvBU4WCzaCp08zG61lACoKg9ogO2oFKx5Fy9fxwdb/JG+atG54VGmMTWhF9FRR9cPdekPk5GDyLu38RtPPoqBekdqOn2S1w3gUASIPHgJkJkZ0DOg== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DM6PR12MB4356.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(4636009)(376002)(39860400002)(136003)(346002)(396003)(366004)(451199015)(2616005)(316002)(186003)(6512007)(54906003)(478600001)(2906002)(15650500001)(1076003)(38070700005)(6916009)(8936002)(6486002)(26005)(5660300002)(83380400001)(91956017)(66476007)(66556008)(38100700002)(122000001)(64756008)(66946007)(4326008)(8676002)(66446008)(71200400001)(76116006)(6506007)(41300700001)(86362001)(36756003);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?hjrsSiLfvvu6cK3qXa91eDk?= =?iso-8859-1?q?QlDxTUzfsb1ihJAp8wE4OISDKDI0jX+U9P1lhtaLWZXo9y7JVreBDekZKWJP?= =?iso-8859-1?q?2w+6FxGoOcYwUJFTOychEePUYyxtLAweWxkcD/KiaXDcqemP0izpqSJjr0UK?= =?iso-8859-1?q?HPVjCo6yKo+gSyVc9AKgYg4jvQq+K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Dgt/dv?= =?iso-8859-1?q?kqyXFrVjaZbmSwLEgQ/A9LEUl2+rM9EBfgFCMoid92vj6Q7VxgzcswDHs8CC?= =?iso-8859-1?q?RDTK4T9KSKfybbg5aa+mqcOsvOI4KRTiQK8ebHxWdGtn/6F0FOv7bDeDehvY?= =?iso-8859-1?q?WiAoZoDr+7zQaK7dCvWsKcrA0KKIPQ7w5pceduIhrJLjK+Zp1oysd4PGRSuW?= =?iso-8859-1?q?ui0xHZ6HzFPNewDY37Tw69/l/FXjwhoLG2Sf7Bh4VTnVbY9dt7jFrpbUCNjd?= =?iso-8859-1?q?UrQaXNy48BvFriPrOG/5dOymjJbTdHnyf8rtAA4ASYlETduO7VDusG9h+JUI?= =?iso-8859-1?q?ZEt63EJs9orOl+O1bwFPthyF/pYyZMVkX/ckD8vBcSqqpuICkMNG/7uL2bQb?= =?iso-8859-1?q?SVVTdEjByzUv1hBLM6Iarf0qvhmT/sZGqTFu18F8OzpdWoLfHJOP6rjPrpVl?= =?iso-8859-1?q?7efiAVJer//Z/+N1WOtcmp0/zd9DdJlmVkPwKByRGIpDtPQs4WG/fHIW0QCl?= =?iso-8859-1?q?C8aJRm4abGfu66iT2seC5ehU480kvP925YjDOPC2MicQiWtlKFxJQ/HKWFgn?= =?iso-8859-1?q?bzICj8FUPW7US0VOG?= MIME-Version: 1.0 X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: DM6PR12MB4356.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 11de4563-968c-42dc-0ba2-08daf0301f56 X-MS-Exchange-CrossTenant-originalarrivaltime: 06 Jan 2023 21:51:10.0550 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: NZiMAg0+4WAGUwDjOQoNf60cvSz9EUV4r4pKfJ18TXfu9x+e6yGJrMVOMy3UINoxS6nm+waHovfEbsVBPx7nuQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB5976 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org To allow further flexibility in the git hook, the smtp header information of the email that git-send-email intends to send, is now passed as a 2nd argument to the sendemail-validate hook. A new t9001 test was added to test this 2nd arg and docs are also updated. As an example, this can be useful for acting upon keywords in the subject or specific email addresses. Cc: Luben Tuikov Cc: brian m. carlson Signed-off-by: Michael Strawbridge Reviewed-by: Luben Tuikov --- Documentation/githooks.txt | 8 +++--- git-send-email.perl | 55 +++++++++++++++++++++++++------------- t/t9001-send-email.sh | 25 +++++++++++++++++ 3 files changed, 65 insertions(+), 23 deletions(-) diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt index a16e62bc8c..346e536cbe 100644 --- a/Documentation/githooks.txt +++ b/Documentation/githooks.txt @@ -583,10 +583,10 @@ processed by rebase. sendemail-validate ~~~~~~~~~~~~~~~~~~ -This hook is invoked by linkgit:git-send-email[1]. It takes a single parameter, -the name of the file that holds the e-mail to be sent. Exiting with a -non-zero status causes `git send-email` to abort before sending any -e-mails. +This hook is invoked by linkgit:git-send-email[1]. It takes two parameters, +the name of a file that holds the patch and the name of a file that holds the +SMTP headers. Exiting with a non-zero status causes `git send-email` to abort +before sending any e-mails. fsmonitor-watchman ~~~~~~~~~~~~~~~~~~ diff --git a/git-send-email.perl b/git-send-email.perl index 5861e99a6e..5a626a4238 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -787,14 +787,6 @@ sub is_format_patch_arg { @files = handle_backup_files(@files); -if ($validate) { - foreach my $f (@files) { - unless (-p $f) { - validate_patch($f, $target_xfer_encoding); - } - } -} - if (@files) { unless ($quiet) { print $_,"\n" for (@files); @@ -1495,16 +1487,7 @@ sub file_name_is_absolute { return File::Spec::Functions::file_name_is_absolute($path); } -# Prepares the email, then asks the user what to do. -# -# If the user chooses to send the email, it's sent and 1 is returned. -# If the user chooses not to send the email, 0 is returned. -# If the user decides they want to make further edits, -1 is returned and the -# caller is expected to call send_message again after the edits are performed. -# -# If an error occurs sending the email, this just dies. - -sub send_message { +sub gen_header { my @recipients = unique_email_list(@to); @cc = (grep { my $cc = extract_valid_address_or_die($_); not grep { $cc eq $_ || $_ =~ /<\Q${cc}\E>$/ } @recipients @@ -1546,6 +1529,22 @@ sub send_message { if (@xh) { $header .= join("\n", @xh) . "\n"; } + my $recipients_ref = \@recipients; + return ($recipients_ref, $to, $date, $gitversion, $cc, $ccline, $header); +} + +# Prepares the email, then asks the user what to do. +# +# If the user chooses to send the email, it's sent and 1 is returned. +# If the user chooses not to send the email, 0 is returned. +# If the user decides they want to make further edits, -1 is returned and the +# caller is expected to call send_message again after the edits are performed. +# +# If an error occurs sending the email, this just dies. + +sub send_message { + my ($recipients_ref, $to, $date, $gitversion, $cc, $ccline, $header) = gen_header(); + my @recipients = @$recipients_ref; my @sendmail_parameters = ('-i', @recipients); my $raw_from = $sender; @@ -1955,6 +1954,15 @@ sub process_file { } } + + if ($validate) { + foreach my $f (@files) { + unless (-p $f) { + validate_patch($f, $target_xfer_encoding); + } + } + } + my $message_was_sent = send_message(); if ($message_was_sent == -1) { do_edit($t); @@ -2088,11 +2096,20 @@ sub validate_patch { chdir($repo->wc_path() or $repo->repo_path()) or die("chdir: $!"); local $ENV{"GIT_DIR"} = $repo->repo_path(); + + my ($recipients_ref, $to, $date, $gitversion, $cc, $ccline, $header) = gen_header(); + + require File::Temp; + my ($header_filehandle, $header_filename) = File::Temp::tempfile( + ".gitsendemail.header.XXXXXX", DIR => $repo->repo_path()); + print $header_filehandle $header; + my @cmd = ("git", "hook", "run", "--ignore-missing", $hook_name, "--"); my @cmd_msg = (@cmd, ""); - my @cmd_run = (@cmd, $target); + my @cmd_run = (@cmd, $target, $header_filename); $hook_error = system_or_msg(\@cmd_run, undef, "@cmd_msg"); + unlink($header_filehandle); chdir($cwd_save) or die("chdir: $!"); } if ($hook_error) { diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh index 1130ef21b3..11e68f9c18 100755 --- a/t/t9001-send-email.sh +++ b/t/t9001-send-email.sh @@ -565,6 +565,31 @@ test_expect_success $PREREQ "--validate respects absolute core.hooksPath path" ' test_cmp expect actual ' +test_expect_success $PREREQ "--validate hook supports header argument" ' + test_when_finished "rm my-hooks.ran" && + write_script my-hooks/sendemail-validate <<-\EOF && + filesize=$(stat -c%s "$2") + if [ "$filesize" != "0" ]; then + >my-hooks.ran + fi + exit 1 + EOF + test_config core.hooksPath "my-hooks" && + test_must_fail git send-email \ + --from="Example " \ + --to=nobody@example.com \ + --smtp-server="$(pwd)/fake.sendmail" \ + --validate \ + longline.patch 2>actual && + test_path_is_file my-hooks.ran && + cat >expect <<-EOF && + fatal: longline.patch: rejected by sendemail-validate hook + fatal: command '"'"'git hook run --ignore-missing sendemail-validate -- '"'"' died with exit code 1 + warning: no patches were sent + EOF + test_cmp expect actual +' + for enc in 7bit 8bit quoted-printable base64 do test_expect_success $PREREQ "--transfer-encoding=$enc produces correct header" '