From patchwork Tue Jan 17 01:39:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Strawbridge X-Patchwork-Id: 13104034 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 4B4B2C67871 for ; Tue, 17 Jan 2023 01:40:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234945AbjAQBkC (ORCPT ); Mon, 16 Jan 2023 20:40:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235109AbjAQBjp (ORCPT ); Mon, 16 Jan 2023 20:39:45 -0500 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2066.outbound.protection.outlook.com [40.107.220.66]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34D552B601 for ; Mon, 16 Jan 2023 17:39:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=S5LM4+un0rvsBL5n02QB0ulfhBVLcM9CcOrkyUiJUcjfkQkJpowNv8B0CTHACdprnmm34lz0gVxT8nTWN2V7lJJ9BRe8XRbc0DR1FsH5kMJ9WkZIMgyqGgjoARV5T6PesKxAYIERZij0JN53EG2RLCO83h+/xueXlZk0WbDYUIvPTTq0E6EegzIQTWvVjigZ0bTuW1ZfHzzTIpNcCoLIu5kph1FWnuMF8uPLRBYm2u2lWkn9C/WAbqqPNlZRkRxTVj5UiAhPrp8bF7xd7jzMrLe5GI24FBFLfFrj9fWmp4k6YbaiD92v0QfRHhgekkVQ9KNvZUfVJ/TVD6rloEuTQw== 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=L9M+LtdeDtARP6sIeVV+OY/iK4R1+9zkz6iAYEq5W3s=; b=m2G2iBiFWvy0E/QNxzPq0y9JRceRofuRBHtvzHqBEQGs0hABjrHXjZVflnsTUFgysAP2n/wyT/omiCi2M39mUykda1YyIFFXmT0hBB5GyDn0duAuP4i4LztOLk8VPxDHgzUq4G5JqLwCY2pj/o/l4sUKW7KTHbvuwpgwYGUSpnil0hOG0wI4+y4aknkWpPxfJ/mrvFObYG0AJr9RNSUvmfbe1rnuHLVOpwk6bJ96TXEIVqdNefJ/98DijyDXisMgXsttQ9+yam3s5q6xePxezDoC6g5gLI4HwAtFgqycE7b5PgFKWA+IynqZx04rNtaEfeZ2RU82ENeA0tiBSuzH9g== 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=L9M+LtdeDtARP6sIeVV+OY/iK4R1+9zkz6iAYEq5W3s=; b=1Hz1usePLnne0a9OLdIZSQvn+LjjElaKM3OpMo3EC6M3IRnWYdztnc7AG9QtiM8Md7rxqUS9HYrEnLkKVQ98AU270AA6pr29nV1wwq7W5PURJAFEErBEu2vEZPke/LbHZ+0V7J+aHKBRJ9Ya70A6C+G93EImfroXoEPsarIdAqI= Received: from DM6PR12MB4356.namprd12.prod.outlook.com (2603:10b6:5:2aa::8) by DM6PR12MB5518.namprd12.prod.outlook.com (2603:10b6:5:1b9::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.13; Tue, 17 Jan 2023 01:39:41 +0000 Received: from DM6PR12MB4356.namprd12.prod.outlook.com ([fe80::5484:99ef:2b52:eb77]) by DM6PR12MB4356.namprd12.prod.outlook.com ([fe80::5484:99ef:2b52:eb77%3]) with mapi id 15.20.5986.019; Tue, 17 Jan 2023 01:39:41 +0000 From: "Strawbridge, Michael" To: "git@vger.kernel.org" CC: "Strawbridge, Michael" , "Tuikov, Luben" , Junio C Hamano Subject: [PATCH v6 1/2] send-email: refactor header generation functions Thread-Topic: [PATCH v6 1/2] send-email: refactor header generation functions Thread-Index: AQHZKhSRIu302wxjykuV6JI01Ath/g== Date: Tue, 17 Jan 2023 01:39:41 +0000 Message-ID: <20230117013932.47570-2-michael.strawbridge@amd.com> References: <20230117013932.47570-1-michael.strawbridge@amd.com> In-Reply-To: <20230117013932.47570-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_|DM6PR12MB5518:EE_ x-ms-office365-filtering-correlation-id: 3099e9d5-481c-4b88-9b8d-08daf82bb420 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: N/01c0ydFq1Yahb3Caphw9Azo6gSfqQ5ajuUhRTSaEGq5Yz7k39l5GD6AoUm+lhInjz6XwrckLYYAysRhn0bfmBAQrTykUtOH1qK+3vn2LVFV/m74YFXuB0SMRaPX5KZq+27UiPypvq1GS1I9HJydrCpWn8FrI2ZJn05gmDGigYWp7dSwfeQcVQRRLdJV/UJV1SLiS01fJc9ZyS8+2KbHrrz9RGPHlGuVgFjb6l9W04fkG1nSkLgop69bIlcDJnY0iRPeS4Uze5IleBhkrRzaxHCnLKCostsn4LUrUxr4lg+4FitDI3fL12FcFjBKTwbhmDn3Xn5W2Ia7tv1StWRAi1BWMoMjkLifpMKRGD58kEY0JJNFuzhK6IKGc/VLBU2oUxNlD+Uk0FmRgFQgdEpJAusDs2H4jBPIhpra6oRfGpRDBsPFyTysX5gkpojUvBmh6L7Hb65MmzNopatWjwyWkRLetBHGz1FjrH4mxR8L0ZY1JTod4NPJDZ6UkIj0/Flv0TzogtqfzfIg/4I0WEIlIjkJ55pbzjwaDXZa/M3HXxHHIp5JuQm0dDAO7W57vlZb3RORVE/B/vjz0/0Rjtv6O8ZP9/heK9Ysdt0PX/5B15/zRp/DAxNsl0yzp+rK5quhEdrYSLkmhiGM22ocCLMfdgq/xv6SC1rgsIvAio3ZndSaMko3Dxvdq9tNTyD0JCbcfNcY5PXdViMd6Y76i7xEA== 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)(366004)(346002)(136003)(396003)(39860400002)(451199015)(36756003)(478600001)(71200400001)(6486002)(54906003)(6512007)(26005)(6506007)(2906002)(41300700001)(8936002)(5660300002)(316002)(6916009)(4326008)(8676002)(91956017)(66946007)(66556008)(66476007)(66446008)(64756008)(76116006)(122000001)(186003)(38070700005)(38100700002)(2616005)(1076003)(86362001)(83380400001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?4MFmYvRRkjupJToWUve8NUn?= =?iso-8859-1?q?wVqOO3egJdjKK8FeAgCSMmkgYulpcedy/xNukOcV4mb61AyH6c+CVhqNh0Ub?= =?iso-8859-1?q?aeGQczMvqW+pZ4wVVbpSX51afZweKKAzF2aVrBaRqLXx24en5v249tKyb4r4?= =?iso-8859-1?q?7P/jqbp9FzkKFU2Yk6lbM0XFu09r4P7jAX71qWVgYlToMcxAfSIrG/X//rrV?= =?iso-8859-1?q?cb8uFgLfU1pFQIpM0xpRIt7V5JFOTZRhNkEXB3E8YUTLc/HPY6w0P0N2+eeh?= =?iso-8859-1?q?/TC2tniLAT7l5bSqRBjdDYRLGmSjZl0Y5hk4Dj7NYGwZroi8Q997eBOoc0Gd?= =?iso-8859-1?q?NF3RdrssNcFeoSnWTno4LgI66Cj1h9sP2wui6Kv5ge4xVK6vZO7AD13FzIQs?= =?iso-8859-1?q?WBGGOcXLpaL60r2BA2RwjMvWIJLKcgeo1Xc0yZddU+gpnptnJR9d46QPtaSV?= =?iso-8859-1?q?+eNlS46phaC+F3EH1eB5JlIojJUiF1+yCmc1vgrliArfsXHL3SP+4UfI2qOc?= =?iso-8859-1?q?ZuApN3fD31jg+eib7bjEnYAHTbZfU/f4UiCy87VM6kJQCihMrJjPqWp+kkaJ?= =?iso-8859-1?q?INB462hZ//wyg+K+4ESNjsOTr8uj6R+ylopmBM8E4TFNZvjfHzPyMhScst4E?= =?iso-8859-1?q?3SE9KZNIS0BPZCpvCtUNpdVy8uSDKCG8smGqxRWtx1ej4LapeihK8hlybVCM?= =?iso-8859-1?q?5yBFp4CLEBh2YePNuU1fF/uEx6puh6UmOhkuhKB5NKeJ/Kpnh2cz0XM9Q74N?= =?iso-8859-1?q?xVpoQeWPl+0Q2CxXola+X9PhBT67+KaFk/XvQJg0JXgz2jHFqj5kGZduNlAp?= =?iso-8859-1?q?zBljieOLjVC4uTxTq71QkTRXTNH+RljomBti3YN85wkJiCPnxTpO/6ooiHRr?= =?iso-8859-1?q?e4H39L0/vzzNPlNK+ItrwklvbBkKhAn37xvxCbifUwyOlzcPEEnAmOo778Ow?= =?iso-8859-1?q?MVNALGQq8fxyWFlyzKhEmz9Cp/GCmQzYY7CjJhtfclowFl9jyCjAJCsuft/s?= =?iso-8859-1?q?GsKRJGsGwNUWz/2zuBBvS7/Apr2IbbA9cAmmBQqFqUf6HGC1mzngrjUxOx9f?= =?iso-8859-1?q?4fPbnmSQPbY1JcocnnkAPcU13oLsGlPKse98DtrJmNkGrlNQBp9zyEz8YorC?= =?iso-8859-1?q?9TphQmz9BDTcLSFKLO6SN16OCw2avtPN2IFnDl3tlxqoQ2JutRkv0DrappvE?= =?iso-8859-1?q?0pvFoUAG8DaT7TeMyMpCmKtZ10vMBeyCL1r7zdxZs3SCTjC25Rv8PGrChGZv?= =?iso-8859-1?q?PmdHmeO5WgLcy9ajVZMmyk128jCBicHN7edvJvfnSEcbRRe+LDrXyH23Evsu?= =?iso-8859-1?q?JA/nFyOYZ3P4O7ihv6vGlI/r37nom1H47CXTwsrMRxKj8FeT0hp1Ck7Cn53Q?= =?iso-8859-1?q?2gRjH8KBEl8+CPlSPdonjTNrKauwP8Xu3FsG+Q8YC49SE4xlWc8O54ObnJKn?= =?iso-8859-1?q?jOWTlfGu3kvXHM9SgOATvtlH+2VTRq/9Bi4TbwcPkmW2rUIUM+xyzwlw28PX?= =?iso-8859-1?q?96Y9i4eQIIXnye2zJf7nRnZBo+oCSlDkOiqbiaggciGQNAe2CfsIpfM0kWPY?= =?iso-8859-1?q?aoMFvx9SLiKOy3FJzLXMAkEc4xOHmqyote66gBv0BhLsk+X+jsCbttlwHOsR?= =?iso-8859-1?q?g4if9zvY8ioYdm8gR?= 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: 3099e9d5-481c-4b88-9b8d-08daf82bb420 X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Jan 2023 01:39:41.5508 (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: hbGfIL4cHVJ26KSx+fnz1unqpWJPiVLik2Hl5/CsQFfYtZS2SLfBTYlzoLOB0oXRlhfq146sbWlghRozDhC5wQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB5518 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Split process_file and send_message into easier to use functions. Making SMTP header information more widely available. Cc: Luben Tuikov Cc: Junio C Hamano Signed-off-by: Michael Strawbridge --- git-send-email.perl | 49 ++++++++++++++++++++++++++++----------------- 1 file changed, 31 insertions(+), 18 deletions(-) diff --git a/git-send-email.perl b/git-send-email.perl index 5861e99a6e..810dd1f1ce 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -1495,16 +1495,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 +1537,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; @@ -1735,11 +1742,8 @@ sub send_message { $references = $initial_in_reply_to || ''; $message_num = 0; -# Prepares the email, prompts the user, sends it out -# Returns 0 if an edit was done and the function should be called again, or 1 -# otherwise. -sub process_file { - my ($t) = @_; +sub pre_process_file { + my ($t, $quiet) = @_; open my $fh, "<", $t or die sprintf(__("can't open file %s"), $t); @@ -1893,9 +1897,9 @@ sub process_file { } close $fh; - push @to, recipients_cmd("to-cmd", "to", $to_cmd, $t) + push @to, recipients_cmd("to-cmd", "to", $to_cmd, $t, $quiet) if defined $to_cmd; - push @cc, recipients_cmd("cc-cmd", "cc", $cc_cmd, $t) + push @cc, recipients_cmd("cc-cmd", "cc", $cc_cmd, $t, $quiet) if defined $cc_cmd && !$suppress_cc{'cccmd'}; if ($broken_encoding{$t} && !$has_content_type) { @@ -1954,6 +1958,15 @@ sub process_file { @initial_to = @to; } } +} + +# Prepares the email, prompts the user, sends it out +# Returns 0 if an edit was done and the function should be called again, or 1 +# otherwise. +sub process_file { + my ($t) = @_; + + pre_process_file($t, $quiet); my $message_was_sent = send_message(); if ($message_was_sent == -1) { @@ -2002,7 +2015,7 @@ sub process_file { # Execute a command (e.g. $to_cmd) to get a list of email addresses # and return a results array sub recipients_cmd { - my ($prefix, $what, $cmd, $file) = @_; + my ($prefix, $what, $cmd, $file, $quiet) = @_; my @addresses = (); open my $fh, "-|", "$cmd \Q$file\E" From patchwork Tue Jan 17 01:39:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Strawbridge X-Patchwork-Id: 13104035 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 25DE1C54EBE for ; Tue, 17 Jan 2023 01:40:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234972AbjAQBkF (ORCPT ); Mon, 16 Jan 2023 20:40:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235113AbjAQBjq (ORCPT ); Mon, 16 Jan 2023 20:39:46 -0500 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2066.outbound.protection.outlook.com [40.107.220.66]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D401229E3C for ; Mon, 16 Jan 2023 17:39:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fmHe1SDlk0AL4Pko8V+sBOLbqAhcSnzt3OkvJ2NabUchI/QUTQR6XNKiZ77gbkfP7k9IvH4reErwT5So93OjLcnvY45hE0jUUlGnpIEKhVaRGwE9UEqbUL1RqkQY9kE30gW964nZ+EevW6dwE6V//5Ug7Irn6pb2xwCoTIrUwVjisAocpBJH4KlWciVTfDcxbEwYm2aaTE6I8AvWaAzHTm7imCIrB44jQdDmT56owTxwnSMNGsdWhD3vLCuw2Cz4c2rc9OqWGBF4prnScaMMG2TpKIs6cD8KV2CjS3AUcZrIKeAuKCrNldyxIb5GGg/p+lyTw1ChYWNRLRJWTg/54A== 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=0DyAUqG3b9/btB8pZwR/kWEKxSxFoTgTjgmQu0O+N5U=; b=XNbsL+y+Ule9g2xLbmWx5IuHsO+2j2AjXenpTR31TaYpgcEZO47tec1dM9+eqmZtn2mbDR7zUt9F+uPegZcXuuzCfsghaqIuhyMBmMvEiBaaZpMXilI3Vmhmubuc4Axv0iIvda+ltWyIRRUxOZQ0wRy5IDn0amY3ecQrY8DeSqUPdGiTbkbyURNgTVZnHM98Ga4z4SwGF0kjxXKgvTcKWofHbNstt+gfR9i+Q84YwkKsIi7+3rxfXRjjFdfW7U2jOTtEVJ+IJ+eovhBjIpJI5qFK5OiCOMkMqGQGPf6Zg2IvDhIp00TH3jnj0Y2z1/bSUVcPCbMRx7ybFAmsORVrsA== 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=0DyAUqG3b9/btB8pZwR/kWEKxSxFoTgTjgmQu0O+N5U=; b=uYb3g0tmgypQzBvUAL6cpowaax/XOmtRGcJUcoPOuSrpRgrYA95EChA1vWk/ChF2bPq758pJiEDMRCTz76o4L1hMBnpjAnHeTL5E+vsjHlZigmwHtwUa+kr6kYlZOwfkmMKPPyC8R252KuP7NE0lAekrlJRBalUDeVXA2qwDBy0= Received: from DM6PR12MB4356.namprd12.prod.outlook.com (2603:10b6:5:2aa::8) by DM6PR12MB5518.namprd12.prod.outlook.com (2603:10b6:5:1b9::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6002.13; Tue, 17 Jan 2023 01:39:43 +0000 Received: from DM6PR12MB4356.namprd12.prod.outlook.com ([fe80::5484:99ef:2b52:eb77]) by DM6PR12MB4356.namprd12.prod.outlook.com ([fe80::5484:99ef:2b52:eb77%3]) with mapi id 15.20.5986.019; Tue, 17 Jan 2023 01:39:43 +0000 From: "Strawbridge, Michael" To: "git@vger.kernel.org" CC: "Strawbridge, Michael" , "Tuikov, Luben" , Junio C Hamano Subject: [PATCH v6 2/2] send-email: expose header information to git-send-email's sendemail-validate hook Thread-Topic: [PATCH v6 2/2] send-email: expose header information to git-send-email's sendemail-validate hook Thread-Index: AQHZKhSS7YRHI5G1yk+daSce60b9bA== Date: Tue, 17 Jan 2023 01:39:42 +0000 Message-ID: <20230117013932.47570-3-michael.strawbridge@amd.com> References: <20230117013932.47570-1-michael.strawbridge@amd.com> In-Reply-To: <20230117013932.47570-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_|DM6PR12MB5518:EE_ x-ms-office365-filtering-correlation-id: be7b5833-1db5-4817-8d9c-08daf82bb4f2 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: Q0ou63iixF/LZcqC3UpkZnUxXm0qHaRhk92SbCSpNKsXBTtjHWncgWq9eC+kzVJaFEzEo9syo/+zmB7uLnAUJ5S1rkisqNYj5Kn0yAd4gPSFT1p8fhNFPy7NAxS/aEIavtFYGE3sJO3uWMsHI31eIK4mRVNN/ubufwpeiGQeuAe3BELN9HCqnkexjwCh7FigHNlmhH965qYXF15EgQsnJFQT+02+dYlU91y5a1wuf9wiJL3Yhhm9qbtabuwtvwiMBfT3Mlm2focgUWAOupdTjP969tHLcgqIJhVmHaP75jsvhJn/itlZI1rgQmhhdRnQE3CkyN0OWbcQjJcaAEa1POZJLiEXKxl/ft45AZVo/V0z/mqHxxkBIL5GOs0SQuzCeH8FuYhs/5j2q+H0tSKQETAbxQpGWxEyg3+T/mHUQnBp/e9TLcuQh57EzuQuQSIfU43N4/EVm5xPAWJ9MJP7U7hb9B4QfQ5EnUCy8Kz+vw0vONw59b8jI/ME5gvFa6QckYBOA1UgzRv97qZ/9wbTO4KbAGllXNXhPxSy0qVB3BbMDFCi243YLU5ZrkR9fgVBJmJTnu/e7AHr47q4oqzZaN2mllAHh7OXCOFiMsOoBcn87mxh2ppgLkedw8Gb2idlTCMVk4mA0Is+4Rf878caVAcCISOea6EeMrS0btURwU36g16roDT2pJd8hPLSWZVZA1HtGh320d2DwryqrquynA== 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)(366004)(346002)(136003)(396003)(39860400002)(451199015)(36756003)(478600001)(71200400001)(6486002)(54906003)(6512007)(26005)(6506007)(15650500001)(2906002)(41300700001)(8936002)(5660300002)(316002)(6916009)(4326008)(8676002)(91956017)(66946007)(66556008)(66476007)(66446008)(64756008)(76116006)(122000001)(186003)(38070700005)(38100700002)(2616005)(1076003)(86362001)(83380400001);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?LMljlWf/cM9B6vOGk69z5HV?= =?iso-8859-1?q?dswGQNCEWiANdzLcUusFLCSTtOaX+zQaoMJ2wVJDRkpASkzkdGHla7+97m7f?= =?iso-8859-1?q?v4413xJ7JrtjxfJBq9/xKO0h0mgmrYM/Co2orZjRceLprYctTunBRx/X/wv8?= =?iso-8859-1?q?wj0SFasIlGFWrcdsUz+7/khCtmqz8UiE6NViYI3/nQGjBiTMBWlZC9TA8u06?= =?iso-8859-1?q?a0erOgJmJRnASAWoAM8/WoOjIYX/TdueqU0znnqZqCk5Y61yUKT11xjsbekV?= =?iso-8859-1?q?k8WgnnqrpGaWW26H9i9JNB7n/8045auUCCaM1B99Dx+JkxNbaJXDv1VoaL3S?= =?iso-8859-1?q?W0J+mnpc3TzBGxgbkux7pYzJbevVNqItbcgoXVa68IPtBTQg1B6Jr3d9Ml/1?= =?iso-8859-1?q?ne0/pLwcJ6zD/bCDVmb93/EIjzkURTrO40dIzgZG59UpldyBSsKu46VwGYpz?= =?iso-8859-1?q?Ler+VTW/N/GbpuXXaryDk5r8iZ+xpZ5nLFyXvtjHdp4m0Ifkv0m1HXrE0tQ+?= =?iso-8859-1?q?N+w3CtzMTb4oe/pzPJ1gZ2hNhjn5XJqTU6gEO2pNfUwQ2N+tQUHKTDLeSfUc?= =?iso-8859-1?q?CKfSBs4xc8M7HHm6g+HBwCuRBo7xoll4q08AGz6T7TFWSqfpf2PX6lfKFJnN?= =?iso-8859-1?q?kLigGa/OQc90ab+1oEIjHSi9PiGnDqlamtMmdRAKF2fChbMPpO1hVwqD3CwQ?= =?iso-8859-1?q?3hKm35OytpgYFrRwdX9i5aPC5RIgh2p2rs/K13cJjpI2VRly/i2pMRmehXdw?= =?iso-8859-1?q?Ep7aBfs2IK6BInAUcT605aj7tehueh9Qm2fjwyQLlBBQxZN0rbE1+snIkr3L?= =?iso-8859-1?q?C0s13AsX7+FZZ15r5CKtpZy9xZ31VEt7eiInoT6E6fnNakRjbG0tp1xV7jSn?= =?iso-8859-1?q?Rkc76SaIoMHh5T4o/syerNhAWnnqB2819MnhYJIomdvtZtI0kGpqR0DwLewg?= =?iso-8859-1?q?MQQJpBpwI8GH4TzXlrmv2HX2ClFNKRAPZYQnK2ZCYAGC/mU2uVfIE/EcHEO0?= =?iso-8859-1?q?uaDWcjYo8b/0IN/KTEDxjYbkRUInLgRzhUegCmzl2Nmfw6CY+tqvNcqCqcjH?= =?iso-8859-1?q?1HpMjG2KQTcsQ3FeQcYcXSWsOdY+/4YjSt2f9vVeToAlEWZO23QpBVuZj7wk?= =?iso-8859-1?q?QyO+byiesdfrwvi3l6rN0O4L1Yc3i0LDGrx8yp6XYUc+OzW1quMDyVnOdgB0?= =?iso-8859-1?q?vtCE0AAurljyf0KmvyaodCAHYLoOBGCrzik0D5toGrgMtmbBVatOxyR66RjR?= =?iso-8859-1?q?C31VM/lOqLT0hKwAaJvn+7xatmNQb7VMbCgKNxgObQqxQX4GJRk/Cc7i4kjn?= =?iso-8859-1?q?Fnd+hvfEejpMm0Gpytgx1C61PluxPl2gE1Xp4bo6hXJBhTBS5EHFlhdw9Hwu?= =?iso-8859-1?q?GPUNUJrzm/fLTtSWyPR1kTdwYlotLENjrMoQZGc07vK+iOwPoOGM7J2mdNZm?= =?iso-8859-1?q?46EuvKQ+HA9PgqsoGGN4tB409srqWQFjxCcUuuvc9GPj327CfKOh6UdIFXAa?= =?iso-8859-1?q?w+W8sjfj0dSPBPAf4HpfHdaD27nl0U5DA7sRr8QIetC0lem7Ps8OWsMYuzeF?= =?iso-8859-1?q?gGo6sYkglHYdBKnoICHyLT29/EE7eWYf1OsDbuCi6//4LiD+R44RX9Cl0NOf?= =?iso-8859-1?q?T2806tvhyGJ25NI/C?= 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: be7b5833-1db5-4817-8d9c-08daf82bb4f2 X-MS-Exchange-CrossTenant-originalarrivaltime: 17 Jan 2023 01:39:42.9267 (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: ymhARyBa0NVrVlBotB25k8HWXKM7z9+sHV0G/z8v/cdrBvat9TSH8DoNSf21XA5z/FpjrgDdJiMUroCfxdRCTw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB5518 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. As an example, this can be useful for acting upon keywords in the subject or specific email addresses. Cc: Luben Tuikov Cc: Junio C Hamano Signed-off-by: Michael Strawbridge --- Documentation/githooks.txt | 29 +++++++++++++++++++---- git-send-email.perl | 31 +++++++++++++++++-------- t/t9001-send-email.sh | 47 ++++++++++++++++++++++++++++++++++++-- 3 files changed, 91 insertions(+), 16 deletions(-) diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt index a16e62bc8c..e80f481efd 100644 --- a/Documentation/githooks.txt +++ b/Documentation/githooks.txt @@ -583,10 +583,31 @@ 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 these command line arguments: +1. the name of the file that holds the e-mail to be sent. +2. the name of the file that holds the SMTP headers to be used. + +The SMTP headers will be passed to the hook in the below format. +Take notice of the capitalization and multi-line tab structure. + + From: Example + To: to@example.com + Cc: cc@example.com, + A , + One , + two@example.com + Subject: PATCH-STRING + Date: DATE-STRING + Message-Id: MESSAGE-ID-STRING + X-Mailer: X-MAILER-STRING + Reply-To: Reply + MIME-Version: 1.0 + Content-Transfer-Encoding: quoted-printable + +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 810dd1f1ce..b2adca515e 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); @@ -1738,6 +1730,16 @@ sub send_message { return 1; } +if ($validate) { + foreach my $f (@files) { + unless (-p $f) { + pre_process_file($f, 1); + + validate_patch($f, $target_xfer_encoding); + } + } +} + $in_reply_to = $initial_in_reply_to; $references = $initial_in_reply_to || ''; $message_num = 0; @@ -2101,11 +2103,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_msg = (@cmd, "", "
"); + 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..346ff1463e 100755 --- a/t/t9001-send-email.sh +++ b/t/t9001-send-email.sh @@ -540,7 +540,7 @@ test_expect_success $PREREQ "--validate respects relative core.hooksPath path" ' 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 + fatal: command '"'"'git hook run --ignore-missing sendemail-validate --
'"'"' died with exit code 1 warning: no patches were sent EOF test_cmp expect actual @@ -559,12 +559,55 @@ test_expect_success $PREREQ "--validate respects absolute core.hooksPath path" ' 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 + fatal: command '"'"'git hook run --ignore-missing sendemail-validate --
'"'"' died with exit code 1 warning: no patches were sent EOF test_cmp expect actual ' +test_expect_success $PREREQ 'setup expect' " +cat >expected-headers <<\EOF +From: Example +To: to@example.com +Cc: cc@example.com, + A , + One , + two@example.com +Subject: [PATCH 1/1] Second. +Date: DATE-STRING +Message-Id: MESSAGE-ID-STRING +X-Mailer: X-MAILER-STRING +Reply-To: Reply +MIME-Version: 1.0 +Content-Transfer-Encoding: quoted-printable +EOF +" + +test_expect_success $PREREQ "--validate hook supports header argument" ' + write_script my-hooks/sendemail-validate <<-\EOF && + if test -s "$2" + then + cat "$2" >actual + exit 1 + fi + EOF + test_config core.hooksPath "my-hooks" && + test_must_fail git send-email \ + --dry-run \ + --suppress-cc=sob \ + --from="Example " \ + --reply-to="Reply " \ + --to=to@example.com \ + --cc=cc@example.com \ + --bcc=bcc@example.com \ + --smtp-server="$(pwd)/fake.sendmail" \ + --validate \ + longline.patch && + cat actual | replace_variable_fields \ + >actual-headers && + test_cmp expected-headers actual-headers +' + for enc in 7bit 8bit quoted-printable base64 do test_expect_success $PREREQ "--transfer-encoding=$enc produces correct header" '