From patchwork Wed Apr 19 20:27:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Strawbridge X-Patchwork-Id: 13217320 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 3C8C4C77B73 for ; Wed, 19 Apr 2023 20:27:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229514AbjDSU1q (ORCPT ); Wed, 19 Apr 2023 16:27:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44012 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229888AbjDSU1o (ORCPT ); Wed, 19 Apr 2023 16:27:44 -0400 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2078.outbound.protection.outlook.com [40.107.223.78]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82478268F for ; Wed, 19 Apr 2023 13:27:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cJ3gsBeOJhHknYrhZollcKW4c2vQhhUbgcpxZPmzvwDKgysaqEz54Vzo8cs0Is4uV2zuUklX5Ri4hZzvLfQWOy73yNXKNARs9ILBFzlicGiCcyRp6aHXDkpj1u647JSmGU3Da+M8bBstMCxCBv8F9vRi8mmHYD17n808R5ud+TXQDl5EAGyv7rvT2JcJbhWSdbFGeMuZxuz6tQ4Co6Osg3/nlRco+tw93++OZLdd0Sp+KkbgorYz7D15JtlviNL7LAlmbV7xoHsosWWL1p7truGFLzVnu7XyeUo/NftTa4jAMQpiDuuJa7cC8gpBPGF0u7M94/4jrO4knB6Zo0yUpw== 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=Vb7quleK5Pa+jW/t3v77fztsoFQloaqcQVf8p1ffHvo=; b=A6C+seFbKgXCAgO2UGtoHsP/YlPtPfhpEjE+5xtFDazxAICvQ5ay9yizxkcyxxGHlrvyz71L0v6AMvDMFvcx/INn66ySKvCCXzglhd4xhft/SNO+tUp/QufK9ktmnd9IN6X/v4hX4yVnIYroJrKFmMe6IDqWhDzcjdDEzXTmDS8DLHJnJLQKLcJVGv/a+6kkyFZgnte8VXy69UhyAzRujcI6p3XDXel/R0afnAtIPOTTg6A/E7qy3NLqAfNPbIF7NDnFTnQChJ/En9pAPZYlxZ6YGgYimSyBlKD/eK4GVOWDpXkivjU7LCax2V06OcAyr+fpEI2Qtsey4V9HP5+0wQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); 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=Vb7quleK5Pa+jW/t3v77fztsoFQloaqcQVf8p1ffHvo=; b=tcVGL50ATwzqBFPp+s4wi6JzHNQkIIw8ErE4a+UwCbSeT0aLFeZJAJjxyhyvo0KPajkOYyxBtjYcm08kSWNfbHf35IVh4IumGFRpY/ieMlmE9MikN/XRhJ+GqRZNm0e9RWS46FW3uMreboqqHTqRUlnwXU4dkI0YhgqbDwQh4cY= Received: from MW4PR03CA0160.namprd03.prod.outlook.com (2603:10b6:303:8d::15) by DS0PR12MB6487.namprd12.prod.outlook.com (2603:10b6:8:c4::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.45; Wed, 19 Apr 2023 20:27:40 +0000 Received: from CO1NAM11FT095.eop-nam11.prod.protection.outlook.com (2603:10b6:303:8d:cafe::cc) by MW4PR03CA0160.outlook.office365.com (2603:10b6:303:8d::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.22 via Frontend Transport; Wed, 19 Apr 2023 20:27:39 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT095.mail.protection.outlook.com (10.13.174.179) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6319.22 via Frontend Transport; Wed, 19 Apr 2023 20:27:39 +0000 Received: from smtp.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Wed, 19 Apr 2023 15:27:38 -0500 From: Michael Strawbridge To: CC: , Luben Tuikov , "Junio C Hamano" , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v10 1/2] send-email: refactor header generation functions Date: Wed, 19 Apr 2023 16:27:02 -0400 Message-ID: <20230419202703.2911836-2-michael.strawbridge@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230419202703.2911836-1-michael.strawbridge@amd.com> References: <20230419202703.2911836-1-michael.strawbridge@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT095:EE_|DS0PR12MB6487:EE_ X-MS-Office365-Filtering-Correlation-Id: b1c81855-84f1-4253-249c-08db4114855c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OsgU2lJAkpOoo4HYraBvOj0wHcceWCl5T1MdaCJ1bZyyTkcf1g7mUgGbkUtg7zlMYz6gqVDEdOPG4WqGbKewZFffFcAsi8cC3CIxJ3BYnO7og4ArXg/fcDD3e2bLEPYAOHZZdRbVkJKyphFY2tjNiI1R6hPDIrFUNs0dLpsTFKu64EzWvhud9Aeyf+ENKonNqCS4LoCDqoWB0fRJ4NKmpv4W35WMJEjM/sig3HAt/2sLhxp4YtoVsPSa3kEDWiABjmHfSnGDXCjk9r2xJ61hBUGqvb/cFbRNixZpCjdy3c0ef/bDelt28M1163la1x+74V5VTZAtTCBFCm9bj1FhHXGpVKPkOVg+6WlmyIDw6A4QE2Iz1QiP78PDQNAL23IOpKZ5XE4n4k5F8WEwUSAWhJB05QbBDK7Ep6g8444OwC+75yTR+c6XsBxNZySFogQ+GYBmm1CFt7lOSlOExUWvw32VkbP/VJwMYWriFkpWAe02rv3zFcEYQYPeFRgtoCi17L0DKKHHtkfq8hqspOo3CKz2Qc+Hddm7YbFWnk0iniO3r4/V4VpBu5ZK5Du1KhLx7rFu8xYzcmz2tS0s0hspLc97VzeEor/wABPD+/BQ8ToQVIwC2pKyzClu1W88SzMJtX6q/TOK1gxAJ42O5eDCHnIRGZ+Thcknyojz2ZvOSaBJgCc0mGNvk9e10OCyWsTBrg4OlnU3zuy49luAQioXUTe4lcdlbT3bcUNAfRWNF+M= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(346002)(136003)(39860400002)(376002)(396003)(451199021)(46966006)(36840700001)(40470700004)(82310400005)(36756003)(4326008)(1076003)(41300700001)(8676002)(8936002)(86362001)(44832011)(316002)(5660300002)(70206006)(6916009)(70586007)(36860700001)(54906003)(40460700003)(356005)(81166007)(2906002)(26005)(82740400003)(6666004)(47076005)(66574015)(186003)(2616005)(16526019)(40480700001)(336012)(83380400001)(478600001)(426003)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Apr 2023 20:27:39.4210 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b1c81855-84f1-4253-249c-08db4114855c X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT095.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS0PR12MB6487 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 widely available. Cc: Luben Tuikov Cc: Junio C Hamano Cc: Ævar Arnfjörð Bjarmason Acked-by: Luben Tuikov 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 07f2a0cbea..0a44c0e5cb 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -1502,16 +1502,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 @@ -1553,6 +1544,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; @@ -1742,11 +1749,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); @@ -1900,9 +1904,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) { @@ -1961,6 +1965,15 @@ sub process_file { @initial_to = @to; } } +} + +# Prepares the email, prompts the user, and sends it out +# Returns 0 if an edit was done and the function should be called again, or 1 +# on the email being successfully sent out. +sub process_file { + my ($t) = @_; + + pre_process_file($t, $quiet); my $message_was_sent = send_message(); if ($message_was_sent == -1) { @@ -2009,7 +2022,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 Wed Apr 19 20:27:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Michael Strawbridge X-Patchwork-Id: 13217321 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 AB753C6FD18 for ; Wed, 19 Apr 2023 20:27:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229888AbjDSU16 (ORCPT ); Wed, 19 Apr 2023 16:27:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230505AbjDSU1z (ORCPT ); Wed, 19 Apr 2023 16:27:55 -0400 Received: from NAM02-BN1-obe.outbound.protection.outlook.com (mail-bn1nam02on2061f.outbound.protection.outlook.com [IPv6:2a01:111:f400:7eb2::61f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6745559D1 for ; Wed, 19 Apr 2023 13:27:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=m1JY87GTrtWT7a8DL/4LtWjY8AjNSNePeCe3UmUCF0O1q+Gc2hsly46+AKgndE78W+WE/1T9yjA/MueK+f/v98akOXwBJIR1YPehYu/nm7epk3Ku0fzWhC8rYSKtasFiVhJ9blFuf4rtRV8Kq+opjFK1h+onss8Vqbf35wRd89RfHy7qKI3on5MWrY/+bAlybpo6EbOD1sI/QNLbGHYF1JFmIfT2sSHVUGWq6LspottN6IENQl2AqpD20S4OUCSELamT59IBJ7+h1mLYrvX7jijZrnQL+UXGSsc3WyNKLqy2nhcK/5UYenkPWTne+aKrfyG5zlB5yPHu7e8y0Sozag== 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=QtQhZwi4ZUeKKLCXPY/HEGEa9T00obtZ5fXNncAy1AU=; b=hNcjkcVNCbjXlLplfiFQOy8wgz5ay6p+/xc5wB4iGXhoqxn8e+Bs7A0sEEyhp6N+XBY74hMWND/QNerhsosDynW6oNDOG7ghIpF66fDj05gcoX44y7z/PKvgvygXLmZa236/9H9cR4gpurYkT2G9Ey7XuiNvny68JgP6ZokkToN9hOdhkKTgcOhGeNq6T0+zNsrD97uD+z91qd/dIbaeQ3hScm6ouemMUeqrYlRtLqhhkKGnGzstyrAY/bWDZViWUIDG8zWRw9BxmXSNG2TmEdP4/FNLqnii+3DvvNwU89TEX+9cg/PtjxsNIUySq8Kn/4yIZfhAhXkNowRKN6N2Sg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); 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=QtQhZwi4ZUeKKLCXPY/HEGEa9T00obtZ5fXNncAy1AU=; b=LhIG/ej3WSfnACVozyZ2R6zhCQt8OLH3QaHw9Dyq9BYad3XWmkCDHWNyoaHXf5AoBSzrxaENLYnLLj1wYe3/YVfsIEBSvpsbvDUJyv9wnlbOVjP/RAew1YPdPj6B7wEr57GUQljps8N+m2GBGR6oR88Gvc9tcxFb0IH7BtRnxf0= Received: from MW4PR03CA0041.namprd03.prod.outlook.com (2603:10b6:303:8e::16) by SA1PR12MB6920.namprd12.prod.outlook.com (2603:10b6:806:258::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6298.45; Wed, 19 Apr 2023 20:27:48 +0000 Received: from CO1NAM11FT089.eop-nam11.prod.protection.outlook.com (2603:10b6:303:8e:cafe::8b) by MW4PR03CA0041.outlook.office365.com (2603:10b6:303:8e::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6319.22 via Frontend Transport; Wed, 19 Apr 2023 20:27:42 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C Received: from SATLEXMB04.amd.com (165.204.84.17) by CO1NAM11FT089.mail.protection.outlook.com (10.13.175.179) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.6319.22 via Frontend Transport; Wed, 19 Apr 2023 20:27:42 +0000 Received: from smtp.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.34; Wed, 19 Apr 2023 15:27:40 -0500 From: Michael Strawbridge To: CC: , Luben Tuikov , "Junio C Hamano" , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= Subject: [PATCH v10 2/2] send-email: expose header information to git-send-email's sendemail-validate hook Date: Wed, 19 Apr 2023 16:27:03 -0400 Message-ID: <20230419202703.2911836-3-michael.strawbridge@amd.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230419202703.2911836-1-michael.strawbridge@amd.com> References: <20230419202703.2911836-1-michael.strawbridge@amd.com> MIME-Version: 1.0 X-Originating-IP: [10.180.168.240] X-ClientProxiedBy: SATLEXMB04.amd.com (10.181.40.145) To SATLEXMB04.amd.com (10.181.40.145) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CO1NAM11FT089:EE_|SA1PR12MB6920:EE_ X-MS-Office365-Filtering-Correlation-Id: ccbef714-0e50-468e-edf5-08db411486f6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 17AqjjdWqbj2YV1187RbdQtH+nBfU/7ozx0cccUGl1qsjNlydBRBbLF+RGxYWbLdN+/UMW2UoKqcd9hKJXna2GFVZrwuJ4XtV0O0fIrCkywzH1oIjSLa200Wq36YvAKR0oWS4y55rRri+Z2XwDg3ccSc22SsnRslIBTeLYk2mFC/tKimrG1PhFNdjtVnNlvhBKJ+oTd98K8dAD0tiRVZDpkvoMSLIlX/d/XD2WFGCX57QlY0CgqIfDZ5pwG3Tja1k/GznF9KMqN5xxEA1zyfVRy4RFdilYxpcS3s7o4gah2uHf5cb7DhEHt7IctCItu1ffzC0wypdaMyXg7jCkXQUmY3psQ+z9UstMli+a1/poczVXbBUstYhDK4NRmS055YZ/S/FdyB54jMzFxGSM67+y/ptikYVhA8+QMPeBfjeIFzA91Zn7RAbx3zJLdw2c7Ss5ipq6aTzOnIZfG6EWEWjFj4+B1+5ie064bDJMeA+Vbliy5CRbsgicDvqeQHtVuOWU/fM0VWyDq/i5KVOBQeuXHP9V55IVqOujb0y94XlOQjCNmlSA32x6Rpen7PSBMZckjNo3B5b26w3bcYJX5tlTDDVfXDxgPMavwQA0pnT8mqnTEvw/XUV+vexPftF8yGu5Uc5Tln5TXEJ3s3kCD7JbHvXXZozF25OfmkKJAdY3G3WiHAEVKRrwB1xTpPeUrdK1dK9RMu4o0cLhxP6oR7OssAHiF/d1E0Bqltw2h1HQc= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(376002)(346002)(136003)(396003)(451199021)(40470700004)(46966006)(36840700001)(478600001)(6666004)(8936002)(8676002)(316002)(82740400003)(41300700001)(6916009)(4326008)(70586007)(70206006)(40480700001)(54906003)(81166007)(356005)(186003)(40460700003)(15650500001)(2906002)(16526019)(36756003)(26005)(83380400001)(1076003)(426003)(86362001)(336012)(47076005)(82310400005)(66574015)(36860700001)(5660300002)(2616005)(44832011)(36900700001);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Apr 2023 20:27:42.1132 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ccbef714-0e50-468e-edf5-08db411486f6 X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT089.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB6920 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 which git-send-email intends to send, is now passed as the 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 Cc: Ævar Arnfjörð Bjarmason Acked-by: Luben Tuikov Signed-off-by: Michael Strawbridge --- Documentation/githooks.txt | 27 +++++++++++++++++---- git-send-email.perl | 48 +++++++++++++++++++++++--------------- t/t9001-send-email.sh | 27 +++++++++++++++++++-- 3 files changed, 77 insertions(+), 25 deletions(-) diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt index 62908602e7..9896ffafaf 100644 --- a/Documentation/githooks.txt +++ b/Documentation/githooks.txt @@ -595,10 +595,29 @@ 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. They are, +1. the name of the file which holds the contents of the email to be sent. +2. The name of the file which holds the SMTP headers of the email. + +The SMTP headers are passed in the exact same way as they are passed to the +user's Mail Transport Agent (MTA). In effect, the email given to the user's +MTA, is the contents of $2 followed by the contents of $1. + +An example of a few common headers is shown below. 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 + +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 0a44c0e5cb..a3bc7b33d4 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -792,16 +792,31 @@ sub is_format_patch_arg { @rev_list_opts); } -@files = handle_backup_files(@files); +if (defined $sender) { + $sender =~ s/^\s+|\s+$//g; + ($sender) = expand_aliases($sender); +} else { + $sender = $repoauthor->() || $repocommitter->() || ''; +} + +# $sender could be an already sanitized address +# (e.g. sendemail.from could be manually sanitized by user). +# But it's a no-op to run sanitize_address on an already sanitized address. +$sender = sanitize_address($sender); + +$time = time - scalar $#files; if ($validate) { foreach my $f (@files) { unless (-p $f) { + pre_process_file($f, 1); validate_patch($f, $target_xfer_encoding); } } } +@files = handle_backup_files(@files); + if (@files) { unless ($quiet) { print $_,"\n" for (@files); @@ -1050,18 +1065,6 @@ sub file_declares_8bit_cte { } } -if (defined $sender) { - $sender =~ s/^\s+|\s+$//g; - ($sender) = expand_aliases($sender); -} else { - $sender = $repoauthor->() || $repocommitter->() || ''; -} - -# $sender could be an already sanitized address -# (e.g. sendemail.from could be manually sanitized by user). -# But it's a no-op to run sanitize_address on an already sanitized address. -$sender = sanitize_address($sender); - my $to_whom = __("To whom should the emails be sent (if anyone)?"); my $prompting = 0; if (!@initial_to && !defined $to_cmd) { @@ -1221,10 +1224,6 @@ sub make_message_id { #print "new message id = $message_id\n"; # Was useful for debugging } - - -$time = time - scalar $#files; - sub unquote_rfc2047 { local ($_) = @_; my $charset; @@ -2108,10 +2107,21 @@ 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( + TEMPLATE => ".gitsendemail.header.XXXXXX", + DIR => $repo->repo_path(), + UNLINK => 1, + ); + 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"); chdir($cwd_save) or die("chdir: $!"); } diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh index 323952a572..e8c96d0d4e 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,35 @@ 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" ' + write_script my-hooks/sendemail-validate <<-\EOF && + if test "$#" -ge 2 + then + grep "X-test-header: v1.0" "$2" + else + echo "No header arg passed" + exit 1 + fi + EOF + test_config core.hooksPath "my-hooks" && + rm -fr outdir && + git format-patch \ + --add-header="X-test-header: v1.0" \ + -n HEAD^1 -o outdir && + git send-email \ + --dry-run \ + --to=nobody@example.com \ + --smtp-server="$(pwd)/fake.sendmail" \ + --validate \ + outdir/000?-*.patch +' + for enc in 7bit 8bit quoted-printable base64 do test_expect_success $PREREQ "--transfer-encoding=$enc produces correct header" '