From patchwork Tue Apr 25 18:50:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Cournoyer X-Patchwork-Id: 13223679 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 ADF6CC6FD18 for ; Tue, 25 Apr 2023 18:51:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234920AbjDYSvy (ORCPT ); Tue, 25 Apr 2023 14:51:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45578 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232927AbjDYSve (ORCPT ); Tue, 25 Apr 2023 14:51:34 -0400 Received: from mail-qv1-xf2f.google.com (mail-qv1-xf2f.google.com [IPv6:2607:f8b0:4864:20::f2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 969F517DF0 for ; Tue, 25 Apr 2023 11:50:58 -0700 (PDT) Received: by mail-qv1-xf2f.google.com with SMTP id 6a1803df08f44-5f95cedb135so26885876d6.1 for ; Tue, 25 Apr 2023 11:50:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682448622; x=1685040622; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ExOD1zuQlVMzcH2TB4SpjSglrq8X0SSSdYI+5SJaUHU=; b=GYjsDuJu+rH7m+F+4CaKDHzQYMixpvSYvEnKL991IqTnrOahnyRPbLHtVz8HtwKL7R QYt8k1j758C6QuJ9ReGU9HLWox4o4UzuSk7SBkgZgE1ZWJyISMfQtMgRD0hNWUhmAi3M RLYlU9zwOGgMmaO1c5ZDXdE6ckSRtx9hYvwatiQ7SRdn1zp8GavM1YAb9W9jfLrXcnyi RmYvvCFxraAo04jal1MoN/01YvvXpxeib8jD0aLLcdjnnEEhi5o9UFCbWIkGhuR8xjqn gQcdqKoDrylXZcxoMzAlOCm+7D1Pej3pbMnbRzWcCMLEkSEhDWqU8+FlPyA0o9eY2v9h vbeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682448622; x=1685040622; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ExOD1zuQlVMzcH2TB4SpjSglrq8X0SSSdYI+5SJaUHU=; b=IFYUHpydPn6S+WDHiQlZ3+/FEJvsPglhyF7QiwCB9/8RlVpAHQZ99IJmmwLdzsEPTK S8mkQ1vsLkRa2sjcXA4YE53Y5ekUZw4wJpr4wNMT70hgw22HlGNJi5EZoAV5tznCIHwt xBxxrf1Y/JuZtIt4WGiUDAA74trTD5QKXnjgmPbldQioqPDWgL/BBnIIhcyvVJgNtTRl EydvqnhX/7N8AGRIPMD3We9poyMJruroheBnfUHf1WwWFoMlkKBZcnNPt3VrJkWVdYUv 1qJAnBLddbO3Oc5VCjsOHanB/lpPYhgS6eHOWxLlcEeKR+R1fz4TzqV/qdxCVRtbXVmV bZPQ== X-Gm-Message-State: AAQBX9dv7s2wjBB+MRZb1VpEuFh+8i51Ioo3uXA1ty076K2W7h4wFSrJ TG0zuOMzlGZSjbgV4mfoxuRB2+Dmt4s= X-Google-Smtp-Source: AKy350a/AbZrDo9vc4QUVnunR5Aex5tzZwe9S4O1vN0HSkJdNT+hr4svLrkMkt60jM3s8TY9/2DSEA== X-Received: by 2002:a05:6214:404:b0:5ef:4435:f1bb with SMTP id z4-20020a056214040400b005ef4435f1bbmr31745217qvx.28.1682448622258; Tue, 25 Apr 2023 11:50:22 -0700 (PDT) Received: from localhost.localdomain ([2607:fad8:4:3::1003]) by smtp.gmail.com with ESMTPSA id h11-20020a0cf44b000000b005fd79831ac7sm4050080qvm.84.2023.04.25.11.50.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Apr 2023 11:50:21 -0700 (PDT) From: Maxim Cournoyer To: git@vger.kernel.org Cc: gitster@pobox.com, Maxim Cournoyer Subject: [PATCH v3 1/3] send-email: extract execute_cmd from recipients_cmd Date: Tue, 25 Apr 2023 14:50:11 -0400 Message-Id: <20230425185013.14351-2-maxim.cournoyer@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230425185013.14351-1-maxim.cournoyer@gmail.com> References: <20230425185013.14351-1-maxim.cournoyer@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org This refactor is to pave the way for the addition of the new '--header-cmd' option to the send-email command. Signed-off-by: Maxim Cournoyer --- git-send-email.perl | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/git-send-email.perl b/git-send-email.perl index fd8cd0d46f..b8d77ad214 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -2,6 +2,7 @@ # # Copyright 2002,2005 Greg Kroah-Hartman # Copyright 2005 Ryan Anderson +# Copyright 2023 Maxim Cournoyer # # GPL v2 (See COPYING) # @@ -2006,15 +2007,29 @@ sub process_file { } } +# Execute a command and return its output lines as an array. +sub execute_cmd { + my ($prefix, $cmd, $file) = @_; + my @lines = (); + open my $fh, "-|", "$cmd \Q$file\E" + or die sprintf(__("(%s) Could not execute '%s'"), $prefix, $cmd); + while (my $line = <$fh>) { + last if $line =~ /^$/; + push @lines, $line; + } + close $fh + or die sprintf(__("(%s) failed to close pipe to '%s'"), $prefix, $cmd); + return @lines; +} + # 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 @lines = (); my @addresses = (); - open my $fh, "-|", "$cmd \Q$file\E" - or die sprintf(__("(%s) Could not execute '%s'"), $prefix, $cmd); - while (my $address = <$fh>) { + @lines = execute_cmd($prefix, $cmd, $file); + for my $address (@lines) { $address =~ s/^\s*//g; $address =~ s/\s*$//g; $address = sanitize_address($address); @@ -2023,8 +2038,6 @@ sub recipients_cmd { printf(__("(%s) Adding %s: %s from: '%s'\n"), $prefix, $what, $address, $cmd) unless $quiet; } - close $fh - or die sprintf(__("(%s) failed to close pipe to '%s'"), $prefix, $cmd); return @addresses; } From patchwork Tue Apr 25 18:50:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Cournoyer X-Patchwork-Id: 13223680 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 4DE40C77B61 for ; Tue, 25 Apr 2023 18:51:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234606AbjDYSv4 (ORCPT ); Tue, 25 Apr 2023 14:51:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46196 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234565AbjDYSvg (ORCPT ); Tue, 25 Apr 2023 14:51:36 -0400 Received: from mail-qv1-xf33.google.com (mail-qv1-xf33.google.com [IPv6:2607:f8b0:4864:20::f33]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D8DC193E9 for ; Tue, 25 Apr 2023 11:51:01 -0700 (PDT) Received: by mail-qv1-xf33.google.com with SMTP id 6a1803df08f44-5ef51c44141so29473256d6.2 for ; Tue, 25 Apr 2023 11:51:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682448623; x=1685040623; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VttJntrI2VaeKWvcSOLzxvznrsfLZroTpvzWFLKfr2g=; b=IHjjqtgputIKJOUGje+wKFfUQXssSJz9RuXPh4xdgBPNZOVJxT/kxSOBKolcDbctIy CzLJL3suqJg+n4A6h7DW/VXXf4hKcNhReq/UcWswLtgNtfo9+3o76PgqKtHxGZOMcnfQ 3zvYn3RKtIGn5TxjmU6JULw2bAcm30ZlCKG/YnyKKPDmqXM/z0PZv3xJ0UZqG1EpE9zT 5O2pmTii5+cOpbaN9jfo8qEqsEyiZFJlhIC0wqINK/57wyy9tdvtvKG4FpamOLpoxslC Hmbm9yVyl6VGnHbbhT+Ll+TvxwVaf1eqD6sNTLLLYPKJOtoPaajiqOzcluwiCAlv6fSC uDfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682448623; x=1685040623; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VttJntrI2VaeKWvcSOLzxvznrsfLZroTpvzWFLKfr2g=; b=OKKjJ0LINnr+tSQ9ggModj4ZbsdINtnp9FDGSP7GrTbkpVMhIqu1diRSG+57UPedCs 43d5goNcXHp0T1thTBYmj8o5Ew3lsaMjLU5mZMlenQvi1rVJMcv+bxa7+Anz36fbO4SN eFXcgYZefxCKJ7Xhj9OuSUWWxDBy8bkGewvF0Nk1kSKmKZeulh4NP4znEU412FyyBszJ NXtGwcHOoz/08Q/OPV/LtbfGzhMXdHxB2q9RwC4w/QUQyexAsx13NKIG8xRXuC/+MRFI f9826gzGsrbfhgX541vpjpeQgdcDkxUdsP8S+1zCPfyqPCDurzV3ZrBbup+dSgW+jrp3 fFUw== X-Gm-Message-State: AAQBX9f9woU5KF5KvzLVVimWkviyHgjPNQTZR6P/tRIx6TsBWqG91Xhi PgteCrFjmT7jHMVp4pIy2FSCCKk2c+A= X-Google-Smtp-Source: AKy350acdXCa6IOXqaQjWFWyZi89D2LO6x1/L35VT0Nkk1GGiCqbaA1hPZf21lzd5Ey0DYa5e+nZHg== X-Received: by 2002:a05:6214:d88:b0:5ef:4bdd:42e0 with SMTP id e8-20020a0562140d8800b005ef4bdd42e0mr28524713qve.51.1682448623443; Tue, 25 Apr 2023 11:50:23 -0700 (PDT) Received: from localhost.localdomain ([2607:fad8:4:3::1003]) by smtp.gmail.com with ESMTPSA id h11-20020a0cf44b000000b005fd79831ac7sm4050080qvm.84.2023.04.25.11.50.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Apr 2023 11:50:23 -0700 (PDT) From: Maxim Cournoyer To: git@vger.kernel.org Cc: gitster@pobox.com, Maxim Cournoyer Subject: [PATCH v3 2/3] send-email: add --header-cmd option Date: Tue, 25 Apr 2023 14:50:12 -0400 Message-Id: <20230425185013.14351-3-maxim.cournoyer@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230425185013.14351-1-maxim.cournoyer@gmail.com> References: <20230425185013.14351-1-maxim.cournoyer@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Sometimes, adding a header different than CC or TO is desirable; for example, when using Debbugs, it is best to use 'X-Debbugs-Cc' headers to keep people in CC; this is an example use case enabled by the new '--header-cmd' option. The header unfolding logic is extracted to a subroutine so that it can be reused; a test is added for coverage. --- Documentation/config/sendemail.txt | 1 + Documentation/git-send-email.txt | 8 +++++ git-send-email.perl | 49 +++++++++++++++++++++++------- t/t9001-send-email.sh | 39 ++++++++++++++++++++++-- 4 files changed, 84 insertions(+), 13 deletions(-) diff --git a/Documentation/config/sendemail.txt b/Documentation/config/sendemail.txt index 51da7088a8..92a9ebe98c 100644 --- a/Documentation/config/sendemail.txt +++ b/Documentation/config/sendemail.txt @@ -61,6 +61,7 @@ sendemail.ccCmd:: sendemail.chainReplyTo:: sendemail.envelopeSender:: sendemail.from:: +sendemail.headerCmd:: sendemail.signedoffbycc:: sendemail.smtpPass:: sendemail.suppresscc:: diff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt index b0f438ec99..295a3dd67c 100644 --- a/Documentation/git-send-email.txt +++ b/Documentation/git-send-email.txt @@ -320,6 +320,14 @@ Automating Output of this command must be single email address per line. Default is the value of `sendemail.ccCmd` configuration value. +--header-cmd=:: + Specify a command that is executed once per outgoing message + and output RFC 2822 style header lines to be inserted into + them. When the `sendemail.headerCmd` configuration variable is + set, its value is always used. When --header-cmd is provided + at the command line, its value takes precedence over the + `sendemail.headerCmd` configuration variable. + --[no-]chain-reply-to:: If this is set, each email will be sent as a reply to the previous email sent. If disabled with "--no-chain-reply-to", all emails after diff --git a/git-send-email.perl b/git-send-email.perl index b8d77ad214..666b37adc9 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -88,8 +88,9 @@ sub usage { Automating: --identity * Use the sendemail. options. - --to-cmd * Email To: via ` \$patch_path` - --cc-cmd * Email Cc: via ` \$patch_path` + --to-cmd * Email To: via ` \$patch_path`. + --cc-cmd * Email Cc: via ` \$patch_path`. + --header-cmd * Add headers via ` \$patch_path`. --suppress-cc * author, self, sob, cc, cccmd, body, bodycc, misc-by, all. --[no-]cc-cover * Email Cc: addresses in the cover letter. --[no-]to-cover * Email To: addresses in the cover letter. @@ -270,7 +271,7 @@ sub do_edit { # Variables with corresponding config settings my ($suppress_from, $signed_off_by_cc); my ($cover_cc, $cover_to); -my ($to_cmd, $cc_cmd); +my ($to_cmd, $cc_cmd, $header_cmd); my ($smtp_server, $smtp_server_port, @smtp_server_options); my ($smtp_authuser, $smtp_encryption, $smtp_ssl_cert_path); my ($batch_size, $relogin_delay); @@ -319,6 +320,7 @@ sub do_edit { "tocmd" => \$to_cmd, "cc" => \@config_cc, "cccmd" => \$cc_cmd, + "headercmd" => \$header_cmd, "aliasfiletype" => \$aliasfiletype, "bcc" => \@config_bcc, "suppresscc" => \@suppress_cc, @@ -520,6 +522,7 @@ sub config_regexp { "compose" => \$compose, "quiet" => \$quiet, "cc-cmd=s" => \$cc_cmd, + "header-cmd=s" => \$header_cmd, "suppress-from!" => \$suppress_from, "no-suppress-from" => sub {$suppress_from = 0}, "suppress-cc=s" => \@suppress_cc, @@ -1766,17 +1769,15 @@ sub process_file { $subject = $initial_subject; $message = ""; $message_num++; - # First unfold multiline header fields + # Retrieve and unfold header fields. + my @header_lines = (); while(<$fh>) { last if /^\s*$/; - if (/^\s+\S/ and @header) { - chomp($header[$#header]); - s/^\s+/ /; - $header[$#header] .= $_; - } else { - push(@header, $_); - } + push(@header_lines, $_); } + @header = unfold_headers(@header_lines); + # Add computed headers, if applicable. + push @header, invoke_header_cmd($header_cmd, $t) if defined $header_cmd; # Now parse the header foreach(@header) { if (/^From /) { @@ -2022,6 +2023,32 @@ sub execute_cmd { return @lines; } +# Process headers lines, unfolding multiline headers as defined by RFC +# 2822. +sub unfold_headers { + my @headers; + foreach(@_) { + last if /^\s*$/; + if (/^\s+\S/ and @headers) { + chomp($headers[$#headers]); + s/^\s+/ /; + $headers[$#headers] .= $_; + } else { + push(@headers, $_); + } + } + return @headers; +} + +# Invoke the provided CMD with FILE as an argument, which should +# output RFC 2822 email headers. Fold multiline headers and return the +# headers as an array. +sub invoke_header_cmd { + my ($cmd, $file) = @_; + my @lines = execute_cmd("header-cmd", $header_cmd, $file); + return unfold_headers(@lines); +} + # Execute a command (e.g. $to_cmd) to get a list of email addresses # and return a results array sub recipients_cmd { diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh index 0de83b5d2b..230f436f23 100755 --- a/t/t9001-send-email.sh +++ b/t/t9001-send-email.sh @@ -374,13 +374,16 @@ test_expect_success $PREREQ,!AUTOIDENT 'broken implicit ident aborts send-email' ) ' -test_expect_success $PREREQ 'setup tocmd and cccmd scripts' ' +test_expect_success $PREREQ 'setup cmd scripts' ' write_script tocmd-sed <<-\EOF && sed -n -e "s/^tocmd--//p" "$1" EOF - write_script cccmd-sed <<-\EOF + write_script cccmd-sed <<-\EOF && sed -n -e "s/^cccmd--//p" "$1" EOF + write_script headercmd-sed <<-\EOF + sed -n -e "s/^headercmd--//p" "$1" + EOF ' test_expect_success $PREREQ 'tocmd works' ' @@ -410,6 +413,38 @@ test_expect_success $PREREQ 'cccmd works' ' grep "^ cccmd@example.com" msgtxt1 ' +test_expect_success $PREREQ 'headercmd works' ' + clean_fake_sendmail && + cp $patches headercmd.patch && + echo "headercmd--X-Debbugs-CC: dummy@example.com" >>headercmd.patch && + git send-email \ + --from="Example " \ + --to=nobody@example.com \ + --header-cmd=./headercmd-sed \ + --smtp-server="$(pwd)/fake.sendmail" \ + headercmd.patch \ + && + grep "^X-Debbugs-CC: dummy@example.com" msgtxt1 +' + +test_expect_success $PREREQ 'multiline fields are correctly unfolded' ' + clean_fake_sendmail && + cp $patches headercmd.patch && + write_script headercmd-multiline <<-\EOF && + echo "X-Debbugs-CC: someone@example.com +FoldedField: This is a tale + best told using + multiple lines." + EOF + git send-email \ + --from="Example " \ + --to=nobody@example.com \ + --header-cmd=./headercmd-multiline \ + --smtp-server="$(pwd)/fake.sendmail" \ + headercmd.patch && + grep "^FoldedField: This is a tale best told using multiple lines.$" msgtxt1 +' + test_expect_success $PREREQ 'reject long lines' ' z8=zzzzzzzz && z64=$z8$z8$z8$z8$z8$z8$z8$z8 && From patchwork Tue Apr 25 18:50:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Cournoyer X-Patchwork-Id: 13223681 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 D2A1BC6FD18 for ; Tue, 25 Apr 2023 18:52:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234775AbjDYSwD (ORCPT ); Tue, 25 Apr 2023 14:52:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46242 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234990AbjDYSvj (ORCPT ); Tue, 25 Apr 2023 14:51:39 -0400 Received: from mail-qv1-xf2e.google.com (mail-qv1-xf2e.google.com [IPv6:2607:f8b0:4864:20::f2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0262A49D8 for ; Tue, 25 Apr 2023 11:51:08 -0700 (PDT) Received: by mail-qv1-xf2e.google.com with SMTP id 6a1803df08f44-5eefa0a5561so59806166d6.1 for ; Tue, 25 Apr 2023 11:51:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682448624; x=1685040624; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=cAct69PiTDSb12l0VGXuEjtP4Zgiclim1I0CkY8RaMc=; b=rrRd1Dq+aZnGk4YAWWOP7xxsH7vljJdtsKfJdVWdlVhpr8y1NDVky8vJIV0G+5KssR EgpKeApFtPGU+GCU/7DCn683DEJ/55B4ilRaY2yDYRMoNG9EZYUKRz+5QM+koC3WuInv SajAz9MyPEtMPMryB97XGK8MEOG774R2c5WEm9msnSDdify2/afOyyFKa/2g+MI4+bIE MYeQH3dyGeoF4JV+wOAsG4bBKL0a/wVQhRVxEJucqOuBfF9n1VacuaCI3j6PVzCYlm3B 45Dew1W2fhI71h+981Z7oihUsrzjwmyZvsD3L1tOnMSD0ITW+yKTWBlbsgmHWGEXiiH+ QIOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682448624; x=1685040624; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cAct69PiTDSb12l0VGXuEjtP4Zgiclim1I0CkY8RaMc=; b=T+N7rCcu1v5R/EseWabG4IZTX5GeIC0X51ACbqBqSx+eRdk1TTZo7IpN/z3eoJlaN4 vw7AA8TJCKLRuHZFJaZp95tleM30j2Gqt745HJA2SS6um3Y1Ww3HR0boZ1VtvQqfj+qZ aWUAzZusoSgsSaHhc2tCU+I1DEqParMgU2dPmuuu67P5W9y8syaOGk6YXCsxRPQ9izyk 7hPNBuO0PU2otDqIkWVHVMx9oZVYvFHGSYdM27D7e4Em1qacJSiRdnVbLvhHTDplypUo kquuxPm8o42EnTJ8Vp06avoznVDM8HL470DVZnzxealeudhFvdjmEDVamRMY2+CBajR3 zz2w== X-Gm-Message-State: AAQBX9f6DS0DlJq1ZgIqp+Ge5W8pbK4+EJ87SZRCrvduTUrXqYf1x0VG wDcMSegTOWDdWQhwZVdrZqBm2eFzESo= X-Google-Smtp-Source: AKy350Yotta6sBETchuHPPHQDfDOXwFbxuP88RtQzzBBbyq8ITo4jAEAK87ChwOtMr/gRkf+HimL4w== X-Received: by 2002:a05:6214:242a:b0:5f1:5f73:aecd with SMTP id gy10-20020a056214242a00b005f15f73aecdmr37489803qvb.17.1682448624474; Tue, 25 Apr 2023 11:50:24 -0700 (PDT) Received: from localhost.localdomain ([2607:fad8:4:3::1003]) by smtp.gmail.com with ESMTPSA id h11-20020a0cf44b000000b005fd79831ac7sm4050080qvm.84.2023.04.25.11.50.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Apr 2023 11:50:24 -0700 (PDT) From: Maxim Cournoyer To: git@vger.kernel.org Cc: gitster@pobox.com, Maxim Cournoyer Subject: [PATCH v3 3/3] send-email: detect empty blank lines in command output Date: Tue, 25 Apr 2023 14:50:13 -0400 Message-Id: <20230425185013.14351-4-maxim.cournoyer@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230425185013.14351-1-maxim.cournoyer@gmail.com> References: <20230425185013.14351-1-maxim.cournoyer@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The email format does not allow blank lines in headers; detect such input and report it as malformed and add a test for it. Signed-off-by: Maxim Cournoyer --- git-send-email.perl | 12 ++++++++++-- t/t9001-send-email.sh | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/git-send-email.perl b/git-send-email.perl index 666b37adc9..5adcbbeb49 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -2008,14 +2008,22 @@ sub process_file { } } -# Execute a command and return its output lines as an array. +# Execute a command and return its output lines as an array. Blank +# lines which do not appear at the end of the output are reported as +# errors. sub execute_cmd { my ($prefix, $cmd, $file) = @_; my @lines = (); + my $seen_blank_line = 0; open my $fh, "-|", "$cmd \Q$file\E" or die sprintf(__("(%s) Could not execute '%s'"), $prefix, $cmd); while (my $line = <$fh>) { - last if $line =~ /^$/; + die sprintf(__("(%s) Malformed output from '%s'"), $prefix, $cmd) + if $seen_blank_line; + if ($line =~ /^$/) { + $seen_blank_line = $line =~ /^$/; + next; + } push @lines, $line; } close $fh diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh index 230f436f23..6701dd8848 100755 --- a/t/t9001-send-email.sh +++ b/t/t9001-send-email.sh @@ -445,6 +445,23 @@ FoldedField: This is a tale grep "^FoldedField: This is a tale best told using multiple lines.$" msgtxt1 ' +# Blank lines in the middle of the output of a command are invalid. +test_expect_success $PREREQ 'malform output reported on blank lines in command output' ' + clean_fake_sendmail && + cp $patches headercmd.patch && + write_script headercmd-malformed-output <<-\EOF && + echo "X-Debbugs-CC: someone@example.com + +SomeOtherField: someone-else@example.com" + EOF + ! git send-email \ + --from="Example " \ + --to=nobody@example.com \ + --header-cmd=./headercmd-malformed-output \ + --smtp-server="$(pwd)/fake.sendmail" \ + headercmd.patch +' + test_expect_success $PREREQ 'reject long lines' ' z8=zzzzzzzz && z64=$z8$z8$z8$z8$z8$z8$z8$z8 &&