From patchwork Tue Jan 10 21:16:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Strawbridge X-Patchwork-Id: 13095676 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 6B1FFC54EBC for ; Tue, 10 Jan 2023 21:16:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231409AbjAJVQc (ORCPT ); Tue, 10 Jan 2023 16:16:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230389AbjAJVQa (ORCPT ); Tue, 10 Jan 2023 16:16:30 -0500 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2081.outbound.protection.outlook.com [40.107.94.81]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 817285C1FC for ; Tue, 10 Jan 2023 13:16:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DOS8hma+Z4s3JTQPXft7bhYrI7psBT+c/K+9DHpI/NnOX0Ssc6SwCn3Q5XTxHkVoaFpZgdx4Xqad1NwDNzhmBanh+RU2vLf6C2k8D74XoM/vZqcBOAj8zS6pRV4FsKGM0RDOz4RWSdE9pNeAfg98O+7zgoXZH76m82UI74lWEaGQoBELl/LTTpfkg0sv/FyJtm9tvJjPBYWUls6kN6AMZbuLC+xmhXX9CfsRTBvSEPCR0Oi0SqumvZEZaGu7OMpcVFd8qxyCYv6MdOY8Sf2tVaaye7ELHZ9xSqNwJGVN41+gZw9LMpOIGUQYaAA8egAODxrH//NS1xmE53i1RZYsJg== 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=ZjSOdWt74epodPAz/2k4+tm6BctbmkC+4mHdl2gO1OwF8gxFGYORvIYEk+yOoRBxjn+lOqaxXCX7zzO4i1AYV53Dzjeo/6UMDSsct6wPMfNIm7f31UdHXpnhoR6OX0F+w9A+r4rhXC/a1jgwTZQnkmkM7mg10yEgQYWUcamNJjEBj0wFZp6kjGpq8UjRgHu8SKQ7r6ciPGuWI3D2EITlwgLV04bqvL0MUG5gL8cT8kcC89e/YPvHh97v+WLzmLxx6iCGwwx8vy/x9BfxvEtI3uMrcfyX41E/wuiVvahVuw8y8M67lx/TliItuTtc8mKbu13ISJy6I+IU+BihizPG8g== 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=bVSOkWkugdhGTR7s4G203RuV7DGelPlsxh6bk/De2mOR49ZE+1QkewGdw2i774HqgiIAplKYMu+RMR/+L7eYfOzLwIVueIT/G3yZWtZlhll9yuDeHRiOQjxYb416W34Ih25eocYoIHXqX8pZv2F+OJ93pZPmzvywKDNMglOSeug= Received: from DM6PR12MB4356.namprd12.prod.outlook.com (2603:10b6:5:2aa::8) by DS7PR12MB6264.namprd12.prod.outlook.com (2603:10b6:8:94::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.18; Tue, 10 Jan 2023 21:16:26 +0000 Received: from DM6PR12MB4356.namprd12.prod.outlook.com ([fe80::b282:6c4:7660:583f]) by DM6PR12MB4356.namprd12.prod.outlook.com ([fe80::b282:6c4:7660:583f%8]) with mapi id 15.20.5986.018; Tue, 10 Jan 2023 21:16:26 +0000 From: "Strawbridge, Michael" To: "git@vger.kernel.org" CC: "Strawbridge, Michael" , "Tuikov, Luben" , Junio C Hamano Subject: [PATCH v5 1/2] send-email: refactor header generation functions Thread-Topic: [PATCH v5 1/2] send-email: refactor header generation functions Thread-Index: AQHZJTjMQkM7Bmd4+kuTSVtnSb0OZg== Date: Tue, 10 Jan 2023 21:16:26 +0000 Message-ID: <20230110211452.2568535-2-michael.strawbridge@amd.com> References: <20230110211452.2568535-1-michael.strawbridge@amd.com> In-Reply-To: <20230110211452.2568535-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_|DS7PR12MB6264:EE_ x-ms-office365-filtering-correlation-id: 313a9a08-14b3-4ea0-66e0-08daf34fef4d x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: ChBm37HH1y0T6cK3Z1PVyw6i0vkstGr7YLYNsOhfrmH6tfBY55hZmkxMVukLeOMgNJImCJ4SSH5dYiAsyUvAz7AjMSBGMCI/0y7QTzP5fbJTkTuHlcxoORS7Cbx9ceN8j0Puui/fC2NdponFtegXwXIUSASv796IVoSW2CNTY4bEOB3ZxH1k6CAy3JbbtoIoAuH9vEGnwJ/1LSV12xjrWXghOZeUU6Y0rp298ID3BCn5/v6h9OmiJgL/mKSAQ8zQNvhh+SDC+++tQ3vkJBDdThR9VqgEbSlbtRx9f6MdqyZGu5+2pCeNKAuQxVNlE0El1MZxwOca1KRSTBFgeE+09gWGy3VsLCKt6gJw+i9rxyzrNiUw9CColZkOGfx792E+rt+Z4asCvuXdSULOr1th+8f2CyvHCNUC6zwPG5WWRi0WJYWy8aCu9mHgC0O1IBZLB4E4xzbxcHRTREojCBfsWFDZKT3V40WnkUfKjWSya/IfbkrQ7vaVhyH/2S3ZsrlpmEb6jTx5F+45jtKC3NKEa5sKfLmLUQ4EoY842bKBvHd3ajom4sKDPDOc+XPfwp/XMCQwmjhfpKsN/EfbSkkKs/2vkSTYHSF8EOUFlUOqArF7AZCTbjIj70iKITtIWlAl8lkx4Bw6MgDIjv0F0RAtRQY8vdaZ6xTo3uHLaW4/4fF+wDdBIZdLfVmwIXd9ijA7eZ1mLOqULEnfum8+k0bmJA== 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)(396003)(136003)(346002)(366004)(451199015)(6506007)(478600001)(26005)(6486002)(1076003)(186003)(6916009)(6512007)(66476007)(76116006)(64756008)(8676002)(71200400001)(2616005)(41300700001)(66446008)(91956017)(66946007)(54906003)(4326008)(316002)(83380400001)(86362001)(38070700005)(38100700002)(122000001)(66556008)(2906002)(8936002)(5660300002)(36756003);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?ZHwXxTJzlEqg86aDL6bPYXa?= =?iso-8859-1?q?9IJxjDqitP5USDghXPZSsslc/pFCQRBMJM/FU4rPjrZ0Td2rlFGor9Y5s+Lo?= =?iso-8859-1?q?2fYl+Yv95jFDlvR6w0BCbSpRnYUQJqwU0AsV32zC+4YdMVUxG1vcvgxW7sks?= =?iso-8859-1?q?LJZvzC27KXzoWf97YqWRrVcLMlyxlVn2wTI2KPcGl9wUWnfFDMDeLoKf+Tst?= =?iso-8859-1?q?46BSb6OlhgGpWcvLRSwBitgXywnMNyE2LK6zbE7ztLdEBDK7eFUlvzNv54a9?= =?iso-8859-1?q?ScY+7Zr1yj6V6ziexJmVv4xWXHiUt8WGi56uhDooviberLO4Fr7Mb6AqZ62W?= =?iso-8859-1?q?SsxZf+Ge47nPiOyxmJQuM/VTDmE+KhI0qSYGB/jkoWSdYU4eFjFcdldItVzG?= =?iso-8859-1?q?4AHCETDUolNdfz1Ilc3g+Am7qigmZ0QDWxNdMoF2z8V2z09sgwBRaIk0eZfe?= =?iso-8859-1?q?38vEOZCsDx5i7mssgHgblh2NpnZhGE5qMev+sJzuWoprEc1pz0ieyOwbbi9O?= =?iso-8859-1?q?4NL2YmzpmBiBiznqUEnecPm1bHpY5OiG1E+ue0rTor9DgAwKKc9CiXr21NeG?= =?iso-8859-1?q?6J8MD7oukbZvyKA6t/O63FNXrJQeSDerDzlMoEiT+h5RxKq388r9wo42zpf4?= =?iso-8859-1?q?UCoj0S877Q5p+m7QtAnVM4VRNWGeQrniZVGNf5xiX8YQKrUFTQrlDpVddLiH?= =?iso-8859-1?q?9NzSq8EkpFLROIBBCKBHkR7EHhODbang1UUE173SSUQ6n7fQqa0+xE7n1AsG?= =?iso-8859-1?q?BOIbaCYlZwxCuvVUu2Fn9CJF33W32SMiRcoBWdCSC0Pp/rvWzZsvCRARYVfJ?= =?iso-8859-1?q?sLRukTqgY+epnn0O5XLAOD/XdB7QaAh1xWPctmrxI6ra9gppPs63WnzT+13z?= =?iso-8859-1?q?WkS1AmdXU+CU0lnhga7nAhDPxngB+l+1G8rtGIWRV1klmNrqQaiW2qmLNudD?= =?iso-8859-1?q?4cgzKBh1IIN6ANopB34CvfwtsrVVsWZLOUWRA+dIuBvuwZXbGj7hMxoUDqvZ?= =?iso-8859-1?q?H1ghAQI7oafcH9BJoO43O8UFb3BaUyzCSZuTDS6OmjPHrdWFB2YQvB/ECk5N?= =?iso-8859-1?q?F1KsBMSbNubp5jCwon/QvzjxlYorzrSN01Xoi1w8DC0Q+Ww+RgIv3QfPq7XA?= =?iso-8859-1?q?g7VRrcqU4uk7WqrumYtBsmP/fSE9zz7SqTNBNKfoyg2JhAB6I33Kzs8/4PP1?= =?iso-8859-1?q?mDI/N9uxFDMjT77H11z/2CXq6gxqFTTB3G/R3UGMXc01dYvnBhEqE+Fu1lyn?= =?iso-8859-1?q?SR+lMBaV63W4lQEnwb4LidOJ9eW1Qdq1uxpfWWdweRcmqyepzb0zyyqRj5YE?= =?iso-8859-1?q?LPEZKa3j8oJyZ3Ly0g4bb7QddDCFANngsPzwq2/tb0f1wx4uZuizxWgZAyNr?= =?iso-8859-1?q?ga5fsik/0BlB/pfm8PIcG1Ydudx7AtDGlw6fmxEJyGOj8IccRrEi7kE522GT?= =?iso-8859-1?q?pgBmoNSEM3CeMJgc8Uy7UX/IlYfOntPoy/D8tpbLUQBh65HQe8Qu8jVyISEb?= =?iso-8859-1?q?lZYTTyMXRL5e0CW89ytPNmTLcVbj9Iuxn3Crsf0kURt66yW4iIjkzuCRyxea?= =?iso-8859-1?q?gyJ6UGqXxsQG9l8UX54BH+6Sipu68lb9sFQgUNkcX0lClAFFknR+0d1C+4lB?= =?iso-8859-1?q?Ejb2ot8h8oqXqXMrb?= 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: 313a9a08-14b3-4ea0-66e0-08daf34fef4d X-MS-Exchange-CrossTenant-originalarrivaltime: 10 Jan 2023 21:16:26.8671 (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: xR/W0qcZ1cJGwKQGeJA0Hupr2zCg6CfBbyq+a1w7M/M1kNRcqvDXnsF0Pz8ooqrhGLfruRUaHXX3LR25ncoI0g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB6264 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 10 21:16:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Strawbridge X-Patchwork-Id: 13095677 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 6A606C46467 for ; Tue, 10 Jan 2023 21:16:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233118AbjAJVQe (ORCPT ); Tue, 10 Jan 2023 16:16:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232025AbjAJVQb (ORCPT ); Tue, 10 Jan 2023 16:16:31 -0500 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10on2078.outbound.protection.outlook.com [40.107.94.78]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25DFF5EC26 for ; Tue, 10 Jan 2023 13:16:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GadSSr95opzhRXwg1kQoVWMumiOxLom9ATWVYBFFp/iy7CPFXsKU1OkFFonc6L4bVZ+U5wFxPi2LdDA/48JUTS6iSkkgkiMxTyoi6aM6wWSkQSqr/XymZqWZKYfezAYMCWj6jmWqfC264JUxMle07gVQVxzya6rfL0dTxsTZ1KY7SL+R4NC8jJRPsS0VDvXSHTcNqxTk+mtRBfeaoRUYVKtNrkoUrd/FVWJn7A3Td0v1Mj9MqCyQ4QP7oCOd3XyddBfFyZWmdAXHyb+/ROTxzmJ0Jy0aYexJkQTVg57IU4F3lFIiaQad67j5s1+EbZcqI/OQi/kviVGWPD95ShObJQ== 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=unJ/BcNM1w47KD5X/qrbM56l0bB74cFhM+aATeoFI4I=; b=O8+3ZZxxtfgMp6rPDX9XNQ/hcFyh+c0wuCm6ylx0qX8q1YDotfFdQpA7c8K/GnCGZMQTHvHEfF16Ds/4NE7CprBuaiAyZBrYjSZTFOOoLA9L9gFgtvnfAxU/YOjv5XhCv6D8WSDN3JQ3Qb+xl1V2EW2HOMaLAYUjTro2/9qN1NEZdMPg23zbCDJudajCQXESo3vWGA4txJ5CnpSGGFVsNVf0zil/M0kV0Ag7O2NqA2hNhEoTvxnYxs4cxfwJVp2k487Dv5mqVQSKJhbMkOI0U/qV34ettY+6mEunJ3Urozfe34m/QL3C/zqlKL26ZBlGv3+NBusy5qS6LZPPWFhamA== 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=unJ/BcNM1w47KD5X/qrbM56l0bB74cFhM+aATeoFI4I=; b=fFw9C7b+P2sZG0bowdD3TCXurlsS3JSfkF1YPt5F9MOMGTZAnjG1Fu1acXXuzHgoLcBpGSw7bsMMQhBk7iU4BVVTsy3A1Mf08nJbXGN/9RamVHb2//17RymwsvKqre1JVxJs66RPC26ckOnmlacCx01XZEg0bn3L3qfAISMIRHc= Received: from DM6PR12MB4356.namprd12.prod.outlook.com (2603:10b6:5:2aa::8) by DS7PR12MB6264.namprd12.prod.outlook.com (2603:10b6:8:94::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5986.18; Tue, 10 Jan 2023 21:16:28 +0000 Received: from DM6PR12MB4356.namprd12.prod.outlook.com ([fe80::b282:6c4:7660:583f]) by DM6PR12MB4356.namprd12.prod.outlook.com ([fe80::b282:6c4:7660:583f%8]) with mapi id 15.20.5986.018; Tue, 10 Jan 2023 21:16:28 +0000 From: "Strawbridge, Michael" To: "git@vger.kernel.org" CC: "Strawbridge, Michael" , "Tuikov, Luben" , Junio C Hamano Subject: [PATCH v5 2/2] send-email: expose header information to git-send-email's sendemail-validate hook Thread-Topic: [PATCH v5 2/2] send-email: expose header information to git-send-email's sendemail-validate hook Thread-Index: AQHZJTjNDVmgpxBQjUKjqEOVS11wHA== Date: Tue, 10 Jan 2023 21:16:28 +0000 Message-ID: <20230110211452.2568535-3-michael.strawbridge@amd.com> References: <20230110211452.2568535-1-michael.strawbridge@amd.com> In-Reply-To: <20230110211452.2568535-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_|DS7PR12MB6264:EE_ x-ms-office365-filtering-correlation-id: eb44aa8b-888c-477c-073c-08daf34ff04f x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: EVnlXKqN4HzoQipFUFpcTCmydazvHucX1bjdk8QTRbNQUAcCSGHyp9jwQ3+Tsdl7SAXc7J6DoWwY2jp3OqHIEBop7mnD5Kfn6QnUpZb7M/Z5Ptrey1uhH7DO0uNoA16IObbVREDys5OYZonkGIpyzPZh2WZD8hZ/jqjNXGdO+wySvTZUurcuPIjSzL3i6JPhRzS0tjMVNQdXPaXIx1vARf4MEN2y3zBP2ztllVVKwXXCf9X/6juT0UYvr2wFEOJQTAJcuMjDHTroT13f70EaGHc+2u8CUcU+lB7bqSnaXk89Q+2efO8iEEOOhcDqRws4XdVmdIOcOvlTuRdp/Ay0ryWhzBTrv/qjsxrHUD+dHJe0ErRVnqr90rqBiMZU2ORrizMITmMjejJi56+GxmC4pyww4/uM6KUSVGN7eXh1FML/Q1kSOS5rKLnhI7sefcBGUOKCzh3N+lYTPtTCfzLbnljuF3jMA5RzacvYvvpy/LKxTAcgVd8PuLFtU76vB2hCBb9nB/4KiZN7QAataF/dRukRw2X5yi4LETpyHVz6HrTdvMsNKqWcS3GsgDGsrooXGXPG22/8HnjE7F5qis2LZFQHSgTTabZ/hggLu6qrnpdOqiZeY614s+VG6x2e2bwx687OcCTGdckIYKIhKXGPl/ADWfD79G25r9FPapnPe5bbgE9NE6FzEFBaML70uWQFRXInyTCHd44CbqeACYxnxw== 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)(396003)(136003)(346002)(366004)(451199015)(6506007)(478600001)(26005)(6486002)(1076003)(186003)(6916009)(6512007)(66476007)(76116006)(64756008)(8676002)(71200400001)(2616005)(41300700001)(66446008)(91956017)(66946007)(54906003)(4326008)(316002)(83380400001)(86362001)(38070700005)(38100700002)(122000001)(66556008)(2906002)(8936002)(5660300002)(15650500001)(36756003);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?bezoWJiWXCA/rCVbnDDfPjF?= =?iso-8859-1?q?qVds21HEvIlWpBkuw6mG2fx2L5Ra4d5RKDNj3+EphzVAUeCYFNHHyTYJDAKb?= =?iso-8859-1?q?NMkw7Br1Rr1YPBdBhfutlnYeTEP932oxrxdQiv6WawAWD7kyZxu3CrQ327Dd?= =?iso-8859-1?q?gr5EW+diiZWmyxPTQKdEbpVHD7TRR83AP5gc2Q0LEU+Z6e/Rb9L/YvjcRY4O?= =?iso-8859-1?q?+IDLPe75x4QDiw4QTqauRV4kgAZsvq0IutFK15eMaa9TnDY5Yw34chrcOxiW?= =?iso-8859-1?q?Z5JRZebB3AK5fL9L+B+PppHMInz705VmSmptxyhRJD4zJfygWl9+9bwACm/4?= =?iso-8859-1?q?861e61j+KPXIwvxu2UrguulBuW/6xk/hO7IWnoeVg2FPAybYbTxpSnCmJj8d?= =?iso-8859-1?q?lQF9LbUYORjrMEWGPtr17FbSOqPcv1HbZNmsDNg8t3iuU/WuE+rpFiFmjqxi?= =?iso-8859-1?q?x85kwWbOcrftGI4yRCq/wY+KsLfDQkaN5cIm/7aV5Uvjjulssp3H57/ntec6?= =?iso-8859-1?q?x+VRT2L4+hldUUDHbVc3U/CpZ05oepU/K28Xwm7qIca9AFQDA6qo0SZ88Jsb?= =?iso-8859-1?q?yMVmCXZhCKm5l5u3SXlAzEmndEmCsCOdPRgOM5R7UKWdoq9joyKPyMVu3pvS?= =?iso-8859-1?q?sKKJIsFx4TpfEKtMpSjLMPK7IJldfdPK/z8cWqa3YCkOENQTiW4L2S6nuR53?= =?iso-8859-1?q?J4egh9uFqwjrE74cbR6JC5gVTyVaRwtEZBk1OY3TuamXojfwZwPIRsz65oss?= =?iso-8859-1?q?5jWTjXoIJ0+Qi+YYd59YNNxwPPJqKXQmZj21hIGXUS76slWOrmctwrKhLgvx?= =?iso-8859-1?q?K91HO4jO0jqiSDr6oCV8QgH5plbkP7etG1hVTLDBgYFee/1H/2RCXCJSWf8z?= =?iso-8859-1?q?V5SgOlR1MmWNR1s/f11MqEFVNm7PfwdmniqQD1sypKtNxxNW7gzKSdLCkTPy?= =?iso-8859-1?q?kbd96s3MJZvG4SlN5tKIufOdZBMfp0Nnkc9Fu3/jLCgay7Zr3csemvzlwPKh?= =?iso-8859-1?q?HN6N0/RN0ixG1y4YoGKXlMzLTM6PsqvnlHAMO5eFGHZOXtrhf15sf9AaCYJH?= =?iso-8859-1?q?mHk1tK53q/I24tvrt3RsA87DWKq3Cc7S9yD78u8dNU9DY375HRruMXt2Mlhs?= =?iso-8859-1?q?Ff5BL8M5/dGxHyyiUB6xiDfYxHG4cuCfFWI55iRatRwedcPhiKmwVgGwN29u?= =?iso-8859-1?q?xccpaUGP7dkblpSWXlGtbJXRqjI5NQkRaqRtYU/9z34bLwdW03KGAR9kBMsA?= =?iso-8859-1?q?OPj8Vcl8JSH574C7TjEzhhl2bXnzqMDiuyaHbifWIZmdL4+RtO8cl8/GDcLC?= =?iso-8859-1?q?uGQ+YZT3bFDsuUHRWoYBXlXC1tzjDbslF0hPKOWf8JZy/24Ab4O1uD0kOkLt?= =?iso-8859-1?q?ZVhsbNcz2fCRcOZf2JP24f1TNW+vuda9Rgv5MpY42l5ZtTiEa346oC6+0RHa?= =?iso-8859-1?q?RCH9Y4ZJl67NB8R+72Ua4CxXFcN4YncRPFVWoIOqPCJvFrRmPZhz6f8nhLAi?= =?iso-8859-1?q?6w02evxmjjnAVmO+c+s32lLWuBFXu7ELoNrFFyR1lLR3Hbh68+Lh0VtRGJdG?= =?iso-8859-1?q?6iR1FNRqVm7spjWDJ0jvywQStVjGxoAouLHfFaHepJsTV00cMnk0DDt4ihXh?= =?iso-8859-1?q?58sF0zg10CKtGhbWb?= 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: eb44aa8b-888c-477c-073c-08daf34ff04f X-MS-Exchange-CrossTenant-originalarrivaltime: 10 Jan 2023 21:16:28.5554 (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: 2lOogkl5zb0FJ2ASSLqS41pWIqqkh7StL3TzvIeXNHFc+kIBOHAGEaOwgzbJ65L0hxvYMMcCs/SN1keXp/3Z7Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR12MB6264 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 | 17 +++++++++++++---- git-send-email.perl | 31 +++++++++++++++++++++---------- t/t9001-send-email.sh | 29 +++++++++++++++++++++++++++-- 3 files changed, 61 insertions(+), 16 deletions(-) diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt index a16e62bc8c..2b5c6640cc 100644 --- a/Documentation/githooks.txt +++ b/Documentation/githooks.txt @@ -583,10 +583,19 @@ 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 hook doesn't need to support multiple header names (for example only Cc +is passed). However, it does need to understand that lines beginning with +whitespace belong to the previous header. The header information follows +the same format as the confirmation given at the end of send-email. + +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..f02b1eba16 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,7 +559,32 @@ 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 "--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