From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wj0-f171.google.com (mail-wj0-f171.google.com [209.85.210.171]) by dpdk.org (Postfix) with ESMTP id DF17F58C5 for ; Thu, 1 Dec 2016 14:45:02 +0100 (CET) Received: by mail-wj0-f171.google.com with SMTP id qp4so205070429wjc.3 for ; Thu, 01 Dec 2016 05:45:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references; bh=cXB8dPn9K7qO+QpBMQkjAbsM3ZFaCQttSFZM1CbT9qc=; b=vpC2yX2U9dg64Mzj5xyB+zemPfsSNSFS1PP7Hd8zWEjynITTo3feei3aYOSZA5/Eus cU0YLyT0U+oeN9MJvu0v7oTZoRjw+g78SkdptEYJRJcS23txFnDny7tflJ2RFOvZNJ+y zr8Om3zEy2zSMr09hMYs/wDhAsKMClSvsYIrd0hUvedCPjo1+mb8bl7yX7jbx7qyNrnI Xe95mVJ8vZHKIum7WZ0DtKP9nC7a4nzT0o+J4mk/0ov9Jx5yK2vEmn5rqQawZEYvCUBn XAuai+EMCzu3m87EOCF22ZiiXm0vGv0vdHaqwvLYG+hnXIz+YL0HLMbgvN8Mp47KV5sF WwIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=cXB8dPn9K7qO+QpBMQkjAbsM3ZFaCQttSFZM1CbT9qc=; b=P+o6nFMXaJeijLR06Wmbn3Tv3VjmVdovyamIpsXkrQjjclM/fkrOc/HHvLCD0hDR+q RdwT1WskZo0yOL54H/gnW524x+Ury+hVtyQzqVWVxh7q8fAQEzw5I1ob0iwqsSldRduN 6hpu/Ezxm7eqwEh1YbZVaJUIJC5uXbNO4VN17awLNMARt3L83Fc6ZVIltpZQHE5NzACG scRd6b/wz8swy8hx1zTLg5FVrtcQfsE21uie7i9t8CqZwUIBe/+7r3xBuOhYBsufMEwE X2hiZ6FKaE2jybCjHPLvvPlcP39uiz0NPk41GhhUfJweX2tb1W03hILNfU/heSsGn60Z eBaA== X-Gm-Message-State: AKaTC03trIns06dIIW5Udz5+RjbMhrlSXxw+0cs1CIJ/OsioamawsUR4mYIdvcMfDkk45ohG X-Received: by 10.194.150.108 with SMTP id uh12mr36417649wjb.107.1480599902138; Thu, 01 Dec 2016 05:45:02 -0800 (PST) Received: from XPS13.localdomain (184.203.134.77.rev.sfr.net. [77.134.203.184]) by smtp.gmail.com with ESMTPSA id c202sm15808333wme.1.2016.12.01.05.45.01 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 01 Dec 2016 05:45:01 -0800 (PST) From: Thomas Monjalon To: ci@dpdk.org Date: Thu, 1 Dec 2016 14:44:46 +0100 Message-Id: <1480599892-14190-2-git-send-email-thomas.monjalon@6wind.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1480599892-14190-1-git-send-email-thomas.monjalon@6wind.com> References: <1480093334-29957-1-git-send-email-thomas.monjalon@6wind.com> <1480599892-14190-1-git-send-email-thomas.monjalon@6wind.com> Subject: [dpdk-ci] [PATCH v2 1/7] tools: add mail filter X-BeenThere: ci@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: CI discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 01 Dec 2016 13:45:03 -0000 This script acts as a pipe which blocks non-patch emails. It can be used as a first filter before processing a patch. Signed-off-by: Thomas Monjalon --- tools/filter-patch-email.sh | 76 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100755 tools/filter-patch-email.sh diff --git a/tools/filter-patch-email.sh b/tools/filter-patch-email.sh new file mode 100755 index 0000000..fd75271 --- /dev/null +++ b/tools/filter-patch-email.sh @@ -0,0 +1,76 @@ +#! /bin/sh -e + +# This file is in the public domain. + +print_usage () { + cat <<- END_OF_HELP + usage: $(basename $0) < email + + Filter out email from stdin if does not match patch criterias. + END_OF_HELP +} + +while getopts h arg ; do + case $arg in + h ) print_usage ; exit 0 ;; + ? ) print_usage ; exit 1 ;; + esac +done + +if [ -t 0 ] ; then + echo 'nothing to read on stdin' >&2 + exit 0 +fi + +fifo=/tmp/$(basename $0 sh)$$ +mkfifo $fifo +trap "rm -f $fifo" INT EXIT + +parse () +{ + gitsend=false + patchsubject=false + content=false + minusline=false + plusline=false + atline=false + done=false + while IFS= read -r line ; do + printf '%s\n' "$line" + set -- $line + if ! $content ; then + [ "$1" != 'X-Mailer:' -o "$2" != 'git-send-email' ] || gitsend=true + if echo "$line" | grep -qa '^Subject:.*\[PATCH' ; then + subject=$(echo "$line" | sed 's,^Subject:[[:space:]]*,,') + while [ -n "$subject" ] ; do + echo "$subject" | grep -q '^\[' || break + if echo "$subject" | grep -q '^\[PATCH' ; then + patchsubject=true + break + fi + subject=$(echo "$subject" | sed 's,^[^]]*\][[:space:]]*,,') + done + fi + [ -n "$line" ] || content=true + elif ! $done ; then + $gitsend || $patchsubject || break + [ "$1" != '---' ] || minusline=true + [ "$1" != '+++' ] || plusline=true + [ "$1" != '@@' ] || atline=true + if $minusline && $plusline && $atline ; then + echo 1 >$fifo + done=true + fi + fi + done + $done || echo 0 >$fifo + exec >&- +} + +waitparsing () +{ + result=$(cat $fifo) + [ "$result" = 0 ] || cat +} + +parse | waitparsing -- 2.7.0