From patchwork Thu May 6 15:02:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= X-Patchwork-Id: 12242241 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 82EC6C433ED for ; Thu, 6 May 2021 15:02:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 492DE61176 for ; Thu, 6 May 2021 15:02:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234976AbhEFPDf (ORCPT ); Thu, 6 May 2021 11:03:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234901AbhEFPDe (ORCPT ); Thu, 6 May 2021 11:03:34 -0400 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C5C4C061574 for ; Thu, 6 May 2021 08:02:36 -0700 (PDT) Received: by mail-pf1-x435.google.com with SMTP id x188so5330428pfd.7 for ; Thu, 06 May 2021 08:02:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=J8BP0qExcG0FrEfDfLsQkmEa/B5z6sIKx/Gs9+7DUi4=; b=Ujwk1AaS7mDAEDEh5UJH69TTBQBoQ/noskSCWvNOl7B7T6QNgozB809IxyAwFNfoIM WdaLL5+v3ARkKffLVs22yD7khEnmxj4pQbHNYNX4fekTszSis+VogCVmrYKd4IiGZG/E ko8njWwRtskp3oWMUwLlnzgix6W5/YC9LRWG+FJJVx1JDwydVB+JmpS3fybAGfoEovxY +xWny1udb21edLD/VU6IqOgo1K4NCEl6wd/I5XI8LgZvBUfqL3Nrhmzt9J+6aVGaVmq2 ww4QL8Agr2naXPu5HTn673q5JoDKXCZT80xmn+dU0wwgjH8/dSdVI+2VbFOc0ch+EaMZ 74XQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=J8BP0qExcG0FrEfDfLsQkmEa/B5z6sIKx/Gs9+7DUi4=; b=CYvvpODogRtFIdCScaselJy2ds6Tlfk17fBEy25q94iKzDRP+Lmj8GUjvX3SPD4i21 kiLFV2aqXkJiNUAfTP/pvgHb780LjCNzkHhl6Sn5cjl5FzHWD9rb6QFE/VmZuPy7doX+ +HSyRVhJgt80gxT4VWHR9UL98NJPp5ngwXq7j2rdl6TLt6AHTGcPOHCmIq7qkhnr/eyV mZdD7ZR/k1izAsOkHLaodFdDtSvF0VaXSg7+iErPNtG5AJHed+766R1QXmW6Nf1E/p99 w3bTTp+E9C84gpVf4TtTGRsXGSdq1+Uy1KWqxTS7BM5lsNWzAfYzkPKs6yE8zojIKkez fR8A== X-Gm-Message-State: AOAM5307mabuIWhnonXTRbXlzsSKIK7NpHgpoC/BHC/e5v2Q87XnG4zq 5j+F/ED0rOe2Xvkn05kTfCRNNEEanGxUWQ== X-Google-Smtp-Source: ABdhPJyX8jdWUEowlJ7uLjSMoc1Chvs5ocrjCOk5peN6FsFl8tZP+h4J0i1RYtAhgDwT58/+YUuYIg== X-Received: by 2002:a62:8208:0:b029:289:112f:d43d with SMTP id w8-20020a6282080000b0290289112fd43dmr4876345pfd.61.1620313355715; Thu, 06 May 2021 08:02:35 -0700 (PDT) Received: from athena.localdomain ([2402:800:63b8:d379:85bd:c83a:4b40:cd9b]) by smtp.gmail.com with ESMTPSA id v15sm2278377pgc.57.2021.05.06.08.02.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 May 2021 08:02:35 -0700 (PDT) From: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= To: git@vger.kernel.org Cc: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= , Junio C Hamano , "brian m. carlson" Subject: [PATCH v3 1/6] mailinfo: load default metainfo_charset lazily Date: Thu, 6 May 2021 22:02:18 +0700 Message-Id: X-Mailer: git-send-email 2.31.1.448.g9c2f8508d1 In-Reply-To: References: <20210421013404.17383-1-congdanhqx@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In a later change, we will use parse_option to parse mailinfo's options. In mailinfo, both "-u", "-n", and "--encoding" try to set the same field, with "-u" reset that field to some default value from configuration variable "i18n.commitEncoding". Let's delay the setting of that field until we finish processing all options. By doing that, "i18n.commitEncoding" can be parsed on demand. More importantly, it cleans the way for using parse_option. This change introduces some inconsistent brackets "{}" in "if/else if" construct, however, we will rewrite them in the next few changes. Signed-off-by: Đoàn Trần Công Danh --- builtin/mailinfo.c | 40 +++++++++++++++++++++++++++++++--------- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/builtin/mailinfo.c b/builtin/mailinfo.c index cfb667a594..77f96177cc 100644 --- a/builtin/mailinfo.c +++ b/builtin/mailinfo.c @@ -11,17 +11,25 @@ static const char mailinfo_usage[] = "git mailinfo [-k | -b] [-m | --message-id] [-u | --encoding= | -n] [--scissors | --no-scissors] < mail >info"; +struct metainfo_charset +{ + enum { + CHARSET_DEFAULT, + CHARSET_NO_REENCODE, + CHARSET_EXPLICIT, + } policy; + const char *charset; +}; + int cmd_mailinfo(int argc, const char **argv, const char *prefix) { - const char *def_charset; + struct metainfo_charset meta_charset; struct mailinfo mi; int status; char *msgfile, *patchfile; setup_mailinfo(&mi); - - def_charset = get_commit_output_encoding(); - mi.metainfo_charset = def_charset; + meta_charset.policy = CHARSET_DEFAULT; while (1 < argc && argv[1][0] == '-') { if (!strcmp(argv[1], "-k")) @@ -31,12 +39,13 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix) else if (!strcmp(argv[1], "-m") || !strcmp(argv[1], "--message-id")) mi.add_message_id = 1; else if (!strcmp(argv[1], "-u")) - mi.metainfo_charset = def_charset; + meta_charset.policy = CHARSET_DEFAULT; else if (!strcmp(argv[1], "-n")) - mi.metainfo_charset = NULL; - else if (starts_with(argv[1], "--encoding=")) - mi.metainfo_charset = argv[1] + 11; - else if (!strcmp(argv[1], "--scissors")) + meta_charset.policy = CHARSET_NO_REENCODE; + else if (starts_with(argv[1], "--encoding=")) { + meta_charset.policy = CHARSET_EXPLICIT; + meta_charset.charset = argv[1] + 11; + } else if (!strcmp(argv[1], "--scissors")) mi.use_scissors = 1; else if (!strcmp(argv[1], "--no-scissors")) mi.use_scissors = 0; @@ -50,6 +59,19 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix) if (argc != 3) usage(mailinfo_usage); + switch (meta_charset.policy) { + case CHARSET_DEFAULT: + mi.metainfo_charset = get_commit_output_encoding(); + break; + case CHARSET_NO_REENCODE: + mi.metainfo_charset = NULL; + break; + case CHARSET_EXPLICIT: + break; + default: + BUG("invalid meta_charset.policy"); + } + mi.input = stdin; mi.output = stdout; From patchwork Thu May 6 15:02:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= X-Patchwork-Id: 12242273 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9738CC433B4 for ; Thu, 6 May 2021 15:02:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 731AB611AE for ; Thu, 6 May 2021 15:02:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235020AbhEFPDp (ORCPT ); Thu, 6 May 2021 11:03:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234998AbhEFPDi (ORCPT ); Thu, 6 May 2021 11:03:38 -0400 Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3553DC0613ED for ; Thu, 6 May 2021 08:02:40 -0700 (PDT) Received: by mail-pl1-x634.google.com with SMTP id v20so3531708plo.10 for ; Thu, 06 May 2021 08:02:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=G8iY5go8vQPeeCur26C/uXnuJ/W0z5Jvi2wjVCYgpSI=; b=dMvvCpAsfom5E8uGzNgN1ubJ/Vth3oAjsQTBmEDv0U46S958xUCa6fGG3zlppmH2mD BUIIrEaPryN2Ki5mTs8l8L7FscoEJRNf8qD6VWkjSeLyBLBzbc+0Dfxm72RlVO7/B0OC WmNOIEZfWjNu2LOhiZafbWRiyO0i+mKD1v4L1dYGRBOsUdD21gAfs0OerA5zzSi4WjOF IM9pzP8z8JCY8j7IeOJ4APsI3ozMXQrfYsaxa0TLFrdq3UgOTjBHk+OCtxMdjcEvs7dw W60rS0Oi25qTtT/cLYuuwlF9WEaJBnSbInT2HjlwsC62tQi5/t6svr6B1xS8xA2WMnMA t5aA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=G8iY5go8vQPeeCur26C/uXnuJ/W0z5Jvi2wjVCYgpSI=; b=QotQXIJnzsyWYE2LxU8zxJOXok+VX/Me69hD7cq7lhLPGLtQI0nUQBVtyysoZGzdsj mFFRcqfnKSL3xmrlut3eJmE9FYATM/QPRWjRdEB7qG3FXaad32tf8cKBsp/+w/fgQb7U jkVI4WWGRzrk1QaDoAuq0wHjz0FiZdMOjTgt1j6tovMMQqXMnwNO6US7oZ4gjPhC2KUh XqPH5yoEur65XzKVNKwmcnhTl/e4ZixkZWb0EZGRkZ0zoQm89SpQF5L84Wm5p8Srm2JB p4UGwg0JAB2X27NVHnfhRxefzGp/vgLpKnHbXq2rpEfAqJg1KM8WpPjDDC2pIQDLXA5z 07dg== X-Gm-Message-State: AOAM532/ZiGu34kN5AB4etPxl1vbHVZB8c9QCGzIKwk+HM9VOr/7bgF2 M+QiMEBN5ssSrCFPthtXtg9d54ms91oaoQ== X-Google-Smtp-Source: ABdhPJzGjk5MdyeIm5VjBifFpua/UXZP5yJesdyis4NN6ZdWvdzgP/J6tsawH7uw6ZiYdVgnuvOvpg== X-Received: by 2002:a17:902:a614:b029:ed:3d5f:768 with SMTP id u20-20020a170902a614b02900ed3d5f0768mr5042242plq.18.1620313359601; Thu, 06 May 2021 08:02:39 -0700 (PDT) Received: from athena.localdomain ([2402:800:63b8:d379:85bd:c83a:4b40:cd9b]) by smtp.gmail.com with ESMTPSA id v15sm2278377pgc.57.2021.05.06.08.02.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 May 2021 08:02:39 -0700 (PDT) From: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= To: git@vger.kernel.org Cc: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= , Junio C Hamano , "brian m. carlson" Subject: [PATCH v3 2/6] mailinfo: stop parsing options manually Date: Thu, 6 May 2021 22:02:20 +0700 Message-Id: <1fb08bb37dc534296b3bf89efc9bfaad67a9b068.1620311544.git.congdanhqx@gmail.com> X-Mailer: git-send-email 2.31.1.448.g9c2f8508d1 In-Reply-To: References: <20210421013404.17383-1-congdanhqx@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In a later change, mailinfo will learn more options, let's switch to our robust parse_options framework before that step. Signed-off-by: Đoàn Trần Công Danh --- builtin/mailinfo.c | 75 +++++++++++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 30 deletions(-) diff --git a/builtin/mailinfo.c b/builtin/mailinfo.c index 77f96177cc..f55549a097 100644 --- a/builtin/mailinfo.c +++ b/builtin/mailinfo.c @@ -7,9 +7,13 @@ #include "utf8.h" #include "strbuf.h" #include "mailinfo.h" +#include "parse-options.h" -static const char mailinfo_usage[] = - "git mailinfo [-k | -b] [-m | --message-id] [-u | --encoding= | -n] [--scissors | --no-scissors] < mail >info"; +static const char * const mailinfo_usage[] = { + /* TRANSLATORS: keep <> in "<" mail ">" info. */ + N_("git mailinfo [] < mail >info"), + NULL, +}; struct metainfo_charset { @@ -21,6 +25,19 @@ struct metainfo_charset const char *charset; }; +static int parse_opt_explicit_encoding(const struct option *opt, + const char *arg, int unset) +{ + struct metainfo_charset *meta_charset = opt->value; + + BUG_ON_OPT_NEG(unset); + + meta_charset->policy = CHARSET_EXPLICIT; + meta_charset->charset = arg; + + return 0; +} + int cmd_mailinfo(int argc, const char **argv, const char *prefix) { struct metainfo_charset meta_charset; @@ -28,36 +45,34 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix) int status; char *msgfile, *patchfile; + struct option options[] = { + OPT_BOOL('k', NULL, &mi.keep_subject, N_("keep subject")), + OPT_BOOL('b', NULL, &mi.keep_non_patch_brackets_in_subject, + N_("keep non patch brackets in subject")), + OPT_BOOL('m', "message-id", &mi.add_message_id, + N_("copy Message-ID to the end of commit message")), + OPT_SET_INT_F('u', NULL, &meta_charset.policy, + N_("re-code metadata to i18n.commitEncoding"), + CHARSET_DEFAULT, PARSE_OPT_NONEG), + OPT_SET_INT_F('n', NULL, &meta_charset.policy, + N_("disable charset re-coding of metadata"), + CHARSET_NO_REENCODE, PARSE_OPT_NONEG), + OPT_CALLBACK_F(0, "encoding", &meta_charset, N_("encoding"), + N_("re-code metadata to this encoding"), + PARSE_OPT_NONEG, parse_opt_explicit_encoding), + OPT_BOOL(0, "scissors", &mi.use_scissors, N_("use scissors")), + OPT_HIDDEN_BOOL(0, "inbody-headers", &mi.use_inbody_headers, + N_("use headers in message's body")), + OPT_END() + }; + setup_mailinfo(&mi); meta_charset.policy = CHARSET_DEFAULT; - while (1 < argc && argv[1][0] == '-') { - if (!strcmp(argv[1], "-k")) - mi.keep_subject = 1; - else if (!strcmp(argv[1], "-b")) - mi.keep_non_patch_brackets_in_subject = 1; - else if (!strcmp(argv[1], "-m") || !strcmp(argv[1], "--message-id")) - mi.add_message_id = 1; - else if (!strcmp(argv[1], "-u")) - meta_charset.policy = CHARSET_DEFAULT; - else if (!strcmp(argv[1], "-n")) - meta_charset.policy = CHARSET_NO_REENCODE; - else if (starts_with(argv[1], "--encoding=")) { - meta_charset.policy = CHARSET_EXPLICIT; - meta_charset.charset = argv[1] + 11; - } else if (!strcmp(argv[1], "--scissors")) - mi.use_scissors = 1; - else if (!strcmp(argv[1], "--no-scissors")) - mi.use_scissors = 0; - else if (!strcmp(argv[1], "--no-inbody-headers")) - mi.use_inbody_headers = 0; - else - usage(mailinfo_usage); - argc--; argv++; - } + argc = parse_options(argc, argv, prefix, options, mailinfo_usage, 0); - if (argc != 3) - usage(mailinfo_usage); + if (argc != 2) + usage_with_options(mailinfo_usage, options); switch (meta_charset.policy) { case CHARSET_DEFAULT: @@ -75,8 +90,8 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix) mi.input = stdin; mi.output = stdout; - msgfile = prefix_filename(prefix, argv[1]); - patchfile = prefix_filename(prefix, argv[2]); + msgfile = prefix_filename(prefix, argv[0]); + patchfile = prefix_filename(prefix, argv[1]); status = !!mailinfo(&mi, msgfile, patchfile); clear_mailinfo(&mi); From patchwork Thu May 6 15:02:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= X-Patchwork-Id: 12242275 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 15730C43460 for ; Thu, 6 May 2021 15:02:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CE15861168 for ; Thu, 6 May 2021 15:02:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235021AbhEFPDr (ORCPT ); Thu, 6 May 2021 11:03:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234999AbhEFPDm (ORCPT ); Thu, 6 May 2021 11:03:42 -0400 Received: from mail-pl1-x635.google.com (mail-pl1-x635.google.com [IPv6:2607:f8b0:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBA96C06138B for ; Thu, 6 May 2021 08:02:41 -0700 (PDT) Received: by mail-pl1-x635.google.com with SMTP id b3so3527027plg.11 for ; Thu, 06 May 2021 08:02:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NR22P6gyEs/hTUMqqMXXlxC57SP5gUx6uEcOMevDBj8=; b=U2U7uSnkE98qcOPpw38ZE4g/YMYTI7wnxOlm28BtDdHUf13eOOG8zZ4wfqWIyukvHH D8eLJYF/eSdlEYcf648mo317HULLSQxb+pj1K55xEPib+jmnLvVFuwtGPwFkbvXveNcu Nh/dLy3/deBHlqgpyiXfrCcevwKTqrb31Xb5t23RSGiULqTyeEi2Ir+BrnQDDOh4tGhq YjPCHPtDcsLf52pRMmKJ2Xss53V0F6G2oyHoaxjPugyy+088/zaKUqDfKTPxLfPFfRY+ z/YuzN2KKaSWz6/wm4Rz+2HvRH3iU+EuE+usDnG7RImUdZb2bOIO5n5yQfXaFK550Y3b n7Mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NR22P6gyEs/hTUMqqMXXlxC57SP5gUx6uEcOMevDBj8=; b=PTHdmUmmwZDO0ngSUxaEge+v+0MISvTDfceL2zjDVJmNbUzomGL+ot4fT/l0ROKQnH jSy1Q5O9ZvyjKZAirTAeg0BS2HNEOHO4GJIHFC+6x1T9BPOklanP3oUTW8k4SZ9jqPiF 6XGl2UP7a/5LG1k/uw5pjdZR25McHWCvUB2hJY/Z622KmfbCseq2KcST61IC2+OZFiH5 zaUnHAHwYJjU5R1NF3gGL20mehYqgkpJtvWCsZOrRwZW4THhuMM+K2YA1fvBweBCWhcG JxLezuCRH6CI3v/IE2oe9IKpc1x6KQCFxY+Pw7qcMi6IEdx8b51gLGinTgBsxoe06O2Q 6UHQ== X-Gm-Message-State: AOAM530KSWomv3JLHr/Fxxb1qJpCGjrvgiC+0ROJRp4OZ0QDzkEdpNCJ 3l0PuDJjPo/XlF8eklnpV/WviVmijTN1jg== X-Google-Smtp-Source: ABdhPJwnGB8itY99yrbFrYTo/1+4lvGWNqY125Oh1oABpn6earTCc/qGpPGZ+X9fvufOWm80sPBwDg== X-Received: by 2002:a17:902:b7c8:b029:ed:2577:8dc3 with SMTP id v8-20020a170902b7c8b02900ed25778dc3mr4779689plz.9.1620313361312; Thu, 06 May 2021 08:02:41 -0700 (PDT) Received: from athena.localdomain ([2402:800:63b8:d379:85bd:c83a:4b40:cd9b]) by smtp.gmail.com with ESMTPSA id v15sm2278377pgc.57.2021.05.06.08.02.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 May 2021 08:02:41 -0700 (PDT) From: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= To: git@vger.kernel.org Cc: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= , Junio C Hamano , "brian m. carlson" Subject: [PATCH v3 3/6] mailinfo: warn if CR found in decoded base64/QP email Date: Thu, 6 May 2021 22:02:21 +0700 Message-Id: <5aac2ba38e5442019d2816c63d7b65bf2bcf062a.1620311544.git.congdanhqx@gmail.com> X-Mailer: git-send-email 2.31.1.448.g9c2f8508d1 In-Reply-To: References: <20210421013404.17383-1-congdanhqx@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org When SMTP servers receive 8-bit email messages, possibly with only LF as line ending, some of them decide to change said LF to CRLF. Some mailing list softwares, when receive 8-bit email messages, decide to encode those messages in base64 or quoted-printable. If an email is transfered through above mail servers, then distributed by such mailing list softwares, the recipients will receive an email contains a patch mungled with CRLF encoded inside another encoding. Thus, such CR couldn't be dropped by "mailsplit". Hence, the mailed patch couldn't be applied cleanly. Such accidents have been observed in the wild [1]. Instead of silently rejecting those messages, let's give our users some warnings if such CR is found. [1]: https://nmbug.notmuchmail.org/nmweb/show/m2lf9ejegj.fsf%40guru.guru-group.fi Signed-off-by: Đoàn Trần Công Danh --- mailinfo.c | 14 ++++++++++++++ mailinfo.h | 1 + t/t5100-mailinfo.sh | 15 +++++++++++++++ t/t5100/quoted-cr-info | 5 +++++ t/t5100/quoted-cr-msg | 2 ++ t/t5100/quoted-cr-patch | 22 ++++++++++++++++++++++ t/t5100/quoted-cr.mbox | 22 ++++++++++++++++++++++ 7 files changed, 81 insertions(+) create mode 100644 t/t5100/quoted-cr-info create mode 100644 t/t5100/quoted-cr-msg create mode 100644 t/t5100/quoted-cr-patch create mode 100644 t/t5100/quoted-cr.mbox diff --git a/mailinfo.c b/mailinfo.c index 5681d9130d..dcf579700d 100644 --- a/mailinfo.c +++ b/mailinfo.c @@ -994,6 +994,11 @@ static void handle_filter_flowed(struct mailinfo *mi, struct strbuf *line, const char *rest; if (!mi->format_flowed) { + if (len >= 2 && + line->buf[len - 2] == '\r' && + line->buf[len - 1] == '\n') { + mi->have_quoted_cr = 1; + } handle_filter(mi, line); return; } @@ -1033,6 +1038,12 @@ static void handle_filter_flowed(struct mailinfo *mi, struct strbuf *line, handle_filter(mi, line); } +static void summarize_quoted_cr(struct mailinfo *mi) +{ + if (mi->have_quoted_cr) + warning("quoted CR detected"); +} + static void handle_body(struct mailinfo *mi, struct strbuf *line) { struct strbuf prev = STRBUF_INIT; @@ -1051,6 +1062,8 @@ static void handle_body(struct mailinfo *mi, struct strbuf *line) handle_filter(mi, &prev); strbuf_reset(&prev); } + summarize_quoted_cr(mi); + mi->have_quoted_cr = 0; if (!handle_boundary(mi, line)) goto handle_body_out; } @@ -1100,6 +1113,7 @@ static void handle_body(struct mailinfo *mi, struct strbuf *line) if (prev.len) handle_filter(mi, &prev); + summarize_quoted_cr(mi); flush_inbody_header_accum(mi); diff --git a/mailinfo.h b/mailinfo.h index 79b1d6774e..b394ef9bce 100644 --- a/mailinfo.h +++ b/mailinfo.h @@ -24,6 +24,7 @@ struct mailinfo { struct strbuf charset; unsigned int format_flowed:1; unsigned int delsp:1; + unsigned int have_quoted_cr:1; char *message_id; enum { TE_DONTCARE, TE_QP, TE_BASE64 diff --git a/t/t5100-mailinfo.sh b/t/t5100-mailinfo.sh index 147e616533..c7ea1b30df 100755 --- a/t/t5100-mailinfo.sh +++ b/t/t5100-mailinfo.sh @@ -228,4 +228,19 @@ test_expect_success 'mailinfo handles unusual header whitespace' ' test_cmp expect actual ' +check_quoted_cr_mail () { + git mailinfo -u "$@" quoted-cr-msg quoted-cr-patch \ + <"$DATA/quoted-cr.mbox" >quoted-cr-info 2>quoted-cr-err && + test_cmp "expect-cr-msg" quoted-cr-msg && + test_cmp "expect-cr-patch" quoted-cr-patch && + test_cmp "$DATA/quoted-cr-info" quoted-cr-info +} + +test_expect_success 'mailinfo warn CR in base64 encoded email' ' + sed "s/%%/$(printf \\015)/" "$DATA/quoted-cr-msg" >expect-cr-msg && + sed "s/%%/$(printf \\015)/" "$DATA/quoted-cr-patch" >expect-cr-patch && + check_quoted_cr_mail && + grep "quoted CR detected" quoted-cr-err +' + test_done diff --git a/t/t5100/quoted-cr-info b/t/t5100/quoted-cr-info new file mode 100644 index 0000000000..dab2228b70 --- /dev/null +++ b/t/t5100/quoted-cr-info @@ -0,0 +1,5 @@ +Author: A U Thor +Email: mail@example.com +Subject: sample +Date: Mon, 3 Aug 2020 22:40:55 +0700 + diff --git a/t/t5100/quoted-cr-msg b/t/t5100/quoted-cr-msg new file mode 100644 index 0000000000..a148bc7e26 --- /dev/null +++ b/t/t5100/quoted-cr-msg @@ -0,0 +1,2 @@ +On different distro, pytest is suffixed with different patterns.%% +%% diff --git a/t/t5100/quoted-cr-patch b/t/t5100/quoted-cr-patch new file mode 100644 index 0000000000..580e2bddb8 --- /dev/null +++ b/t/t5100/quoted-cr-patch @@ -0,0 +1,22 @@ +---%% + configure | 2 +-%% + 1 file changed, 1 insertion(+), 1 deletion(-)%% +%% +diff --git a/configure b/configure%% +index db3538b3..f7c1c095 100755%% +--- a/configure%% ++++ b/configure%% +@@ -814,7 +814,7 @@ if [ $have_python3 -eq 1 ]; then%% + printf "Checking for python3 pytest (>= 3.0)... "%% + conf=$(mktemp)%% + printf "[pytest]\nminversion=3.0\n" > $conf%% +- if pytest-3 -c $conf --version >/dev/null 2>&1; then%% ++ if "$python" -m pytest -c $conf --version >/dev/null 2>&1; then%% + printf "Yes.\n"%% + have_python3_pytest=1%% + else%% +-- %% +2.28.0%% +_______________________________________________ +example mailing list -- list@example.org +To unsubscribe send an email to list-leave@example.org diff --git a/t/t5100/quoted-cr.mbox b/t/t5100/quoted-cr.mbox new file mode 100644 index 0000000000..6ea9806a6b --- /dev/null +++ b/t/t5100/quoted-cr.mbox @@ -0,0 +1,22 @@ +From: A U Thor +To: list@example.org +Subject: [PATCH v2] sample +Date: Mon, 3 Aug 2020 22:40:55 +0700 +Message-Id: +Content-Type: text/plain; charset="utf-8" +Content-Transfer-Encoding: base64 + +T24gZGlmZmVyZW50IGRpc3RybywgcHl0ZXN0IGlzIHN1ZmZpeGVkIHdpdGggZGlmZmVyZW50IHBh +dHRlcm5zLg0KDQotLS0NCiBjb25maWd1cmUgfCAyICstDQogMSBmaWxlIGNoYW5nZWQsIDEgaW5z +ZXJ0aW9uKCspLCAxIGRlbGV0aW9uKC0pDQoNCmRpZmYgLS1naXQgYS9jb25maWd1cmUgYi9jb25m +aWd1cmUNCmluZGV4IGRiMzUzOGIzLi5mN2MxYzA5NSAxMDA3NTUNCi0tLSBhL2NvbmZpZ3VyZQ0K +KysrIGIvY29uZmlndXJlDQpAQCAtODE0LDcgKzgxNCw3IEBAIGlmIFsgJGhhdmVfcHl0aG9uMyAt +ZXEgMSBdOyB0aGVuDQogICAgIHByaW50ZiAiQ2hlY2tpbmcgZm9yIHB5dGhvbjMgcHl0ZXN0ICg+ +PSAzLjApLi4uICINCiAgICAgY29uZj0kKG1rdGVtcCkNCiAgICAgcHJpbnRmICJbcHl0ZXN0XVxu +bWludmVyc2lvbj0zLjBcbiIgPiAkY29uZg0KLSAgICBpZiBweXRlc3QtMyAtYyAkY29uZiAtLXZl +cnNpb24gPi9kZXYvbnVsbCAyPiYxOyB0aGVuDQorICAgIGlmICIkcHl0aG9uIiAtbSBweXRlc3Qg +LWMgJGNvbmYgLS12ZXJzaW9uID4vZGV2L251bGwgMj4mMTsgdGhlbg0KICAgICAgICAgcHJpbnRm +ICJZZXMuXG4iDQogICAgICAgICBoYXZlX3B5dGhvbjNfcHl0ZXN0PTENCiAgICAgZWxzZQ0KLS0g +DQoyLjI4LjANCl9fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f +CmV4YW1wbGUgbWFpbGluZyBsaXN0IC0tIGxpc3RAZXhhbXBsZS5vcmcKVG8gdW5zdWJzY3JpYmUg +c2VuZCBhbiBlbWFpbCB0byBsaXN0LWxlYXZlQGV4YW1wbGUub3JnCg== From patchwork Thu May 6 15:02:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= X-Patchwork-Id: 12242277 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B3D00C433ED for ; Thu, 6 May 2021 15:02:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 858AD61166 for ; Thu, 6 May 2021 15:02:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235022AbhEFPDs (ORCPT ); Thu, 6 May 2021 11:03:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54970 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235005AbhEFPDn (ORCPT ); Thu, 6 May 2021 11:03:43 -0400 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A58AEC061574 for ; Thu, 6 May 2021 08:02:43 -0700 (PDT) Received: by mail-pj1-x1036.google.com with SMTP id lj11-20020a17090b344bb029015bc3073608so3624751pjb.3 for ; Thu, 06 May 2021 08:02:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/5lExw1vZ7ka/NkzP+5W4viDl4rKesc07FS0isOms6g=; b=scdiNBWr6IwQydq1BiTwm3jKBsTqe3UR7a8KInqEP2ZI6srJKFavs6MMYQ2u8or2p6 QRTHl8mZ7ibpWfm+hnL/ZaI8TQYsh7xMmjilBeK/ROi0ewsYff+4EBgyQy0VeL6H3CyJ m+UO8TTu+BZwPz9ipZTlKq4xkd1cFIPoOvwuZOT5YOde3tsjTBrPrdMzPdw10DeuIFgz uSGUBCjgTlD2Pre3D0D+kORedwT/y6jIYLuAskztGyTP3Y2zXD1Qy6pjEYVbYiScin6y vvOwhlGBHXGdHrqpqIfHdGVrm1JcFQ4A6VAs1r2imVL1NDHUIr0PWjtwpsx3My/ELCoC eN+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/5lExw1vZ7ka/NkzP+5W4viDl4rKesc07FS0isOms6g=; b=FV5bFuBh/Z1pdgIKtHyrFD7V5SDTKOVm1asH29oDVClXJ0mLko6aCRZjDl6PiKmOj9 cXenm3Mion5P6SX+YslXVA7rLiPLcNvbBYTOKoYXmqWKIMOupjW1arIq2JxO2HTZ3AG8 UiGwB3ALkBxDAAfjo3njckHdPkonHMgqaF7xoZ1C9iVzjrZUW8EKQCZnaLe6upVDFCvc 2AHSJ7xrTuPBpn+hgFDLwCnDkwrJcPWFV/VKhjcPNoY6kEBKXED7GSDbADmj2/eob+1v nSXkBOwIGne7GSZOIoHdaa+lUNLngzQfw77p1eOHJViBt16uoZ6TCqsJtMblHLlUIeAt anRw== X-Gm-Message-State: AOAM533p7Ycs36Uir5qbEFPZ3HRLNPTBT/CVHliTtMTOjVkxveIpwsIx fZV/C6tiLRVy7e2zemQZnCrEoqpeNu8KcA== X-Google-Smtp-Source: ABdhPJyyGH1ypfWAxvGm88W/ThnQ6a4kJa/YcMeih6lAzyZ1QFRe68t5+G4yZYLXQgc5zh326hkdkw== X-Received: by 2002:a17:90b:31cc:: with SMTP id jv12mr18410368pjb.105.1620313363018; Thu, 06 May 2021 08:02:43 -0700 (PDT) Received: from athena.localdomain ([2402:800:63b8:d379:85bd:c83a:4b40:cd9b]) by smtp.gmail.com with ESMTPSA id v15sm2278377pgc.57.2021.05.06.08.02.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 May 2021 08:02:42 -0700 (PDT) From: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= To: git@vger.kernel.org Cc: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= , Junio C Hamano , "brian m. carlson" Subject: [PATCH v3 4/6] mailinfo: allow squelching quoted CR warning Date: Thu, 6 May 2021 22:02:22 +0700 Message-Id: X-Mailer: git-send-email 2.31.1.448.g9c2f8508d1 In-Reply-To: References: <20210421013404.17383-1-congdanhqx@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In previous change, Git starts to warn for quoted CR in decoded base64/QP email. Despite those warnings are usually helpful, quoted CR could be part of some users' workflow. Let's give them an option to turn off the warning completely. Signed-off-by: Đoàn Trần Công Danh --- Documentation/git-mailinfo.txt | 20 +++++++++++++++++++- builtin/mailinfo.c | 12 ++++++++++++ mailinfo.c | 20 +++++++++++++++++++- mailinfo.h | 7 +++++++ t/t5100-mailinfo.sh | 6 ++++-- 5 files changed, 61 insertions(+), 4 deletions(-) diff --git a/Documentation/git-mailinfo.txt b/Documentation/git-mailinfo.txt index d343f040f5..824947a070 100644 --- a/Documentation/git-mailinfo.txt +++ b/Documentation/git-mailinfo.txt @@ -9,7 +9,9 @@ git-mailinfo - Extracts patch and authorship from a single e-mail message SYNOPSIS -------- [verse] -'git mailinfo' [-k|-b] [-u | --encoding= | -n] [--[no-]scissors] +'git mailinfo' [-k|-b] [-u | --encoding= | -n] + [--[no-]scissors] [--quoted-cr=] + DESCRIPTION @@ -89,6 +91,22 @@ This can be enabled by default with the configuration option mailinfo.scissors. --no-scissors:: Ignore scissors lines. Useful for overriding mailinfo.scissors settings. +--quoted-cr=:: + Action when processes email messages sent with base64 or + quoted-printable encoding, and the decoded lines end with a CRLF + instead of a simple LF. ++ +The valid actions are: ++ +-- +* `nowarn`: Git will do nothing when such a CRLF is found. +* `warn`: Git will issue a warning for each message if such a CRLF is + found. +-- ++ +The default action could be set by configuration option `mailinfo.quotedCR`. +If no such configuration option has been set, `warn` will be used. + :: The commit log message extracted from e-mail, usually except the title line which comes from e-mail Subject. diff --git a/builtin/mailinfo.c b/builtin/mailinfo.c index f55549a097..01d16ef9e5 100644 --- a/builtin/mailinfo.c +++ b/builtin/mailinfo.c @@ -38,6 +38,15 @@ static int parse_opt_explicit_encoding(const struct option *opt, return 0; } +static int parse_opt_quoted_cr(const struct option *opt, const char *arg, int unset) +{ + BUG_ON_OPT_NEG(unset); + + if (mailinfo_parse_quoted_cr_action(arg, opt->value) != 0) + return error(_("bad action '%s' for '%s'"), arg, "--quoted-cr"); + return 0; +} + int cmd_mailinfo(int argc, const char **argv, const char *prefix) { struct metainfo_charset meta_charset; @@ -61,6 +70,9 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix) N_("re-code metadata to this encoding"), PARSE_OPT_NONEG, parse_opt_explicit_encoding), OPT_BOOL(0, "scissors", &mi.use_scissors, N_("use scissors")), + OPT_CALLBACK_F(0, "quoted-cr", &mi.quoted_cr, N_(""), + N_("action when quoted CR is found"), + PARSE_OPT_NONEG, parse_opt_quoted_cr), OPT_HIDDEN_BOOL(0, "inbody-headers", &mi.use_inbody_headers, N_("use headers in message's body")), OPT_END() diff --git a/mailinfo.c b/mailinfo.c index dcf579700d..c57eed25a5 100644 --- a/mailinfo.c +++ b/mailinfo.c @@ -1040,7 +1040,8 @@ static void handle_filter_flowed(struct mailinfo *mi, struct strbuf *line, static void summarize_quoted_cr(struct mailinfo *mi) { - if (mi->have_quoted_cr) + if (mi->have_quoted_cr && + mi->quoted_cr == quoted_cr_warn) warning("quoted CR detected"); } @@ -1220,6 +1221,17 @@ int mailinfo(struct mailinfo *mi, const char *msg, const char *patch) return mi->input_error; } +int mailinfo_parse_quoted_cr_action(const char *actionstr, int *action) +{ + if (!strcmp(actionstr, "nowarn")) + *action = quoted_cr_nowarn; + else if (!strcmp(actionstr, "warn")) + *action = quoted_cr_warn; + else + return -1; + return 0; +} + static int git_mailinfo_config(const char *var, const char *value, void *mi_) { struct mailinfo *mi = mi_; @@ -1230,6 +1242,11 @@ static int git_mailinfo_config(const char *var, const char *value, void *mi_) mi->use_scissors = git_config_bool(var, value); return 0; } + if (!strcmp(var, "mailinfo.quotedcr")) { + if (mailinfo_parse_quoted_cr_action(value, &mi->quoted_cr) != 0) + return error(_("bad action '%s' for '%s'"), value, var); + return 0; + } /* perhaps others here */ return 0; } @@ -1242,6 +1259,7 @@ void setup_mailinfo(struct mailinfo *mi) strbuf_init(&mi->charset, 0); strbuf_init(&mi->log_message, 0); strbuf_init(&mi->inbody_header_accum, 0); + mi->quoted_cr = quoted_cr_warn; mi->header_stage = 1; mi->use_inbody_headers = 1; mi->content_top = mi->content; diff --git a/mailinfo.h b/mailinfo.h index b394ef9bce..768d06ac2a 100644 --- a/mailinfo.h +++ b/mailinfo.h @@ -5,6 +5,11 @@ #define MAX_BOUNDARIES 5 +enum quoted_cr_action { + quoted_cr_nowarn, + quoted_cr_warn, +}; + struct mailinfo { FILE *input; FILE *output; @@ -14,6 +19,7 @@ struct mailinfo { struct strbuf email; int keep_subject; int keep_non_patch_brackets_in_subject; + int quoted_cr; /* enum quoted_cr_action */ int add_message_id; int use_scissors; int use_inbody_headers; @@ -40,6 +46,7 @@ struct mailinfo { int input_error; }; +int mailinfo_parse_quoted_cr_action(const char *actionstr, int *action); void setup_mailinfo(struct mailinfo *); int mailinfo(struct mailinfo *, const char *msg, const char *patch); void clear_mailinfo(struct mailinfo *); diff --git a/t/t5100-mailinfo.sh b/t/t5100-mailinfo.sh index c7ea1b30df..51e8690fbd 100755 --- a/t/t5100-mailinfo.sh +++ b/t/t5100-mailinfo.sh @@ -236,11 +236,13 @@ check_quoted_cr_mail () { test_cmp "$DATA/quoted-cr-info" quoted-cr-info } -test_expect_success 'mailinfo warn CR in base64 encoded email' ' +test_expect_success 'mailinfo handle CR in base64 encoded email' ' sed "s/%%/$(printf \\015)/" "$DATA/quoted-cr-msg" >expect-cr-msg && sed "s/%%/$(printf \\015)/" "$DATA/quoted-cr-patch" >expect-cr-patch && check_quoted_cr_mail && - grep "quoted CR detected" quoted-cr-err + grep "quoted CR detected" quoted-cr-err && + check_quoted_cr_mail --quoted-cr=nowarn && + test_must_be_empty quoted-cr-err ' test_done From patchwork Thu May 6 15:02:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= X-Patchwork-Id: 12242279 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id AE2AFC433B4 for ; Thu, 6 May 2021 15:02:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 77C40613C7 for ; Thu, 6 May 2021 15:02:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235038AbhEFPDv (ORCPT ); Thu, 6 May 2021 11:03:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235003AbhEFPDo (ORCPT ); Thu, 6 May 2021 11:03:44 -0400 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59A29C061761 for ; Thu, 6 May 2021 08:02:45 -0700 (PDT) Received: by mail-pj1-x102b.google.com with SMTP id gq14-20020a17090b104eb029015be008ab0fso3609482pjb.1 for ; Thu, 06 May 2021 08:02:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XV+70STJKt6SOYsN1RvyNwxoJVQzbE8euUx3eDzXmq8=; b=GlleocEF/8ZnO0aazMuu2do7n0rMOWFFb/WG+I63490gH8u0ZYc0kh9PRyRTgvnp4a ihx7doPLe6kVVnzPO/iH9nKE6HY9lLM6cjKeMwe7a6oFkRiFqxHPlZixNKxQ7favabNl oQBRlGNGgXQJ+dqTAOBKrZyP+uAqdLWMpYXZm2OOmHm+diQSUtupeFhimnXep8A0P8Zc VeYPqH6aCCamczg1xW9pLqOyR6Kxwm88G+s4H06cbSQrrkacJgtqwa9YVp5AdWdWtgB7 9Z5IAXFcwuscvQqQNgBb1T6LQfwgs1wIfU34N4WFhnJNZAmn1kAUiZ5QHGerQ7v6bgut YXVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XV+70STJKt6SOYsN1RvyNwxoJVQzbE8euUx3eDzXmq8=; b=LfRvRuz+mEY7mFGS28jpv3u/IDBYu9Wu7bYwbDTeHEn0ZXWwldEHvFSQxQ2oSFKns4 +wkGSYvpzNviV0IlJNzyHZJfkJjWfCuEEJUSegRG7Hw1xPdypdcT2O405+7rwoYY2Ool rAy6gdSadktFF8cNQS/11tgBZysl+VRM8jy8udeasTFQ6wKhZUNaMgUyC7jzI5BxiysH pHSsHrLeei1cEJc09wItuxP9CE8wbsrQRg/Df6N8KW6nrW4OauozjRAD4c1HGCp0Xt+E MqcUQ15uCiT11m+ZzyTvOHGQTj2FGg33BYczWW8rXZ8BNwbyoxdYAn1Nd/CsS2FNc3IQ EVKw== X-Gm-Message-State: AOAM531myxcmyOXj23b5k8ct3hOvD8FqDnEYkzO2n/61x2p3pPWx7Zoh si1/eHjV0LxAE8lGBb+AGgPOYnDWQ8TCmw== X-Google-Smtp-Source: ABdhPJys14X9hTsGUJyJqyeSPAPgO2z+MajsXCXeEl0BLlLFPF6HW84/eRUp3ct3291TxVRQxw45Yw== X-Received: by 2002:a17:90b:1811:: with SMTP id lw17mr17974256pjb.154.1620313364720; Thu, 06 May 2021 08:02:44 -0700 (PDT) Received: from athena.localdomain ([2402:800:63b8:d379:85bd:c83a:4b40:cd9b]) by smtp.gmail.com with ESMTPSA id v15sm2278377pgc.57.2021.05.06.08.02.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 May 2021 08:02:44 -0700 (PDT) From: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= To: git@vger.kernel.org Cc: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= , Junio C Hamano , "brian m. carlson" Subject: [PATCH v3 5/6] mailinfo: allow stripping quoted CR without warning Date: Thu, 6 May 2021 22:02:23 +0700 Message-Id: <9e96d4bf5e06df57b13af1dec354ca5cf2ea58a1.1620311544.git.congdanhqx@gmail.com> X-Mailer: git-send-email 2.31.1.448.g9c2f8508d1 In-Reply-To: References: <20210421013404.17383-1-congdanhqx@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In previous changes, we've turned on warning for quoted CR in base64 or quoted-printable email messages. Some projects see those quoted CR a lot, they know that it happens most of the time, and they find it's desirable to always strip those CR. Those projects in question usually fall back to use other tools to handle patches when receive such patches. Let's help those projects handle those patches by stripping those excessive CR. Signed-off-by: Đoàn Trần Công Danh --- Documentation/git-mailinfo.txt | 1 + mailinfo.c | 7 +++++++ mailinfo.h | 1 + t/t5100-mailinfo.sh | 4 ++++ 4 files changed, 13 insertions(+) diff --git a/Documentation/git-mailinfo.txt b/Documentation/git-mailinfo.txt index 824947a070..3fcfd965fd 100644 --- a/Documentation/git-mailinfo.txt +++ b/Documentation/git-mailinfo.txt @@ -102,6 +102,7 @@ The valid actions are: * `nowarn`: Git will do nothing when such a CRLF is found. * `warn`: Git will issue a warning for each message if such a CRLF is found. +* `strip`: Git will convert those CRLF to LF. -- + The default action could be set by configuration option `mailinfo.quotedCR`. diff --git a/mailinfo.c b/mailinfo.c index c57eed25a5..5cddcdc8ae 100644 --- a/mailinfo.c +++ b/mailinfo.c @@ -998,6 +998,11 @@ static void handle_filter_flowed(struct mailinfo *mi, struct strbuf *line, line->buf[len - 2] == '\r' && line->buf[len - 1] == '\n') { mi->have_quoted_cr = 1; + if (mi->quoted_cr == quoted_cr_strip) { + strbuf_setlen(line, len - 2); + strbuf_addch(line, '\n'); + len--; + } } handle_filter(mi, line); return; @@ -1227,6 +1232,8 @@ int mailinfo_parse_quoted_cr_action(const char *actionstr, int *action) *action = quoted_cr_nowarn; else if (!strcmp(actionstr, "warn")) *action = quoted_cr_warn; + else if (!strcmp(actionstr, "strip")) + *action = quoted_cr_strip; else return -1; return 0; diff --git a/mailinfo.h b/mailinfo.h index 768d06ac2a..2ddf8be90f 100644 --- a/mailinfo.h +++ b/mailinfo.h @@ -8,6 +8,7 @@ enum quoted_cr_action { quoted_cr_nowarn, quoted_cr_warn, + quoted_cr_strip, }; struct mailinfo { diff --git a/t/t5100-mailinfo.sh b/t/t5100-mailinfo.sh index 51e8690fbd..06807f3852 100755 --- a/t/t5100-mailinfo.sh +++ b/t/t5100-mailinfo.sh @@ -242,6 +242,10 @@ test_expect_success 'mailinfo handle CR in base64 encoded email' ' check_quoted_cr_mail && grep "quoted CR detected" quoted-cr-err && check_quoted_cr_mail --quoted-cr=nowarn && + test_must_be_empty quoted-cr-err && + sed "s/%%//" "$DATA/quoted-cr-msg" >expect-cr-msg && + sed "s/%%//" "$DATA/quoted-cr-patch" >expect-cr-patch && + check_quoted_cr_mail --quoted-cr=strip && test_must_be_empty quoted-cr-err ' From patchwork Thu May 6 15:02:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= X-Patchwork-Id: 12242281 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 11A34C433B4 for ; Thu, 6 May 2021 15:02:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E1F3861166 for ; Thu, 6 May 2021 15:02:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234999AbhEFPDz (ORCPT ); Thu, 6 May 2021 11:03:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235028AbhEFPDx (ORCPT ); Thu, 6 May 2021 11:03:53 -0400 Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D0AFC061574 for ; Thu, 6 May 2021 08:02:55 -0700 (PDT) Received: by mail-pl1-x62e.google.com with SMTP id s20so3525147plr.13 for ; Thu, 06 May 2021 08:02:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZC991hWkO/SL4oUy6K1NQgdSl8FhQADyPBSCC6LSt5M=; b=nP2DxJYoLb5+9c3h1yvxh6VYiJgZO1S9KjLxFi8YmF/0ntqD7/hUDIGL3/V66mL3gS +2G5TGcwpw6ajJIj19ZxB9eoogZubwKxTxu5Gg4tulOjGcn3Y7LXLT4S2HwW02b5IRxP 6svw+Dq1XOMqosUnIBdcUQT97whA4/EoX7wUkEbLmYTtiLVTc5TPY0sXMYXxT1/oFEHH sfQYe47yxooaxJN8UFW+UGrtr4buDxqdpGHNO9YUCXbq/UhEhrdDDzO8+TwElt4im/Fm Vvoc0K3UxvjHzqDTNb+eWddIlRWig++EUu5QAGKjTGaQL1Y/bF51qjSkKFa8E9yfD+Hl Mp2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZC991hWkO/SL4oUy6K1NQgdSl8FhQADyPBSCC6LSt5M=; b=LNHHe5PNJZHQMZk3lq/rjrq+nWh1hZmHp3HHitIJRY+sD1kSaV2tYCL3e1YPcpCIdI 36e6nwXAg7FlYACEbt88oERhItFOlDDfwURRvDpRB6eo+97yEZ7m8Xo1PlGl43S11j3Z 6L79CJIFI8mXkuVs/syMbYrWxcKJNK+c3wZOIikyLvA6FQ+3m4Ol8Mdfj2XteydJIT52 zdAle5vs61yKbG6vhrgtLB7SKVaNW9rvj4MV8YVgZXeyAb+XKXTv1jUjv05gsCJiTmB+ OMcGa1hkl0s2TmDiPXqWTPGb+pwkYgjs8huXvBpYKFT+nMbnFHph1qGkZkgiWLMu/Rly JwrQ== X-Gm-Message-State: AOAM531c2sp0a69gXrYlWgR65Z6gT2qJ8KIm1+I6SDXrAhMXrvgbFhkJ AKtQG+b70Cx3OolDR2KaOrro5kUz93pmgA== X-Google-Smtp-Source: ABdhPJw12Fm/0A4VFVS7mHaq428/c9wHQ0wGTVqcMCgJmq0UGqiVUd2a9nDE1gl7G7xceeDUZKh4ig== X-Received: by 2002:a17:90a:6c43:: with SMTP id x61mr1433915pjj.124.1620313368200; Thu, 06 May 2021 08:02:48 -0700 (PDT) Received: from athena.localdomain ([2402:800:63b8:d379:85bd:c83a:4b40:cd9b]) by smtp.gmail.com with ESMTPSA id v15sm2278377pgc.57.2021.05.06.08.02.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 May 2021 08:02:46 -0700 (PDT) From: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= To: git@vger.kernel.org Cc: =?utf-8?b?xJBvw6BuIFRy4bqnbiBDw7RuZyBEYW5o?= , Junio C Hamano , "brian m. carlson" Subject: [PATCH v3 6/6] am: learn to process quoted lines that ends with CRLF Date: Thu, 6 May 2021 22:02:24 +0700 Message-Id: X-Mailer: git-send-email 2.31.1.448.g9c2f8508d1 In-Reply-To: References: <20210421013404.17383-1-congdanhqx@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In previous changes, mailinfo has learnt to process lines that decoded from base64 or quoted-printable, and ends with CRLF. Let's teach "am" that new trick, too. Signed-off-by: Đoàn Trần Công Danh --- Documentation/git-am.txt | 4 ++ builtin/am.c | 51 ++++++++++++++++++++++++++ contrib/completion/git-completion.bash | 5 +++ mailinfo.h | 1 + t/t4258-am-quoted-cr.sh | 37 +++++++++++++++++++ t/t4258/mbox | 12 ++++++ 6 files changed, 110 insertions(+) create mode 100755 t/t4258-am-quoted-cr.sh create mode 100644 t/t4258/mbox diff --git a/Documentation/git-am.txt b/Documentation/git-am.txt index decd8ae122..8714dfcb76 100644 --- a/Documentation/git-am.txt +++ b/Documentation/git-am.txt @@ -15,6 +15,7 @@ SYNOPSIS [--whitespace=